-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.c
49 lines (37 loc) · 987 Bytes
/
test.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
#include "crc.h"
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <speex/speex.h>
#define FRAME_SIZE 8000
void decode(int header) {
FILE * fin = fopen("audiopacket2.spx", "r");
FILE * fout = fopen("decoded_audio.raw", "w");
int i;
short out[FRAME_SIZE];
float output[FRAME_SIZE];
char cbits[331-20];
SpeexBits bits;
void * state;
state = speex_decoder_init(&speex_nb_mode);
speex_bits_init(&bits);
while(1) {
if(feof(fin))
break;
/* on lit 307 octets (un paquet) vers cbits */
fread(cbits, 1, 331-20, fin);
/* on le copie vers une structure bit-stream */
speex_bits_read_from(&bits, cbits+header, 331-20-header);
/* on decode */
speex_decode(state, &bits, output);
for(i=0 ; i< FRAME_SIZE ; i++)
out[i]= output[i];
fwrite(out, sizeof(short), FRAME_SIZE, fout);
}
}
int main(int argc, char ** argv){
decode(atoi(argv[1]));
return 0;
}