我正在尝试使用Alsa驱动程序将原始音频数据写入特定文件。
下面的代码:
ofstream binaryFile ("file.raw", ios::out | ios::binary);
if(inputData==NULL)
{
inputData = (uint8_t *)malloc(sizeOfDataInBytes);
}
while (audio_en)
{
snd_pcm_sframes_t numAudioFramesRead = snd_pcm_readi(ndi_AudioSupport.m_captureHandle,inputData,
ndi_AudioSupport.m_numAudioFramesPerVideoFrame);
if(numAudioFramesRead > 0)
{
binaryFile.write ((char*)inputData, sizeof (inputData));
}
}
binaryFile.close();
发布于 2020-07-26 22:15:01
编写包括raw在内的多种不同音频格式的一种方法是使用sox音频库(libsox)。gtkIOStream中内置了libsox类和C++类。
捕获到原始音频文件的示例来自ALSACapture.C source code here。基本概念是打开捕获设备和原始音频文件,然后循环捕获音频并使用Sox写入文件:
Capture capture("default"); // open the default ALSA capture device
Sox<int> sox;
int ret=sox.openWrite("audio.raw", fs, capture.getChannels(), pow(2.,(double)snd_pcm_format_width(format)));
while (continue){
capture>>buffer;
sox.write(buffer);
}
使用libsox的好处是您不再局限于原始音频格式。
https://stackoverflow.com/questions/63049328
复制相似问题