Decoded as short[]

Dec 13, 2010 at 8:49 PM


I've noticed that this project decodes data and returns it in a short[] format. This seems a little unusual given that a byte array is used for the encoding. How can I convert from the short[] into a byte array so that I can use the decoded values for playback?

Dec 14, 2010 at 10:36 AM


the encoder does also take a short[] as input. Anyway, the reason I am using short is that Speex is doing it the same way. Each sample has a resolution of 16 bit  thus short.

It is quite easy to convert from short to byte just use the BitConverter:

foreach (var sample in decodedSamples)
  var shortBytes = BitConverter.GetBytes(sample)

Alternative, checkout the documentation where the conversation between short and bytes is also used.