Commit fbb7c2bb authored by sagnowski's avatar sagnowski
Browse files

Clean up buffer conversions header

parent b425bfe9
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -789,11 +789,11 @@ int main(
            /* Do buffer conversions */
            if ( inputFileIsFloat )
            {
                copyBufferInterleavedFloatToPackedInt( audioReadBufFloat, numSamplesRead, audioFeedBufInt, pcmBufNumSamplesPerChannel, pcmBufNumChannels, NULL );
                copyBufferInterleavedFloatToPackedInt( audioReadBufFloat, numSamplesRead / pcmBufNumChannels, audioFeedBufInt, pcmBufNumSamplesPerChannel, pcmBufNumChannels, NULL );
            }
            else
            {
                copyBufferInterleavedIntToPackedInt( audioReadBufInt, numSamplesRead, audioFeedBufInt, pcmBufNumSamplesPerChannel, pcmBufNumChannels );
                copyBufferInterleavedIntToPackedInt( audioReadBufInt, numSamplesRead / pcmBufNumChannels, audioFeedBufInt, pcmBufNumSamplesPerChannel, pcmBufNumChannels );
            }

            /* Feed input audio */
@@ -808,11 +808,11 @@ int main(
            /* Do buffer conversions */
            if ( inputFileIsFloat )
            {
                copyBufferInterleavedFloatToPackedFloat( audioReadBufFloat, numSamplesRead, audioFeedBufFloat, pcmBufNumSamplesPerChannel, pcmBufNumChannels );
                copyBufferInterleavedFloatToPackedFloat( audioReadBufFloat, numSamplesRead / pcmBufNumChannels, audioFeedBufFloat, pcmBufNumSamplesPerChannel, pcmBufNumChannels );
            }
            else
            {
                copyBufferInterleavedIntToPackedFloat( audioReadBufInt, numSamplesRead, audioFeedBufFloat, pcmBufNumSamplesPerChannel, pcmBufNumChannels );
                copyBufferInterleavedIntToPackedFloat( audioReadBufInt, numSamplesRead / pcmBufNumChannels, audioFeedBufFloat, pcmBufNumSamplesPerChannel, pcmBufNumChannels );
            }

            /* Feed input audio */
+44 −60
Original line number Diff line number Diff line
@@ -43,29 +43,25 @@
 *--------------------------------------------------------------------------*/
void copyBufferInterleavedFloatToPackedFloat(
    const float *srcBuffer,
    const int16_t srcBufferTotalNumSamples,
    const int16_t srcBufferNumSamplesPerChannel,
    float *dstBuffer,
    const int16_t dstBufferNumSamplesPerChannel,
    const int16_t dstBufferNumChannels )
    const int16_t numChannels )
{
    int16_t chnl, smpl, i;

    i = 0;
    int16_t chnl, smpl;

    for ( smpl = 0; smpl < dstBufferNumSamplesPerChannel; ++smpl )
    {
        for ( chnl = 0; chnl < dstBufferNumChannels; ++chnl )
        for ( chnl = 0; chnl < numChannels; ++chnl )
        {
            if ( i < srcBufferTotalNumSamples )
            if ( smpl < srcBufferNumSamplesPerChannel )
            {
                dstBuffer[chnl * dstBufferNumSamplesPerChannel + smpl] = srcBuffer[i];
                dstBuffer[chnl * dstBufferNumSamplesPerChannel + smpl] = srcBuffer[smpl * numChannels + chnl];
            }
            else
            {
                dstBuffer[chnl * dstBufferNumSamplesPerChannel + smpl] = 0.f;
            }

            ++i;
        }
    }

@@ -78,37 +74,33 @@ void copyBufferInterleavedFloatToPackedFloat(
 *--------------------------------------------------------------------------*/
void copyBufferInterleavedFloatToPackedInt(
    const float *srcBuffer,
    const int16_t srcBufferTotalNumSamples,
    const int16_t srcBufferNumSamplesPerChannel,
    int16_t *dstBuffer,
    const int16_t dstBufferNumSamplesPerChannel,
    const int16_t dstBufferNumChannels,
    const int16_t numChannels,
    int16_t ( *float2int )( float ) )
{
    int16_t chnl, smpl, i;

    i = 0;
    int16_t chnl, smpl;

    for ( smpl = 0; smpl < dstBufferNumSamplesPerChannel; ++smpl )
    {
        for ( chnl = 0; chnl < dstBufferNumChannels; ++chnl )
        for ( chnl = 0; chnl < numChannels; ++chnl )
        {
            if ( i < srcBufferTotalNumSamples )
            if ( smpl < srcBufferNumSamplesPerChannel )
            {
                if ( float2int == NULL )
                if ( float2int != NULL )
                {
                    dstBuffer[chnl * dstBufferNumSamplesPerChannel + smpl] = (int16_t) srcBuffer[i];
                    dstBuffer[chnl * dstBufferNumSamplesPerChannel + smpl] = float2int( srcBuffer[smpl * numChannels + chnl] );
                }
                else
                {
                    dstBuffer[chnl * dstBufferNumSamplesPerChannel + smpl] = float2int( srcBuffer[i] );
                    dstBuffer[chnl * dstBufferNumSamplesPerChannel + smpl] = (int16_t) srcBuffer[smpl * numChannels + chnl];
                }
            }
            else
            {
                dstBuffer[chnl * dstBufferNumSamplesPerChannel + smpl] = 0;
            }

            ++i;
        }
    }

@@ -121,29 +113,25 @@ void copyBufferInterleavedFloatToPackedInt(
 *--------------------------------------------------------------------------*/
void copyBufferInterleavedIntToPackedFloat(
    const int16_t *srcBuffer,
    const int16_t srcBufferTotalNumSamples,
    const int16_t srcBufferNumSamplesPerChannel,
    float *dstBuffer,
    const int16_t dstBufferNumSamplesPerChannel,
    const int16_t dstBufferNumChannels )
    const int16_t numChannels )
{
    int16_t chnl, smpl, i;

    i = 0;
    int16_t chnl, smpl;

    for ( smpl = 0; smpl < dstBufferNumSamplesPerChannel; ++smpl )
    {
        for ( chnl = 0; chnl < dstBufferNumChannels; ++chnl )
        for ( chnl = 0; chnl < numChannels; ++chnl )
        {
            if ( i < srcBufferTotalNumSamples )
            if ( smpl < srcBufferNumSamplesPerChannel )
            {
                dstBuffer[chnl * dstBufferNumSamplesPerChannel + smpl] = (float) srcBuffer[i];
                dstBuffer[chnl * dstBufferNumSamplesPerChannel + smpl] = (float) srcBuffer[smpl * numChannels + chnl];
            }
            else
            {
                dstBuffer[chnl * dstBufferNumSamplesPerChannel + smpl] = 0.f;
            }

            ++i;
        }
    }

@@ -156,29 +144,25 @@ void copyBufferInterleavedIntToPackedFloat(
 *--------------------------------------------------------------------------*/
void copyBufferInterleavedIntToPackedInt(
    const int16_t *srcBuffer,
    const int16_t srcBufferTotalNumSamples,
    const int16_t srcBufferNumSamplesPerChannel,
    int16_t *dstBuffer,
    const int16_t dstBufferNumSamplesPerChannel,
    const int16_t dstBufferNumChannels )
    const int16_t numChannels )
{
    int16_t chnl, smpl, i;

    i = 0;
    int16_t chnl, smpl;

    for ( smpl = 0; smpl < dstBufferNumSamplesPerChannel; ++smpl )
    {
        for ( chnl = 0; chnl < dstBufferNumChannels; ++chnl )
        for ( chnl = 0; chnl < numChannels; ++chnl )
        {
            if ( i < srcBufferTotalNumSamples )
            if ( smpl < srcBufferNumSamplesPerChannel )
            {
                dstBuffer[chnl * dstBufferNumSamplesPerChannel + smpl] = srcBuffer[i];
                dstBuffer[chnl * dstBufferNumSamplesPerChannel + smpl] = srcBuffer[smpl * numChannels + chnl];
            }
            else
            {
                dstBuffer[chnl * dstBufferNumSamplesPerChannel + smpl] = 0;
            }

            ++i;
        }
    }

@@ -194,21 +178,21 @@ void copyBufferPackedFloatToInterleavedFloat(
    const int16_t srcBufferNumSamplesPerChannel,
    float *dstBuffer,
    const int16_t dstBufferNumSamplesPerChannel,
    const int16_t dstBufferNumChannels )
    const int16_t numChannels )
{
    int16_t chnl, smpl;

    for ( smpl = 0; smpl < dstBufferNumSamplesPerChannel; ++smpl )
    {
        for ( chnl = 0; chnl < dstBufferNumChannels; ++chnl )
        for ( chnl = 0; chnl < numChannels; ++chnl )
        {
            if ( smpl < srcBufferNumSamplesPerChannel )
            {
                dstBuffer[smpl * dstBufferNumChannels + chnl] = srcBuffer[chnl * srcBufferNumSamplesPerChannel + smpl];
                dstBuffer[smpl * numChannels + chnl] = srcBuffer[chnl * srcBufferNumSamplesPerChannel + smpl];
            }
            else
            {
                dstBuffer[smpl * dstBufferNumChannels + chnl] = 0.0f;
                dstBuffer[smpl * numChannels + chnl] = 0.0f;
            }
        }
    }
@@ -225,29 +209,29 @@ void copyBufferPackedFloatToInterleavedInt(
    const int16_t srcBufferNumSamplesPerChannel,
    int16_t *dstBuffer,
    const int16_t dstBufferNumSamplesPerChannel,
    const int16_t dstBufferNumChannels,
    const int16_t numChannels,
    int16_t ( *float2int )( float ) )
{
    int16_t chnl, smpl;

    for ( smpl = 0; smpl < dstBufferNumSamplesPerChannel; ++smpl )
    {
        for ( chnl = 0; chnl < dstBufferNumChannels; ++chnl )
        for ( chnl = 0; chnl < numChannels; ++chnl )
        {
            if ( smpl < srcBufferNumSamplesPerChannel )
            {
                if ( float2int == NULL )
                if ( float2int != NULL )
                {
                    dstBuffer[smpl * dstBufferNumChannels + chnl] = (int16_t) srcBuffer[chnl * srcBufferNumSamplesPerChannel + smpl];
                    dstBuffer[smpl * numChannels + chnl] = float2int( srcBuffer[chnl * srcBufferNumSamplesPerChannel + smpl] );
                }
                else
                {
                    dstBuffer[smpl * dstBufferNumChannels + chnl] = float2int( srcBuffer[chnl * srcBufferNumSamplesPerChannel + smpl] );
                    dstBuffer[smpl * numChannels + chnl] = (int16_t) srcBuffer[chnl * srcBufferNumSamplesPerChannel + smpl];
                }
            }
            else
            {
                dstBuffer[smpl * dstBufferNumChannels + chnl] = 0;
                dstBuffer[smpl * numChannels + chnl] = 0;
            }
        }
    }
@@ -264,21 +248,21 @@ void copyBufferPackedIntToInterleavedFloat(
    const int16_t srcBufferNumSamplesPerChannel,
    float *dstBuffer,
    const int16_t dstBufferNumSamplesPerChannel,
    const int16_t dstBufferNumChannels )
    const int16_t numChannels )
{
    int16_t chnl, smpl;

    for ( smpl = 0; smpl < dstBufferNumSamplesPerChannel; ++smpl )
    {
        for ( chnl = 0; chnl < dstBufferNumChannels; ++chnl )
        for ( chnl = 0; chnl < numChannels; ++chnl )
        {
            if ( smpl < srcBufferNumSamplesPerChannel )
            {
                dstBuffer[smpl * dstBufferNumChannels + chnl] = (float) srcBuffer[chnl * srcBufferNumSamplesPerChannel + smpl];
                dstBuffer[smpl * numChannels + chnl] = (float) srcBuffer[chnl * srcBufferNumSamplesPerChannel + smpl];
            }
            else
            {
                dstBuffer[smpl * dstBufferNumChannels + chnl] = 0.0f;
                dstBuffer[smpl * numChannels + chnl] = 0.0f;
            }
        }
    }
@@ -295,21 +279,21 @@ void copyBufferPackedIntToInterleavedInt(
    const int16_t srcBufferNumSamplesPerChannel,
    int16_t *dstBuffer,
    const int16_t dstBufferNumSamplesPerChannel,
    const int16_t dstBufferNumChannels )
    const int16_t numChannels )
{
    int16_t chnl, smpl;

    for ( smpl = 0; smpl < dstBufferNumSamplesPerChannel; ++smpl )
    {
        for ( chnl = 0; chnl < dstBufferNumChannels; ++chnl )
        for ( chnl = 0; chnl < numChannels; ++chnl )
        {
            if ( smpl < srcBufferNumSamplesPerChannel )
            {
                dstBuffer[smpl * dstBufferNumChannels + chnl] = srcBuffer[chnl * srcBufferNumSamplesPerChannel + smpl];
                dstBuffer[smpl * numChannels + chnl] = srcBuffer[chnl * srcBufferNumSamplesPerChannel + smpl];
            }
            else
            {
                dstBuffer[smpl * dstBufferNumChannels + chnl] = 0;
                dstBuffer[smpl * numChannels + chnl] = 0;
            }
        }
    }
+48 −43
Original line number Diff line number Diff line
@@ -39,65 +39,70 @@
#ifdef FLOAT_INTERFACE_ENC

void copyBufferInterleavedFloatToPackedFloat(
    const float *srcBuffer,
    const int16_t srcBufferTotalNumSamples, /* TODO(sgi): Change to num samples per channel */
    float *dstBuffer,
    const int16_t dstBufferNumSamplesPerChannel,
    const int16_t dstBufferNumChannels );
    const float *srcBuffer,                      /* i  : Source buffer                                                                                          */
    const int16_t srcBufferNumSamplesPerChannel, /* i  : Length (per channel) of source buffer                                                                                */
    float *dstBuffer,                            /* o  : Destination buffer                                                                                     */
    const int16_t dstBufferNumSamplesPerChannel, /* o  : Length of destination buffer. If longer than source buffer, the remaining samples will be set to zero. */
    const int16_t numChannels                    /* i  : Number of channels - must be equal for both buffers                                                    */
);

void copyBufferInterleavedFloatToPackedInt(
    const float *srcBuffer,
    const int16_t srcBufferTotalNumSamples, /* TODO(sgi): Change to num samples per channel */
    int16_t *dstBuffer,
    const int16_t dstBufferNumSamplesPerChannel,
    const int16_t dstBufferNumChannels,
    const float *srcBuffer,                      /* i  : Source buffer                                                                                          */
    const int16_t srcBufferNumSamplesPerChannel, /* i  : Length (per channel) of source buffer                                                                                */
    int16_t *dstBuffer,                          /* o  : Destination buffer                                                                                     */
    const int16_t dstBufferNumSamplesPerChannel, /* o  : Length of destination buffer. If longer than source buffer, the remaining samples will be set to zero. */
    const int16_t numChannels,                   /* i  : Number of channels - must be equal for both buffers                                                    */
    int16_t ( *float2int )( float )              /* i  : Custom float-to-int conversion function. If NULL, conversion will be done via a simple cast.           */
);

void copyBufferInterleavedIntToPackedFloat(
    const int16_t *srcBuffer,
    const int16_t srcBufferTotalNumSamples, /* TODO(sgi): Change to num samples per channel */
    float *dstBuffer,
    const int16_t dstBufferNumSamplesPerChannel,
    const int16_t dstBufferNumChannels );
    const int16_t *srcBuffer,                    /* i  : Source buffer                                                                                          */
    const int16_t srcBufferNumSamplesPerChannel, /* i  : Length (per channel) of source buffer                                                                                */
    float *dstBuffer,                            /* o  : Destination buffer                                                                                     */
    const int16_t dstBufferNumSamplesPerChannel, /* o  : Length of destination buffer. If longer than source buffer, the remaining samples will be set to zero. */
    const int16_t numChannels                    /* i  : Number of channels - must be equal for both buffers                                                    */
);

void copyBufferInterleavedIntToPackedInt(
    const int16_t *srcBuffer,
    const int16_t srcBufferTotalNumSamples, /* TODO(sgi): Change to num samples per channel */
    int16_t *dstBuffer,
    const int16_t dstBufferNumSamplesPerChannel,
    const int16_t dstBufferNumChannels );
    const int16_t *srcBuffer,                    /* i  : Source buffer                                                                                          */
    const int16_t srcBufferNumSamplesPerChannel, /* i  : Length (per channel) of source buffer                                                                                */
    int16_t *dstBuffer,                          /* o  : Destination buffer                                                                                     */
    const int16_t dstBufferNumSamplesPerChannel, /* o  : Length of destination buffer. If longer than source buffer, the remaining samples will be set to zero. */
    const int16_t numChannels                    /* i  : Number of channels - must be equal for both buffers                                                    */
);

void copyBufferPackedFloatToInterleavedFloat(
    const float *srcBuffer,
    const int16_t srcBufferNumSamplesPerChannel,
    float *dstBuffer,
    const int16_t dstBufferNumSamplesPerChannel,
    const int16_t dstBufferNumChannels );
    const float *srcBuffer,                      /* i  : Source buffer                                                                                          */
    const int16_t srcBufferNumSamplesPerChannel, /* i  : Length (per channel) of source buffer                                                                                */
    float *dstBuffer,                            /* o  : Destination buffer                                                                                     */
    const int16_t dstBufferNumSamplesPerChannel, /* o  : Length of destination buffer. If longer than source buffer, the remaining samples will be set to zero. */
    const int16_t numChannels                    /* i  : Number of channels - must be equal for both buffers                                                    */
);

void copyBufferPackedFloatToInterleavedInt(
    const float *srcBuffer,
    const int16_t srcBufferNumSamplesPerChannel,
    int16_t *dstBuffer,
    const int16_t dstBufferNumSamplesPerChannel,
    const int16_t dstBufferNumChannels,
    const float *srcBuffer,                      /* i  : Source buffer                                                                                          */
    const int16_t srcBufferNumSamplesPerChannel, /* i  : Length (per channel) of source buffer                                                                                */
    int16_t *dstBuffer,                          /* o  : Destination buffer                                                                                     */
    const int16_t dstBufferNumSamplesPerChannel, /* o  : Length of destination buffer. If longer than source buffer, the remaining samples will be set to zero. */
    const int16_t numChannels,                   /* i  : Number of channels - must be equal for both buffers                                                    */
    int16_t ( *float2int )( float )              /* i  : Custom float-to-int conversion function. If NULL, conversion will be done via a simple cast.           */
);

void copyBufferPackedIntToInterleavedFloat(
    const int16_t *srcBuffer,
    const int16_t srcBufferNumSamplesPerChannel,
    float *dstBuffer,
    const int16_t dstBufferNumSamplesPerChannel,
    const int16_t dstBufferNumChannels );
    const int16_t *srcBuffer,                    /* i  : Source buffer                                                                                          */
    const int16_t srcBufferNumSamplesPerChannel, /* i  : Length (per channel) of source buffer                                                                                */
    float *dstBuffer,                            /* o  : Destination buffer                                                                                     */
    const int16_t dstBufferNumSamplesPerChannel, /* o  : Length of destination buffer. If longer than source buffer, the remaining samples will be set to zero. */
    const int16_t numChannels                    /* i  : Number of channels - must be equal for both buffers                                                    */
);

void copyBufferPackedIntToInterleavedInt(
    const int16_t *srcBuffer,
    const int16_t srcBufferNumSamplesPerChannel,
    int16_t *dstBuffer,
    const int16_t dstBufferNumSamplesPerChannel,
    const int16_t dstBufferNumChannels );

    const int16_t *srcBuffer,                    /* i  : Source buffer                                                                                          */
    const int16_t srcBufferNumSamplesPerChannel, /* i  : Length (per channel) of source buffer                                                                                */
    int16_t *dstBuffer,                          /* o  : Destination buffer                                                                                     */
    const int16_t dstBufferNumSamplesPerChannel, /* o  : Length of destination buffer. If longer than source buffer, the remaining samples will be set to zero. */
    const int16_t numChannels                    /* i  : Number of channels - must be equal for both buffers                                                    */
);

#endif /* FLOAT_INTERFACE_ENC */