opentok / opentok-windows-sdk-samples

Sample applications illustrating best practices using OpenTok Windows SDK
MIT License
9 stars 29 forks source link

AudioBus output wave format and bits per sample #35

Closed hendrihendri closed 1 year ago

hendrihendri commented 3 years ago

Hi, I am trying to implement custom audio renderer/capturer using IAudioDevice and SetCustomAudioDevice API. I noticed that the interface were only asked to provide SamplingRate and Channels as the renderer/capturer settings via GetAudioCapturerSettings/GetAudioRendererSettings. What is the expected wave format and bits per sample that the AudioBus is expecting (e.g. PCM, IEEE)?

Thanks!

sergioturgil-vonage commented 1 year ago

Hi! It expects PCM with 2 byte signed integers.

The batches of samples provided via the write_samples and read_samples callbacks (included in AudioBus class during the init callback) have the following example format:

F1C1 F1C2 F2C1 F2C2
...
FnC1 FnC2

Each of these FxCy is a signed 2-byte short with the value for frame x and channel y (this is of course for a stereo sequence with two channels. A mono sequence would only include the values for FxC1 and a dolby with 6 channels would include samples from FxC1 to FxC6). So a frame includes a sample for each channel. And for the read_samples/write_samples callbacks we need to provide the complete number of frames, which for example, for a 10ms batch of 48Khz audio stream, would be 480, independently of the number of channels.

Please, let me know if I wasn't too clear on the explanation.

v-kpheng commented 1 year ago

Thanks, @sergioturgil-vonage! @hendrihendri, any other issues, please let us know. Thanks!