QtQuick使用QAudioOutput音频播放

  • a9_707245
    了解作者
  • 4.2KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-14 22:34
    上传日期
使用QAudioOutput将QAudioinput音频播放的一个小例子,具体可以看博客 https://www.jianshu.com/p/5c4c50b9f84c
AudioSampleAndPlay.zip
  • qtquickcontrols2.conf
    326B
  • DataSource.cpp
    2.8KB
  • AudioSampleAndPlay.pro
    1.2KB
  • DataSource.h
    1.2KB
  • qml.qrc
    136B
  • main.qml
    3.7KB
  • main.cpp
    815B
内容介绍
#include "DataSource.h" #include <QtQuick/QQuickItem> #include <QtCore/QDebug> #include <QtCore/QtMath> #include <QTime> DataSource::DataSource( QObject *parent) : QIODevice(parent), m_readPos(0) { } qint64 DataSource::readData(char * data, qint64 maxSize) { qint64 total = 0; auto chunk = qMin(((qint64)m_audioData.size() - m_readPos), maxSize); memcpy(data + total, m_audioData.data() + m_readPos, chunk); m_readPos = m_readPos + chunk; total += chunk; return total; } qint64 DataSource::writeData(const char * data, qint64 maxSize) { m_audioData.append(data, maxSize); return maxSize; } void DataSource::startRecord() { int sampleRate = 16000; int channels = 2; int sampleSize = 16; QAudioFormat formatAudio; formatAudio.setSampleRate(sampleRate); formatAudio.setChannelCount(channels); formatAudio.setSampleSize(sampleSize); formatAudio.setCodec("audio/pcm"); formatAudio.setByteOrder(QAudioFormat::LittleEndian); formatAudio.setSampleType(QAudioFormat::UnSignedInt); QAudioDeviceInfo inputDevices = QAudioDeviceInfo::defaultInputDevice(); memcpy(m_wavFileHead.RIFFNAME, "RIFF", 4); memcpy(m_wavFileHead.WAVNAME, "WAVE", 4); memcpy(m_wavFileHead.FMTNAME, "fmt ", 4); memcpy(m_wavFileHead.DATANAME, "data", 4); m_wavFileHead.nRIFFLength = 36; m_wavFileHead.nFMTLength = sampleSize; m_wavFileHead.nAudioFormat = 0x01; m_wavFileHead.nChannleNumber = channels; m_wavFileHead.nSampleRate = sampleRate; m_wavFileHead.nBytesPerSecond = (sampleSize / 8) * channels * sampleRate; m_wavFileHead.nBytesPerSample = (sampleSize / 8) * channels; m_wavFileHead.nBitsPerSample = sampleSize; m_wavFileHead.nDataLength = 0; m_audioInput.reset(new QAudioInput(inputDevices, formatAudio)); m_audioInput->start(this); } void DataSource::stopRecord() { m_audioInput->stop(); } void DataSource::saveAsWavFile() { QFile f("test.wav"); bool bisOk = f.open(QIODevice::WriteOnly); if(bisOk == true) { m_wavFileHead.nDataLength = m_audioData.size() / 2; f.write((char *)&m_wavFileHead, sizeof(WavFileHead)); f.write(m_audioData.data(), m_audioData.size()); f.close(); }else{ } } void DataSource::startPlay() { QAudioFormat format; format.setSampleRate(16000); format.setChannelCount(2); format.setSampleSize(16); format.setCodec("audio/pcm"); format.setByteOrder(QAudioFormat::LittleEndian); format.setSampleType(QAudioFormat::SignedInt); auto device = QAudioDeviceInfo::defaultOutputDevice(); m_audioOutput.reset(new QAudioOutput(device, format)); m_audioOutput->start(this); } void DataSource::stopPlay() { m_audioOutput->stop(); }
评论
    相关推荐
    • CasseBrique:https
      CasseBrique:https
    • plaintextoffenders:https
      纯文字罪犯 向报告的域的公开列表
    • 使用socket post 数据到httphttps
      使用socket post 数据到httphttps
    • nodejs http-server开启https的证书
      https证书文件,nodejs http-server开启https的证书,可以直接在本地启动https的协议,方便部署和使用。
    • http https 切换
      http https切换代码,能够实现网站在传输信息的过程中不易遭人盗取
    • Http2Https-crx插件
      将书签中的http转换为https 害怕用https书签替换旧的http书签? 随着许多网站迁移到https,旧的http书签使星标图像为空。 搜索并转换为https! ****************************************************** ***********...
    • LocomotiveCMS https to http-crx插件
      语言:English 将登录网址从https替换为http以进行开发 此扩展程序供使用机车cms开发应用程序时供个人使用。 为了易于在开发模式下使用,此扩展程序将https登录网址替换为http
    • http:https的镜像
      框架HTTP
    • CookieIsolator:分离 HTTPHTTPS cookie
      松散隔离:HTTP cookie 只能在 HTTP 通道中发送,而 HTTPS cookie 可以在 HTTP(不带安全标志)和 HTTPS 通道中发送。 严格隔离:HTTP cookie 和 HTTPS cookie 只能分别在 HTTPHTTPS 通道中发送。 Ext Secure...
    • https协议
      NULL 博文链接:https://willwen.iteye.com/blog/1988199