gpt4 book ai didi

C++ 录制音频并压缩到 GSM

转载 作者:太空宇宙 更新时间:2023-11-04 14:13:28 33 4
gpt4 key购买 nike

我正在开发一个 C++ 程序,用于录制音频并将其压缩到 GSM。我能够录制音频并将原始数据写入文件。但我无法让 GSM 压缩工作。我正在尝试使用我在这个网站上找到的源代码进行压缩 ftp://ftp.cs.cmu.edu/project/fgdata/speech-compression/GSM/gsm_13200bps .

我认为我的问题是在使用 gsm_encode() 函数时。编码并将压缩数据保存到文件后,播放此文件时听不见。我知道原始音频数据是正确的,但压缩后的音频数据不正确。

gsm_encode() 对 160 个 13 位样本的数组进行编码(给定为gsm_signal 的,至少 16 位的有符号整数值)到一个 33 字节的 gsm_frame。

这是我的函数,我是否错误地将数据发送到 gsm_encode()?或者我的功能还有其他问题吗?感谢您的帮助:)

int CAudioGSM::CompressAudio(unsigned char * pRawBuffer, _int32 uiRawBufferSize, unsigned char  * pCompressedBuffer, _int32 uiCompressedBufferSize)
{
// Note: uiRawBufferSize must be a multiple of 640 (AUDIO_DMA_DESCRITOR_LEN)
if(!pRawBuffer || uiRawBufferSize == 0 || !pCompressedBuffer || uiCompressedBufferSize == 0 || uiRawBufferSize % AUDIO_DMA_DESCRITOR_LEN != 0)
{
return -1; //invalid parameters
}

_int32 uiBytesCompressed = 0; // Number of bytes that have been compressed. At the end of the function this should be equal to iRawBufferSize meaning we have compressed the whole raw buffer
_int32 uiCompBuffOffset = 0; // Offset into the compressed buffer

while(uiBytesCompressed < uiRawBufferSize)
{
if(uiCompressedBufferSize - uiCompBuffOffset < GSM_OUTPUT_SIZE || uiCompBuffOffset >= uiCompressedBufferSize)
{
return -2; // Compressed buffer is too small
}

gsm_encode(&m_GSM_EncodeStruture,(long *)pRawBuffer,m_Buffer);
//Now we need to move the data to compressed buffer
if(m_bFirstHalfOfBlockRecord)
{
//Just copy the data over
memcpy(&pCompressedBuffer[uiCompBuffOffset],m_Buffer,GSM_OUTPUT_SIZE_FIRST_HALF);
m_bFirstHalfOfBlockRecord = false;
uiCompBuffOffset += GSM_OUTPUT_SIZE_FIRST_HALF;
}
else
{
memcpy(&pCompressedBuffer[uiCompBuffOffset],m_Buffer,GSM_OUTPUT_SIZE);
m_bFirstHalfOfBlockRecord = true;
uiCompBuffOffset += GSM_OUTPUT_SIZE;
}

uiBytesCompressed += AUDIO_DMA_DESCRITOR_LEN;
}

return uiCompBuffOffset; // Success, we have compressed the buffer return compressed data size
}

最佳答案

没关系,我想通了 pRawBuffer 永远不会递增它应该是

gsm_encode(&m_GSM_EncodeStruture,(long *)&pRawBuffer[uiBytesCompressed],m_Buffer);

关于C++ 录制音频并压缩到 GSM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13088795/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com