ios - Converting 16-bit short to 32 bit float -
in tone generator example ios:http://www.cocoawithlove.com/2010/10/ios-tone-generator-introduction-to.html
i trying convert short array float32 in ios.
float32 *buffer = (float32 *)iodata->mbuffers[channel].mdata; short* outputshortbuffer = static_cast<short*>(outputbuffer); (uint32 frame = 0, j=0; frame < innumberframes; frame++, j=j+2) { buffer[frame] = outputshortbuffer[frame]; }
for reasons, hearing added noise when played speaker. think there problem conversion short float32?
yes, there is.
consider value-range floating point samples -1.0 <= xn <= 1.0
, signed short
-32767 <= xn <= +32767
. merely casting result in clipping on virtually samples.
so taking account:
float32 *buffer = (float32 *)iodata->mbuffers[channel].mdata; short* outputshortbuffer = static_cast<short*>(outputbuffer); (uint32 frame = 0, j=0; frame < innumberframes; frame++, j=j+2) { buffer[frame] = ((float) outputshortbuffer[frame]) / 32767.0f; }
[note: not optimal way of doing this].
however, sure frames mono? if not might cause of audio corruption you'll copying 1 channel.
as aside, why, if output buffer float
s not using them throughout?
Comments
Post a Comment