diff --git a/README b/README index b75ef84aaaa1e268732facd4df4183ac2cf7bea0..589d119efce92a92431b9360f131c41150ae8e91 100644 --- a/README +++ b/README @@ -23,10 +23,10 @@ To build from the git repository, the following steps are necessary % make -Once you have compiled the codec, there will be a test_harmony executable in +Once you have compiled the codec, there will be a test_opus executable in the src/ directory. This can be in the following way: -% ./test_harmony 48000 1 960 80 input.sw output.sw +% ./test_opus 48000 1 960 80 input.sw output.sw The arguments are: 1) The sampling rate (only 48000 supported for now) diff --git a/configure.ac b/configure.ac index dd644889f25d508c690ecac0454413e6e2afb7cb..21d6b325683e48c38e8b9d75be398d252ab0070b 100644 --- a/configure.ac +++ b/configure.ac @@ -2,8 +2,8 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ([2.59]) -AC_INIT(src/harmony.h) -AM_INIT_AUTOMAKE(harmony,20100921) +AC_INIT(src/opus.h) +AM_INIT_AUTOMAKE(opus,20100921) # Checks for programs. AC_PROG_CC diff --git a/src/Makefile.am b/src/Makefile.am index f3f024004562c79630db2679e7adcd500bbc50aa..1eb239a1efeae48725ed523e86b98b83e2ff2459 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2,12 +2,12 @@ INCLUDES = -I$(top_srcdir)/celt/libcelt/ -I$(top_srcdir)/silk/interface lib_LTLIBRARIES = libietfcodec.la -libietfcodec_la_SOURCES = harmony_decoder.c harmony_encoder.c +libietfcodec_la_SOURCES = opus_decoder.c opus_encoder.c -noinst_HEADERS = harmony_decoder.h harmony_encoder.h +noinst_HEADERS = opus_decoder.h opus_encoder.h -pkginclude_HEADERS = harmony.h +pkginclude_HEADERS = opus.h -noinst_PROGRAMS = test_harmony -test_harmony_SOURCES = test_harmony.c $(top_srcdir)/silk/test/SKP_debug.c -test_harmony_LDADD = libietfcodec.la $(top_builddir)/celt/libcelt/libcelt0.la $(top_builddir)/silk/libSKP_SILK_SDK.la +noinst_PROGRAMS = test_opus +test_opus_SOURCES = test_opus.c $(top_srcdir)/silk/test/SKP_debug.c +test_opus_LDADD = libietfcodec.la $(top_builddir)/celt/libcelt/libcelt0.la $(top_builddir)/silk/libSKP_SILK_SDK.la diff --git a/src/framepack.c b/src/framepack.c index c7a84c0e435aa3628ef8ac587ac2e55c5959fd3b..21209ace235253fbf448403b6a92e5b2d9a4c5db 100644 --- a/src/framepack.c +++ b/src/framepack.c @@ -100,7 +100,7 @@ int count_frames(unsigned char *packet, int len) } #define MAX_FRAMES 256 -int harmony_merge_packets(unsigned char **packets, int *plen, int nb_packets, +int opus_merge_packets(unsigned char **packets, int *plen, int nb_packets, unsigned *output, int maxlen) { int i; diff --git a/src/harmony.h b/src/opus.h similarity index 63% rename from src/harmony.h rename to src/opus.h index ed8d1f34ff5878090d66ad8ade872c2f62a3f6e2..85578fa1893126f166b19b459484df0968219e92 100644 --- a/src/harmony.h +++ b/src/opus.h @@ -29,8 +29,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef HARMONY_H -#define HARMONY_H +#ifndef OPUS_H +#define OPUS_H #ifdef __cplusplus extern "C" { @@ -59,44 +59,44 @@ extern "C" { -#define HARMONY_SET_MODE_REQUEST 0 -#define HARMONY_SET_MODE(x) HARMONY_SET_MODE_REQUEST, __check_int(x) -#define HARMONY_GET_MODE_REQUEST 1 -#define HARMONY_GET_MODE(x) HARMONY_GET_MODE_REQUEST, __check_int_ptr(x) +#define OPUS_SET_MODE_REQUEST 0 +#define OPUS_SET_MODE(x) OPUS_SET_MODE_REQUEST, __check_int(x) +#define OPUS_GET_MODE_REQUEST 1 +#define OPUS_GET_MODE(x) OPUS_GET_MODE_REQUEST, __check_int_ptr(x) -#define HARMONY_SET_BANDWIDTH_REQUEST 2 -#define HARMONY_SET_BANDWIDTH(x) HARMONY_SET_BANDWIDTH_REQUEST, __check_int(x) -#define HARMONY_GET_BANDWIDTH_REQUEST 3 -#define HARMONY_GET_BANDWIDTH(x) HARMONY_GET_BANDWIDTH_REQUEST, __check_int_ptr(x) +#define OPUS_SET_BANDWIDTH_REQUEST 2 +#define OPUS_SET_BANDWIDTH(x) OPUS_SET_BANDWIDTH_REQUEST, __check_int(x) +#define OPUS_GET_BANDWIDTH_REQUEST 3 +#define OPUS_GET_BANDWIDTH(x) OPUS_GET_BANDWIDTH_REQUEST, __check_int_ptr(x) -#define HARMONY_SET_VBR_RATE_REQUEST 4 -#define HARMONY_SET_VBR_RATE(x) HARMONY_SET_VBR_RATE_REQUEST, __check_int(x) -#define HARMONY_GET_VBR_RATE_REQUEST 5 -#define HARMONY_GET_VBR_RATE(x) HARMONY_GET_VBR_RATE_REQUEST, __check_int_ptr(x) +#define OPUS_SET_VBR_RATE_REQUEST 4 +#define OPUS_SET_VBR_RATE(x) OPUS_SET_VBR_RATE_REQUEST, __check_int(x) +#define OPUS_GET_VBR_RATE_REQUEST 5 +#define OPUS_GET_VBR_RATE(x) OPUS_GET_VBR_RATE_REQUEST, __check_int_ptr(x) -typedef struct HarmonyEncoder HarmonyEncoder; -typedef struct HarmonyDecoder HarmonyDecoder; +typedef struct OpusEncoder OpusEncoder; +typedef struct OpusDecoder OpusDecoder; -HarmonyEncoder *harmony_encoder_create(int Fs); +OpusEncoder *opus_encoder_create(int Fs); -int harmony_encode(HarmonyEncoder *st, const short *pcm, int frame_size, +int opus_encode(OpusEncoder *st, const short *pcm, int frame_size, unsigned char *data, int bytes_per_packet); -void harmony_encoder_destroy(HarmonyEncoder *st); +void opus_encoder_destroy(OpusEncoder *st); -void harmony_encoder_ctl(HarmonyEncoder *st, int request, ...); +void opus_encoder_ctl(OpusEncoder *st, int request, ...); -HarmonyDecoder *harmony_decoder_create(int Fs); +OpusDecoder *opus_decoder_create(int Fs); -int harmony_decode(HarmonyDecoder *st, const unsigned char *data, int len, +int opus_decode(OpusDecoder *st, const unsigned char *data, int len, short *pcm, int frame_size); -void harmony_decoder_ctl(HarmonyDecoder *st, int request, ...); +void opus_decoder_ctl(OpusDecoder *st, int request, ...); -void harmony_decoder_destroy(HarmonyDecoder *st); +void opus_decoder_destroy(OpusDecoder *st); #ifdef __cplusplus } #endif -#endif /* HARMONY_H */ +#endif /* OPUS_H */ diff --git a/src/harmony_decoder.c b/src/opus_decoder.c similarity index 88% rename from src/harmony_decoder.c rename to src/opus_decoder.c index 7177d60e87af072a20d8b79ea5e19900108d9861..ded9c80f3ea1dcee230c7744cb2228026621f491 100644 --- a/src/harmony_decoder.c +++ b/src/opus_decoder.c @@ -36,18 +36,18 @@ #include <stdlib.h> #include <stdio.h> #include <stdarg.h> -#include "harmony_decoder.h" +#include "opus_decoder.h" #include "entdec.h" #include "modes.h" #include "SKP_Silk_SDK_API.h" -HarmonyDecoder *harmony_decoder_create(int Fs) +OpusDecoder *opus_decoder_create(int Fs) { char *raw_state; int ret, silkDecSizeBytes, celtDecSizeBytes; CELTMode *celtMode; - HarmonyDecoder *st; + OpusDecoder *st; /* We should not have to create a CELT mode for each encoder state */ celtMode = celt_mode_create(Fs, Fs/50, NULL); @@ -58,10 +58,10 @@ HarmonyDecoder *harmony_decoder_create(int Fs) /* Handle error */ } celtDecSizeBytes = celt_decoder_get_size(celtMode, 1); - raw_state = calloc(sizeof(HarmonyDecoder)+silkDecSizeBytes+celtDecSizeBytes, 1); - st = (HarmonyDecoder*)raw_state; - st->silk_dec = (void*)(raw_state+sizeof(HarmonyDecoder)); - st->celt_dec = (CELTDecoder*)(raw_state+sizeof(HarmonyDecoder)+silkDecSizeBytes); + raw_state = calloc(sizeof(OpusDecoder)+silkDecSizeBytes+celtDecSizeBytes, 1); + st = (OpusDecoder*)raw_state; + st->silk_dec = (void*)(raw_state+sizeof(OpusDecoder)); + st->celt_dec = (CELTDecoder*)(raw_state+sizeof(OpusDecoder)+silkDecSizeBytes); st->Fs = Fs; st->celt_mode = celtMode; @@ -78,7 +78,7 @@ HarmonyDecoder *harmony_decoder_create(int Fs) return st; } -int harmony_decode(HarmonyDecoder *st, const unsigned char *data, +int opus_decode(OpusDecoder *st, const unsigned char *data, int len, short *pcm, int frame_size) { int i, silk_ret=0, celt_ret=0; @@ -164,7 +164,7 @@ int harmony_decode(HarmonyDecoder *st, const unsigned char *data, } -void harmony_decoder_ctl(HarmonyDecoder *st, int request, ...) +void opus_decoder_ctl(OpusDecoder *st, int request, ...) { va_list ap; @@ -172,39 +172,39 @@ void harmony_decoder_ctl(HarmonyDecoder *st, int request, ...) switch (request) { - case HARMONY_SET_MODE_REQUEST: + case OPUS_SET_MODE_REQUEST: { int value = va_arg(ap, int); st->mode = value; } break; - case HARMONY_GET_MODE_REQUEST: + case OPUS_GET_MODE_REQUEST: { int *value = va_arg(ap, int*); *value = st->mode; } break; - case HARMONY_SET_BANDWIDTH_REQUEST: + case OPUS_SET_BANDWIDTH_REQUEST: { int value = va_arg(ap, int); st->bandwidth = value; } break; - case HARMONY_GET_BANDWIDTH_REQUEST: + case OPUS_GET_BANDWIDTH_REQUEST: { int *value = va_arg(ap, int*); *value = st->bandwidth; } break; default: - fprintf(stderr, "unknown harmony_decoder_ctl() request: %d", request); + fprintf(stderr, "unknown opus_decoder_ctl() request: %d", request); break; } va_end(ap); } -void harmony_decoder_destroy(HarmonyDecoder *st) +void opus_decoder_destroy(OpusDecoder *st) { celt_mode_destroy(st->celt_mode); diff --git a/src/harmony_decoder.h b/src/opus_decoder.h similarity index 93% rename from src/harmony_decoder.h rename to src/opus_decoder.h index 18f5c9ecd67869a80594b7f2d944a1f5e484f6ef..9bb81061507b7dcb82f9350cf98f4dd28df11884 100644 --- a/src/harmony_decoder.h +++ b/src/opus_decoder.h @@ -29,13 +29,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef HARMONY_DECODER_H -#define HARMONY_DECODER_H +#ifndef OPUS_DECODER_H +#define OPUS_DECODER_H #include "celt.h" -#include "harmony.h" +#include "opus.h" -struct HarmonyDecoder { +struct OpusDecoder { CELTMode *celt_mode; CELTDecoder *celt_dec; void *silk_dec; @@ -47,5 +47,5 @@ struct HarmonyDecoder { }; -#endif /* HARMONY_DECODER_H */ +#endif /* OPUS_DECODER_H */ diff --git a/src/harmony_encoder.c b/src/opus_encoder.c similarity index 88% rename from src/harmony_encoder.c rename to src/opus_encoder.c index 569eb7a359d25c6691645c2e6354407eb65f200a..e15f94ba8d2f982258240fe65a2cf5db077242d4 100644 --- a/src/harmony_encoder.c +++ b/src/opus_encoder.c @@ -36,16 +36,16 @@ #include <stdlib.h> #include <stdio.h> #include <stdarg.h> -#include "harmony_encoder.h" +#include "opus_encoder.h" #include "entenc.h" #include "modes.h" #include "SKP_Silk_SDK_API.h" -HarmonyEncoder *harmony_encoder_create(int Fs) +OpusEncoder *opus_encoder_create(int Fs) { char *raw_state; CELTMode *celtMode; - HarmonyEncoder *st; + OpusEncoder *st; int ret, silkEncSizeBytes, celtEncSizeBytes; SKP_SILK_SDK_EncControlStruct encControl; @@ -58,10 +58,10 @@ HarmonyEncoder *harmony_encoder_create(int Fs) /* Handle error */ } celtEncSizeBytes = celt_encoder_get_size(celtMode, 1); - raw_state = calloc(sizeof(HarmonyEncoder)+silkEncSizeBytes+celtEncSizeBytes, 1); - st = (HarmonyEncoder*)raw_state; - st->silk_enc = (void*)(raw_state+sizeof(HarmonyEncoder)); - st->celt_enc = (CELTEncoder*)(raw_state+sizeof(HarmonyEncoder)+silkEncSizeBytes); + raw_state = calloc(sizeof(OpusEncoder)+silkEncSizeBytes+celtEncSizeBytes, 1); + st = (OpusEncoder*)raw_state; + st->silk_enc = (void*)(raw_state+sizeof(OpusEncoder)); + st->celt_enc = (CELTEncoder*)(raw_state+sizeof(OpusEncoder)+silkEncSizeBytes); st->Fs = Fs; st->celt_mode = celtMode; @@ -87,7 +87,7 @@ HarmonyEncoder *harmony_encoder_create(int Fs) return st; } -int harmony_encode(HarmonyEncoder *st, const short *pcm, int frame_size, +int opus_encode(OpusEncoder *st, const short *pcm, int frame_size, unsigned char *data, int bytes_per_packet) { int i; @@ -199,7 +199,7 @@ int harmony_encode(HarmonyEncoder *st, const short *pcm, int frame_size, data[0] = 0x80; data[0] |= tmp << 5; data[0] |= period<<3; - } else /* Harmony */ + } else /* Opus */ { data[0] = 0x60; data[0] |= (st->bandwidth-BANDWIDTH_SUPERWIDEBAND)<<4; @@ -210,7 +210,7 @@ int harmony_encode(HarmonyEncoder *st, const short *pcm, int frame_size, return ret+1; } -void harmony_encoder_ctl(HarmonyEncoder *st, int request, ...) +void opus_encoder_ctl(OpusEncoder *st, int request, ...) { va_list ap; @@ -218,51 +218,51 @@ void harmony_encoder_ctl(HarmonyEncoder *st, int request, ...) switch (request) { - case HARMONY_SET_MODE_REQUEST: + case OPUS_SET_MODE_REQUEST: { int value = va_arg(ap, int); st->mode = value; } break; - case HARMONY_GET_MODE_REQUEST: + case OPUS_GET_MODE_REQUEST: { int *value = va_arg(ap, int*); *value = st->mode; } break; - case HARMONY_SET_BANDWIDTH_REQUEST: + case OPUS_SET_BANDWIDTH_REQUEST: { int value = va_arg(ap, int); st->bandwidth = value; } break; - case HARMONY_GET_BANDWIDTH_REQUEST: + case OPUS_GET_BANDWIDTH_REQUEST: { int *value = va_arg(ap, int*); *value = st->bandwidth; } break; - case HARMONY_SET_VBR_RATE_REQUEST: + case OPUS_SET_VBR_RATE_REQUEST: { int value = va_arg(ap, int); st->vbr_rate = value; } break; - case HARMONY_GET_VBR_RATE_REQUEST: + case OPUS_GET_VBR_RATE_REQUEST: { int *value = va_arg(ap, int*); *value = st->vbr_rate; } break; default: - fprintf(stderr, "unknown harmony_encoder_ctl() request: %d", request); + fprintf(stderr, "unknown opus_encoder_ctl() request: %d", request); break; } va_end(ap); } -void harmony_encoder_destroy(HarmonyEncoder *st) +void opus_encoder_destroy(OpusEncoder *st) { celt_mode_destroy(st->celt_mode); free(st); diff --git a/src/harmony_encoder.h b/src/opus_encoder.h similarity index 93% rename from src/harmony_encoder.h rename to src/opus_encoder.h index 045d273347a25902b568cd031f50873a8717f436..8c952abb1119e289c04b985531c7c9df340e1a00 100644 --- a/src/harmony_encoder.h +++ b/src/opus_encoder.h @@ -29,17 +29,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef HARMONY_ENCODER_H -#define HARMONY_ENCODER_H +#ifndef OPUS_ENCODER_H +#define OPUS_ENCODER_H #include "celt.h" -#include "harmony.h" +#include "opus.h" #include "SKP_Silk_SDK_API.h" /* FIXME: This is only valid for 48 kHz */ #define ENCODER_DELAY_COMPENSATION 130 -struct HarmonyEncoder { +struct OpusEncoder { CELTMode *celt_mode; CELTEncoder *celt_enc; void *silk_enc; @@ -54,5 +54,5 @@ struct HarmonyEncoder { }; -#endif /* HARMONY_ENCODER_H */ +#endif /* OPUS_ENCODER_H */ diff --git a/src/test_harmony.c b/src/test_opus.c similarity index 85% rename from src/test_harmony.c rename to src/test_opus.c index 6c873ce764ab458774e75ec878845304375efc37..5dbca2095ea08d5345772aa83426280dddb842bd 100644 --- a/src/test_harmony.c +++ b/src/test_opus.c @@ -38,7 +38,7 @@ #include <stdlib.h> #include <math.h> #include <string.h> -#include "harmony.h" +#include "opus.h" #define MAX_PACKET 1024 @@ -48,8 +48,8 @@ int main(int argc, char *argv[]) int err; char *inFile, *outFile; FILE *fin, *fout; - HarmonyEncoder *enc; - HarmonyDecoder *dec; + OpusEncoder *enc; + OpusDecoder *dec; int len; int frame_size, channels; int bytes_per_packet; @@ -66,7 +66,7 @@ int main(int argc, char *argv[]) double bits=0; if (argc != 9 && argc != 8 && argc != 7) { - fprintf (stderr, "Usage: test_harmony <rate (kHz)> <channels> <frame size> " + fprintf (stderr, "Usage: test_opus <rate (kHz)> <channels> <frame size> " " <bytes per packet> [<VBR rate (kb/s)>] [<packet loss rate>] " "<input> <output>\n"); return 1; @@ -105,15 +105,15 @@ int main(int argc, char *argv[]) return 1; } - enc = harmony_encoder_create(rate); - dec = harmony_decoder_create(rate); + enc = opus_encoder_create(rate); + dec = opus_decoder_create(rate); mode = MODE_HYBRID; - harmony_encoder_ctl(enc, HARMONY_SET_BANDWIDTH(BANDWIDTH_FULLBAND)); - harmony_encoder_ctl(enc, HARMONY_SET_MODE(mode)); + opus_encoder_ctl(enc, OPUS_SET_BANDWIDTH(BANDWIDTH_FULLBAND)); + opus_encoder_ctl(enc, OPUS_SET_MODE(mode)); if (vbr) - harmony_encoder_ctl(enc, HARMONY_SET_VBR_RATE(vbr)); + opus_encoder_ctl(enc, OPUS_SET_VBR_RATE(vbr)); skip = 5*rate/1000 + 10; @@ -130,14 +130,14 @@ int main(int argc, char *argv[]) for (i=err;i<frame_size*channels;i++) in[i] = 0; } - len = harmony_encode(enc, in, frame_size, data, bytes_per_packet); + len = opus_encode(enc, in, frame_size, data, bytes_per_packet); if (len <= 0) { - fprintf (stderr, "harmony_encode() returned %d\n", len); + fprintf (stderr, "opus_encode() returned %d\n", len); return 1; } bits += len*8; - harmony_decode(dec, rand()%100<loss ? NULL : data, len, out, frame_size); + opus_decode(dec, rand()%100<loss ? NULL : data, len, out, frame_size); count++; tot_written += (frame_size-skip)*channels; write_samples = frame_size; @@ -150,8 +150,8 @@ int main(int argc, char *argv[]) skip = 0; } fprintf (stderr, "average bit-rate: %f kb/s\n", bits*rate/(frame_size*(double)count)); - harmony_encoder_destroy(enc); - harmony_decoder_destroy(dec); + opus_encoder_destroy(enc); + opus_decoder_destroy(dec); fclose(fin); fclose(fout); free(in);