-
Notifications
You must be signed in to change notification settings - Fork 690
Expand file tree
/
Copy pathDecoder.c
More file actions
589 lines (529 loc) · 20.6 KB
/
Copy pathDecoder.c
File metadata and controls
589 lines (529 loc) · 20.6 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
/***********************************************************************
Copyright (c) 2006-2012, Skype Limited. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, (subject to the limitations in the disclaimer below)
are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of Skype Limited, nor the names of specific
contributors, may be used to endorse or promote products derived from
this software without specific prior written permission.
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED
BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***********************************************************************/
/*****************************/
/* Silk decoder test program */
/*****************************/
#ifdef _WIN32
#define _CRT_SECURE_NO_DEPRECATE 1
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "SKP_Silk_SDK_API.h"
#include "SKP_Silk_SigProc_FIX.h"
/* Define codec specific settings should be moved to h file */
#define MAX_BYTES_PER_FRAME 1024
#define MAX_INPUT_FRAMES 5
#define MAX_FRAME_LENGTH 480
#define FRAME_LENGTH_MS 20
#define MAX_API_FS_KHZ 48
#define MAX_LBRR_DELAY 2
#ifdef _SYSTEM_IS_BIG_ENDIAN
/* Function to convert a little endian int16 to a */
/* big endian int16 or vica verca */
void swap_endian(
SKP_int16 vec[],
SKP_int len
)
{
SKP_int i;
SKP_int16 tmp;
SKP_uint8 *p1, *p2;
for( i = 0; i < len; i++ ){
tmp = vec[ i ];
p1 = (SKP_uint8 *)&vec[ i ]; p2 = (SKP_uint8 *)&tmp;
p1[ 0 ] = p2[ 1 ]; p1[ 1 ] = p2[ 0 ];
}
}
#endif
#if (defined(_WIN32) || defined(_WINCE))
#include <windows.h> /* timer */
#else // Linux or Mac
#include <sys/time.h>
#endif
#ifdef _WIN32
unsigned long GetHighResolutionTime() /* O: time in usec*/
{
/* Returns a time counter in microsec */
/* the resolution is platform dependent */
/* but is typically 1.62 us resolution */
LARGE_INTEGER lpPerformanceCount;
LARGE_INTEGER lpFrequency;
QueryPerformanceCounter(&lpPerformanceCount);
QueryPerformanceFrequency(&lpFrequency);
return (unsigned long)((1000000*(lpPerformanceCount.QuadPart)) / lpFrequency.QuadPart);
}
#else // Linux or Mac
unsigned long GetHighResolutionTime() /* O: time in usec*/
{
struct timeval tv;
gettimeofday(&tv, 0);
return((tv.tv_sec*1000000)+(tv.tv_usec));
}
#endif // _WIN32
/* Seed for the random number generator, which is used for simulating packet loss */
static SKP_int32 rand_seed = 1;
static void print_usage(char* argv[]) {
fprintf(stderr, "\nVersion:20160922 Build By kn007 (kn007.net)");
fprintf(stderr, "\nGithub: https://github.com/kn007/silk-v3-decoder\n");
fprintf(stderr, "\nusage: %s in.bit out.pcm [settings]\n", argv[ 0 ] );
fprintf(stderr, "\nin.bit : Bitstream input to decoder" );
fprintf(stderr, "\nout.pcm : Speech output from decoder" );
fprintf(stderr, "\n settings:" );
fprintf(stderr, "\n-Fs_API <Hz> : Sampling rate of output signal in Hz; default: 24000" );
fprintf(stderr, "\n-loss <perc> : Simulated packet loss percentage (0-100); default: 0" );
fprintf(stderr, "\n-quiet : Print out just some basic values" );
fprintf(stderr, "\n" );
}
int main( int argc, char* argv[] )
{
unsigned long tottime, starttime;
double filetime;
size_t counter;
SKP_int32 args, totPackets, i, k;
SKP_int16 ret, len, tot_len;
SKP_int16 nBytes;
SKP_uint8 payload[ MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES * ( MAX_LBRR_DELAY + 1 ) ];
SKP_uint8 *payloadEnd = NULL, *payloadToDec = NULL;
SKP_uint8 FECpayload[ MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES ], *payloadPtr;
SKP_int16 nBytesFEC;
SKP_int16 nBytesPerPacket[ MAX_LBRR_DELAY + 1 ], totBytes;
SKP_int16 out[ ( ( FRAME_LENGTH_MS * MAX_API_FS_KHZ ) << 1 ) * MAX_INPUT_FRAMES ], *outPtr;
char speechOutFileName[ 150 ], bitInFileName[ 150 ];
#ifdef _WIN32
HANDLE bitInFile, speechOutFile;
DWORD dwCounter;
#else
FILE *bitInFile, *speechOutFile;
#endif
SKP_int32 packetSize_ms=0, API_Fs_Hz = 0;
SKP_int32 decSizeBytes;
void *psDec;
SKP_float loss_prob;
SKP_int32 frames, lost, quiet;
SKP_SILK_SDK_DecControlStruct DecControl;
if( argc < 3 ) {
print_usage( argv );
exit( 0 );
}
/* default settings */
quiet = 0;
loss_prob = 0.0f;
/* get arguments */
args = 1;
strcpy( bitInFileName, argv[ args ] );
args++;
strcpy( speechOutFileName, argv[ args ] );
args++;
while( args < argc ) {
if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-loss" ) == 0 ) {
sscanf( argv[ args + 1 ], "%f", &loss_prob );
args += 2;
} else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-Fs_API" ) == 0 ) {
sscanf( argv[ args + 1 ], "%d", &API_Fs_Hz );
args += 2;
} else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-quiet" ) == 0 ) {
quiet = 1;
args++;
} else {
fprintf(stderr, "Error: unrecognized setting: %s\n\n", argv[ args ] );
print_usage( argv );
exit( 0 );
}
}
if( !quiet ) {
fprintf(stderr,"********** Silk Decoder (Fixed Point) v %s ********************\n", SKP_Silk_SDK_get_version());
fprintf(stderr,"********** Compiled for %d bit cpu *******************************\n", (int)sizeof(void*) * 8 );
fprintf(stderr, "Input: %s\n", bitInFileName );
fprintf(stderr, "Output: %s\n", speechOutFileName );
}
/* Open files */
#ifdef _WIN32
if(!SKP_STR_CASEINSENSITIVE_COMPARE(bitInFileName, "-")) {
bitInFile = GetStdHandle(STD_INPUT_HANDLE);
} else {
bitInFile = CreateFileA(bitInFileName,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL
);
}
#else
bitInFile = SKP_STR_CASEINSENSITIVE_COMPARE(bitInFileName, "-") ? fopen( bitInFileName, "rb" ) : stdin;
#endif
if( bitInFile == NULL ) {
fprintf(stderr, "Error: could not open input file %s\n", bitInFileName );
exit( 0 );
}
/* Check Silk header */
{
char header_buf[ 50 ];
#ifdef _WIN32
ReadFile(bitInFile, header_buf, sizeof(char), NULL, NULL);
#else
fread(header_buf, sizeof(char), 1, bitInFile);
#endif
header_buf[ strlen( "" ) ] = '\0'; /* Terminate with a null character */
if( strcmp( header_buf, "" ) != 0 ) {
#ifdef _WIN32
DWORD dwCounter;
ReadFile(bitInFile, header_buf, sizeof(char)*strlen( "!SILK_V3" ),&dwCounter,NULL);
counter = dwCounter / sizeof(char);
#else
counter = fread( header_buf, sizeof( char ), strlen( "!SILK_V3" ), bitInFile );
#endif
header_buf[ strlen( "!SILK_V3" ) ] = '\0'; /* Terminate with a null character */
if( strcmp( header_buf, "!SILK_V3" ) != 0 ) {
/* Non-equal strings */
fprintf(stderr, "Error: Wrong Header %s\n", header_buf );
exit( 0 );
}
} else {
#ifdef _WIN32
ReadFile(bitInFile, header_buf, sizeof(char)*strlen( "#!SILK_V3" ),&dwCounter,NULL);
counter = dwCounter / sizeof(char);
#else
counter = fread( header_buf, sizeof( char ), strlen( "#!SILK_V3" ), bitInFile );
#endif
header_buf[ strlen( "#!SILK_V3" ) ] = '\0'; /* Terminate with a null character */
if( strcmp( header_buf, "#!SILK_V3" ) != 0 ) {
/* Non-equal strings */
fprintf(stderr, "Error: Wrong Header %s\n", header_buf );
exit( 0 );
}
}
}
#ifdef _WIN32
if (!SKP_STR_CASEINSENSITIVE_COMPARE(speechOutFileName, "-"))
{
speechOutFile = GetStdHandle(STD_OUTPUT_HANDLE);
} else {
speechOutFile = CreateFileA(speechOutFileName,
GENERIC_WRITE,
FILE_SHARE_READ,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL
);
}
#else
speechOutFile = SKP_STR_CASEINSENSITIVE_COMPARE(bitInFileName, "-") ? fopen( speechOutFileName, "wb" ) : stdout;
#endif
if( speechOutFile == NULL ) {
fprintf(stderr, "Error: could not open output file %s\n", speechOutFileName );
exit( 0 );
}
/* Set the samplingrate that is requested for the output */
if( API_Fs_Hz == 0 ) {
DecControl.API_sampleRate = 24000;
} else {
DecControl.API_sampleRate = API_Fs_Hz;
}
/* Initialize to one frame per packet, for proper concealment before first packet arrives */
DecControl.framesPerPacket = 1;
/* Create decoder */
ret = SKP_Silk_SDK_Get_Decoder_Size( &decSizeBytes );
if( ret ) {
fprintf(stderr, "\nSKP_Silk_SDK_Get_Decoder_Size returned %d", ret );
}
psDec = malloc( decSizeBytes );
/* Reset decoder */
ret = SKP_Silk_SDK_InitDecoder( psDec );
if( ret ) {
fprintf(stderr, "\nSKP_Silk_InitDecoder returned %d", ret );
}
totPackets = 0;
tottime = 0;
payloadEnd = payload;
/* Simulate the jitter buffer holding MAX_FEC_DELAY packets */
for( i = 0; i < MAX_LBRR_DELAY; i++ ) {
/* Read payload size */
#ifdef _WIN32
ReadFile(bitInFile, &nBytes, sizeof(SKP_int16), &dwCounter, NULL);
counter = dwCounter / sizeof(SKP_int16);
#else
counter = fread( &nBytes, sizeof( SKP_int16 ), 1, bitInFile );
#endif
#ifdef _SYSTEM_IS_BIG_ENDIAN
swap_endian( &nBytes, 1 );
#endif
/* Read payload */
#ifdef _WIN32
ReadFile(bitInFile, payloadEnd, sizeof(SKP_uint8)*nBytes, &dwCounter, NULL);
counter = dwCounter / sizeof(SKP_uint8);
#else
counter = fread( payloadEnd, sizeof( SKP_uint8 ), nBytes, bitInFile );
#endif
if( ( SKP_int16 )counter < nBytes ) {
break;
}
nBytesPerPacket[ i ] = nBytes;
payloadEnd += nBytes;
totPackets++;
}
while( 1 ) {
/* Read payload size */
#ifdef _WIN32
ReadFile(bitInFile,&nBytes,sizeof(SKP_int16),&dwCounter,NULL);
counter = dwCounter / sizeof(SKP_int16);
#else
counter = fread( &nBytes, sizeof( SKP_int16 ), 1, bitInFile );
#endif
#ifdef _SYSTEM_IS_BIG_ENDIAN
swap_endian( &nBytes, 1 );
#endif
if( nBytes < 0 || counter < 1 ) {
break;
}
/* Read payload */
#ifdef _WIN32
ReadFile(bitInFile,payloadEnd,sizeof(SKP_uint8)*nBytes,&dwCounter,NULL);
counter = dwCounter / sizeof(SKP_uint8);
#else
counter = fread( payloadEnd, sizeof( SKP_uint8 ), nBytes, bitInFile );
#endif
if( ( SKP_int16 )counter < nBytes ) {
break;
}
/* Simulate losses */
rand_seed = SKP_RAND( rand_seed );
if( ( ( ( float )( ( rand_seed >> 16 ) + ( 1 << 15 ) ) ) / 65535.0f >= ( loss_prob / 100.0f ) ) && ( counter > 0 ) ) {
nBytesPerPacket[ MAX_LBRR_DELAY ] = nBytes;
payloadEnd += nBytes;
} else {
nBytesPerPacket[ MAX_LBRR_DELAY ] = 0;
}
if( nBytesPerPacket[ 0 ] == 0 ) {
/* Indicate lost packet */
lost = 1;
/* Packet loss. Search after FEC in next packets. Should be done in the jitter buffer */
payloadPtr = payload;
for( i = 0; i < MAX_LBRR_DELAY; i++ ) {
if( nBytesPerPacket[ i + 1 ] > 0 ) {
starttime = GetHighResolutionTime();
SKP_Silk_SDK_search_for_LBRR( payloadPtr, nBytesPerPacket[ i + 1 ], ( i + 1 ), FECpayload, &nBytesFEC );
tottime += GetHighResolutionTime() - starttime;
if( nBytesFEC > 0 ) {
payloadToDec = FECpayload;
nBytes = nBytesFEC;
lost = 0;
break;
}
}
payloadPtr += nBytesPerPacket[ i + 1 ];
}
} else {
lost = 0;
nBytes = nBytesPerPacket[ 0 ];
payloadToDec = payload;
}
/* Silk decoder */
outPtr = out;
tot_len = 0;
starttime = GetHighResolutionTime();
if( lost == 0 ) {
/* No Loss: Decode all frames in the packet */
frames = 0;
do {
/* Decode 20 ms */
ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 0, payloadToDec, nBytes, outPtr, &len );
if( ret ) {
fprintf(stderr, "\nSKP_Silk_SDK_Decode returned %d", ret );
}
frames++;
outPtr += len;
tot_len += len;
if( frames > MAX_INPUT_FRAMES ) {
/* Hack for corrupt stream that could generate too many frames */
outPtr = out;
tot_len = 0;
frames = 0;
}
/* Until last 20 ms frame of packet has been decoded */
} while( DecControl.moreInternalDecoderFrames );
} else {
/* Loss: Decode enough frames to cover one packet duration */
for( i = 0; i < DecControl.framesPerPacket; i++ ) {
/* Generate 20 ms */
ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 1, payloadToDec, nBytes, outPtr, &len );
if( ret ) {
fprintf(stderr, "\nSKP_Silk_Decode returned %d", ret );
}
outPtr += len;
tot_len += len;
}
}
packetSize_ms = tot_len / ( DecControl.API_sampleRate / 1000 );
tottime += GetHighResolutionTime() - starttime;
totPackets++;
/* Write output to file */
#ifdef _SYSTEM_IS_BIG_ENDIAN
swap_endian( out, tot_len );
#endif
#ifdef _WIN32
WriteFile(speechOutFile, out, sizeof(SKP_int16)*tot_len,NULL,NULL);
#else
fwrite( out, sizeof( SKP_int16 ), tot_len, speechOutFile );
#endif
/* Update buffer */
totBytes = 0;
for( i = 0; i < MAX_LBRR_DELAY; i++ ) {
totBytes += nBytesPerPacket[ i + 1 ];
}
/* Check if the received totBytes is valid */
if (totBytes < 0 || totBytes > sizeof(payload))
{
fprintf( stderr, "\rPackets decoded: %d", totPackets );
return -1;
}
SKP_memmove( payload, &payload[ nBytesPerPacket[ 0 ] ], totBytes * sizeof( SKP_uint8 ) );
payloadEnd -= nBytesPerPacket[ 0 ];
SKP_memmove( nBytesPerPacket, &nBytesPerPacket[ 1 ], MAX_LBRR_DELAY * sizeof( SKP_int16 ) );
if( !quiet ) {
fprintf( stderr, "\rPackets decoded: %d", totPackets );
}
}
/* Empty the recieve buffer */
for( k = 0; k < MAX_LBRR_DELAY; k++ ) {
if( nBytesPerPacket[ 0 ] == 0 ) {
/* Indicate lost packet */
lost = 1;
/* Packet loss. Search after FEC in next packets. Should be done in the jitter buffer */
payloadPtr = payload;
for( i = 0; i < MAX_LBRR_DELAY; i++ ) {
if( nBytesPerPacket[ i + 1 ] > 0 ) {
starttime = GetHighResolutionTime();
SKP_Silk_SDK_search_for_LBRR( payloadPtr, nBytesPerPacket[ i + 1 ], ( i + 1 ), FECpayload, &nBytesFEC );
tottime += GetHighResolutionTime() - starttime;
if( nBytesFEC > 0 ) {
payloadToDec = FECpayload;
nBytes = nBytesFEC;
lost = 0;
break;
}
}
payloadPtr += nBytesPerPacket[ i + 1 ];
}
} else {
lost = 0;
nBytes = nBytesPerPacket[ 0 ];
payloadToDec = payload;
}
/* Silk decoder */
outPtr = out;
tot_len = 0;
starttime = GetHighResolutionTime();
if( lost == 0 ) {
/* No loss: Decode all frames in the packet */
frames = 0;
do {
/* Decode 20 ms */
ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 0, payloadToDec, nBytes, outPtr, &len );
if( ret ) {
fprintf(stderr, "\nSKP_Silk_SDK_Decode returned %d", ret );
}
frames++;
outPtr += len;
tot_len += len;
if( frames > MAX_INPUT_FRAMES ) {
/* Hack for corrupt stream that could generate too many frames */
outPtr = out;
tot_len = 0;
frames = 0;
}
/* Until last 20 ms frame of packet has been decoded */
} while( DecControl.moreInternalDecoderFrames );
} else {
/* Loss: Decode enough frames to cover one packet duration */
/* Generate 20 ms */
for( i = 0; i < DecControl.framesPerPacket; i++ ) {
ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 1, payloadToDec, nBytes, outPtr, &len );
if( ret ) {
fprintf(stderr, "\nSKP_Silk_Decode returned %d", ret );
}
outPtr += len;
tot_len += len;
}
}
packetSize_ms = tot_len / ( DecControl.API_sampleRate / 1000 );
tottime += GetHighResolutionTime() - starttime;
totPackets++;
/* Write output to file */
#ifdef _SYSTEM_IS_BIG_ENDIAN
swap_endian( out, tot_len );
#endif
#ifdef _WIN32
WriteFile(speechOutFile, out, sizeof(SKP_int16)*tot_len,NULL,NULL);
#else
fwrite( out, sizeof( SKP_int16 ), tot_len, speechOutFile );
#endif
/* Update Buffer */
totBytes = 0;
for( i = 0; i < MAX_LBRR_DELAY; i++ ) {
totBytes += nBytesPerPacket[ i + 1 ];
}
/* Check if the received totBytes is valid */
if (totBytes < 0 || totBytes > sizeof(payload))
{
fprintf( stderr, "\rPackets decoded: %d", totPackets );
return -1;
}
SKP_memmove( payload, &payload[ nBytesPerPacket[ 0 ] ], totBytes * sizeof( SKP_uint8 ) );
payloadEnd -= nBytesPerPacket[ 0 ];
SKP_memmove( nBytesPerPacket, &nBytesPerPacket[ 1 ], MAX_LBRR_DELAY * sizeof( SKP_int16 ) );
if( !quiet ) {
fprintf( stderr, "\rPackets decoded: %d", totPackets );
}
}
if( !quiet ) {
fprintf(stderr, "\nDecoding Finished \n" );
}
/* Free decoder */
free( psDec );
/* Close files */
#ifdef _WIN32
CloseHandle(speechOutFile);
CloseHandle(bitInFile);
#else
fclose( speechOutFile );
fclose( bitInFile );
#endif
filetime = totPackets * 1e-3 * packetSize_ms;
if( !quiet ) {
fprintf(stderr,"\nFile length: %.3f s", filetime);
fprintf(stderr,"\nTime for decoding: %.3f s (%.3f%% of realtime)", 1e-6 * tottime, 1e-4 * tottime / filetime);
fprintf(stderr,"\n\n");
} else {
/* print time and % of realtime */
fprintf(stderr, "%.3f %.3f %d\n", 1e-6 * tottime, 1e-4 * tottime / filetime, totPackets );
}
return 0;
}