Commit fc5f32c5 authored by jm's avatar jm
Browse files

cleanup: all use of libc has been moved to misc.c to make porting easier.


git-svn-id: http://svn.xiph.org/trunk/speex@4201 0101bb08-14d6-0310-b084-bc0e0c8e3800
parent 9bb8a9d0
......@@ -45,36 +45,6 @@ Permission is granted to copy, distribute and/or modify this document under
A copy of the license is included in the section entitled "GNU Free Documentati
on License".
\layout Section*
Disclaimer
\layout Standard
This document is meant to provide useful information on the Speex codec
but there is absolutely no warranty regarding usefulness or correctness
of the information provided.
Also, some techniques used in Speex are said to be
\begin_inset Quotes eld
\end_inset
similar
\begin_inset Quotes erd
\end_inset
to techniques used in known codecs.
This should not be understood as an acknowledgment that Speex is using
any patented algorithm used in these codecs, but merely that comprehension
of Speex can be facilitated by thinking that the principles of operation
are the same or similar.
Of course, there's also the obligatory
\begin_inset Quotes eld
\end_inset
all trademarks are property of their respective owner
\begin_inset Quotes erd
\end_inset
.
\layout Standard
\pagebreak_top \pagebreak_bottom
......
......@@ -33,8 +33,6 @@
*/
#include "speex_bits.h"
#include <stdio.h>
#include <stdlib.h>
#include "misc.h"
void speex_bits_init(SpeexBits *bits)
......@@ -91,8 +89,7 @@ void speex_bits_read_from(SpeexBits *bits, char *bytes, int len)
int i;
if (len > MAX_BYTES_PER_FRAME)
{
fprintf (stderr, "Trying to init frame with too many bits");
exit(1);
speex_error ("Trying to init frame with too many bits");
}
for (i=0;i<len;i++)
bits->bytes[i]=bytes[i];
......@@ -162,7 +159,7 @@ void speex_bits_pack(SpeexBits *bits, int data, int nbBits)
bit = (d>>(nbBits-1))&1;
bits->bytes[bits->bytePtr] |= bit<<(7-bits->bitPtr);
bits->bitPtr++;
/*fprintf(stderr, "%d %d\n", nbBits, bit);*/
if (bits->bitPtr==8)
{
bits->bitPtr=0;
......
......@@ -30,12 +30,11 @@
*/
#include <stdlib.h>
#include "cb_search.h"
#include "filters.h"
#include "stack_alloc.h"
#include "vq.h"
#include "misc.h"
void split_cb_search_shape_sign(
float target[], /* target vector */
......@@ -384,8 +383,5 @@ SpeexBits *bits,
void *stack
)
{
int i;
for (i=0;i<nsf;i++)
exc[i]+=3*((((float)rand())/RAND_MAX)-.5);
speex_rand_vec(1, exc, nsf);
}
......@@ -44,8 +44,6 @@ Modified by Jean-Marc Valin
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "lsp.h"
#include "stack_alloc.h"
......@@ -54,6 +52,9 @@ Modified by Jean-Marc Valin
#define M_PI 3.14159265358979323846 /* pi */
#endif
#ifndef NULL
#define NULL 0
#endif
/*---------------------------------------------------------------------------*\
......
......@@ -31,7 +31,6 @@
*/
#include <math.h>
#include <stdio.h>
#include "ltp.h"
#include "stack_alloc.h"
#include "filters.h"
......
......@@ -104,3 +104,38 @@ void *speex_move (void *dest, void *src, int n)
{
return memmove(dest,src,n);
}
void speex_error(char *str)
{
fprintf (stderr, "Fatal error: %s\n", str);
exit(1);
}
void speex_warning(char *str)
{
fprintf (stderr, "warning: %s\n", str);
}
void speex_warning_int(char *str, int val)
{
fprintf (stderr, "warning: %s %d\n", str, val);
}
void speex_rand_vec(float std, float *data, int len)
{
int i;
for (i=0;i<len;i++)
data[i]+=3*std*((((float)rand())/RAND_MAX)-.5);
}
float speex_rand(float std)
{
return 3*std*((((float)rand())/RAND_MAX)-.5);
}
float _speex_putc(int ch, void *file)
{
FILE *f = (FILE *)file;
fputc(ch, f);
}
......@@ -59,4 +59,16 @@ void speex_free (void *ptr);
/** Speex wrapper for mem_move */
void *speex_move (void *dest, void *src, int n);
void speex_error(char *str);
void speex_warning(char *str);
void speex_warning_int(char *str, int val);
void speex_rand_vec(float std, float *data, int len);
float speex_rand(float std);
float _speex_putc(int ch, void *file);
#endif
......@@ -32,8 +32,6 @@
*/
#include <stdlib.h>
#include <stdio.h>
#include "modes.h"
#include "ltp.h"
#include "quant_lsp.h"
......@@ -41,6 +39,11 @@
#include "sb_celp.h"
#include "nb_celp.h"
#include "vbr.h"
#include "misc.h"
#ifndef NULL
#define NULL 0
#endif
SpeexMode *speex_mode_list[SPEEX_NB_MODES] = {&speex_nb_mode, &speex_wb_mode, &speex_uwb_mode};
......@@ -571,7 +574,7 @@ static void nb_mode_query(void *mode, int request, void *ptr)
*((int*)ptr) = m->submodes[*((int*)ptr)]->bits_per_frame;
break;
default:
fprintf(stderr, "Unknown wb_mode_query request: %d\n", request);
speex_warning_int("Unknown nb_mode_query request: ", request);
}
}
......@@ -589,7 +592,7 @@ static void wb_mode_query(void *mode, int request, void *ptr)
*((int*)ptr) = m->submodes[*((int*)ptr)]->bits_per_frame;
break;
default:
fprintf(stderr, "Unknown wb_mode_query request: %d\n", request);
speex_warning_int("Unknown wb_mode_query request: ", request);
}
}
......
......@@ -29,8 +29,6 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "nb_celp.h"
#include "lpc.h"
......@@ -55,6 +53,10 @@
#define M_PI 3.14159265358979323846 /* pi */
#endif
#ifndef NULL
#define NULL 0
#endif
#define SUBMODE(x) st->submodes[st->submodeID]->x
float exc_gain_quant_scal3[8]={-2.794750, -1.810660, -1.169850, -0.848119, -0.587190, -0.329818, -0.063266, 0.282826};
......@@ -687,7 +689,7 @@ int nb_encode(void *state, float *in, SpeexBits *bits)
st->pitch[sub]=pitch;
} else {
fprintf (stderr, "No pitch prediction, what's wrong\n");
speex_error ("No pitch prediction, what's wrong");
}
/* Update target for adaptive codebook contribution */
......@@ -741,14 +743,15 @@ int nb_encode(void *state, float *in, SpeexBits *bits)
ener_1 = 1/ener;
if (0) {
#if 0
{
int start=rand()%35;
printf ("norm_exc: ");
for (i=start;i<start+5;i++)
printf ("%f ", ener_1*st->buf2[i]);
printf ("\n");
}
#endif
/* Normalize innovation */
for (i=0;i<st->subframeSize;i++)
target[i]*=ener_1;
......@@ -767,7 +770,7 @@ int nb_encode(void *state, float *in, SpeexBits *bits)
for (i=0;i<st->subframeSize;i++)
exc[i] += innov[i];
} else {
fprintf(stderr, "No fixed codebook\n");
speex_error("No fixed codebook");
}
/* In some (rare) modes, we do a second search (more bits) to reduce noise even more */
......@@ -1013,7 +1016,7 @@ static void nb_decode_lost(DecState *st, float *out, void *stack)
#else
/*exc[i]=pitch_gain*exc[i-st->last_pitch] + fact*st->innov[i+offset];*/
exc[i]=pitch_gain*exc[i-st->last_pitch] +
fact*sqrt(1-pitch_gain)*3*innov_gain*((((float)rand())/RAND_MAX)-.5);
fact*sqrt(1-pitch_gain)*speex_rand(innov_gain);
#endif
}
}
......@@ -1094,7 +1097,7 @@ int nb_decode(void *state, SpeexBits *bits, float *out)
wideband = speex_bits_unpack_unsigned(bits, 1);
if (wideband)
{
fprintf (stderr, "Corrupted stream?\n");
speex_error ("Corrupted stream?");
}
}
......@@ -1143,11 +1146,10 @@ int nb_decode(void *state, SpeexBits *bits, float *out)
pitch_gain=.6;
for (i=0;i<st->frameSize;i++)
innov_gain += st->innov[i]*st->innov[i];
innov_gain=sqrt(innov_gain/160);
innov_gain=sqrt(innov_gain/st->frameSize);
for (i=0;i<st->frameSize;i++)
{
st->exc[i]=3*innov_gain*((((float)rand())/RAND_MAX)-.5);
}
st->exc[i]=0;
speex_rand_vec(innov_gain, st->exc, st->frameSize);
}
......@@ -1340,7 +1342,7 @@ int nb_decode(void *state, SpeexBits *bits, float *out)
best_pitch_gain=.85;*/
}
} else {
fprintf (stderr, "No pitch prediction, what's wrong\n");
speex_error("No pitch prediction, what's wrong");
}
/* Unquantize the innovation */
......@@ -1373,7 +1375,7 @@ int nb_decode(void *state, SpeexBits *bits, float *out)
/*Fixed codebook contribution*/
SUBMODE(innovation_unquant)(innov, SUBMODE(innovation_params), st->subframeSize, bits, stack);
} else {
fprintf(stderr, "No fixed codebook\n");
speex_error("No fixed codebook");
}
/* De-normalize innovation and update excitation */
......@@ -1638,7 +1640,7 @@ void nb_encoder_ctl(void *state, int request, void *ptr)
(*(float*)ptr)=st->relative_quality;
break;
default:
fprintf(stderr, "Unknown nb_ctl request: %d\n", request);
speex_warning_int("Unknown nb_ctl request: ", request);
}
}
......@@ -1723,6 +1725,6 @@ void nb_decoder_ctl(void *state, int request, void *ptr)
}
break;
default:
fprintf(stderr, "Unknown nb_ctl request: %d\n", request);
speex_warning_int("Unknown nb_ctl request: ", request);
}
}
......@@ -32,7 +32,6 @@
#include "quant_lsp.h"
#include <math.h>
#include <stdio.h>
extern int lsp_nb_vqid[64];
static float quant_weight[MAX_LSP_SIZE];
......
......@@ -30,10 +30,7 @@
*/
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
/*#include "nb_celp.h"*/
#include "sb_celp.h"
#include "stdlib.h"
#include "filters.h"
......@@ -600,6 +597,7 @@ int sb_encode(void *state, float *in, SpeexBits *bits)
scale = gc*sqrt(1+el)/filter_ratio;
scale_1 = 1/scale;
#if 0
if (0 && rand()%5==0)
{
float sc = 1/sqrt(.1+eh/st->subframeSize);
......@@ -613,7 +611,7 @@ int sb_encode(void *state, float *in, SpeexBits *bits)
printf (" %f", tmp);
}
}
#endif
for (i=0;i<st->subframeSize;i++)
exc[i]=0;
exc[0]=1;
......@@ -677,8 +675,8 @@ int sb_encode(void *state, float *in, SpeexBits *bits)
exc[i] += innov2[i];
}
if (0) {
#if 0
{
float en=0;
for (i=0;i<st->subframeSize;i++)
en+=exc[i]*exc[i];
......@@ -687,7 +685,7 @@ int sb_encode(void *state, float *in, SpeexBits *bits)
exc[i]*=en;
printf ("correction high: %f\n", en);
}
#endif
}
/*Keep the previous memory*/
......@@ -1317,7 +1315,7 @@ void sb_encoder_ctl(void *state, int request, void *ptr)
(*(float*)ptr)=st->relative_quality;
break;
default:
fprintf(stderr, "Unknown nb_ctl request: %d\n", request);
speex_warning_int("Unknown nb_ctl request: ", request);
}
}
......@@ -1400,7 +1398,7 @@ void sb_decoder_ctl(void *state, int request, void *ptr)
}
break;
default:
fprintf(stderr, "Unknown sb_ctl request: %d\n", request);
speex_warning_int("Unknown nb_ctl request: ", request);
}
}
......@@ -33,7 +33,7 @@
*/
#include "speex_callbacks.h"
#include <stdio.h>
#include "misc.h"
int speex_inband_handler(SpeexBits *bits, SpeexCallback *callback_list, void *state)
{
......@@ -119,9 +119,8 @@ int speex_std_vbr_quality_request_handler(SpeexBits *bits, void *state, void *da
int speex_std_char_handler(SpeexBits *bits, void *state, void *data)
{
unsigned char ch;
FILE *f = (FILE *)data;
ch = speex_bits_unpack_unsigned(bits, 8);
fputc(ch, f);
_speex_putc(ch, data);
return 0;
}
......
......@@ -33,9 +33,11 @@
#include "speex_header.h"
#include "misc.h"
#include <stdio.h>
#include "speex.h"
#include <stdlib.h>
#ifndef NULL
#define NULL 0
#endif
#define ENDIAN_SWITCH(x) {x=le_int(x);}
......@@ -83,7 +85,7 @@ void speex_init_header(SpeexHeader *header, int rate, int nb_channels, SpeexMode
header->mode = m->modeID;
header->mode_bitstream_version = m->bitstream_version;
if (m->modeID<0)
fprintf (stderr, "This mode is meant to be used alone\n");
speex_warning("This mode is meant to be used alone");
header->nb_channels = nb_channels;
header->bitrate = -1;
speex_mode_query(m, SPEEX_MODE_FRAME_SIZE, &header->frame_size);
......@@ -125,14 +127,15 @@ SpeexHeader *speex_packet_to_header(char *packet, int size)
char *h = "Speex ";
for (i=0;i<8;i++)
if (packet[i]!=h[i])
{
fprintf (stderr, "This doesn't look like a Speex file\n");
return NULL;
}
{
speex_warning ("This doesn't look like a Speex file");
return NULL;
}
/*FIXME: Do we allow larger headers?*/
if (sizeof(SpeexHeader) != size)
{
fprintf (stderr, "Speex header size mismarch\n");
speex_warning("Speex header size mismarch");
return NULL;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment