-
Notifications
You must be signed in to change notification settings - Fork 3
/
decoder.c
139 lines (106 loc) · 4.28 KB
/
decoder.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
ITU-T G.729A Speech Coder with Annex B ANSI-C Source Code
Version 1.4 Last modified: November 2000
Copyright (c) 1996,
AT&T, France Telecom, NTT, Universite de Sherbrooke, Lucent Technologies,
Rockwell International
All rights reserved.
*/
/*-----------------------------------------------------------------*
* Main program of the G.729A 8.0 kbit/s decoder. *
* *
* Usage : decoder bitstream_file synth_file *
* *
*-----------------------------------------------------------------*/
#include <stdlib.h>
#include <stdio.h>
#include "typedef.h"
#include "basic_op.h"
#include "ld8a.h"
#include "dtx.h"
#include "octet.h"
int16_t bad_lsf; /* bad LSF indicator */
/*
This variable should be always set to zero unless transmission errors
in LSP indices are detected.
This variable is useful if the channel coding designer decides to
perform error checking on these important parameters. If an error is
detected on the LSP indices, the corresponding flag is
set to 1 signalling to the decoder to perform parameter substitution.
(The flags should be set back to 0 for correct transmission).
*/
/*-----------------------------------------------------------------*
* Main decoder routine *
*-----------------------------------------------------------------*/
int main(int argc, char *argv[] )
{
int16_t synth_buf[L_FRAME+M], *synth; /* Synthesis */
int16_t parm[PRM_SIZE+2]; /* Synthesis parameters */
int16_t Az_dec[MP1*2]; /* Decoded Az for post-filter */
int16_t T2[2]; /* Pitch lag for 2 subframes */
int16_t i, Vad;
int32_t count_frame;
FILE *f_syn, *f_serial;
printf("\n");
printf("************ ITU G.729A 8.0 KBIT/S SPEECH DECODER ************\n");
printf(" (WITH ANNEX B) \n");
printf("\n");
printf("------------------ Fixed point C simulation --------------------\n");
printf("\n");
printf("------------------ Version 1.4 --------------------\n");
printf("\n");
/* Passed arguments */
if ( argc != 3){
printf("Usage :%s bitstream_file outputspeech_file\n",argv[0]);
printf("\n");
printf("Format for bitstream_file:\n");
printf(" One (2-byte) synchronization word \n");
printf(" One (2-byte) size word,\n");
printf(" 80 words (2-byte) containing 80 bits.\n");
printf("\n");
printf("Format for outputspeech_file:\n");
printf(" Synthesis is written to a binary file of 16 bits data.\n");
exit( 1 );
}
/* Open file for synthesis and packed serial stream */
if( (f_serial = fopen(argv[1],"rb") ) == NULL )
{
printf("%s - Error opening file %s !!\n", argv[0], argv[1]);
exit(0);
}
if( (f_syn = fopen(argv[2], "wb") ) == NULL )
{
printf("%s - Error opening file %s !!\n", argv[0], argv[2]);
exit(0);
}
printf("Input bitstream file : %s\n",argv[1]);
printf("Synthesis speech file : %s\n",argv[2]);
#ifndef OCTET_TX_MODE
printf("OCTET TRANSMISSION MODE is disabled\n");
#endif
/*-----------------------------------------------------------------*
* Initialization of decoder *
*-----------------------------------------------------------------*/
for (i=0; i<M; i++) synth_buf[i] = 0;
synth = synth_buf + M;
bad_lsf = 0; /* Initialize bad LSF indicator */
Init_Decod_ld8a();
Init_Post_Filter();
Init_Post_Process();
/* for G.729b */
Init_Dec_cng();
/*-----------------------------------------------------------------*
* Loop for each "L_FRAME" speech data *
*-----------------------------------------------------------------*/
count_frame = 0L;
while(read_frame(f_serial, parm) != 0)
{
printf("Frame = %ld\r", count_frame++);
Decod_ld8a(parm, synth, Az_dec, T2, &Vad);
Post_Filter(synth, Az_dec, T2, Vad); /* Post-filter */
Post_Process(synth, L_FRAME);
fwrite(synth, sizeof(short), L_FRAME, f_syn);
}
printf("%ld frames decoded\n", count_frame);
return(0);
}