当前位置:网站首页>Player actual combat 12 QT playing audio
Player actual combat 12 QT playing audio
2022-06-12 14:08:00 【Sister Suo】
We mainly use the following three classes :
QAudioDeviceInfo Class provides an audio output device
QAudioFormat Class provides audio parameter settings
QAudioOutput Class provides the PCM The interface that sends raw audio data to the audio output device .
1. Import the header file and open PCM file
#include <QtCore/QCoreApplication>
#include<qaudioformat.h>
#include<qaudiooutput.h>
#include<qthread.h>
#include<iostream>
using namespace std;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
FILE* fp = fopen("test.pcm","rb");
if (fp)
cout << " Open the success " << endl;
else
cout << " Open the failure " << endl;
2. Instantiation QAudioFormat And set the parameters
QAudioFormat fmt;
fmt.setSampleRate(44100);
fmt.setSampleSize(16);// Number of sampling bits
fmt.setChannelCount(2);
fmt.setCodec("audio/pcm");
fmt.setByteOrder(QAudioFormat::LittleEndian);// Byte order , Not bitwise , such as 16, The small end 16 Big end 61
fmt.setSampleType(QAudioFormat::UnSignedInt);
3. Open up a QAudioOutput Space , Use the object instantiated above fmt As its new Make the constructor arguments
And call QAudioOutput Of start Method to start playing ( Just turned on the switch , The data has not yet started to flow , To hear the playing sound, you need to use io->wirte() take PCM Data to play )
QAudioOutput* out = new QAudioOutput(fmt);
QIODevice* io = out->start();
4. Put the audio data to be played into the buffer queue in batches and play
int size = out->periodSize();
char* buf = new char[size];
while (!feof(fp))
{
if (out->bytesFree() < size)
{
QThread::msleep(1);
continue;
}
int len=fread(buf, 1, size, fp);
if (len <= 0)
break;
io->write(buf, len);
}
fclose(fp);
delete buf;
buf = 0;
return a.exec();
}
out->periodSize() Is the size of the incoming data
When the free size of the buffer is smaller than the size of the data put in at one time , Has reached the awaited , Wait until the extra data in the buffer is played and enough space is left before putting data into the buffer , Judge with the following statement if (out->bytesFree() < size)
int len=fread(buf, 1, size, fp); take fp Point to the PCM The data reads buf in
use buf As a media connection QT Original documents
io->write(buf, len);// Resampled PCM Pass to QT, Just started playing
边栏推荐
- one × Convolution kernel of 1
- What is the default gateway
- Pay attention to click and pursue more users to enter the website. What bidding strategy can you choose?
- For cross-border e-commerce, the bidding strategy focusing more on revenue - Google SEM
- 280 weeks /2171 Take out the least number of magic beans
- Tool notes - common custom tool classes (regular, random, etc.)
- Shell notes
- Formal analysis of Woo Lam protocol with scyther tool
- To SystemC Beginners: the first program
- Cmake basic tutorial - 02 b-hello-cmake
猜你喜欢

PostgreSQL14安装使用教程

正点原子STM32F429核心板的插座型号

Des File Encryptor based on MFC framework

注重点击,追求更多用户进入网站,可以选择什么出价策略?

Single bus temperature sensor 18B20 data on cloud (Alibaba cloud)

简述CGI与FASTCGI区别

对于跨境电商,更侧重收入的出价策略 —Google SEM
![[MySQL advanced] index classification and index optimization scheme (V)](/img/8b/2284783d8b81ba2e8fa45a239107ba.png)
[MySQL advanced] index classification and index optimization scheme (V)

Compile and install lamp architecture of WordPress and discuz for multi virtual hosts based on fastcgi mode

拆改广告机---业余解压
随机推荐
Is MySQL query limit 1000,10 as fast as limit 10? How to crack deep paging
工具笔记 —— 常用自定义工具类(正则,随机数等)
测试工程师如何转型测开
Explanation of static and extern keywords
Go language functions as parameters of functions
A method of quickly creating test window
Des File Encryptor based on MFC framework
Postgresql14 installation and use tutorial
NotePad 常用设置
Single bus temperature sensor 18B20 data on cloud (Alibaba cloud)
Simple implementation of gpuimage chain texture
To SystemC Beginners: the first program
M1 pod install pod lint failure solution
Chapter IV expression
注重点击,追求更多用户进入网站,可以选择什么出价策略?
Llvm pass-- virtual function protection
Leetcode questions brushing February /1020 Number of enclaves
如果要打造品牌知名度,可以选择什么出价策略?
Interview question 17.14 Minimum number of K (almost double hundreds)
Shell脚本到底是什么高大上的技术吗?