[英]Get sample in tremor
I have to use tremor to decode ogg vorbis in my project due to much simplier integration (to use on ESP-32). 由于集成非常简单(在ESP-32上使用),因此我必须在项目中使用tremor解码ogg vorbis。 Its docks says:
它的码头说:
It returns up to the specified number of bytes of decoded audio in host-endian, signed 16 bit PCM format.
它以主机端序格式,带符号的16位PCM格式最多返回指定数量的解码音频字节。 If the audio is multichannel, the channels are interleaved in the output buffer.
如果音频是多声道,则声道在输出缓冲区中交错。
…
...
Signature: long ov_read(OggVorbis_File *vf, char *buffer , int length, int *bitstream);
签名:long ov_read(OggVorbis_File * vf, char * buffer ,int length,int * bitstream);
Now I'm confused about how to read 16-bit signed samples from char array. 现在,我对如何从char数组读取16位带符号样本感到困惑。 Do I have to follow some advices from here Convert 2 char into 1 int or do some other thing?
我是否必须从这里遵循一些建议将2个字符转换为1个int或做其他事情?
Iterate the buffer two elements at a time. 一次迭代缓冲区两个元素。 Since the data is in little-endian form ( according to documentation ) you can directly represent two characters as a signed 16 bit integer, in this case 'short'
由于数据采用小尾数形式(根据文档),因此您可以将两个字符直接表示为带符号的16位整数,在这种情况下为'short'
long numBytesRead = ov_read(vf, buffer, length, bitstream); //length is typically 4096
if( numBytesRead > 0 )
{
for(int i=0; (i+1)<numBytesRead; i=i+2)
{
unsigned char high = (unsigned char)buffer[i];
unsigned char low = (unsigned char)buffer[i + 1];
int16_t var = (int16_t)( (low << 8) | high );
//here var is signed 16 bit integer.
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.