简体   繁体   English

在震颤中获取样本

[英]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.

相关问题 获取 malloc 合并错误的示例程序 - Sample example program to get the malloc consolidate error 获取磁盘转速示例代码 - Get Rotation Speed of Disk Sample Code 在android ndk中向C发送一个值并获得示例(if)响应 - Send a value to C in android ndk and get sample (if) response 如何编译和链接示例代码以获取二进制文件? - How do I compile and link the sample code to get a binary? 我如何获得此readdir代码示例以搜索其他目录 - how can I get this readdir code sample to search other directories Android:如何在C / C ++中获得首选(本机)音频缓冲区大小和音频采样率? - Android : How to get the preferred (native) audio buffer size and audio sample rate in C/C++? 在哪里可以获取C / C ++示例代码以对链接列表进行合并排序? - Where can I get C/C++ sample code for merge sort a link list? 我可以用 C 写一个 fib(我有一个示例),但是有没有像 Python 一样更有效的方法,当我尝试时会出错 - I can write a fib in C(i have a sample), but is there a more effective way like in Python, i get error when i try 适用于Linux的GPIO示例代码 - GPIO sample code for Linux 带有加速功能的示例openmp程序 - A sample openmp program with speedup
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM