当前位置:网站首页>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
边栏推荐
- Display logs in the database through loganalyzer
- English learning plan
- Comparator summary
- Dynamic search advertising intelligent search for matching keywords
- Llvm 13.1 new pass plug-in form [for win]
- Go language functions as parameters of functions
- SystemC learning materials
- 浅谈中国程序员为什么要跳槽?
- 注重点击,追求更多用户进入网站,可以选择什么出价策略?
- QA of some high frequency problems in oauth2 learning
猜你喜欢

chapter19 Allocation
![[advanced MySQL] evolution of MySQL index data structure (IV)](/img/eb/e32387b172eb4c3a4152dbc3b0cb8f.png)
[advanced MySQL] evolution of MySQL index data structure (IV)

Implementation of Ackermann function with simulated recursion

阿裏雲開發板HaaS510報送設備屬性

Dismantle and modify the advertising machine - Amateur decompression
![[WUSTCTF2020]颜值成绩查询-1](/img/90/e4c2882357e0a1c6a80f778887e3f5.png)
[WUSTCTF2020]颜值成绩查询-1

Mold and remainder
Introduction to color coding format

Alibaba cloud development board haas510 sends the serial port data to the Internet of things platform

What is automatic bidding? What are its advantages?
随机推荐
2000. reverse word prefix
What is the default gateway
Player screen orientation scheme
Dynamic search advertising intelligent search for matching keywords
Introduction to database system (Fifth Edition) notes Chapter 1 Introduction
Crack WinRAR to ad pop-up window
阿里云开发板HaaS510响应UART串口指令
Postgresql14 installation and use tutorial
拆改广告机---业余解压
正点原子STM32F429核心板的插座型号
How to realize the bidding strategy that pays more attention to transformation in the company's operation Google sem
对于跨境电商,更侧重收入的出价策略 —Google SEM
QA of some high frequency problems in oauth2 learning
3. Process concealment under the ring ----- continuous concealment and new opening prevention
2022版Redis数据删除策略
如何使用android studio制作一个阿里云物联网APP
Codeforces Round #798 (Div. 2)(A~D)
SystemC:SC_ Thread and SC_ METHOD
基于Profibus-DP协议的PLC智能从站设计
Lua common built-in functions