#include <QCoreApplication>
#include<QAudioFormat>
#include<QAudioOutput>
#include<QIODevice>
#include<QThread>
#include <QFile>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QAudioFormat fmt;
fmt.setSampleRate(44100); //采样率
fmt.setSampleSize(16); // 32->16 音频重采样
fmt.setChannelCount(2); //通道数 2
fmt.setCodec("audio/pcm"); //通用格式
fmt.setByteOrder(QAudioFormat::LittleEndian);//小端
fmt.setSampleType(QAudioFormat::SignedInt);
QAudioOutput* out = new QAudioOutput(fmt);
QIODevice* io = out->start();
int size = out->periodSize();
char* buffer = new char[size];
FILE * fp = fopen("D:/desktop/out.pcm","rb");
if(!fp)
{
printf("open failed");
return -1;
}
while (!feof(fp)) {
if(out->bytesFree() < size)
{
QThread::msleep(1);
continue;
}
int len = fread(buffer, 1, size, fp);
if(len <= 0)
{
break;
}
io->write(buffer, len);
}
fclose(fp);
delete[] buffer;
return a.exec();
}