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 floats not using them throughout?


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -