2
* Siren Encoder/Decoder library
4
* @author: Youness Alaoui <kakaroto@kakaroto.homelinux.net>
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Library General Public
8
* License as published by the Free Software Foundation; either
9
* version 2 of the License, or (at your option) any later version.
11
* This library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* Library General Public License for more details.
16
* You should have received a copy of the GNU Library General Public
17
* License along with this library; if not, write to the
18
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19
* Boston, MA 02111-1307, USA.
26
static int rmlt_initialized = 0;
27
static float rmlt_window_640[640];
28
static float rmlt_window_320[320];
30
#define PI_2 1.57079632679489661923
32
void siren_rmlt_init() {
36
for (i = 0; i < 640; i++) {
37
angle = (float) (((i + 0.5) * PI_2) / 640);
38
rmlt_window_640[i] = (float) sin(angle);
40
for (i = 0; i < 320; i++) {
41
angle = (float) (((i + 0.5) * PI_2) / 320);
42
rmlt_window_320[i] = (float) sin(angle);
48
int siren_rmlt_encode_samples(float *samples, float *old_samples, int dct_length, float *rmlt_coefs) {
49
int half_dct_length = dct_length / 2;
50
float *old_ptr = old_samples + half_dct_length;
51
float *coef_high = rmlt_coefs + half_dct_length;
52
float *coef_low = rmlt_coefs + half_dct_length;
53
float *samples_low = samples;
54
float *samples_high = samples + dct_length;
55
float *window_low = NULL;
56
float *window_high = NULL;
59
if (rmlt_initialized == 0)
62
if (dct_length == 320)
63
window_low = rmlt_window_320;
64
else if (dct_length == 640)
65
window_low = rmlt_window_640;
69
window_high = window_low + dct_length;
72
for (i = 0; i < half_dct_length; i++) {
73
*--coef_low = *--old_ptr;
74
*coef_high++ = (*samples_low * *--window_high) - (*--samples_high * *window_low);
75
*old_ptr = (*samples_high * *window_high) + (*samples_low++ * *window_low++);
77
siren_dct4(rmlt_coefs, rmlt_coefs, dct_length);
84
int siren_rmlt_decode_samples(float *coefs, float *old_coefs, int dct_length, float *samples) {
85
int half_dct_length = dct_length / 2;
86
float *old_low = old_coefs;
87
float *old_high = old_coefs + half_dct_length;
88
float *samples_low = samples ;
89
float *samples_high = samples + dct_length;
90
float *samples_middle_low = samples + half_dct_length;
91
float *samples_middle_high = samples + half_dct_length;
92
float *window_low = NULL;
93
float *window_high = NULL;
94
float *window_middle_low = NULL;
95
float *window_middle_high = NULL;
97
float sample_high_val;
98
float sample_middle_low_val;
99
float sample_middle_high_val;
102
if (rmlt_initialized == 0)
105
if (dct_length == 320)
106
window_low = rmlt_window_320;
107
else if (dct_length == 640)
108
window_low = rmlt_window_640;
113
window_high = window_low + dct_length;
114
window_middle_low = window_low + half_dct_length;
115
window_middle_high = window_low + half_dct_length;
117
siren_dct4(coefs, samples, dct_length);
119
for (i = 0; i < half_dct_length; i+=2) {
120
sample_low_val = *samples_low;
121
sample_high_val = *--samples_high;
122
sample_middle_low_val = *--samples_middle_low;
123
sample_middle_high_val = *samples_middle_high;
124
*samples_low++ = (*old_low * *--window_high) + (sample_middle_low_val * *window_low);
125
*samples_high = (sample_middle_low_val * *window_high) - (*old_low * *window_low++);
126
*samples_middle_high++ = (sample_low_val * *window_middle_high) - (*--old_high * *--window_middle_low);
127
*samples_middle_low = (*old_high * *window_middle_high++) + (sample_low_val * *window_middle_low);
128
*old_low++ = sample_middle_high_val;
129
*old_high = sample_high_val;