📄 io-sparc.c
字号:
/*************************************************************************//* *//* 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 <fcntl.h>#include <stdio.h>#include "common.h"#include "prototyp.h"extern int fprintf();extern void audio_read_filehdr();extern int read(int, char*, int);real rscale=0.125; /* Scaling factor for input */char * xfile_name;#ifdef CODERint oxfd = 0; /* output file (codebook indices) */int ifd = 1; /* input file */char *ifile_name;voidinit_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); }}voidput_index(int x){ short sx = x; write(oxfd, &sx, 2);}#endif#ifdef DECODERchar * 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 CODERint read_sound_buffer(int n, real buf[]){ short s; int i, c=0; for (i=0; i<n && read(ifd, &s, 2) > 0; i++) { buf[c++] = rscale * (real) s; } return c;}#endif#ifdef DECODERintwrite_sound_buffer(int n, real buf[]){ int i; short s; float xx; for (i=0; i<n; i++) { xx = buf[i]/rscale; if (xx > 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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -