这是一个创建于 2574 天前的主题,其中的信息可能已经有所发展或是发生改变。
#include <iostream>
#include "QtCore/QCoreApplication"
#include "QtMultimedia/QAudioInput"
extern "C"{
#include "libswresample/swresample.h"
#include "libavutil/channel_layout.h"//libavutil/channel_layout.h
#include "libswscale/swscale.h"
#include "libavcodec/avcodec.h"
#include "libavutil/frame.h"
#include "libavformat/avformat.h"
}
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, const char * argv[]) {
QAudioFormat fmt;
fmt.setSampleRate(44100);
fmt.setChannelCount(2);
fmt.setSampleSize(16);
fmt.setSampleType(QAudioFormat::UnSignedInt);
fmt.setCodec("audio/pcm");
fmt.setByteOrder(QAudioFormat::LittleEndian);
QAudioDeviceInfo device = QAudioDeviceInfo::defaultInputDevice();
if(!device.isFormatSupported(fmt)){
std::cout << "设备不支持该类型的音频格式" << std:: endl;
return -1;
}
QAudioInput *input = new QAudioInput(fmt);
QIODevice *io = input->start();
char *buf = new char[4096];
while(true){
if(input->bytesReady() < 4096) continue;
int size = 0;
while(size != 4096){
int len = io->read(buf+size, 4096-size);
if(len <0)break;
size += len;
}
if(size != 4096) continue;
std::fstream fsw("/Users/tangwei/Desktop/test.txt", std::ios::in | std::ios::out | std::ios::ate);//把原始数据写入到文件,判断原数据是否有问题
if(!fsw)
std::cout << "文件打开失败" << std::endl;
fsw << buf << std::endl;
fsw.close();
}
}
代码如上
1 条回复 • 2020-07-04 23:20:20 +08:00
|
|
1
snana 2020-07-04 23:20:20 +08:00
解决了吗楼主,我 win 也是这样.
|