Browse Source

Remove unused framework

master
Christopher Snowhill 3 weeks ago
parent
commit
3cdebc8425
17 changed files with 0 additions and 2871 deletions
  1. +0
    -28
      Frameworks/g7221/g7221/Info.plist
  2. +0
    -43
      Frameworks/g7221/g7221/g7221.c
  3. +0
    -23
      Frameworks/g7221/g7221/g7221.h
  4. +0
    -529
      Frameworks/g7221/g7221/libsiren/common.c
  5. +0
    -146
      Frameworks/g7221/g7221/libsiren/common.h
  6. +0
    -199
      Frameworks/g7221/g7221/libsiren/dct4.c
  7. +0
    -30
      Frameworks/g7221/g7221/libsiren/dct4.h
  8. +0
    -273
      Frameworks/g7221/g7221/libsiren/decoder.c
  9. +0
    -63
      Frameworks/g7221/g7221/libsiren/decoder.h
  10. +0
    -267
      Frameworks/g7221/g7221/libsiren/encoder.c
  11. +0
    -60
      Frameworks/g7221/g7221/libsiren/encoder.h
  12. +0
    -425
      Frameworks/g7221/g7221/libsiren/huffman.c
  13. +0
    -42
      Frameworks/g7221/g7221/libsiren/huffman.h
  14. +0
    -528
      Frameworks/g7221/g7221/libsiren/huffman_consts.h
  15. +0
    -149
      Frameworks/g7221/g7221/libsiren/rmlt.c
  16. +0
    -30
      Frameworks/g7221/g7221/libsiren/rmlt.h
  17. +0
    -36
      Frameworks/g7221/g7221/libsiren/siren7.h

+ 0
- 28
Frameworks/g7221/g7221/Info.plist View File

@@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2015 Christopher Snowhill. All rights reserved.</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>

+ 0
- 43
Frameworks/g7221/g7221/g7221.c View File

@@ -1,43 +0,0 @@
//
// g7221.c
// g7221
//
// Created by Christopher Snowhill on 1/24/15.
// Copyright (c) 2015 Christopher Snowhill. All rights reserved.
//

#include "g7221.h"

#include "libsiren/siren7.h"

g7221_handle * g7221_init(int bytes_per_frame, int bandwidth)
{
g7221_handle * handle = 0;
int sample_rate = bytes_per_frame * 8 * 50;
if ( sample_rate >= 16000 && sample_rate <= 48000 )
{
if ( ( ( sample_rate / 800 ) * 800 ) == sample_rate )
{
if ( bandwidth == 7000 || bandwidth == 14000 )
{
handle = (g7221_handle *) Siren7_NewDecoder( sample_rate, ( bandwidth == 7000 ) ? 1 : 2 );
}
}
}
return handle;
}

void g7221_decode_frame(g7221_handle *handle, void *code_words, void *sample_buffer)
{
Siren7_DecodeFrame((SirenDecoder)handle, (unsigned char *)code_words, (unsigned char *)sample_buffer);
}

void g7221_reset(g7221_handle *handle)
{
Siren7_ResetDecoder ((SirenDecoder)handle);
}

void g7221_free(g7221_handle *handle)
{
Siren7_CloseDecoder((SirenDecoder) handle);
}

+ 0
- 23
Frameworks/g7221/g7221/g7221.h View File

@@ -1,23 +0,0 @@
/*
Interface to reference G.722.1 decoder
*/

#ifndef G7221_H
#define G7221_H

/* forward definition for the opaque handle object */
typedef struct g7221_handle_s g7221_handle;

/* return a handle for decoding on successful init, NULL on failure */
g7221_handle * g7221_init(int bytes_per_frame, int bandwidth);

/* decode a frame, at code_words, into 16-bit PCM in sample_buffer */
void g7221_decode_frame(g7221_handle *handle, void *code_words, void *sample_buffer);

/* reset the decoder to its initial state */
void g7221_reset(g7221_handle *handle);

/* free resources */
void g7221_free(g7221_handle *handle);

#endif

+ 0
- 529
Frameworks/g7221/g7221/libsiren/common.c View File

@@ -1,529 +0,0 @@
/*
* Siren Encoder/Decoder library
*
* @author: Youness Alaoui <kakaroto@kakaroto.homelinux.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/

#include "siren7.h"

int region_size;
float region_size_inverse;

float standard_deviation[64];
float deviation_inverse[64];
float region_power_table_boundary[63];

int expected_bits_table[8] = { 52, 47, 43, 37, 29, 22, 16, 0 };
int vector_dimension[8] = { 2, 2, 2, 4, 4, 5, 5, 1 };
int number_of_vectors[8] = { 10, 10, 10, 5, 5, 4, 4, 20 };
float dead_zone[8] = { 0.3f, 0.33f, 0.36f, 0.39f, 0.42f, 0.45f, 0.5f, 0.5f };

int max_bin[8] = {
13,
9,
6,
4,
3,
2,
1,
1
};

float step_size[8] = {
0.3536f,
0.5f,
0.70709997f,
1.0f,
1.4141999f,
2.0f,
2.8283999f,
2.8283999f
};

float step_size_inverse[8];

static int siren_initialized = 0;

/*
STEPSIZE = 2.0 * log(sqrt(2));
*/
#define STEPSIZE 0.3010299957

void
siren_init (void)
{
int i;
float region_power;

if (siren_initialized == 1)
return;

region_size = 20;
region_size_inverse = 1.0f / region_size;

for (i = 0; i < 64; i++) {
region_power = (float) pow (10, (i - 24) * STEPSIZE);
standard_deviation[i] = (float) sqrt (region_power);
deviation_inverse[i] = (float) 1.0 / standard_deviation[i];
}

for (i = 0; i < 63; i++)
region_power_table_boundary[i] =
(float) pow (10, (i - 24 + 0.5) * STEPSIZE);

for (i = 0; i < 8; i++)
step_size_inverse[i] = (float) 1.0 / step_size[i];

siren_dct4_init ();
siren_rmlt_init ();

siren_initialized = 1;
}


int
categorize_regions (int number_of_regions, int number_of_available_bits,
int *absolute_region_power_index, int *power_categories,
int *category_balance)
{
int region, delta, i, temp;
int expected_number_of_code_bits;
int min, max;
int offset,
num_rate_control_possibilities,
raw_value, raw_max_idx = 0, raw_min_idx = 0;
int max_rate_categories[28];
int min_rate_categories[28];
int temp_category_balances[64];
int *min_rate_ptr = NULL;
int *max_rate_ptr = NULL;

if (number_of_regions == 14) {
num_rate_control_possibilities = 16;
if (number_of_available_bits > 320)
number_of_available_bits =
((number_of_available_bits - 320) * 5 / 8) + 320;
} else {
num_rate_control_possibilities = 32;
if (number_of_regions == 28 && number_of_available_bits > 640)
number_of_available_bits =
((number_of_available_bits - 640) * 5 / 8) + 640;
}

offset = -32;
for (delta = 32; number_of_regions > 0 && delta > 0; delta /= 2) {
expected_number_of_code_bits = 0;
for (region = 0; region < number_of_regions; region++) {
i = (delta + offset - absolute_region_power_index[region]) >> 1;
if (i > 7)
i = 7;
else if (i < 0)
i = 0;

power_categories[region] = i;
expected_number_of_code_bits += expected_bits_table[i];

}
if (expected_number_of_code_bits >= number_of_available_bits - 32)
offset += delta;
}

expected_number_of_code_bits = 0;
for (region = 0; region < number_of_regions; region++) {
i = (offset - absolute_region_power_index[region]) >> 1;
if (i > 7)
i = 7;
else if (i < 0)
i = 0;
max_rate_categories[region] = min_rate_categories[region] =
power_categories[region] = i;
expected_number_of_code_bits += expected_bits_table[i];
}


min = max = expected_number_of_code_bits;
min_rate_ptr = max_rate_ptr =
temp_category_balances + num_rate_control_possibilities;
for (i = 0; i < num_rate_control_possibilities - 1; i++) {
if (min + max > number_of_available_bits * 2) {
raw_value = -99;
for (region = number_of_regions - 1; region >= 0; region--) {
if (min_rate_categories[region] < 7) {
temp =
offset - absolute_region_power_index[region] -
2 * min_rate_categories[region];
if (temp > raw_value) {
raw_value = temp;
raw_min_idx = region;
}
}
}
*min_rate_ptr++ = raw_min_idx;
min +=
expected_bits_table[min_rate_categories[raw_min_idx] + 1] -
expected_bits_table[min_rate_categories[raw_min_idx]];
min_rate_categories[raw_min_idx]++;
} else {
raw_value = 99;
for (region = 0; region < number_of_regions; region++) {
if (max_rate_categories[region] > 0) {
temp =
offset - absolute_region_power_index[region] -
2 * max_rate_categories[region];
if (temp < raw_value) {
raw_value = temp;
raw_max_idx = region;
}
}
}

*--max_rate_ptr = raw_max_idx;
max +=
expected_bits_table[max_rate_categories[raw_max_idx] - 1] -
expected_bits_table[max_rate_categories[raw_max_idx]];
max_rate_categories[raw_max_idx]--;
}
}

for (region = 0; region < number_of_regions; region++)
power_categories[region] = max_rate_categories[region];

for (i = 0; i < num_rate_control_possibilities - 1; i++)
category_balance[i] = *max_rate_ptr++;


return 0;
}



/*
Looks like the flag means what kind of encoding is used
for now, it looks like :
0 : the sample rate is not encoded in the frame
1 - 2 : the sample rate is fixed in the frame
3 : sample rate is variable and there is one for each frame
*/

int
GetSirenCodecInfo (int flag, int sample_rate, int *number_of_coefs,
int *sample_rate_bits, int *rate_control_bits,
int *rate_control_possibilities, int *checksum_bits, int *esf_adjustment,
int *scale_factor, int *number_of_regions, int *sample_rate_code,
int *bits_per_frame)
{
switch (flag) {
case 0:
*number_of_coefs = 320;
*sample_rate_bits = 0;
*rate_control_bits = 4;
*rate_control_possibilities = 16;
*checksum_bits = 0;
*esf_adjustment = 7;
*number_of_regions = 14;
*sample_rate_code = 0;
*scale_factor = 22;
break;
case 1:
*number_of_coefs = 320;
*sample_rate_bits = 2;
*rate_control_bits = 4;
*rate_control_possibilities = 16;
*checksum_bits = 4;
*esf_adjustment = -2;
*number_of_regions = 14;
*scale_factor = 1;
if (sample_rate == 16000)
*sample_rate_code = 1;
else if (sample_rate == 24000)
*sample_rate_code = 2;
else if (sample_rate == 32000)
*sample_rate_code = 3;
else
return 3;
break;
case 2:
*number_of_coefs = 640;
*sample_rate_bits = 2;
*rate_control_bits = 5;
*rate_control_possibilities = 32;
*checksum_bits = 4;
*esf_adjustment = 7;
*number_of_regions = 28;
*scale_factor = 33;

if (sample_rate == 24000)
*sample_rate_code = 1;
else if (sample_rate == 32000)
*sample_rate_code = 2;
else if (sample_rate == 48000)
*sample_rate_code = 3;
else
return 3;

break;
case 3:
*number_of_coefs = 640;
*sample_rate_bits = 6;
*rate_control_bits = 5;
*rate_control_possibilities = 32;
*checksum_bits = 4;
*esf_adjustment = 7;
*scale_factor = 33;

switch (sample_rate) {
case 8800:
*number_of_regions = 12;
*sample_rate_code = 59;
break;
case 9600:
*number_of_regions = 12;
*sample_rate_code = 1;
break;
case 10400:
*number_of_regions = 12;
*sample_rate_code = 13;
break;
case 10800:
*number_of_regions = 12;
*sample_rate_code = 14;
break;
case 11200:
*number_of_regions = 12;
*sample_rate_code = 15;
break;
case 11600:
*number_of_regions = 12;
*sample_rate_code = 16;
break;
case 12000:
*number_of_regions = 12;
*sample_rate_code = 2;
break;
case 12400:
*number_of_regions = 12;
*sample_rate_code = 17;
break;
case 12800:
*number_of_regions = 12;
*sample_rate_code = 18;
break;
case 13200:
*number_of_regions = 12;
*sample_rate_code = 19;
break;
case 13600:
*number_of_regions = 12;
*sample_rate_code = 20;
break;
case 14000:
*number_of_regions = 12;
*sample_rate_code = 21;
break;
case 14400:
*number_of_regions = 16;
*sample_rate_code = 3;
break;
case 14800:
*number_of_regions = 16;
*sample_rate_code = 22;
break;
case 15200:
*number_of_regions = 16;
*sample_rate_code = 23;
break;
case 15600:
*number_of_regions = 16;
*sample_rate_code = 24;
break;
case 16000:
*number_of_regions = 16;
*sample_rate_code = 25;
break;
case 16400:
*number_of_regions = 16;
*sample_rate_code = 26;
break;
case 16800:
*number_of_regions = 18;
*sample_rate_code = 4;
break;
case 17200:
*number_of_regions = 18;
*sample_rate_code = 27;
break;
case 17600:
*number_of_regions = 18;
*sample_rate_code = 28;
break;
case 18000:
*number_of_regions = 18;
*sample_rate_code = 29;
break;
case 18400:
*number_of_regions = 18;
*sample_rate_code = 30;
break;
case 18800:
*number_of_regions = 18;
*sample_rate_code = 31;
break;
case 19200:
*number_of_regions = 20;
*sample_rate_code = 5;
break;
case 19600:
*number_of_regions = 20;
*sample_rate_code = 32;
break;
case 20000:
*number_of_regions = 20;
*sample_rate_code = 33;
break;
case 20400:
*number_of_regions = 20;
*sample_rate_code = 34;
break;
case 20800:
*number_of_regions = 20;
*sample_rate_code = 35;
break;
case 21200:
*number_of_regions = 20;
*sample_rate_code = 36;
break;
case 21600:
*number_of_regions = 22;
*sample_rate_code = 6;
break;
case 22000:
*number_of_regions = 22;
*sample_rate_code = 37;
break;
case 22400:
*number_of_regions = 22;
*sample_rate_code = 38;
break;
case 22800:
*number_of_regions = 22;
*sample_rate_code = 39;
break;
case 23200:
*number_of_regions = 22;
*sample_rate_code = 40;
break;
case 23600:
*number_of_regions = 22;
*sample_rate_code = 41;
break;
case 24000:
*number_of_regions = 24;
*sample_rate_code = 7;
break;
case 24400:
*number_of_regions = 24;
*sample_rate_code = 42;
break;
case 24800:
*number_of_regions = 24;
*sample_rate_code = 43;
break;
case 25200:
*number_of_regions = 24;
*sample_rate_code = 44;
break;
case 25600:
*number_of_regions = 24;
*sample_rate_code = 45;
break;
case 26000:
*number_of_regions = 24;
*sample_rate_code = 46;
break;
case 26400:
*number_of_regions = 26;
*sample_rate_code = 8;
break;
case 26800:
*number_of_regions = 26;
*sample_rate_code = 47;
break;
case 27200:
*number_of_regions = 26;
*sample_rate_code = 48;
break;
case 27600:
*number_of_regions = 26;
*sample_rate_code = 49;
break;
case 28000:
*number_of_regions = 26;
*sample_rate_code = 50;
break;
case 28400:
*number_of_regions = 26;
*sample_rate_code = 51;
break;
case 28800:
*number_of_regions = 28;
*sample_rate_code = 9;
break;
case 29200:
*number_of_regions = 28;
*sample_rate_code = 52;
break;
case 29600:
*number_of_regions = 28;
*sample_rate_code = 53;
break;
case 30000:
*number_of_regions = 28;
*sample_rate_code = 54;
break;
case 30400:
*number_of_regions = 28;
*sample_rate_code = 55;
break;
case 30800:
*number_of_regions = 28;
*sample_rate_code = 56;
break;
case 31200:
*number_of_regions = 28;
*sample_rate_code = 10;
break;
case 31600:
*number_of_regions = 28;
*sample_rate_code = 57;
break;
case 32000:
*number_of_regions = 28;
*sample_rate_code = 58;
break;
default:
return 3;
break;
}
break;
default:
return 6;
}

*bits_per_frame = sample_rate / 50;
return 0;
}

+ 0
- 146
Frameworks/g7221/g7221/libsiren/common.h View File

@@ -1,146 +0,0 @@
/*
* Siren Encoder/Decoder library
*
* @author: Youness Alaoui <kakaroto@kakaroto.homelinux.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/


#ifndef _SIREN_COMMON_H
#define _SIREN_COMMON_H

typedef struct {
unsigned int RiffId;
unsigned int RiffSize;
} RiffHeader;

typedef struct {
unsigned short Format;
unsigned short Channels;
unsigned int SampleRate;
unsigned int ByteRate;
unsigned short BlockAlign;
unsigned short BitsPerSample;
} FmtChunk;


typedef struct {
FmtChunk fmt;
unsigned short ExtraSize;
unsigned short DctLength;
} SirenFmtChunk;

typedef struct {
RiffHeader riff;
unsigned int WaveId;

unsigned int FmtId;
unsigned int FmtSize;

SirenFmtChunk fmt;

unsigned int FactId;
unsigned int FactSize;
unsigned int Samples;

unsigned int DataId;
unsigned int DataSize;
} SirenWavHeader;

typedef struct {
RiffHeader riff;
unsigned int WaveId;

unsigned int FmtId;
unsigned int FmtSize;

FmtChunk fmt;

unsigned int FactId;
unsigned int FactSize;
unsigned int Samples;

unsigned int DataId;
unsigned int DataSize;
} PCMWavHeader;

#define RIFF_ID 0x46464952
#define WAVE_ID 0x45564157
#define FMT__ID 0x20746d66
#define DATA_ID 0x61746164
#define FACT_ID 0x74636166


extern int region_size;
extern float region_size_inverse;
extern float standard_deviation[64];
extern float deviation_inverse[64];
extern float region_power_table_boundary[63];
extern int expected_bits_table[8];
extern int vector_dimension[8];
extern int number_of_vectors[8];
extern float dead_zone[8];
extern int max_bin[8];
extern float step_size[8];
extern float step_size_inverse[8];



extern void siren_init(void);
extern int categorize_regions(int number_of_regions, int number_of_available_bits, int *absolute_region_power_index, int *power_categories, int *category_balance);
extern int GetSirenCodecInfo(int flag, int sample_rate, int *number_of_coefs, int *sample_rate_bits, int *rate_control_bits, int *rate_control_possibilities, int *checksum_bits, int *esf_adjustment, int *scale_factor, int *number_of_regions, int *sample_rate_code, int *bits_per_frame );


#ifdef __BIG_ENDIAN__

#define POW_2_8 256
#define POW_2_16 65536
#define POW_2_24 16777216

#define IDX(val, i) ((unsigned int) ((unsigned char *) &val)[i])



#define ME_FROM_LE16(val) ( (unsigned short) ( IDX(val, 0) + IDX(val, 1) * 256 ))
#define ME_FROM_LE32(val) ( (unsigned int) (IDX(val, 0) + IDX(val, 1) * 256 + \
IDX(val, 2) * 65536 + IDX(val, 3) * 16777216))


#define ME_TO_LE16(val) ( (unsigned short) ( \
(((unsigned short)val % 256) & 0xff) << 8 | \
((((unsigned short)val / POW_2_8) % 256) & 0xff) ))

#define ME_TO_LE32(val) ( (unsigned int) ( \
((((unsigned int) val ) % 256) & 0xff) << 24 | \
((((unsigned int) val / POW_2_8 ) % 256) & 0xff) << 16| \
((((unsigned int) val / POW_2_16) % 256) & 0xff) << 8 | \
((((unsigned int) val / POW_2_24) % 256) & 0xff) ))

#else

#define ME_TO_LE16(val) ( (unsigned short) (val))
#define ME_TO_LE32(val) ( (unsigned int) (val))
#define ME_FROM_LE16(val) ( (unsigned short) (val))
#define ME_FROM_LE32(val) ( (unsigned int) (val))


#endif



#endif /* _SIREN_COMMON_H */


+ 0
- 199
Frameworks/g7221/g7221/libsiren/dct4.c View File

@@ -1,199 +0,0 @@
/*
* Siren Encoder/Decoder library
*
* @author: Youness Alaoui <kakaroto@kakaroto.homelinux.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/


#include "siren7.h"


#define PI 3.1415926

typedef struct
{
float cos;
float msin;
} dct_table_type;

static float dct_core_320[100];
static float dct_core_640[100];
static dct_table_type dct_table_5[5];
static dct_table_type dct_table_10[10];
static dct_table_type dct_table_20[20];
static dct_table_type dct_table_40[40];
static dct_table_type dct_table_80[80];
static dct_table_type dct_table_160[160];
static dct_table_type dct_table_320[320];
static dct_table_type dct_table_640[640];
static dct_table_type *dct_tables[8] = { dct_table_5,
dct_table_10,
dct_table_20,
dct_table_40,
dct_table_80,
dct_table_160,
dct_table_320,
dct_table_640
};

static int dct4_initialized = 0;

void
siren_dct4_init (void)
{
int i, j = 0;
double scale_320 = (float) sqrt (2.0 / 320);
double scale_640 = (float) sqrt (2.0 / 640);
double angle;
double scale;

/* set up dct4 tables */
for (i = 0; i < 10; i++) {
angle = (float) ((i + 0.5) * PI);
for (j = 0; j < 10; j++) {
dct_core_320[(i * 10) + j] =
(float) (scale_320 * cos ((j + 0.5) * angle / 10));
dct_core_640[(i * 10) + j] =
(float) (scale_640 * cos ((j + 0.5) * angle / 10));
}
}

for (i = 0; i < 8; i++) {
scale = (float) (PI / ((5 << i) * 4));
for (j = 0; j < (5 << i); j++) {
angle = (float) (j + 0.5) * scale;
dct_tables[i][j].cos = (float) cos (angle);
dct_tables[i][j].msin = (float) -sin (angle);
}
}

dct4_initialized = 1;
}


void
siren_dct4 (float *Source, float *Destination, int dct_length)
{
int log_length = 0;
float *dct_core = NULL;
dct_table_type **dct_table_ptr_ptr = NULL;
dct_table_type *dct_table_ptr = NULL;
float OutBuffer1[640];
float OutBuffer2[640];
float *Out_ptr;
float *NextOut_ptr;
float *In_Ptr = NULL;
float *In_Ptr_low = NULL;
float *In_Ptr_high = NULL;
float In_val_low;
float In_val_high;
float *Out_ptr_low = NULL;
float *Out_ptr_high = NULL;
float mult1, mult2, mult3, mult4, mult5, mult6, mult7, mult8, mult9, mult10;
int i, j;

if (dct4_initialized == 0)
siren_dct4_init ();

if (dct_length == 640) {
log_length = 5;
dct_core = dct_core_640;
} else {
log_length = 4;
dct_core = dct_core_320;
}

Out_ptr = OutBuffer1;
NextOut_ptr = OutBuffer2;
In_Ptr = Source;
for (i = 0; i <= log_length; i++) {
for (j = 0; j < (1 << i); j++) {
Out_ptr_low = Out_ptr + (j * (dct_length >> i));
Out_ptr_high = Out_ptr + ((j + 1) * (dct_length >> i));
do {
In_val_low = *In_Ptr++;
In_val_high = *In_Ptr++;
*Out_ptr_low++ = In_val_low + In_val_high;
*--Out_ptr_high = In_val_low - In_val_high;
} while (Out_ptr_low < Out_ptr_high);
}

In_Ptr = Out_ptr;
Out_ptr = NextOut_ptr;
NextOut_ptr = In_Ptr;
}

for (i = 0; i < (2 << log_length); i++) {
for (j = 0; j < 10; j++) {
mult1 = In_Ptr[(i * 10)] * dct_core[j * 10];
mult2 = In_Ptr[(i * 10) + 1] * dct_core[(j * 10) + 1];
mult3 = In_Ptr[(i * 10) + 2] * dct_core[(j * 10) + 2];
mult4 = In_Ptr[(i * 10) + 3] * dct_core[(j * 10) + 3];
mult5 = In_Ptr[(i * 10) + 4] * dct_core[(j * 10) + 4];
mult6 = In_Ptr[(i * 10) + 5] * dct_core[(j * 10) + 5];
mult7 = In_Ptr[(i * 10) + 6] * dct_core[(j * 10) + 6];
mult8 = In_Ptr[(i * 10) + 7] * dct_core[(j * 10) + 7];
mult9 = In_Ptr[(i * 10) + 8] * dct_core[(j * 10) + 8];
mult10 = In_Ptr[(i * 10) + 9] * dct_core[(j * 10) + 9];
Out_ptr[(i * 10) + j] = mult1 + mult2 + mult3 + mult4 +
mult5 + mult6 + mult7 + mult8 + mult9 + mult10;
}
}


In_Ptr = Out_ptr;
Out_ptr = NextOut_ptr;
NextOut_ptr = In_Ptr;
dct_table_ptr_ptr = dct_tables;
for (i = log_length; i >= 0; i--) {
dct_table_ptr_ptr++;
for (j = 0; j < (1 << i); j++) {
dct_table_ptr = *dct_table_ptr_ptr;
if (i == 0)
Out_ptr_low = Destination + (j * (dct_length >> i));
else
Out_ptr_low = Out_ptr + (j * (dct_length >> i));

Out_ptr_high = Out_ptr_low + (dct_length >> i);

In_Ptr_low = In_Ptr + (j * (dct_length >> i));
In_Ptr_high = In_Ptr_low + (dct_length >> (i + 1));
do {
*Out_ptr_low++ =
(*In_Ptr_low * (*dct_table_ptr).cos) -
(*In_Ptr_high * (*dct_table_ptr).msin);
*--Out_ptr_high =
(*In_Ptr_high++ * (*dct_table_ptr).cos) +
(*In_Ptr_low++ * (*dct_table_ptr).msin);
dct_table_ptr++;
*Out_ptr_low++ =
(*In_Ptr_low * (*dct_table_ptr).cos) +
(*In_Ptr_high * (*dct_table_ptr).msin);
*--Out_ptr_high =
(*In_Ptr_low++ * (*dct_table_ptr).msin) -
(*In_Ptr_high++ * (*dct_table_ptr).cos);
dct_table_ptr++;
} while (Out_ptr_low < Out_ptr_high);
}

In_Ptr = Out_ptr;
Out_ptr = NextOut_ptr;
NextOut_ptr = In_Ptr;
}

}

+ 0
- 30
Frameworks/g7221/g7221/libsiren/dct4.h View File

@@ -1,30 +0,0 @@
/*
* Siren Encoder/Decoder library
*
* @author: Youness Alaoui <kakaroto@kakaroto.homelinux.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/


#ifndef _SIREN7_DCT4_H_
#define _SIREN7_DCT4_H_

extern void siren_dct4_init(void);
extern void siren_dct4(float *Source, float *Destination, int dct_length);


#endif /* _SIREN7_DCT4_H_ */

+ 0
- 273
Frameworks/g7221/g7221/libsiren/decoder.c View File

@@ -1,273 +0,0 @@
/*
* Siren Encoder/Decoder library
*
* @author: Youness Alaoui <kakaroto@kakaroto.homelinux.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/


#include "siren7.h"

SirenDecoder
Siren7_NewDecoder (int sample_rate, int flag)
{
SirenDecoder decoder = (SirenDecoder) malloc (sizeof (struct stSirenDecoder));
decoder->sample_rate = sample_rate;
decoder->flag = flag;

#ifdef __WAV_HEADER__
decoder->WavHeader.riff.RiffId = ME_TO_LE32 (RIFF_ID);
decoder->WavHeader.riff.RiffSize = sizeof (PCMWavHeader) - 2 * sizeof (int);
decoder->WavHeader.riff.RiffSize =
ME_TO_LE32 (decoder->WavHeader.riff.RiffSize);
decoder->WavHeader.WaveId = ME_TO_LE32 (WAVE_ID);

decoder->WavHeader.FmtId = ME_TO_LE32 (FMT__ID);
decoder->WavHeader.FmtSize = ME_TO_LE32 (sizeof (FmtChunk));

decoder->WavHeader.fmt.Format = ME_TO_LE16 (0x01);
decoder->WavHeader.fmt.Channels = ME_TO_LE16 (1);
decoder->WavHeader.fmt.SampleRate = ME_TO_LE32 (sample_rate);
decoder->WavHeader.fmt.ByteRate = ME_TO_LE32 (sample_rate * 2);
decoder->WavHeader.fmt.BlockAlign = ME_TO_LE16 (2);
decoder->WavHeader.fmt.BitsPerSample = ME_TO_LE16 (16);

decoder->WavHeader.FactId = ME_TO_LE32 (FACT_ID);
decoder->WavHeader.FactSize = ME_TO_LE32 (sizeof (int));
decoder->WavHeader.Samples = ME_TO_LE32 (0);

decoder->WavHeader.DataId = ME_TO_LE32 (DATA_ID);
decoder->WavHeader.DataSize = ME_TO_LE32 (0);
#endif
Siren7_ResetDecoder(decoder);
siren_init ();
return decoder;
}

void
Siren7_ResetDecoder(SirenDecoder decoder)
{
memset(decoder->context, 0, sizeof(decoder->context));
memset(decoder->backup_frame, 0, sizeof(decoder->backup_frame));

decoder->dw1 = 1;
decoder->dw2 = 1;
decoder->dw3 = 1;
decoder->dw4 = 1;
memset(decoder->absolute_region_power_index, 0, sizeof(decoder->absolute_region_power_index));
memset(decoder->decoder_standard_deviation, 0, sizeof(decoder->decoder_standard_deviation));
memset(decoder->power_categories, 0, sizeof(decoder->power_categories));
memset(decoder->category_balance, 0, sizeof(decoder->category_balance));
}

void
Siren7_CloseDecoder (SirenDecoder decoder)
{
free (decoder);
}

int
Siren7_DecodeFrame (SirenDecoder decoder, unsigned char *DataIn,
unsigned char *DataOut)
{
int number_of_coefs,
sample_rate_bits,
rate_control_bits,
rate_control_possibilities,
checksum_bits,
esf_adjustment,
scale_factor, number_of_regions, sample_rate_code, bits_per_frame;
int decoded_sample_rate_code;

int ChecksumTable[4] = { 0x7F80, 0x7878, 0x6666, 0x5555 };
int i, j;

int dwRes = 0;
int envelope_bits = 0;
int rate_control = 0;
int number_of_available_bits;
int number_of_valid_coefs;
int frame_error = 0;

int In[60];
float coefs[640];
float BufferOut[640];
int sum;
int checksum;
int calculated_checksum;
int idx;
int temp1;
int temp2;

bitstream bs = {0};

dwRes =
GetSirenCodecInfo (decoder->flag, decoder->sample_rate, &number_of_coefs,
&sample_rate_bits, &rate_control_bits, &rate_control_possibilities,
&checksum_bits, &esf_adjustment, &scale_factor, &number_of_regions,
&sample_rate_code, &bits_per_frame);

if (dwRes != 0)
return dwRes;

#ifdef __NO_CONTROL_OR_CHECK_FIELDS__
sample_rate_bits = 0;
checksum_bits = 0;
sample_rate_code = 0;
#endif

j = bits_per_frame / 16;
for (i = 0; i < j; i++)
#ifdef __BIG_ENDIAN_FRAMES__
In[i] = ((short *) DataIn)[i];
#else
In[i] =
((((short *) DataIn)[i] << 8) & 0xFF00) | ((((short *) DataIn)[i] >> 8)
& 0x00FF);
#endif

set_bitstream (&bs, In);

decoded_sample_rate_code = 0;
for (i = 0; i < sample_rate_bits; i++) {
decoded_sample_rate_code <<= 1;
decoded_sample_rate_code |= next_bit (&bs);
}


if (decoded_sample_rate_code != sample_rate_code)
return 7;

number_of_valid_coefs = region_size * number_of_regions;
number_of_available_bits = bits_per_frame - sample_rate_bits - checksum_bits;


envelope_bits =
decode_envelope (&bs, number_of_regions, decoder->decoder_standard_deviation,
decoder->absolute_region_power_index, esf_adjustment);

number_of_available_bits -= envelope_bits;

for (i = 0; i < rate_control_bits; i++) {
rate_control <<= 1;
rate_control |= next_bit (&bs);
}

number_of_available_bits -= rate_control_bits;

categorize_regions (number_of_regions, number_of_available_bits,
decoder->absolute_region_power_index, decoder->power_categories, decoder->category_balance);

for (i = 0; i < rate_control; i++) {
decoder->power_categories[decoder->category_balance[i]]++;
}

number_of_available_bits =
decode_vector (decoder, &bs, number_of_regions, number_of_available_bits,
decoder->decoder_standard_deviation, decoder->power_categories, coefs, scale_factor);


frame_error = 0;
if (number_of_available_bits > 0) {
for (i = 0; i < number_of_available_bits; i++) {
if (next_bit (&bs) == 0)
frame_error = 1;
}
} else if (number_of_available_bits < 0
&& rate_control + 1 < rate_control_possibilities) {
frame_error |= 2;
}

for (i = 0; i < number_of_regions; i++) {
if (decoder->absolute_region_power_index[i] > 33
|| decoder->absolute_region_power_index[i] < -31)
frame_error |= 4;
}

if (checksum_bits > 0) {
bits_per_frame >>= 4;
checksum = In[bits_per_frame - 1] & ((1 << checksum_bits) - 1);
In[bits_per_frame - 1] &= ~checksum;
sum = 0;
idx = 0;
do {
sum ^= (In[idx] & 0xFFFF) << (idx % 15);
} while (++idx < bits_per_frame);

sum = (sum >> 15) ^ (sum & 0x7FFF);
calculated_checksum = 0;
for (i = 0; i < 4; i++) {
temp1 = ChecksumTable[i] & sum;
for (j = 8; j > 0; j >>= 1) {
temp2 = temp1 >> j;
temp1 ^= temp2;
}
calculated_checksum <<= 1;
calculated_checksum |= temp1 & 1;
}

if (checksum != calculated_checksum)
frame_error |= 8;
}

if (frame_error != 0) {
for (i = 0; i < number_of_valid_coefs; i++) {
coefs[i] = decoder->backup_frame[i];
decoder->backup_frame[i] = 0;
}
} else {
for (i = 0; i < number_of_valid_coefs; i++)
decoder->backup_frame[i] = coefs[i];
}


for (i = number_of_valid_coefs; i < number_of_coefs; i++)
coefs[i] = 0;


dwRes = siren_rmlt_decode_samples (coefs, decoder->context, number_of_coefs, BufferOut);


for (i = 0; i < number_of_coefs; i++) {
if (BufferOut[i] > 32767.0)
((short *) DataOut)[i] = (short) ME_TO_LE16 ((short) 32767);
else if (BufferOut[i] <= -32768.0)
((short *) DataOut)[i] = (short) ME_TO_LE16 ((short) 32768);
else
((short *) DataOut)[i] = (short) ME_TO_LE16 ((short) BufferOut[i]);
}

#ifdef __WAV_HEADER__
decoder->WavHeader.Samples = ME_FROM_LE32 (decoder->WavHeader.Samples);
decoder->WavHeader.Samples += number_of_coefs;
decoder->WavHeader.Samples = ME_TO_LE32 (decoder->WavHeader.Samples);
decoder->WavHeader.DataSize = ME_FROM_LE32 (decoder->WavHeader.DataSize);
decoder->WavHeader.DataSize += number_of_coefs * 2;
decoder->WavHeader.DataSize = ME_TO_LE32 (decoder->WavHeader.DataSize);
decoder->WavHeader.riff.RiffSize =
ME_FROM_LE32 (decoder->WavHeader.riff.RiffSize);
decoder->WavHeader.riff.RiffSize += number_of_coefs * 2;
decoder->WavHeader.riff.RiffSize =
ME_TO_LE32 (decoder->WavHeader.riff.RiffSize);
#endif

return 0;
}

+ 0
- 63
Frameworks/g7221/g7221/libsiren/decoder.h View File

@@ -1,63 +0,0 @@
/*
* Siren Encoder/Decoder library
*
* @author: Youness Alaoui <kakaroto@kakaroto.homelinux.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/


#ifndef _SIREN_DECODER_H
#define _SIREN_DECODER_H

#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "dct4.h"
#include "rmlt.h"
#include "huffman.h"
#include "common.h"


typedef struct stSirenDecoder {
int sample_rate;
int flag;
#ifdef __WAV_HEADER__
PCMWavHeader WavHeader;
#endif
float context[640];
float backup_frame[640];
int dw1;
int dw2;
int dw3;
int dw4;
int absolute_region_power_index[28];
float decoder_standard_deviation[28];
int power_categories[28];
int category_balance[32];
} * SirenDecoder;


/* MUST be 16000 to be compatible with MSN Voice clips (I think) */
extern SirenDecoder Siren7_NewDecoder(int sample_rate, int flag); /* flag = 1 for Siren7 and 2 for Siren14 */
extern void Siren7_CloseDecoder(SirenDecoder decoder);
extern void Siren7_ResetDecoder(SirenDecoder decoder);
/* Input bytes / output samples */
/* Siren7: 60 / 320 */
/* Siren14: 120 / 640 */
extern int Siren7_DecodeFrame(SirenDecoder decoder, unsigned char *DataIn, unsigned char *DataOut);

#endif /* _SIREN_DECODER_H */

+ 0
- 267
Frameworks/g7221/g7221/libsiren/encoder.c View File

@@ -1,267 +0,0 @@
/*
* Siren Encoder/Decoder library
*
* @author: Youness Alaoui <kakaroto@kakaroto.homelinux.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/



#include "siren7.h"


SirenEncoder
Siren7_NewEncoder (int sample_rate, int flag)
{
SirenEncoder encoder = (SirenEncoder) malloc (sizeof (struct stSirenEncoder));
encoder->sample_rate = sample_rate;
encoder->flag = flag;

#ifdef __WAV_HEADER__
encoder->WavHeader.riff.RiffId = ME_TO_LE32 (RIFF_ID);
encoder->WavHeader.riff.RiffSize = sizeof (SirenWavHeader) - 2 * sizeof (int);
encoder->WavHeader.riff.RiffSize =
ME_TO_LE32 (encoder->WavHeader.riff.RiffSize);
encoder->WavHeader.WaveId = ME_TO_LE32 (WAVE_ID);

encoder->WavHeader.FmtId = ME_TO_LE32 (FMT__ID);
encoder->WavHeader.FmtSize = ME_TO_LE32 (sizeof (SirenFmtChunk));

encoder->WavHeader.fmt.fmt.Format = ME_TO_LE16 (0x028E);
encoder->WavHeader.fmt.fmt.Channels = ME_TO_LE16 (1);
encoder->WavHeader.fmt.fmt.SampleRate = ME_TO_LE32 (sample_rate);
encoder->WavHeader.fmt.fmt.ByteRate = ME_TO_LE32 (sample_rate * 16 / 3);
encoder->WavHeader.fmt.fmt.BlockAlign = ME_TO_LE16 (40);
encoder->WavHeader.fmt.fmt.BitsPerSample = ME_TO_LE16 (0);
encoder->WavHeader.fmt.ExtraSize = ME_TO_LE16 (2);
encoder->WavHeader.fmt.DctLength = ME_TO_LE16 (flag == 1 ? 320 : 640);

encoder->WavHeader.FactId = ME_TO_LE32 (FACT_ID);
encoder->WavHeader.FactSize = ME_TO_LE32 (sizeof (int));
encoder->WavHeader.Samples = ME_TO_LE32 (0);

encoder->WavHeader.DataId = ME_TO_LE32 (DATA_ID);
encoder->WavHeader.DataSize = ME_TO_LE32 (0);
#endif

memset (encoder->context, 0, sizeof (encoder->context));

memset (encoder->absolute_region_power_index, 0, sizeof(encoder->absolute_region_power_index));
memset (encoder->power_categories, 0, sizeof(encoder->power_categories));
memset (encoder->category_balance, 0, sizeof(encoder->category_balance));
memset (encoder->drp_num_bits, 0, sizeof(encoder->drp_num_bits));
memset (encoder->drp_code_bits, 0, sizeof(encoder->drp_code_bits));
memset (encoder->region_mlt_bit_counts, 0, sizeof(encoder->region_mlt_bit_counts));
memset (encoder->region_mlt_bits, 0, sizeof(encoder->region_mlt_bits));

siren_init ();
return encoder;
}

void
Siren7_CloseEncoder (SirenEncoder encoder)
{
free (encoder);
}



int
Siren7_EncodeFrame (SirenEncoder encoder, unsigned char *DataIn,
unsigned char *DataOut)
{
int number_of_coefs,
sample_rate_bits,
rate_control_bits,
rate_control_possibilities,
checksum_bits,
esf_adjustment,
scale_factor, number_of_regions, sample_rate_code, bits_per_frame;
int sample_rate = encoder->sample_rate;

int ChecksumTable[4] = { 0x7F80, 0x7878, 0x6666, 0x5555 };
int i, j;

int dwRes = 0;
short out_word;
int bits_left;
int current_word_bits_left;
int region_bit_count;
unsigned int current_word;
unsigned int sum;
unsigned int checksum;
int temp1 = 0;
int temp2 = 0;
int region;
int idx = 0;
int envelope_bits = 0;
int rate_control;
int number_of_available_bits;

float coefs[640];
float In[640];
short BufferOut[60];
float *context = encoder->context;

dwRes =
GetSirenCodecInfo (encoder->flag, sample_rate, &number_of_coefs, &sample_rate_bits,
&rate_control_bits, &rate_control_possibilities, &checksum_bits,
&esf_adjustment, &scale_factor, &number_of_regions, &sample_rate_code,
&bits_per_frame);
if (dwRes != 0)
return dwRes;
#ifdef __NO_CONTROL_OR_CHECK_FIELDS__
sample_rate_bits = 0;
checksum_bits = 0;
sample_rate_code = 0;
#endif
for (i = 0; i < number_of_coefs; i++)
In[i] = (float) ((short) ME_FROM_LE16 (((short *) DataIn)[i]));

dwRes = siren_rmlt_encode_samples (In, context, number_of_coefs, coefs);

if (dwRes != 0)
return dwRes;

envelope_bits =
compute_region_powers (number_of_regions, coefs, encoder->drp_num_bits,
encoder->drp_code_bits, encoder->absolute_region_power_index, esf_adjustment);

number_of_available_bits =
bits_per_frame - rate_control_bits - envelope_bits - sample_rate_bits -
checksum_bits;

categorize_regions (number_of_regions, number_of_available_bits,
encoder->absolute_region_power_index, encoder->power_categories, encoder->category_balance);

for (region = 0; region < number_of_regions; region++) {
encoder->absolute_region_power_index[region] += 24;
encoder->region_mlt_bit_counts[region] = 0;
}

rate_control =
quantize_mlt (number_of_regions, rate_control_possibilities,
number_of_available_bits, coefs, encoder->absolute_region_power_index,
encoder->power_categories, encoder->category_balance, encoder->region_mlt_bit_counts,
encoder->region_mlt_bits);

idx = 0;
bits_left = 16 - sample_rate_bits;
out_word = sample_rate_code << (16 - sample_rate_bits);
encoder->drp_num_bits[number_of_regions] = rate_control_bits;
encoder->drp_code_bits[number_of_regions] = rate_control;
for (region = 0; region <= number_of_regions; region++) {
i = encoder->drp_num_bits[region] - bits_left;
if (i < 0) {
out_word += encoder->drp_code_bits[region] << -i;
bits_left -= encoder->drp_num_bits[region];
} else {
BufferOut[idx++] = out_word + (encoder->drp_code_bits[region] >> i);
bits_left += 16 - encoder->drp_num_bits[region];
out_word = encoder->drp_code_bits[region] << bits_left;
}
}

for (region = 0; region < number_of_regions && (16 * idx) < bits_per_frame;
region++) {
current_word_bits_left = region_bit_count = encoder->region_mlt_bit_counts[region];
if (current_word_bits_left > 32)
current_word_bits_left = 32;

current_word = encoder->region_mlt_bits[region * 4];
i = 1;
while (region_bit_count > 0 && (16 * idx) < bits_per_frame) {
if (current_word_bits_left < bits_left) {
bits_left -= current_word_bits_left;
out_word +=
(current_word >> (32 - current_word_bits_left)) << bits_left;
current_word_bits_left = 0;
} else {
BufferOut[idx++] =
(short) (out_word + (current_word >> (32 - bits_left)));
current_word_bits_left -= bits_left;
current_word <<= bits_left;
bits_left = 16;
out_word = 0;
}
if (current_word_bits_left == 0) {
region_bit_count -= 32;
current_word = encoder->region_mlt_bits[(region * 4) + i++];
current_word_bits_left = region_bit_count;
if (current_word_bits_left > 32)
current_word_bits_left = 32;
}
}
}


while ((16 * idx) < bits_per_frame) {
BufferOut[idx++] = (short) ((0xFFFF >> (16 - bits_left)) + out_word);
bits_left = 16;
out_word = 0;
}

if (checksum_bits > 0) {
BufferOut[idx - 1] &= (-1 << checksum_bits);
sum = 0;
idx = 0;
do {
sum ^= (BufferOut[idx] & 0xFFFF) << (idx % 15);
} while ((16 * ++idx) < bits_per_frame);

sum = (sum >> 15) ^ (sum & 0x7FFF);
checksum = 0;
for (i = 0; i < 4; i++) {
temp1 = ChecksumTable[i] & sum;
for (j = 8; j > 0; j >>= 1) {
temp2 = temp1 >> j;
temp1 ^= temp2;
}
checksum <<= 1;
checksum |= temp1 & 1;
}
BufferOut[idx - 1] |= ((1 << checksum_bits) - 1) & checksum;
}

j = bits_per_frame / 16;
for (i = 0; i < j; i++)
#ifdef __BIG_ENDIAN_FRAMES__
((short *) DataOut)[i] = BufferOut[i];
#else
((short *) DataOut)[i] =
((BufferOut[i] << 8) & 0xFF00) | ((BufferOut[i] >> 8) & 0x00FF);
#endif

#ifdef __WAV_HEADER__
encoder->WavHeader.Samples = ME_FROM_LE32 (encoder->WavHeader.Samples);
encoder->WavHeader.Samples += number_of_coefs;
encoder->WavHeader.Samples = ME_TO_LE32 (encoder->WavHeader.Samples);
encoder->WavHeader.DataSize = ME_FROM_LE32 (encoder->WavHeader.DataSize);
encoder->WavHeader.DataSize += bits_per_Frame / 8;
encoder->WavHeader.DataSize = ME_TO_LE32 (encoder->WavHeader.DataSize);
encoder->WavHeader.riff.RiffSize =
ME_FROM_LE32 (encoder->WavHeader.riff.RiffSize);
encoder->WavHeader.riff.RiffSize += bits_per_Frame / 8;
encoder->WavHeader.riff.RiffSize =
ME_TO_LE32 (encoder->WavHeader.riff.RiffSize);
#endif

return 0;
}

+ 0
- 60
Frameworks/g7221/g7221/libsiren/encoder.h View File

@@ -1,60 +0,0 @@
/*
* Siren Encoder/Decoder library
*
* @author: Youness Alaoui <kakaroto@kakaroto.homelinux.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/


#ifndef _SIREN_ENCODER_H
#define _SIREN_ENCODER_H

#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "dct4.h"
#include "rmlt.h"
#include "huffman.h"
#include "common.h"


typedef struct stSirenEncoder {
int sample_rate;
int flag;
#ifdef __WAV_HEADER__
SirenWavHeader WavHeader;
#endif
float context[640];
int absolute_region_power_index[28];
int power_categories[28];
int category_balance[32];
int drp_num_bits[30];
int drp_code_bits[30];
int region_mlt_bit_counts[28];
int region_mlt_bits[112];
} * SirenEncoder;

/* sample_rate MUST be 16000 to be compatible with MSN Voice clips (I think) */
extern SirenEncoder Siren7_NewEncoder(int sample_rate, int flag); /* flag = 1 for Siren7 and 2 for Siren14 */
extern void Siren7_CloseEncoder(SirenEncoder encoder);
/* Input samples / output bytes */
/* Siren7: 320 / 60 */
/* Siren14: 640 / 120 */
extern int Siren7_EncodeFrame(SirenEncoder encoder, unsigned char *DataIn, unsigned char *DataOut);


#endif /* _SIREN_ENCODER_H */

+ 0
- 425
Frameworks/g7221/g7221/libsiren/huffman.c View File

@@ -1,425 +0,0 @@
/*
* Siren Encoder/Decoder library
*
* @author: Youness Alaoui <kakaroto@kakaroto.homelinux.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/


#include "siren7.h"
#include "huffman_consts.h"
#include "huffman.h"

int
next_bit (bitstream *bs)
{
if (bs == NULL || bs->bitstream_ptr == NULL)
return -1;

if (bs->bit_idx == 0) {
bs->current_word = *bs->bitstream_ptr++;
bs->bit_idx = 16;
}

return (bs->current_word >> --bs->bit_idx) & 1;
}

void
set_bitstream (bitstream *bs, int *stream)
{
bs->bitstream_ptr = stream;
bs->current_word = *bs->bitstream_ptr;
bs->bit_idx = 0;
}


int
compute_region_powers (int number_of_regions, float *coefs, int *drp_num_bits,
int *drp_code_bits, int *absolute_region_power_index, int esf_adjustment)
{
float region_power = 0;
int num_bits;
int idx;
int max_idx, min_idx;
int region, i;

for (region = 0; region < number_of_regions; region++) {
region_power = 0.0f;
for (i = 0; i < region_size; i++) {
region_power +=
coefs[(region * region_size) + i] * coefs[(region * region_size) + i];
}
region_power *= region_size_inverse;

min_idx = 0;
max_idx = 64;
for (i = 0; i < 6; i++) {
idx = (min_idx + max_idx) / 2;
if (region_power_table_boundary[idx - 1] <= region_power) {
min_idx = idx;
} else {
max_idx = idx;
}
}
absolute_region_power_index[region] = min_idx - 24;

}

for (region = number_of_regions - 2; region >= 0; region--) {
if (absolute_region_power_index[region] <
absolute_region_power_index[region + 1] - 11)
absolute_region_power_index[region] =
absolute_region_power_index[region + 1] - 11;
}

if (absolute_region_power_index[0] < (1 - esf_adjustment))
absolute_region_power_index[0] = (1 - esf_adjustment);

if (absolute_region_power_index[0] > (31 - esf_adjustment))
absolute_region_power_index[0] = (31 - esf_adjustment);

drp_num_bits[0] = 5;
drp_code_bits[0] = absolute_region_power_index[0] + esf_adjustment;


for (region = 1; region < number_of_regions; region++) {
if (absolute_region_power_index[region] < (-8 - esf_adjustment))
absolute_region_power_index[region] = (-8 - esf_adjustment);
if (absolute_region_power_index[region] > (31 - esf_adjustment))
absolute_region_power_index[region] = (31 - esf_adjustment);
}

num_bits = 5;

for (region = 0; region < number_of_regions - 1; region++) {
idx =
absolute_region_power_index[region + 1] -
absolute_region_power_index[region] + 12;
if (idx < 0)
idx = 0;

absolute_region_power_index[region + 1] =
absolute_region_power_index[region] + idx - 12;
drp_num_bits[region + 1] = differential_region_power_bits[region][idx];
drp_code_bits[region + 1] = differential_region_power_codes[region][idx];
num_bits += drp_num_bits[region + 1];
}

return num_bits;
}


int
decode_envelope (bitstream *bs, int number_of_regions, float *decoder_standard_deviation,
int *absolute_region_power_index, int esf_adjustment)
{
int index;
int i;
int envelope_bits = 0;

index = 0;
for (i = 0; i < 5; i++)
index = (index << 1) | next_bit (bs);
envelope_bits = 5;

absolute_region_power_index[0] = index - esf_adjustment;
decoder_standard_deviation[0] =
standard_deviation[absolute_region_power_index[0] + 24];

for (i = 1; i < number_of_regions; i++) {
index = 0;
do {
index = differential_decoder_tree[i - 1][index][next_bit (bs)];
envelope_bits++;
} while (index > 0);

absolute_region_power_index[i] =
absolute_region_power_index[i - 1] - index - 12;
decoder_standard_deviation[i] =
standard_deviation[absolute_region_power_index[i] + 24];
}

return envelope_bits;
}



static int
huffman_vector (int category, int power_idx, float *mlts, int *out)
{
int i, j;
float temp_value = deviation_inverse[power_idx] * step_size_inverse[category];
int sign_idx, idx, non_zeroes, max, bits_available;
int current_word = 0;
int region_bits = 0;

bits_available = 32;
for (i = 0; i < number_of_vectors[category]; i++) {
sign_idx = idx = non_zeroes = 0;
for (j = 0; j < vector_dimension[category]; j++) {
max = (int) ((fabs (*mlts) * temp_value) + dead_zone[category]);
if (max != 0) {
sign_idx <<= 1;
non_zeroes++;
if (*mlts > 0)
sign_idx++;
if (max > max_bin[category] || max < 0)
max = max_bin[category];

}
mlts++;
idx = (idx * (max_bin[category] + 1)) + max;
}

region_bits += bitcount_tables[category][idx] + non_zeroes;
bits_available -= bitcount_tables[category][idx] + non_zeroes;
if (bits_available < 0) {
*out++ =
current_word + (((code_tables[category][idx] << non_zeroes) +
sign_idx) >> -bits_available);
bits_available += 32;
current_word =
((code_tables[category][idx] << non_zeroes) +
sign_idx) << bits_available;
} else {
current_word +=
((code_tables[category][idx] << non_zeroes) +
sign_idx) << bits_available;
}

}

*out = current_word;
return region_bits;
}

int
quantize_mlt (int number_of_regions, int rate_control_possibilities,
int number_of_available_bits, float *coefs,
int *absolute_region_power_index, int *power_categories,
int *category_balance, int *region_mlt_bit_counts, int *region_mlt_bits)
{
int region;
int mlt_bits = 0;
int rate_control;

for (rate_control = 0; rate_control < ((rate_control_possibilities >> 1) - 1);
rate_control++)
power_categories[category_balance[rate_control]]++;

for (region = 0; region < number_of_regions; region++) {
if (power_categories[region] > 6)
region_mlt_bit_counts[region] = 0;
else
region_mlt_bit_counts[region] =
huffman_vector (power_categories[region],
absolute_region_power_index[region], coefs + (region_size * region),
region_mlt_bits + (4 * region));
mlt_bits += region_mlt_bit_counts[region];
}

while (mlt_bits < number_of_available_bits && rate_control > 0) {
rate_control--;
region = category_balance[rate_control];
power_categories[region]--;

if (power_categories[region] < 0)
power_categories[region] = 0;

mlt_bits -= region_mlt_bit_counts[region];

if (power_categories[region] > 6)
region_mlt_bit_counts[region] = 0;
else
region_mlt_bit_counts[region] =
huffman_vector (power_categories[region],
absolute_region_power_index[region], coefs + (region_size * region),
region_mlt_bits + (4 * region));

mlt_bits += region_mlt_bit_counts[region];
}

while (mlt_bits > number_of_available_bits
&& rate_control < rate_control_possibilities) {
region = category_balance[rate_control];
power_categories[region]++;
mlt_bits -= region_mlt_bit_counts[region];

if (power_categories[region] > 6)
region_mlt_bit_counts[region] = 0;
else
region_mlt_bit_counts[region] =
huffman_vector (power_categories[region],
absolute_region_power_index[region], coefs + (region_size * region),
region_mlt_bits + (4 * region));

mlt_bits += region_mlt_bit_counts[region];

rate_control++;
}

return rate_control;
}

static int
get_dw (SirenDecoder decoder)
{
int ret = decoder->dw1 + decoder->dw4;

if ((ret & 0x8000) != 0)
ret++;

decoder->dw1 = decoder->dw2;
decoder->dw2 = decoder->dw3;
decoder->dw3 = decoder->dw4;
decoder->dw4 = ret;

return ret;
}




int
decode_vector (SirenDecoder decoder, bitstream *bs, int number_of_regions,
int number_of_available_bits, float *decoder_standard_deviation,
int *power_categories, float *coefs, int scale_factor)
{
float *coefs_ptr;
float decoded_value;
float noise;
const int *decoder_tree;

int region;
int category;
int i, j;
int index;
int error;
int dw1;
int dw2;

error = 0;
for (region = 0; region < number_of_regions; region++) {
category = power_categories[region];
coefs_ptr = coefs + (region * region_size);

if (category < 7) {
decoder_tree = decoder_tables[category];

for (i = 0; i < number_of_vectors[category]; i++) {
index = 0;
do {
if (number_of_available_bits <= 0) {
error = 1;
break;
}

index = decoder_tree[index + next_bit (bs)];
number_of_available_bits--;
} while ((index & 1) == 0);

index >>= 1;

if (error == 0 && number_of_available_bits >= 0) {
for (j = 0; j < vector_dimension[category]; j++) {
decoded_value =
mlt_quant[category][index & ((1 << index_table[category]) - 1)];
index >>= index_table[category];

if (decoded_value != 0) {
if (next_bit (bs) == 0)
decoded_value *= -decoder_standard_deviation[region];
else
decoded_value *= decoder_standard_deviation[region];
number_of_available_bits--;
}

*coefs_ptr++ = decoded_value * scale_factor;
}
} else {
error = 1;
break;
}
}

if (error == 1) {
for (j = region + 1; j < number_of_regions; j++)
power_categories[j] = 7;
category = 7;
}
}


coefs_ptr = coefs + (region * region_size);

if (category == 5) {
i = 0;
for (j = 0; j < region_size; j++) {
if (*coefs_ptr != 0) {
i++;
if (fabs (*coefs_ptr) > 2.0 * decoder_standard_deviation[region]) {
i += 3;
}
}
coefs_ptr++;
}

noise = decoder_standard_deviation[region] * noise_category5[i];
} else if (category == 6) {
i = 0;
for (j = 0; j < region_size; j++) {
if (*coefs_ptr++ != 0)
i++;
}

noise = decoder_standard_deviation[region] * noise_category6[i];
} else if (category == 7) {
noise = decoder_standard_deviation[region] * noise_category7;
} else {
noise = 0;
}

coefs_ptr = coefs + (region * region_size);

if (category == 5 || category == 6 || category == 7) {
dw1 = get_dw (decoder);
dw2 = get_dw (decoder);

for (j = 0; j < 10; j++) {
if (category == 7 || *coefs_ptr == 0) {
if ((dw1 & 1))
*coefs_ptr = noise;
else
*coefs_ptr = -noise;
}
coefs_ptr++;
dw1 >>= 1;

if (category == 7 || *coefs_ptr == 0) {
if ((dw2 & 1))
*coefs_ptr = noise;
else
*coefs_ptr = -noise;
}
coefs_ptr++;
dw2 >>= 1;
}
}
}

return error == 1 ? -1 : number_of_available_bits;
}

+ 0
- 42
Frameworks/g7221/g7221/libsiren/huffman.h View File

@@ -1,42 +0,0 @@
/*
* Siren Encoder/Decoder library
*
* @author: Youness Alaoui <kakaroto@kakaroto.homelinux.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/

#ifndef _SIREN7_HUFFMAN_H_
#define _SIREN7_HUFFMAN_H_

#include "decoder.h"

typedef struct bitstream
{