3

I have access to an audio stream of PCM audio buffers. I should be clear I do not have access to the audio file. I only have access to a stream of 4096 byte chunks of the audio data.

The PCM buffers come in with the following format:

  • PCM Int 16
  • Little Endian
  • Two Channels
  • Interleaved

To support audio playback on a standard browser I need to convert the audio to the following format:

  • PCM Float 32
  • Big Endian
  • Two channels (at most)
  • Deinterleaved

This audio is coming from an iOS app so I have access to Swift and Objective C (although I am not very comfortable with Objective C...which makes Apple's Audio Converter Services almost impossible to use because Swift really doesn't like pointers).

Additionally the playback will occur on a browser so I could handle the conversion in client side Javascript or server sider. I am proficient enough in the following server side languages to do a conversion:

  • Java (preferred)
  • PHP
  • Node.js
  • Python

If anyone knows a way to do this in any of these languages please let me know. I have worked on this for long enough that I will probably understand even a very technical description of how to do this.

My current plan is to use bitwise operations to deinterleave the left and right channels, then cast the Int 16 Buffer to a Float 32 Buffer with the Web Audio API. Does this seem like a good plan?

Any help is appreciated, thank you.

William Rosenbloom
  • 2,506
  • 1
  • 14
  • 37

1 Answers1

1

My current plan is to use bitwise operations to deinterleave the left and right channels, then cast the Int 16 Buffer to a Float 32 Buffer with the Web Audio API. Does this seem like a good plan?

Yes, that is exactly what you need to do. I do the exact same thing in my applications, and this method works well and is really the only way that makes sense to do it. You don't want to send 32-bit float samples to the client from the server due to the amount of bandwidth. Do the conversion client-side.

Brad
  • 159,648
  • 54
  • 349
  • 530
  • Thank you so much. A lot of things have failed and I wanted to make sure this bitwise strategy wasn't fundamentally flawed. If you don't mind a follow up question, what have you found is the best way to send audio data from a phone to a client? This is a Chromecast app so all the data must be textual. Right now I am sending the audio data as a base 64 encoded string (which as far as I know is the only way to send textual data to a browser). I would prefer to send a UTF-16 string but I'm concerned this won't be parsed correctly by Javascript. – William Rosenbloom Aug 14 '15 at 19:26
  • @WilliamRosenbloom You can actually send binary data over a websocket. Modern JavaScript implementations support typed arrays, so you can have an array of 16-bit samples in their most raw efficient form. BinaryJS wraps this up for you. (http://binaryjs.com/) You can open an arbitrary stream between the client and server. – Brad Aug 14 '15 at 20:17
  • I am still having some trouble with this. There is a lot of noise in the decoded audio. If you could have a look at my [next question](http://stackoverflow.com/questions/32128206/what-does-interleaved-stereo-pcm-linear-int16-big-endian-audio-look-like) I would very much appreciate it. Thank you again. – William Rosenbloom Aug 20 '15 at 21:13