/*************************************************************************/ /* */ /* LD-CELP G.728 */ /* */ /* Low-Delay Code Excitation Linear Prediction speech compression. */ /* */ /* Code edited by Michael Concannon. */ /* Based on code written by Alex Zatsman, Analog Devices 1993 */ /* */ /*************************************************************************/ #include #include #include "common.h" #include "prototyp.h" extern void audio_read_filehdr(); extern int read(int, char*, int); real rscale=0.125; /* Scaling factor for input */ char * xfile_name; #ifdef CODER int oxfd = 0; /* output file (codebook indices) */ int ifd = 1; /* input file */ char *ifile_name; void init_input() { if ((ifd=open(ifile_name, O_RDONLY)) < 0) { (void) fprintf(stderr, "Can't open \"%s\"\n", ifile_name); exit(1); } if ((oxfd=open(xfile_name, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0) { (void) fprintf(stderr, "Can't open \"%s\"\n", xfile_name); } } void put_index(int x) { short sx = x; write(oxfd, &sx, 2); } #endif #ifdef DECODER char * ofile_name; static int ofd=1; /* Outpu file */ static ixfd = 0; /* Input file (codebook indices) */ int sound_overflow = 0; void init_output() { sound_overflow = 0; if ((ofd=open(ofile_name, O_WRONLY|O_CREAT|O_TRUNC, 0644)) < 0) { extern int errno; extern char *sys_errlist[]; int ee = errno; (void) fprintf(stderr, "Can't open \"%s\" for output\n", ofile_name); printf(sys_errlist[ee]); exit(1); } if ((ixfd = open(xfile_name, O_RDONLY)) < 0) { (void) fprintf(stderr, "Can't open \"%s\"\n", xfile_name); exit(3); } } int get_index() { short sx; if (read(ixfd, (char*)&sx, sizeof(sx)) < sizeof(sx)) return -1; return (int)sx; } #endif /* Return Number of Samples Read */ #ifdef CODER int read_sound_buffer(int n, real buf[]) { short s; int i, c=0; for (i=0; i 0; i++) { buf[c++] = rscale * (real) s; } return c; } #endif #ifdef DECODER int write_sound_buffer(int n, real buf[]) { int i; short s; float xx; for (i=0; i 0.0) if (xx > 32767.0) xx = 32767.0; else xx += 0.5; else if (xx < -32768.0) xx = -32768.0; else xx -= 0.5; s = (short) xx; write(ofd, &s, 2); } return 0; } #endif