QTAUDIEO

QCoreApplication a(argc, argv);

QAudioFormat fmt;
fmt.setSampleRate(44100);
fmt.setSampleSize(16);
fmt.setChannelCount(2);
fmt.setCodec("audio/pcm");
fmt.setSampleType(QAudioFormat::UnSignedInt);
fmt.setByteOrder(QAudioFormat::LittleEndian);
QAudioOutput* out = new QAudioOutput(fmt);
QIODevice* io = out->start();

int size = out->periodSize();
char* buf = new char[size];
    //FILE * fp = fopen("E:/ffmpegproject/Secondcode/bin/out2.pcm", "rb");
FILE* fp = fopen("out2.pcm", "rb");
if (fp==NULL) {
    qDebug() << "fopen fail!" << fp;
   
}
else {
    qDebug() << "fopen success!" << fp;
}

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();

posted on 2023-06-14 09:53  gypufo123  阅读(40)  评论(0)    收藏  举报

导航