Android Raknet Series three transplant Portaudio

Source: Internet
Author: User

Brief introduction

Portaudio is an open source library for cross-platform acquisition and playback of audio, but the Android platform has not yet been supported, so I decided to let Portaudio support Android.
On Android, the library that handles audio is OPENSL ES, the technology that starts with API 9, and through this standard, Android is already fully capable of capturing and playing audio on the native layer.
In other words, Portaudio supports Android, which is support for OpenSL ES.

Details OpenSL ES

Pensl ES is a hardware audio acceleration API that is optimized for embedded systems with no licensing fees, cross-platform. It provides standardized, high-performance, low-response-time audio for native application developers on embedded mobile multimedia devices
function realization method, and realize the direct cross-platform deployment of soft/hardware audio performance, reduce the difficulty of execution and promote the development of advanced audio market.

Realize

Android OpenSL ES Implementation can be understood directly through the official demo. The official demo provides features such as audio capture, audio cache playback, audio URL playback, audio file playback, mixed sound adjustment, and more.

The functions are as follows:

Audio player Operation Static int createaudioplayer (SLOBJECTITF *playerobject, SLENGINEITF Engine, SLOBJECTITF mix, int numchannels, double samplerate, Pasampleformat sampleformat);//build audio static int Openaudioplay ER (paopenslesstream* stream,unsigned long Framesperbuffer,pasampleformat Outputsampleformat);//open audio player static int Setaudioplayervolum (paopenslesstream* stream,int Millibel); Set the audio volume static int pushaudioplayerqueue (paopenslesstream* stream),//Enter data to the audio player, static int Startaudioplayer ( paopenslesstream* stream);//start audio static int closeaudioplayer (paopenslesstream* stream);//Turn off audio static int Setaudioplayermutesolo (paopenslesstream* stream,int chan,int Mutesolo);//Operation mutesolo////////////////////////////// Microphone operation Static int Createaudiorecorder (SLOBJECTITF *recorderobject, SLENGINEITF engine,int numchannels, double Samplerate, Pasampleformat sampleformat); static int Openaudiorecorder (paopenslesstream* stream,unsigned Long Framesperbuffer,pasampleformat Inputsampleformat)///Open mic static int closeaudiorecorder (paopenslesstream* stream);//Turn off microphone static int Startaudiorecorder ( paopenslesstream* stream);//start microphone static int popaudiorecorderqueue (paopenslesstream* stream);//Remove data to audio player

Portaudio OpenSL ES Implementation

The implementation mechanism is as follows--------audio capture cache, audio playback cache, and callback for data processing.

Code according to the source PA_HOSTAPI_SKELETON.C template implementation.

The callback is as follows:

The audio element involves many elements of the audio, which are recorded as follows:

opensles typedef struct SLDATAFORMAT_PCM_ {SLuint32 formattype; Data format definition Sl_dataformat_pcmsluint32 numchannels; Number of channels (consistent with Channelmask) SLuint32 samplespersec, acquisition frequency HzSLuint32 bitspersample per second, sampling bit (sampling format) SLuint32 containersize; Contains size SLuint32 channelmask; Channel mask//stereo, left channel, right channel sluint32endianness; block byte order from 16--32 bit} SLDATAFORMAT_PCM; GUID-----sl_iid_volume  Volume sl_iid_play  playback control sl_iid_bufferqueue  Cache interface Sl_iid_effectsend  sound sl_iid_ Mutesolo   Mute sl_iid_record  Recording Interface sl_iid_playbackrate sample rate control Sl_iid_equalizer Equalizer Sl_iid_presetreverb Preset Reverb sl_iid_ Environmentalreverb Ambient Reverb sl_iid_3dlocation  3D positioning sl_iid_3ddoppler Doppler  effect sl_iid_bassboost  Bass Enhancement sl_iid_ PITCH     Lifting and adjusting Sl_iid_virtualizer  virtualization ...

Acquisition Frequency: Audio sampling frequency, the number of times per second can be sampled, the higher the sampling rate, the higher the sound quality. The examples given are 44100, 22050, 11025 but not limited to these parameters. For example, to collect low-quality audio, you can make
Use 4000, 8000 and so on.

Quantify the number of bits (data bits): A sampled or sampled value used to measure a change in sound fluctuation, or the resolution of a sound card.
1 bytes (i.e. 8bit) can only record 256 numbers, that is, the amplitude can only be divided into 256 levels;
2 bytes (that is, 16bit) can be fine to 65,536 numbers, which is the CD standard;
4 bytes (i.e. 32bit) can subdivide the amplitude to 4,294,967,296 levels, it is not necessary.

Bit rate: It describes the space required for media content of a unit of time. The transfer rate per second.

Channel: The number of channels of the sound. There are often mono and stereo points.

Frame: The number of media frames per unit of time, the length of which is the product of sample length (number of sample bits) and number of channels.

Data Volume: The size of the buffer needed to collect the data
Data Volume (bytes per second) = Acquisition Frequency * Quantization number of bits * channels/8 (bytes) = Frame * bytes

Cycle: The number of frames required for an audio device to be processed at a time, in this case the data access for the audio device and the storage of the audio data.

Interleaved mode: How digital audio signals are stored. The data is stored in a continuous frame, that is, the left channel sample and the right channel sample of frame 1 are recorded first, and then the record of frame 2 is started ...,

Non-interleaved mode: The first record is the left channel sample for all frames in a cycle, and then all the right channel samples are recorded.

Summarize

Portaudio supports Android and facilitates voice calls for raknet.


Android Raknet Series three transplant Portaudio

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.