简体   繁体   English

OpenSL es-操纵音频缓冲区队列

[英]OpenSL es- Manipulating audio buffer queue

I'm very new to opensl es. 我是openl es的新手。 I'm currently experimenting with the recording and playback features of opensl es for android. 我目前正在尝试针对Android的opensl es的录制和播放功能。 Right now I have a recording function which stores data in a buffer queue. 现在,我有一个记录功能,可以将数据存储在缓冲区队列中。 I can then playback the buffer queue. 然后,我可以播放缓冲区队列。 Would anyone be able to explain how I can correctly manipulate the data in the buffer queue? 谁能解释我如何正确处理缓冲区队列中的数据? so the playback sounds different from the recording. 因此播放的声音与录音不同。

My current configuration: 我当前的配置:

sampleFormat.pcmFormat_ = static_cast<uint16_t>(engine.bitsPerSample_);
//the buffer
uint8_t *buf_;

Is there any type of conversion or decoding I need to do to the data in the buffer before manipulating it? 在操作缓冲区之前,我需要对缓冲区中的数据进行任何类型的转换或解码吗?

I would really appreciate some help. 我真的很感谢您的帮助。

Your question is broad, what I can do is tell you how you are supposed to use it, and how you could manipulate audio data obtained from recording. 您的问题很广泛,我所能做的就是告诉您应该如何使用它,以及如何处理从录制中获得的音频数据。

1) Once you setup your OpenSL_ES engine, recorder and player properly (many examples out there), you have given OpenSL_ES a buffer where to read pcm data from mic, and also a buffer where to read from data you would like to provide for the sink of playback, along with 2 callback functions which will be called upon completion, once the process of reading data has finished (after some time according to your settings like sample rate, size of buffer, etc), the record callback is called, from a thread created by OpenSL_ES which depending on the device and configuration might be a high priority thread usually called fast track (so you are not working on your thread in the callback, but in OpenSL_ES' thread and have to be careful not to do blocking operations there). 1)正确设置了OpenSL_ES引擎,记录器和播放器之后(这里有很多示例),您已经为OpenSL_ES提供了一个缓冲区,可以从其中读取mic的pcm数据,还可以从其中读取想要提供给麦克风的pcm数据。回放接收器,以及将在完成时调用的两个回调函数,一旦读取数据的过程完成(根据您的设置(如采样率,缓冲区大小等)一段时间后),就会从以下位置调用记录回调由OpenSL_ES创建的线程,根据设备和配置的不同,该线程可能是通常称为快速通道的高优先级线程(因此,您不在回调中使用线程,而是在OpenSL_ES的线程中使用该线程,请注意不要执行阻塞操作那里)。 Now if what you want is to playback audio as fast as posible, work your audio signal processing from inside the callback, if response time is not too important for you, you may use the callback as a signal for your thread to start reading process audio data in the buffer as you wish. 现在,如果要以尽可能快的速度播放音频,请从回调内部进行音频信号处理,如果响应时间对您而言不太重要,则可以将回调用作信号,让线程开始读取过程音频您希望的数据在缓冲区中。 In both cases to playback the audio you must enqueue the data (processed or unprocessed) for the playback process (playback also calls player callback upon finishing). 在这两种情况下,要播放音频,都必须将数据(已处理或未处理)放入播放过程中(播放也将在完成时调用播放器回调)。

2) Now, if you want to process audio, you need to apply filters, there are many kinds of audio signal filters that can be applied, you should look for dynamic filters in case of real time playback. 2)现在,如果要处理音频,则需要应用滤波器,可以应用多种音频信号滤波器,在实时播放的情况下,您应该寻找动态滤波器。 (some filters require lot of data to start processing and may be bad for real time, some others are optimized to use small chunks of data and dynamically adapt output). (某些过滤器需要大量数据才能开始处理,并且可能对实时性不利,另一些过滤器经过优化以使用小块数据并动态调整输出)。 So you would need to make a chain of filters in a certain order to obtain what you want. 因此,您需要按一定顺序制作一系列过滤器,以获取所需的内容。 The audio world is huge, you need to read quite a lot to start understanding audio processing. 音频世界很大,您需要阅读很多才能开始理解音频处理。 Audio performance is another thing and depends directly from the device you have (hard, soft). 音频性能是另一回事,它直接取决于您所拥有的设备(硬,软)。

3) Data manipulation to the buffer you obtain depends on your processor. 3)对获取的缓冲区的数据操作取决于处理器。 For instance endianess, some processors may work with little or big endian and you get your data in big endian format. 例如字节序,某些处理器可能使用小字节序或大字节序,并且您以大字节序格式获取数据。 There is no compression so pcm data is ready for processing. 没有压缩,因此可以处理pcm数据。 (if you would like to create a wav from it you only need to add a wave header and add pcm data in the data chunk of the header, if you want other format like mp3 you also need to process your data with a compression algorithm according to the format you would like and add that data to the proper header) (如果您想从其中创建一个wav,则只需添加wave标头,然后在标头的数据块中添加pcm数据,如果您希望使用其他格式(如mp3),还需要使用压缩算法根据更改为所需的格式,然后将该数据添加到适当的标题中)

Also to playback data through OpenSL_ES you need uncompressed audio data, so you can't play mp3 directly, you need to uncompress it into pcm data first 另外,要通过OpenSL_ES播放数据,您还需要未压缩的音频数据,因此您不能直接播放mp3,您需要先将其解压缩为pcm数据

This is the basic functioning of OpenSL_ES, hope that answers your question. 这是OpenSL_ES的基本功能,希望能回答您的问题。 If something is unclear let me know. 如果不清楚,请告诉我。

PS: Android says Audio manipulation is easier now with the new library AAudio, which promises to accomplish the same tasks as OpenSL_ES with a third of it's complexity (there might be some issues with latency, some people have encountered but I bet they are being fixed as you read) PS: Android表示,现在有了新库AAudio,音频处理现在变得更容易,它承诺可以完成与OpenSL_ES相同的任务,但它的复杂性只有三分之一(可能存在一些延迟问题,有人遇到过,但我敢肯定,它们已经修复了如您所读)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM