0
0

Hi,
I’m trying to convert the float32 DSP datas to int16 but i don’t know how to do this.
What’s the algorithm?

Thanx for your help.

  • You must to post comments
0
0

[code:9127af28]
// My conversion code
int MixStereo_32To16(void* pSrc, void *pDest, int nSamples)
{
int m_mixStep;

float * p_in = (float *)pSrc;
signed short * p_out = (signed short *)pDest;

m_mixStep >>= 2;

for ( m_mixStep = nSamples; m_mixStep; m_mixStep--)
{

    if ( *p_in >= 1.0 ) *p_out = 32767;
    else if ( *p_in < -1.0 ) *p_out = -32768;
    else *p_out = *p_in * 32768.0;

    p_in++; p_out++;

}

return nSamples >> 1;

}

// Taken and adapted from VLC (aka VideoLan)
int MixStereo_32To16(void* pSrc, void *pDest, int nSamples)
{
int m_mixStep;

float * p_in = (float *)pSrc;
signed short * p_out = (signed short *)pDest;

m_mixStep >>= 2;

for ( m_mixStep = nSamples; m_mixStep; m_mixStep--)
{

    float f_in = *p_in + 384.0;
     __int32 i_in;
    i_in = *(__int32 *)&f_in;
    if ( i_in > 0x43c07fff ) *p_out = 32767;
    else if ( i_in < 0x43bf8000 ) *p_out = -32768;
    else *p_out = i_in - 0x43c00000;

    p_in++; p_out++;

}

return nSamples >> 1;

}
[/code:9127af28]

  • You must to post comments
0
0

Ok, thank you.

That’s what I’m looking for!

lunggom

  • You must to post comments
0
0

Hi, this code is useful.
But how can I convert the float32 DSP datas to 8bit, 24bit, 32bit?
Thanks.

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.