Commit 441d8b14 authored by sagnowski's avatar sagnowski
Browse files

Add float interface to lib_enc [untested]

parent a29ddb4f
Loading
Loading
Loading
Loading
+39 −1
Original line number Diff line number Diff line
@@ -695,13 +695,51 @@ int main(
            }
        }

#ifdef FLOAT_INTERFACE
        float *tmpFloatBuf = NULL;
        bool useFloat = true; /* TODO(sgi): get from input file type or command line flag */
        if (useFloat)
        {
            /* TODO(sgi): Don't allocate on every frame */
            tmpFloatBuf = malloc(pcmBufSize * sizeof(float));
            for (int32_t i = 0; i < pcmBufSize; ++i)
            {
                tmpFloatBuf[i] = pcmBuf[i];
            }
            /* Feed input audio */
            if ( ( error = IVAS_ENC_FeedInputAudioFloat( hIvasEnc, tmpFloatBuf, pcmBufSize ) ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "\nIVAS_ENC_FeedInputAudioInt failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) );
                return error;
            }
        } else {
            /* Feed input audio */
            if ( ( error = IVAS_ENC_FeedInputAudioInt( hIvasEnc, pcmBuf, pcmBufSize ) ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "\nIVAS_ENC_FeedInputAudioInt failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) );
                return error;
            }
        }
#endif

        /* *** Encode one frame *** */
        if ( ( error = IVAS_ENC_EncodeFrameToSerial( hIvasEnc, pcmBuf, pcmBufSize, bitStream, &numBits ) ) != IVAS_ERR_OK )
        if ( ( error = IVAS_ENC_EncodeFrameToSerial( hIvasEnc,
#ifndef FLOAT_INTERFACE
                                                     pcmBuf, pcmBufSize,
#endif
                                                     bitStream, &numBits ) ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "\nencodeFrame failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) );
            goto cleanup;
        }

#ifdef FLOAT_INTERFACE
        if (tmpFloatBuf != NULL)
        {
            free(tmpFloatBuf);
        }
#endif

        /* write bitstream */
        if ( ( error = BS_Writer_WriteFrame_short( hBsWriter, bitStream, numBits, totalBitrate ) ) != IVAS_ERR_OK )
        {
+4 −0
Original line number Diff line number Diff line
@@ -462,7 +462,11 @@ void ivas_FB_mixer_close(

void ivas_fb_mixer_pcm_ingest(
    IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle             */
#ifdef FLOAT_INTERFACE
    float* pcm_in[],               /* i  : input audio channels        */
#else
    float pcm_in[][L_FRAME48k],    /* i  : input audio channels        */
#endif
    float **ppOut_pcm,             /* o  : output audio channels       */
    const int16_t frame_len        /* i  : frame length                */
)
+105 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@
#ifndef IVAS_PROT_H
#define IVAS_PROT_H

#include "ivas_cnst.h"
#include <stdint.h>
#include "options.h"
#include <stdio.h>
@@ -56,14 +57,22 @@

ivas_error ivas_enc(
    Encoder_Struct *st_ivas,                                    /* i  : IVAS encoder structure                  */
#ifdef FLOAT_INTERFACE
    float *data,                                                /* i  : input signal                            */
#else
    const int16_t *data,                                        /* i  : input signal                            */
#endif
    const int16_t n_samples                                     /* i  : number of input samples                 */
);

void stereo_dmx_evs_enc(
    STEREO_DMX_EVS_ENC_HANDLE hStereoDmxEVS,                    /* i/o: Stereo downmix for EVS encoder handle   */
    const int32_t input_Fs,                                     /* i  : input sampling rate                     */
#ifdef FLOAT_INTERFACE
    float data[CPE_CHANNELS],                                   /* i/o: input signal                            */
#else
    int16_t data[CPE_CHANNELS * L_FRAME48k],                    /* i/o: input signal                            */
#endif
    const int16_t n_samples                                     /* i  : number of input samples                 */
);

@@ -177,7 +186,11 @@ ivas_error ivas_cpe_enc(

ivas_error ivas_mct_enc(
    Encoder_Struct *st_ivas,                                    /* i/o: IVAS encoder structure                  */
#ifdef FLOAT_INTERFACE
    float* data[MCT_MAX_CHANNELS],                              /* i  : input signals                           */
#else
    float data[MCT_MAX_CHANNELS][L_FRAME48k],                   /* i  : input signals                           */
#endif
    const int16_t input_frame,                                  /* i  : input frame length per channel          */
    const int16_t nb_bits_metadata                              /* i  : number of metadata bits                 */
);
@@ -844,7 +857,11 @@ ivas_error create_ism_metadata_dec(

ivas_error ivas_ism_enc(
    Encoder_Struct *st_ivas,                                    /* i/o: IVAS encoder structure                      */
#ifdef FLOAT_INTERFACE
    float* data[MAX_NUM_OBJECTS],                               /* i  : input signal                                */
#else
    float data[MAX_NUM_OBJECTS][L_FRAME48k],                    /* i  : input signal                                */
#endif
    const int16_t input_frame,                                  /* i  : input frame length per channel              */
    int16_t *nb_bits_metadata                                   /* i  : number of metadata bits                     */
);
@@ -889,7 +906,11 @@ ivas_error ivas_param_ism_enc_open(

void ivas_param_ism_enc(
    Encoder_Struct *st_ivas,                                    /* i/o: IVAS encoder structure                      */
#ifdef FLOAT_INTERFACE
    float* data[MAX_NUM_OBJECTS],                               /* i  : input signal                                */
#else
    float data[MAX_NUM_OBJECTS][L_FRAME48k],                    /* i  : input signal                                */
#endif
    const int16_t input_frame                                   /* i  : input frame length per channel              */
);

@@ -900,7 +921,11 @@ void ivas_param_ism_enc_close(

void ivas_param_ism_stereo_dmx(
    Encoder_Struct *st_ivas,                                    /* i  : IVAS encoder structure                      */
#ifdef FLOAT_INTERFACE
    float* data[MAX_NUM_OBJECTS],                               /* i/o: input signal/stereo dmx                     */
#else
    float data[MAX_NUM_OBJECTS][L_FRAME48k],                    /* i/o: input signal/stereo dmx                     */
#endif
    const int16_t input_frame                                   /* i  : Length of input frame                       */
);

@@ -3090,7 +3115,11 @@ void ivas_dirac_param_est_enc(
    DIRAC_ENC_HANDLE hDirAC, 
    IVAS_QDIRECTION *q_direction, 
    const uint8_t useLowerRes, 
#ifdef FLOAT_INTERFACE
    float* data_f[], 
#else
    float data_f[][L_FRAME48k], 
#endif
    float **pp_fr_real,
    float **pp_fr_imag,
    const int16_t input_frame, 
@@ -3170,14 +3199,32 @@ int16_t ivas_sba_get_spar_hoa_md_flag(
);

void ivas_sba_zero_vert_comp(
#ifdef FLOAT_INTERFACE
    float* sba_data[],                                          /* i/o: SBA data frame                          */
#else
    float sba_data[][L_FRAME48k],                               /* i/o: SBA data frame                          */
#endif
    const int16_t sba_order,                                    /* i  : Ambisonic (SBA) order                   */
    const int16_t sba_planar,                                   /* i  : SBA planar flag                         */
    const int16_t input_frame                                   /* i  : input frame length                      */
);

#ifdef FLOAT_INTERFACE
/* TODO(sgi): tmp function, remove when FLOAT_INTERFACE is done */
void ivas_sba_zero_vert_comp_old(
    float sba_data[][L_FRAME48k],                               /* i/o: SBA data frame                          */
    const int16_t sba_order,                                    /* i  : Ambisonic (SBA) order                   */
    const int16_t sba_planar,                                   /* i  : SBA planar flag                         */
    const int16_t input_frame                                   /* i  : input frame length                      */
);
#endif

void ivas_sba_getTCs(
#ifdef FLOAT_INTERFACE
    float* sba_data[],                                          /* i  : SBA signals                             */
#else
    float sba_data[][L_FRAME48k],                               /* i  : SBA signals                             */
#endif
    Encoder_Struct *st_ivas,                                    /* i/o: Encoder struct                          */
    const int16_t input_frame                                   /* i  : frame length                            */
);
@@ -3192,10 +3239,23 @@ ivas_error ivas_sba_linear_renderer(
);

int16_t ivas_sba_remapTCs(
#ifdef FLOAT_INTERFACE
    float* sba_data[],                                          /* i/o: SBA signals                             */
#else
    float sba_data[][L_FRAME48k],                               /* i/o: SBA signals                             */
#endif
    Decoder_Struct *st_ivas,                                    /* i/o: decoder struct                          */
    const int16_t output_frame                                  /* i  : frame length                            */
);

#ifdef FLOAT_INTERFACE
/* TODO(sgi): tmp function, remove when FLOAT_INTERFACE is done */
int16_t ivas_sba_remapTCs_old(
    float sba_data[][L_FRAME48k],                               /* i/o: SBA signals                             */
    Decoder_Struct *st_ivas,                                    /* i/o: decoder struct                          */
    const int16_t output_frame                                  /* i  : frame length                            */
);
#endif

void ivas_sba_dirac_stereo_dec(
    Decoder_Struct *st_ivas,                                    /* i/o: IVAS decoder structure                  */
@@ -3248,7 +3308,11 @@ void ivas_dirac_enc(
    BSTR_ENC_HANDLE hMetaData,                                  /* i/o: Metadata bitstream handle               */
    int16_t *nb_bits_metadata,                                  /* o  : number of metadata bits written         */
    const int16_t Opt_DTX_ON,                                   /* i  : flag signaling DTX on                   */
#ifdef FLOAT_INTERFACE
    float* data_f[],                                            /* i/o: SBA channels                            */
#else
    float data_f[][L_FRAME48k],                                 /* i/o: SBA channels                            */
#endif
    const int16_t input_frame,                                  /* i  : input frame length                      */
    const int16_t sba_planar                                    /* i  : SBA planar flag                         */
);
@@ -3588,7 +3652,11 @@ void ivas_param_mc_enc_close(
void ivas_param_mc_enc(
    Encoder_Struct *st_ivas,                                    /* i/o: IVAS Encoder handle                                 */
    BSTR_ENC_HANDLE hMetaData,                                  /* i/o: IVAS Metadata bitstream handle                      */
#ifdef FLOAT_INTERFACE
    float* data_f[],                                            /* i/o: input: CICP6, CICP12, CICP14, CICP16 or CICP19 MC data */
#else
    float data_f[][L_FRAME48k],                                 /* i/o: input: CICP6, CICP12, CICP14, CICP16 or CICP19 MC data */
#endif
    const int16_t input_frame                                   /* i  : input frame length                                  */
);

@@ -3821,7 +3889,11 @@ void ivas_spar_enc_close(

ivas_error ivas_spar_enc(
    Encoder_Struct *st_ivas,                                    /* i/o: IVAS encoder structure                  */
#ifdef FLOAT_INTERFACE
    float* data_f[],                                            /* i/o: input/transport audio channels          */
#else
    float data_f[][L_FRAME48k],                                 /* i/o: input/transport audio channels          */
#endif
    const int16_t input_frame,                                  /* i  : input frame length                      */
    int16_t *nb_bits_metadata,                                  /* i  : number of MD bits written               */
    BSTR_ENC_HANDLE hMetaData                                   /* o  : MetaData handle                         */    
@@ -4493,7 +4565,11 @@ void ivas_masa_encode(

void ivas_masa_estimate_energy(
    MASA_ENCODER_HANDLE hMasa,                                  /* i/o: MASA encoder structure                          */
#ifdef FLOAT_INTERFACE
    float* data_f[],                                            /* i  : Input audio channels                            */
#else
    float data_f[][L_FRAME48k],                                 /* i  : Input audio channels                            */
#endif
    const int16_t input_frame,                                  /* i  : frame length                                    */
    const int16_t nchan_transport                               /* i  : number of MASA input/transport channels         */
);
@@ -4923,7 +4999,11 @@ void ivas_mcmasa_enc(
    MCMASA_ENC_HANDLE hMcMasa,                                  /* i/o: Encoder McMASA handle                             */
    IVAS_QMETADATA_HANDLE hQMeta,                               /* o  : Qmetadata handle                                  */
    MASA_ENCODER_HANDLE hMasa,                                  /* i/o: Encoder MASA handle                               */
#ifdef FLOAT_INTERFACE
    float* data_f[],                                            /* i  : Input frame of audio                              */
#else
    float data_f[][L_FRAME48k],                                 /* i  : Input frame of audio                              */
#endif
    const int16_t input_frame,                                  /* i  : Input frame size                                  */
    const int16_t nchan_transport,                              /* i  : Number of transport channels                      */
    const int16_t nchan_inp                                     /* i  : Number of input channels                          */
@@ -4932,7 +5012,11 @@ void ivas_mcmasa_enc(
void ivas_mcmasa_param_est_enc(
    MCMASA_ENC_HANDLE hMcMasa,                                  /* i/o: Encoder McMASA handle                             */
    MASA_ENCODER_HANDLE hMasa,                                  /* i/o: Encoder MASA handle                               */
#ifdef FLOAT_INTERFACE
    float* data_f[],                                            /* i  : Input frame of audio                              */
#else
    float data_f[][L_FRAME48k],                                 /* i  : Input frame of audio                              */
#endif
    float elevation_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS],   /* o  : Estimated elevation            */
    float azimuth_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS],     /* o  : Estimated azimuth              */
    float energyRatio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS],          /* o  : Estimated direct-to-total ratio*/
@@ -5317,7 +5401,11 @@ void ivas_FB_mixer_close(

void ivas_fb_mixer_pcm_ingest( 
    IVAS_FB_MIXER_HANDLE hFbMixer,                              /* i/o: FB mixer handle                             */
#ifdef FLOAT_INTERFACE
    float* pcm_in[],                                            /* i  : input audio channels                        */
#else
    float pcm_in[][L_FRAME48k],                                 /* i  : input audio channels                        */
#endif
    float **ppOut_pcm,                                          /* o  : output audio channels                       */
    const int16_t frame_length                                  /* i  : frame length                                */
);
@@ -5325,7 +5413,11 @@ void ivas_fb_mixer_pcm_ingest(
void ivas_dirac_enc_spar_delay_synchro(
    Encoder_Struct *st_ivas,                                    /* i/o: IVAS encoder structure                      */
    const int16_t input_frame,                                  /* i  : input frame length                          */
#ifdef FLOAT_INTERFACE
    float* data_f[]                                             /* i/o: SBA channels (ACN / SN3D)                   */
#else
    float data_f[][L_FRAME48k]                                  /* i/o: SBA channels (ACN / SN3D)                   */
#endif
);

void ivas_fb_mixer_update_prior_input(
@@ -5717,6 +5809,19 @@ ivas_error ivas_orient_trk_GetTrackedOrientation(
    float *roll 
);

#ifdef FLOAT_INTERFACE
/*----------------------------------------------------------------------------------*
 * Audio buffer handling
 *----------------------------------------------------------------------------------*/

void save_channel_pointers(
    float* linearBuffer,
    int16_t numChannels,
    int16_t numSamplesPerChannel,
    float** channelArray
);

#endif

/* clang-format on */

+33 −0
Original line number Diff line number Diff line
@@ -321,6 +321,38 @@ int16_t ivas_sba_get_spar_hoa_md_flag(
 *-------------------------------------------------------------------*/

void ivas_sba_zero_vert_comp(
#ifdef FLOAT_INTERFACE
    float* sba_data[],            /* i  : SBA signals                 */
#else
    float sba_data[][L_FRAME48k], /* i  : SBA signals                 */
#endif
    const int16_t sba_order,      /* i  : SBA order                   */
    const int16_t sba_planar,     /* i  : SBA planar flag             */
    const int16_t input_frame     /* i  : frame length                */
)
{
    int16_t i, j;

    /* Channels in the range i^2+1 to (i+1)^2 -1 are zeroed (retain only first and last channel for that order) */
    for ( i = 1; i <= sba_order; i++ )
    {
        /* Keep Z if not planar */
        if ( !sba_planar && i == 1 )
        {
            continue;
        }

        for ( j = ( i * i + 1 ); j < ( ( i + 1 ) * ( i + 1 ) - 1 ); j++ )
        {
            set_zero( sba_data[j], input_frame );
        }
    }

    return;
}

#ifdef FLOAT_INTERFACE
void ivas_sba_zero_vert_comp_old(
    float sba_data[][L_FRAME48k], /* i  : SBA signals                 */
    const int16_t sba_order,      /* i  : SBA order                   */
    const int16_t sba_planar,     /* i  : SBA planar flag             */
@@ -346,3 +378,4 @@ void ivas_sba_zero_vert_comp(

    return;
}
#endif
+32 −0
Original line number Diff line number Diff line
@@ -1218,3 +1218,35 @@ float rand_triangular_signed(
        return 0.5f - 0.5f * sqrtf( 1.0f - rand_val );
    }
}

#ifdef FLOAT_INTERFACE

void save_channel_pointers(
    float* linearBuffer,
    int16_t numChannels,
    int16_t numSamplesPerChannel,
    float** channelArray
)
{
    /* Save a pointer to the beginning of each channel in a linear buffer, so that 2D indexing into a 1D array is possible.
     *
     * With linearBuffer:       111111111111111122222222222222223333333333333333
     * Pointers:                ^               ^               ^
     *                          channelArray[0] |               |
     *                                          channelArray[1] |
     *                                                          channelArray[2]
     *
     * Example 2D indexing:     channelArray[1][3] - returns 4th sample of the second channel
     */

    int16_t i;

    for (i = 0; i < numChannels; ++i)
    {
        channelArray[i] = linearBuffer + i * numSamplesPerChannel;
    }

    return;
}

#endif
 No newline at end of file
Loading