Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions code/dep_codecs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include(ExternalProject)
ExternalProject_Add(
dep_opus
URL https://downloads.xiph.org/releases/opus/opus-1.4.tar.gz
CMAKE_ARGS -DBUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_INSTALL_PREFIX=${DEP_CODECS_DIR} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} -DCMAKE_POLICY_VERSION_MINIMUM=3.5
CMAKE_ARGS -DBUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${DEP_CODECS_DIR} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} -DCMAKE_POLICY_VERSION_MINIMUM=3.5
)

# Fetch fdk-aac(2.0.3) library
Expand All @@ -17,13 +17,13 @@ ExternalProject_Add(
GIT_REPOSITORY https://github.com/mstorsjo/fdk-aac.git
GIT_TAG 716f4394641d53f0d79c9ddac3fa93b03a49f278
PATCH_COMMAND ${CMAKE_COMMAND} -E make_directory <SOURCE_DIR>/libSBRdec/include/log && ${CMAKE_COMMAND} -E echo "void android_errorWriteLog(int i, const char *string){}" > <SOURCE_DIR>/libSBRdec/include/log/log.h
CMAKE_ARGS -DBUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_INSTALL_PREFIX=${DEP_CODECS_DIR} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
CMAKE_ARGS -DBUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${DEP_CODECS_DIR} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
)

# Fetch flac library
include(ExternalProject)
ExternalProject_Add(
dep_flac
URL https://downloads.xiph.org/releases/flac/flac-1.4.2.tar.xz
CMAKE_ARGS -DBUILD_SHARED_LIBS=OFF -DWITH_OGG=OFF -DBUILD_CXXLIBS=OFF -DINSTALL_MANPAGES=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_INSTALL_PREFIX=${DEP_CODECS_DIR} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
CMAKE_ARGS -DBUILD_SHARED_LIBS=OFF -DWITH_OGG=OFF -DBUILD_CXXLIBS=OFF -DINSTALL_MANPAGES=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${DEP_CODECS_DIR} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
)
6 changes: 3 additions & 3 deletions code/src/iamf_dec/audio_effect_peak_limiter.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ void audio_effect_peak_limiter_uninit(AudioEffectPeakLimiter* ths) {
}

void audio_effect_peak_limiter_destroy(AudioEffectPeakLimiter* ths) {
if (!ths) return;
audio_effect_peak_limiter_uninit(ths);
if (ths) free(ths);
free(ths);
}

// threshold_db: Peak threshold in dB
Expand Down Expand Up @@ -90,7 +91,6 @@ int audio_effect_peak_limiter_process_block(AudioEffectPeakLimiter* ths,
float peak;
float channel_peak = 0.0f;
float gain;
int k;
float peakMax = 0.0f;
float* audioBlock = outblock;
float out;
Expand All @@ -103,7 +103,7 @@ int audio_effect_peak_limiter_process_block(AudioEffectPeakLimiter* ths,

#define DB_IDX(i) ((i) % ths->delayBufferSize)

for (k = 0; k < frame_size; k++) {
for (int k = 0; k < frame_size; k++) {
peak = 0.0f;
idx = k + ths->entryIndex;
#ifndef OLD_CODE
Expand Down
9 changes: 3 additions & 6 deletions code/src/iamf_dec/audio_effect_peak_limiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ This software module is out of scope and not part of the IAMF Final Deliverable.

#define USE_TRUEPEAK 0

#define MAX_OUTPUT_CHANNELS 24
#define MAX_DELAYSIZE 4096

#if USE_TRUEPEAK
#include "audio_true_peak_meter.h"
#endif
Expand Down Expand Up @@ -76,15 +73,15 @@ AudioEffectPeakLimiter* audio_effect_peak_limiter_create(void);
/**
* @brief Initialize the peak limiter.
* @param [in] ths : the peak limiter handle
* @param [in] threashold_db : peak threshold in dB
* @param [in] threshold_db : peak threshold in dB
* @param [in] sample_rate : sample rate of audio signal
* @param [in] num_channels : number of channels in frame
* @param [in] atk_sec : attack duration in seconds
* @param [in] atk_sec : release duration in seconds
* @param [in] rel_sec : release duration in seconds
* @param [in] delay_size : number of samples in delay buffer
*/
void audio_effect_peak_limiter_init(AudioEffectPeakLimiter* ths,
float threashold_db, int sample_rate,
float threshold_db, int sample_rate,
int num_channels, float atk_sec,
float rel_sec, int delay_size);

Expand Down
2 changes: 1 addition & 1 deletion code/src/iamf_dec/codec/aac/aac_multistream_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct AacMsDecoder {
};

typedef void (*func_aac_copy_channel_out_t)(void *dst, const void *src,
int frame_size, int channes);
int frame_size, int channels);

void aac_copy_channel_out_short_plane(void *dst, const void *src,
int frame_size, int channels) {
Expand Down
9 changes: 4 additions & 5 deletions code/src/iamf_dec/codec/aac/iamf_aac_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ static int iamf_aac_init(iamf_codec_context_t *ths) {
ck_audio_frame_planar, &ret);
if (!ctx->dec) return IAMF_ERR_INVALID_STATE;

ctx->out = (short *)malloc(sizeof(short) * def_max_aac_frame_size *
(ths->streams + ths->coupled_streams));
ctx->out = def_malloc(
short, (def_max_aac_frame_size) * (ths->streams + ths->coupled_streams));
if (!ctx->out) {
iamf_aac_close(ths);
return IAMF_ERR_ALLOC_FAIL;
Expand Down Expand Up @@ -136,9 +136,8 @@ int iamf_aac_close(iamf_codec_context_t *ths) {
aac_multistream_decoder_close(dec);
ctx->dec = 0;
}
if (ctx->out) {
free(ctx->out);
}
def_free(ctx->out);
ctx->out = 0;

return IAMF_OK;
}
Expand Down
26 changes: 17 additions & 9 deletions code/src/iamf_dec/codec/flac/flac_multistream_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/**
* @file flac_multistream_decoder.c
* @brief FLAC decoder.
* @version 0.1
* @version 2.0.0
* @date Created 03/03/2023
**/

Expand Down Expand Up @@ -47,7 +47,7 @@ typedef struct FlacDecoderHandle {
uint8_t *packet;
uint32_t packet_size;
uint32_t fs;
int buffer[def_max_flac_frame_size];
int buffer[def_max_flac_frame_size * 2];
} flac_decoder_handle_t;

typedef struct FlacMsDecoder {
Expand Down Expand Up @@ -146,17 +146,28 @@ static int flac_header_set_channels(uint8_t *h, uint32_t size, int n) {
static int flac_multistream_decode_native(flac_ms_decoder_t *st,
uint8_t *buffer[], uint32_t size[],
void *pcm, int frame_size) {
flac_decoder_handle_t *handle = NULL;
char *out = (char *)pcm;
int ss = 0;

if (st->streams < 1) {
error("invalid streams count: %d", st->streams);
return IAMF_ERR_BAD_ARG;
}

for (int i = 0; i < st->streams; ++i) {
flac_decoder_handle_t *handle = &st->handles[i];
trace("stream %d", i);
handle = &st->handles[i];
handle->packet = buffer[i];
handle->packet_size = size[i];
handle->fs = 0;

if (!FLAC__stream_decoder_process_single(handle->dec)) {
error("flac decode failed at stream %d", i);
return IAMF_ERR_INTERNAL;
}

if (handle->fs == 0) {
error("no output from stream %d (write callback not invoked)", i);
return IAMF_ERR_INTERNAL;
}

Expand All @@ -167,11 +178,8 @@ static int flac_multistream_decode_native(flac_ms_decoder_t *st,
memcpy(out, handle->buffer, ss);
out += ss;
}
if (!handle) {
return IAMF_ERR_BAD_ARG;
} else {
return handle->fs;
}

return st->handles[st->streams - 1].fs;
}

flac_ms_decoder_t *flac_multistream_decoder_open(uint8_t *config, uint32_t size,
Expand Down
12 changes: 6 additions & 6 deletions code/src/iamf_dec/codec/flac/iamf_flac_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/**
* @file IAMF_flac_decoder.c
* @brief flac codec.
* @version 0.1
* @version 2.0.0
* @date Created 03/03/2023
**/

Expand Down Expand Up @@ -64,11 +64,11 @@ static int iamf_flac_init(iamf_codec_context_t *ths) {
return IAMF_ERR_INTERNAL;
}

ctx->scale_i2f = 1 << (bits - 1);
ctx->scale_i2f = (float)(1u << (bits - 1));
debug("the scale of i%d to float : %f", bits, ctx->scale_i2f);

ctx->out = def_malloc(
int, def_max_flac_frame_size *(ths->streams + ths->coupled_streams));
int, (def_max_flac_frame_size) * (ths->streams + ths->coupled_streams));
if (!ctx->out) {
iamf_flac_close(ths);
return IAMF_ERR_ALLOC_FAIL;
Expand Down Expand Up @@ -108,9 +108,9 @@ int iamf_flac_close(iamf_codec_context_t *ths) {
flac_multistream_decoder_close(dec);
ctx->dec = 0;
}
if (ctx->out) {
free(ctx->out);
}

def_free(ctx->out);
ctx->out = 0;

return IAMF_OK;
}
Expand Down
17 changes: 8 additions & 9 deletions code/src/iamf_dec/codec/opus/iamf_opus_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ static int iamf_opus_close(iamf_codec_context_t *ths);
* */
static int iamf_opus_init(iamf_codec_context_t *ths) {
iamf_opus_context_t *ctx = (iamf_opus_context_t *)ths->priv;
int ec = IAMF_OK;
int ret = 0;

ths->sample_rate = 48000;
Expand All @@ -81,18 +80,18 @@ static int iamf_opus_init(iamf_codec_context_t *ths) {
ths->coupled_streams,
ck_audio_frame_planar, &ret);
if (!ctx->dec) {
error("fail to open opus decoder.");
ec = IAMF_ERR_INVALID_STATE;
error("fail to open opus decoder, error=%d.", ret);
return IAMF_ERR_INVALID_STATE;
}

ctx->out = (short *)malloc(sizeof(short) * def_max_opus_frame_size *
(ths->streams + ths->coupled_streams));
ctx->out = def_malloc(
short, (def_max_opus_frame_size) * (ths->streams + ths->coupled_streams));
if (!ctx->out) {
iamf_opus_close(ths);
return IAMF_ERR_ALLOC_FAIL;
}

return ec;
return IAMF_OK;
}

static int iamf_opus_decode(iamf_codec_context_t *ths, uint8_t *buf[],
Expand Down Expand Up @@ -125,9 +124,9 @@ int iamf_opus_close(iamf_codec_context_t *ths) {
ctx->dec = 0;
}

if (ctx->out) {
free(ctx->out);
}
def_free(ctx->out);
ctx->out = 0;

return IAMF_OK;
}

Expand Down
11 changes: 5 additions & 6 deletions code/src/iamf_dec/codec/opus/opus_multistream2_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/**
* @file opus_multistream2_decoder.c
* @brief opus decoder.
* @version 0.1
* @version 2.0.0
* @date Created 03/03/2023
**/

Expand Down Expand Up @@ -135,7 +135,8 @@ static int opus_multistream2_decoder_decode_native(

trace("stream %d decoded result %d", s, ret);
if (ret <= 0) {
return ret;
error("opus_decode failed for stream %d: %d", s, ret);
return IAMF_ERR_INVALID_PACKET;
}
frame_size = ret;
if (s < st->coupled_streams) {
Expand Down Expand Up @@ -207,14 +208,12 @@ int opus_multistream2_decode(Opus_Ms2_Decoder_t *st, uint8_t *buffer[],
return opus_multistream2_decoder_decode_native(
st, buffer, (opus_int32 *)size, pcm, frame_size,
opus_copy_channel_out_short_plane);
warning("flag is 0x%x, is not implmented.", st->flags);
warning("flag is 0x%x, is not implemented.", st->flags);
return IAMF_ERR_UNIMPLEMENTED;
}

void opus_multistream2_decoder_destroy(Opus_Ms2_Decoder_t *st) {
if (st->buffer) {
free(st->buffer);
}
def_free(st->buffer);
free(st);
}
#endif
4 changes: 2 additions & 2 deletions code/src/iamf_dec/codec/pcm/iamf_pcm_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/**
* @file IAMF_pcm_decoder.c
* @brief pcm codec.
* @version 0.1
* @version 2.0.0
* @date Created 03/03/2023
**/

Expand Down Expand Up @@ -55,7 +55,7 @@ static uint32_t readu24be(uint8_t *data, int offset) {
}

static int reads24be(uint8_t *data, int offset) {
uint32_t ret = readu16le(data, offset) << 8 | data[offset + 2];
uint32_t ret = readu16be(data, offset) << 8 | data[offset + 2];
int iret = ret << 8;
return (iret >> 8);
}
Expand Down
5 changes: 0 additions & 5 deletions code/src/iamf_dec/common/cbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ typedef struct CBufferWrap {
uint32_t size;
} buffer_wrap_t;

typedef struct CBufferIOWrap {
buffer_t* buf;
io_context_t ioctx;
} buffer_io_wrap_t;

buffer_wrap_t* buffer_wrap_default_new();
buffer_wrap_t* buffer_wrap_new(uint32_t size);

Expand Down
14 changes: 6 additions & 8 deletions code/src/iamf_dec/demixer.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/**
* @file demixer.c
* @brief Demixer.
* @version 0.1
* @version 2.0.0
* @date Created 03/03/2023
**/

Expand Down Expand Up @@ -68,7 +68,6 @@ struct Demixer {
float *start_window;
float *stop_window;
float *large_buffer;
float ch_last_sf[ck_iamf_channel_count];
float ch_last_sfavg[ck_iamf_channel_count];

iamf_loudspeaker_layout_t layout;
Expand Down Expand Up @@ -469,7 +468,7 @@ static int dmx_demix(Demixer *ths) {
}

static void dmx_rms(Demixer *ths) {
float N = 7; // 7 frame
float N = 7.0f; // 7 frame
float sf, sfavg;
float filtBuf;
float *out;
Expand All @@ -483,7 +482,8 @@ static void dmx_rms(Demixer *ths) {
out = ths->ch_data[ch];

if (N > 0) {
sfavg = (2 / (N + 1)) * sf + (1 - 2 / (N + 1)) * ths->ch_last_sfavg[ch];
sfavg = (2.0f / (N + 1.0f)) * sf +
(1.0f - 2.0f / (N + 1.0f)) * ths->ch_last_sfavg[ch];
} else {
sfavg = sf;
}
Expand All @@ -497,7 +497,6 @@ static void dmx_rms(Demixer *ths) {
out[i] *= filtBuf;
}

ths->ch_last_sf[ch] = sf;
ths->ch_last_sfavg[ch] = sfavg;
}
}
Expand Down Expand Up @@ -538,7 +537,6 @@ Demixer *demixer_open(uint32_t frame_size) {
}

for (int i = 0; i < ck_iamf_channel_count; ++i) {
ths->ch_last_sf[i] = 1.0;
ths->ch_last_sfavg[i] = 1.0;
}
}
Expand All @@ -558,7 +556,7 @@ void demixer_close(Demixer *ths) {
def_free(ths->start_window);
def_free(ths->stop_window);
def_free(ths->large_buffer);
free(ths);
def_free(ths);
}
}

Expand Down Expand Up @@ -648,7 +646,7 @@ int demixer_set_demixing_info(Demixer *ths, int mode, int w_idx) {

int demixer_set_recon_gain(Demixer *ths, int count, iamf_channel_t *chs,
float *recon_gain, uint32_t flags) {
if (flags && flags ^ ths->chs_recon_gain_list.flags) {
if (flags != ths->chs_recon_gain_list.flags) {
for (int i = 0; i < count; ++i) {
ths->chs_recon_gain_list.ch_recon_gain[i].ch = chs[i];
}
Expand Down
Loading
Loading