📄 celp.c
字号:
/*LINTLIBRARY*/ /*PROTOLIB1*/#include<math.h>#include<stdio.h> #include<stdlib.h> #include "main.h"#include "celp_io.h"#include "showdata.h"#include "cli.h"#include "analysis.h"#include "channel.h"#include "codeparm.h"#include "mark.h"#include "synth.h"
void write_wav(
float output[],
FILE *fp_out,
int size,
int num_samps
);/*************************************************************************** ** U.S. Department of Defense ** CELP Voice Coder ** Version 3.3c ** 1 June 1994 ** ** FOR OFFICIAL U.S. GOVERNMENT CONTRACT USE ONLY ** ** The U.S. Government shall not be held liable for any damages ** resulting from this code. Further reproduction or distribution ** of this code without prior written permission of the U.S. ** Government is prohibited. R224 may be contacted at: ** ** DIRNSA, R224 ** 9800 Savage Road ** Fort Meade, MD 20755-6000 USA ** **==========================================================================** REFERENCES** "Details to Assist in Implementation of Federal Standard 1016 CELP,"* Technical Information Bulletin 92-1, National Communications System,* (included as a Postscript file in CELP 3.3 Release)** "Federal Standard 1016," Telecommunications: Analog-to-Digital * Conversion of Voice by 4800 bit/second Code Excited Linear* Predictive (CELP) Coding, National Communications System, distributed* by the General Services Administration:* GSA Federal Supply Service Bureau* Specification Section, Suite 8100* 470 E. L'Enfant Place, S.W.* Washington, DC 20407* (202)755-0325** Misc: The following articles describe the Federal-Standard-1016* 4.8-kbps CELP coder (it's unnecessary to read more than one):* + Campbell, Joseph P. Jr., Thomas E. Tremain and Vanoy C.* Welch, "The Federal Standard 1016 4800 bps CELP Voice Coder,"* Digital Signal Processing, Academic Press, 1991, Vol. 1, No.* 3, p. 145-155.* + Campbell, Joseph P. Jr., Thomas E. Tremain and Vanoy C.* Welch, "The DoD 4.8 kbps Standard (Proposed Federal Standard* 1016)," in Advances in Speech Coding, ed. Atal, Cuperman and* Gersho, Kluwer Academic Publishers, 1991, Chapter 12, p.* 121-133.* + Campbell, Joseph P. Jr., Thomas E. Tremain and Vanoy C.* Welch, "The Proposed Federal Standard 1016 4800 bps Voice* Coder: CELP," Speech Technology Magazine, April/May 1990, p.* 58-64.* ******************************************************************************* ROUTINE* celp (main)** FUNCTION* Codebook excited linear predictor (main routine)*****************************************************************************/int main(int argc, char **argv){FILE *fp_ifile=NULL, *fp_ofile=NULL, *chan_ofp=NULL;TX_PARAM parameters;float speech_in[F_LEN], speech_out[F_LEN];int *channel_in;int *channel_out;int frame_num=1;void *where;CLI UserParams;
int num_bytes;
/* All the variables that can be changed from the command line */UserParams.channel_type = CLEAR; /* Type of channel to use */UserParams.error_rate = 0.0; /* Error rate for random error channel */UserParams.analysis = TRUE; /* Analysis execution flag */UserParams.synthesis = TRUE; /* Synthesis execution flag */UserParams.write_chan = FALSE; /* Channel file write flag */UserParams.read_chan = FALSE; /* Channel file read flag */UserParams.chan_file = "ChanFile.hex"; /* Name of channel file */UserParams.error_parms = "ErrorParms.txt"; /* Name of error parameter file */UserParams.bit_error = "BitErrors.txt"; /* Name of bit error pattern file */UserParams.edac = FALSE; /* EDAC flag */UserParams.code_param = TRUE; /* Encode/Decode parameters flag */if (Setup(argc, argv, &UserParams, &fp_ifile, &fp_ofile, &chan_ofp) != ALL_VALID) exit(0);if (UserParams.analysis) { where = &speech_in[0];}if (UserParams.synthesis) { if (UserParams.read_chan) { channel_out = (int *)calloc(CELP_BITS, sizeof(int)); where = channel_out; }}/* Read input file and continue until end of file */while(IO_read(fp_ifile, UserParams.read_chan, F_LEN, CELP_BITS, where, &num_bytes) != END) {/* Display frame number to user */ mark(1, frame_num);if (UserParams.analysis) {/* Analyze input speech and calculate parameters */ Analysis(speech_in, ¶meters, frame_num);/* Put analysis parameters into bitstream */ EncodeParameters(parameters, CELP_BITS, UserParams.error_parms, UserParams.edac, frame_num, &channel_in);/* Send bitstream through channel */ Channel(channel_in, UserParams.channel_type, CELP_BITS, UserParams.bit_error, UserParams.error_rate, frame_num, &channel_out);/* Save channel onto disk file */ if (UserParams.write_chan) WriteChannel(channel_out, UserParams.write_chan, chan_ofp);}if (UserParams.synthesis) {/* Get parameters from bitstream */ DecodeParameters(channel_out, CELP_BITS, UserParams.error_parms, UserParams.edac, frame_num, UserParams.smoothing, ¶meters);/* Synthesize parameters into output speech */ Synthesis(parameters, frame_num, speech_out);/* Write output speech */ /*IO_write(speech_out, fp_ofile); */
write_wav(speech_out, fp_ofile, F_LEN, num_bytes);
}/* Keep track of frame number */ frame_num++;}wrapup(fp_ifile, fp_ofile, chan_ofp);return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -