@@ -68,44 +68,13 @@ static void rand_resp(float *a, float *b) {
6868 b [1 ] = .75 * uni_rand ();
6969}
7070
71- void compute_noise (int * noise , float noise_std ) {
72- int i ;
73- for (i = 0 ;i < FRAME_SIZE ;i ++ ) {
74- noise [i ] = (int )floor (.5 + noise_std * .707 * (log_approx (rand ()/(float )RAND_MAX )- log_approx (rand ()/(float )RAND_MAX )));
75- }
76- }
77-
7871static opus_int16 float2short (float x )
7972{
8073 int i ;
8174 i = (int )floor (.5 + x );
8275 return IMAX (-32767 , IMIN (32767 , i ));
8376}
8477
85-
86- void write_audio (LPCNetEncState * st , const opus_int16 * pcm , const int * noise , FILE * file ) {
87- int i ;
88- opus_int16 data [2 * FRAME_SIZE ];
89- for (i = 0 ;i < FRAME_SIZE ;i ++ ) {
90- float p = 0 ;
91- float e ;
92- int j ;
93- for (j = 0 ;j < LPC_ORDER ;j ++ ) p -= st -> features [NB_BANDS + 2 + j ]* st -> sig_mem [j ];
94- e = lin2ulaw (pcm [i ] - p );
95- /* Signal in. */
96- data [2 * i ] = float2short (st -> sig_mem [0 ]);
97- /* Signal out. */
98- data [2 * i + 1 ] = pcm [i ];
99- /* Simulate error on excitation. */
100- e += noise [i ];
101- e = IMIN (255 , IMAX (0 , e ));
102-
103- OPUS_MOVE (& st -> sig_mem [1 ], & st -> sig_mem [0 ], LPC_ORDER - 1 );
104- st -> sig_mem [0 ] = p + ulaw2lin (e );
105- }
106- fwrite (data , 4 * FRAME_SIZE , 1 , file );
107- }
108-
10978int main (int argc , char * * argv ) {
11079 int i ;
11180 char * argv0 ;
@@ -123,13 +92,11 @@ int main(int argc, char **argv) {
12392 FILE * ffeat ;
12493 FILE * fpcm = NULL ;
12594 opus_int16 pcm [FRAME_SIZE ]= {0 };
126- int noisebuf [FRAME_SIZE ]= {0 };
12795 opus_int16 tmp [FRAME_SIZE ] = {0 };
12896 float speech_gain = 1 ;
12997 float old_speech_gain = 1 ;
13098 int one_pass_completed = 0 ;
13199 LPCNetEncState * st ;
132- float noise_std = 0 ;
133100 int training = -1 ;
134101 int burg = 0 ;
135102 int pitch = 0 ;
@@ -202,16 +169,12 @@ int main(int argc, char **argv) {
202169 for (i = 0 ;i < FRAME_SIZE ;i ++ ) x [i ] = tmp [i ];
203170 if (count * FRAME_SIZE_5MS >=10000000 && one_pass_completed ) break ;
204171 if (training && ++ gain_change_count > 2821 ) {
205- float tmp1 , tmp2 ;
206172 speech_gain = pow (10. , (-30 + (rand ()%40 ))/20. );
207173 if (rand ()& 1 ) speech_gain = - speech_gain ;
208174 if (rand ()%20 == 0 ) speech_gain *= .01 ;
209175 if (!pitch && rand ()%100 == 0 ) speech_gain = 0 ;
210176 gain_change_count = 0 ;
211177 rand_resp (a_sig , b_sig );
212- tmp1 = rand ()/(float )RAND_MAX ;
213- tmp2 = rand ()/(float )RAND_MAX ;
214- noise_std = ABS16 (-1.5 * log (1e-4 + tmp1 )- .5 * log (1e-4 + tmp2 ));
215178 if (fnoise != NULL ) {
216179 long pos ;
217180 /* Randomize the fraction because rand() only gives us 31 bits. */
@@ -244,15 +207,10 @@ int main(int argc, char **argv) {
244207 fwrite (ceps , sizeof (float ), 2 * NB_BANDS , ffeat );
245208 }
246209 preemphasis (x , & mem_preemph , x , PREEMPHASIS , FRAME_SIZE );
247- for (i = 0 ;i < FRAME_SIZE ;i ++ ) x [i ] += rand ()/(float )RAND_MAX - .5f ;
248210 /* PCM is delayed by 1/2 frame to make the features centered on the frames. */
249211 for (i = 0 ;i < FRAME_SIZE - TRAINING_OFFSET ;i ++ ) pcm [i + TRAINING_OFFSET ] = float2short (x [i ]);
250212 compute_frame_features (st , x , arch );
251213
252- if (fpcm ) {
253- compute_noise (noisebuf , noise_std );
254- }
255-
256214 if (pitch ) {
257215 signed char pitch_features [PITCH_MAX_PERIOD - PITCH_MIN_PERIOD + PITCH_IF_FEATURES ];
258216 for (i = 0 ;i < PITCH_MAX_PERIOD - PITCH_MIN_PERIOD ;i ++ ) {
@@ -266,7 +224,7 @@ int main(int argc, char **argv) {
266224 fwrite (st -> features , sizeof (float ), NB_TOTAL_FEATURES , ffeat );
267225 }
268226 /*if(pitch) fwrite(pcm, FRAME_SIZE, 2, stdout);*/
269- if (fpcm ) write_audio ( st , pcm , noisebuf , fpcm );
227+ if (fpcm ) fwrite ( pcm , FRAME_SIZE , 2 , fpcm );
270228 /*if (fpcm) fwrite(pcm, sizeof(opus_int16), FRAME_SIZE, fpcm);*/
271229 for (i = 0 ;i < TRAINING_OFFSET ;i ++ ) pcm [i ] = float2short (x [i + FRAME_SIZE - TRAINING_OFFSET ]);
272230 old_speech_gain = speech_gain ;
0 commit comments