diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2025-08-15 12:42:40 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2025-08-15 12:42:40 +0200 |
| commit | 30325d24d107dbf133da39f7c96d1510fd1c9449 (patch) | |
| tree | 932baa5b2a4475821f16dccf9e3e05011daa6d92 /codec2.h | |
| parent | 9022d768021bbe15c7815cc6f8b64218b46f0e10 (diff) | |
Bump to codec2 version 1.2.0erdgeist-bump-to-1.2.0
Diffstat (limited to 'codec2.h')
| -rw-r--r-- | codec2.h | 102 |
1 files changed, 46 insertions, 56 deletions
| @@ -26,26 +26,22 @@ | |||
| 26 | along with this program; if not, see <http://www.gnu.org/licenses/>. | 26 | along with this program; if not, see <http://www.gnu.org/licenses/>. |
| 27 | */ | 27 | */ |
| 28 | 28 | ||
| 29 | #ifndef __CODEC2__ | ||
| 30 | #define __CODEC2__ | ||
| 31 | #include "version.h" | ||
| 32 | #include <stdbool.h> | ||
| 33 | |||
| 29 | #ifdef __cplusplus | 34 | #ifdef __cplusplus |
| 30 | extern "C" { | 35 | extern "C" { |
| 31 | #endif | 36 | #endif |
| 32 | 37 | ||
| 33 | #ifndef __CODEC2__ | 38 | #define CODEC2_MODE_3200 0 |
| 34 | #define __CODEC2__ | 39 | #define CODEC2_MODE_2400 1 |
| 35 | 40 | #define CODEC2_MODE_1600 2 | |
| 36 | #include <version.h> | 41 | #define CODEC2_MODE_1400 3 |
| 37 | 42 | #define CODEC2_MODE_1300 4 | |
| 38 | #define CODEC2_MODE_3200 0 | 43 | #define CODEC2_MODE_1200 5 |
| 39 | #define CODEC2_MODE_2400 1 | 44 | #define CODEC2_MODE_700C 8 |
| 40 | #define CODEC2_MODE_1600 2 | ||
| 41 | #define CODEC2_MODE_1400 3 | ||
| 42 | #define CODEC2_MODE_1300 4 | ||
| 43 | #define CODEC2_MODE_1200 5 | ||
| 44 | #define CODEC2_MODE_700 6 | ||
| 45 | #define CODEC2_MODE_700B 7 | ||
| 46 | #define CODEC2_MODE_700C 8 | ||
| 47 | #define CODEC2_MODE_450 10 | ||
| 48 | #define CODEC2_MODE_450PWB 11 | ||
| 49 | 45 | ||
| 50 | #ifndef CODEC2_MODE_EN_DEFAULT | 46 | #ifndef CODEC2_MODE_EN_DEFAULT |
| 51 | #define CODEC2_MODE_EN_DEFAULT 1 | 47 | #define CODEC2_MODE_EN_DEFAULT 1 |
| @@ -55,76 +51,70 @@ | |||
| 55 | // disable during compile time with -DCODEC2_MODE_1600_EN=0 | 51 | // disable during compile time with -DCODEC2_MODE_1600_EN=0 |
| 56 | // all but CODEC2 1600 are enabled then | 52 | // all but CODEC2 1600 are enabled then |
| 57 | 53 | ||
| 58 | //or the other way round | 54 | // or the other way round |
| 59 | // -DCODEC2_MODE_EN_DEFAULT=0 -DCODEC2_MODE_1600_EN=1 | 55 | // -DCODEC2_MODE_EN_DEFAULT=0 -DCODEC2_MODE_1600_EN=1 |
| 60 | // only CODEC2 Mode 1600 | 56 | // only CODEC2 Mode 1600 |
| 61 | 57 | ||
| 62 | #if !defined(CODEC2_MODE_3200_EN) | 58 | #if !defined(CODEC2_MODE_3200_EN) |
| 63 | #define CODEC2_MODE_3200_EN CODEC2_MODE_EN_DEFAULT | 59 | #define CODEC2_MODE_3200_EN CODEC2_MODE_EN_DEFAULT |
| 64 | #endif | 60 | #endif |
| 65 | #if !defined(CODEC2_MODE_2400_EN) | 61 | #if !defined(CODEC2_MODE_2400_EN) |
| 66 | #define CODEC2_MODE_2400_EN CODEC2_MODE_EN_DEFAULT | 62 | #define CODEC2_MODE_2400_EN CODEC2_MODE_EN_DEFAULT |
| 67 | #endif | 63 | #endif |
| 68 | #if !defined(CODEC2_MODE_1600_EN) | 64 | #if !defined(CODEC2_MODE_1600_EN) |
| 69 | #define CODEC2_MODE_1600_EN CODEC2_MODE_EN_DEFAULT | 65 | #define CODEC2_MODE_1600_EN CODEC2_MODE_EN_DEFAULT |
| 70 | #endif | 66 | #endif |
| 71 | #if !defined(CODEC2_MODE_1400_EN) | 67 | #if !defined(CODEC2_MODE_1400_EN) |
| 72 | #define CODEC2_MODE_1400_EN CODEC2_MODE_EN_DEFAULT | 68 | #define CODEC2_MODE_1400_EN CODEC2_MODE_EN_DEFAULT |
| 73 | #endif | 69 | #endif |
| 74 | #if !defined(CODEC2_MODE_1300_EN) | 70 | #if !defined(CODEC2_MODE_1300_EN) |
| 75 | #define CODEC2_MODE_1300_EN CODEC2_MODE_EN_DEFAULT | 71 | #define CODEC2_MODE_1300_EN CODEC2_MODE_EN_DEFAULT |
| 76 | #endif | 72 | #endif |
| 77 | #if !defined(CODEC2_MODE_1200_EN) | 73 | #if !defined(CODEC2_MODE_1200_EN) |
| 78 | #define CODEC2_MODE_1200_EN CODEC2_MODE_EN_DEFAULT | 74 | #define CODEC2_MODE_1200_EN CODEC2_MODE_EN_DEFAULT |
| 79 | #endif | ||
| 80 | #if !defined(CODEC2_MODE_700_EN) | ||
| 81 | #define CODEC2_MODE_700_EN CODEC2_MODE_EN_DEFAULT | ||
| 82 | #endif | ||
| 83 | #if !defined(CODEC2_MODE_700B_EN) | ||
| 84 | #define CODEC2_MODE_700B_EN CODEC2_MODE_EN_DEFAULT | ||
| 85 | #endif | 75 | #endif |
| 86 | #if !defined(CODEC2_MODE_700C_EN) | 76 | #if !defined(CODEC2_MODE_700C_EN) |
| 87 | #define CODEC2_MODE_700C_EN CODEC2_MODE_EN_DEFAULT | 77 | #define CODEC2_MODE_700C_EN CODEC2_MODE_EN_DEFAULT |
| 88 | #endif | ||
| 89 | #if !defined(CODEC2_MODE_450_EN) | ||
| 90 | #define CODEC2_MODE_450_EN CODEC2_MODE_EN_DEFAULT | ||
| 91 | #endif | ||
| 92 | #if !defined(CODEC2_MODE_450PWB_EN) | ||
| 93 | #define CODEC2_MODE_450PWB_EN CODEC2_MODE_EN_DEFAULT | ||
| 94 | #endif | 78 | #endif |
| 95 | 79 | ||
| 96 | #define CODEC2_MODE_ACTIVE(mode_name, var) ((mode_name##_EN) == 0 ? 0: (var) == mode_name) | 80 | #define CODEC2_MODE_ACTIVE(mode_name, var) \ |
| 81 | ((mode_name##_EN) == 0 ? 0 : (var) == mode_name) | ||
| 97 | 82 | ||
| 98 | struct CODEC2; | 83 | struct CODEC2; |
| 99 | 84 | ||
| 100 | struct CODEC2 * codec2_create(int mode); | 85 | struct CODEC2 *codec2_create(int mode); |
| 101 | void codec2_destroy(struct CODEC2 *codec2_state); | 86 | void codec2_destroy(struct CODEC2 *codec2_state); |
| 102 | void codec2_encode(struct CODEC2 *codec2_state, unsigned char * bits, short speech_in[]); | 87 | void codec2_encode(struct CODEC2 *codec2_state, unsigned char bytes[], |
| 103 | void codec2_decode(struct CODEC2 *codec2_state, short speech_out[], const unsigned char *bits); | 88 | short speech_in[]); |
| 104 | void codec2_decode_ber(struct CODEC2 *codec2_state, short speech_out[], const unsigned char *bits, float ber_est); | 89 | void codec2_decode(struct CODEC2 *codec2_state, short speech_out[], |
| 105 | int codec2_samples_per_frame(struct CODEC2 *codec2_state); | 90 | const unsigned char bytes[]); |
| 106 | int codec2_bits_per_frame(struct CODEC2 *codec2_state); | 91 | void codec2_decode_ber(struct CODEC2 *codec2_state, short speech_out[], |
| 107 | 92 | const unsigned char *bytes, float ber_est); | |
| 108 | void codec2_set_lpc_post_filter(struct CODEC2 *codec2_state, int enable, int bass_boost, float beta, float gamma); | 93 | int codec2_samples_per_frame(struct CODEC2 *codec2_state); |
| 109 | int codec2_get_spare_bit_index(struct CODEC2 *codec2_state); | 94 | int codec2_bits_per_frame(struct CODEC2 *codec2_state); |
| 110 | int codec2_rebuild_spare_bit(struct CODEC2 *codec2_state, int unpacked_bits[]); | 95 | int codec2_bytes_per_frame(struct CODEC2 *codec2_state); |
| 96 | |||
| 97 | void codec2_set_lpc_post_filter(struct CODEC2 *codec2_state, int enable, | ||
| 98 | int bass_boost, float beta, float gamma); | ||
| 99 | int codec2_get_spare_bit_index(struct CODEC2 *codec2_state); | ||
| 100 | int codec2_rebuild_spare_bit(struct CODEC2 *codec2_state, char unpacked_bits[]); | ||
| 111 | void codec2_set_natural_or_gray(struct CODEC2 *codec2_state, int gray); | 101 | void codec2_set_natural_or_gray(struct CODEC2 *codec2_state, int gray); |
| 112 | void codec2_set_softdec(struct CODEC2 *c2, float *softdec); | 102 | void codec2_set_softdec(struct CODEC2 *c2, float *softdec); |
| 113 | float codec2_get_energy(struct CODEC2 *codec2_state, const unsigned char *bits); | 103 | float codec2_get_energy(struct CODEC2 *codec2_state, const unsigned char *bits); |
| 114 | 104 | ||
| 115 | // support for ML and VQ experiments | 105 | // support for ML and VQ experiments |
| 116 | void codec2_open_mlfeat(struct CODEC2 *codec2_state, char *filename); | 106 | void codec2_open_mlfeat(struct CODEC2 *codec2_state, char *feat_filename, |
| 107 | char *model_filename); | ||
| 117 | void codec2_load_codebook(struct CODEC2 *codec2_state, int num, char *filename); | 108 | void codec2_load_codebook(struct CODEC2 *codec2_state, int num, char *filename); |
| 118 | float codec2_get_var(struct CODEC2 *codec2_state); | 109 | float codec2_get_var(struct CODEC2 *codec2_state); |
| 119 | float *codec2_enable_user_ratek(struct CODEC2 *codec2_state, int *K); | 110 | float *codec2_enable_user_ratek(struct CODEC2 *codec2_state, int *K); |
| 120 | 111 | ||
| 121 | // 700C post filter and equaliser | 112 | // 700C post filter and equaliser |
| 122 | void codec2_700c_post_filter(struct CODEC2 *codec2_state, int en); | 113 | void codec2_700c_post_filter(struct CODEC2 *codec2_state, bool en); |
| 123 | void codec2_700c_eq(struct CODEC2 *codec2_state, int en); | 114 | void codec2_700c_eq(struct CODEC2 *codec2_state, bool en); |
| 124 | |||
| 125 | #endif | ||
| 126 | 115 | ||
| 127 | #ifdef __cplusplus | 116 | #ifdef __cplusplus |
| 128 | } | 117 | } |
| 129 | #endif | 118 | #endif |
| 130 | 119 | ||
| 120 | #endif | ||
