1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2009 Mohamed Tarek
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include <sys/types.h>
31 //#define DUMP_RAW_FRAMES
34 # define DEBUGF(message,args ...) printf
40 int main(int argc
, char *argv
[])
43 int res
, datasize
,x
,i
;
45 #ifdef DUMP_RAW_FRAMES
52 uint32_t packet_count
;
57 memset(&q
,0,sizeof(COOKContext
));
58 memset(&rmctx
,0,sizeof(RMContext
));
59 memset(&pkt
,0,sizeof(RMPacket
));
62 DEBUGF("Incorrect number of arguments\n");
66 fd
= open(argv
[1],O_RDONLY
);
68 DEBUGF("Error opening file %s\n", argv
[1]);
72 fd_dec
= open_wav("output.wav");
74 DEBUGF("Error creating output file\n");
77 res
= real_parse_header(fd
, &rmctx
);
78 packet_count
= rmctx
.nb_packets
;
79 rmctx
.audio_framesize
= rmctx
.block_align
;
80 rmctx
.block_align
= rmctx
.sub_packet_size
;
81 fs
= rmctx
.audio_framesize
;
82 sps
= rmctx
.block_align
;
83 h
= rmctx
.sub_packet_h
;
84 cook_decode_init(&rmctx
,&q
);
85 DEBUGF("nb_frames = %d\n",nb_frames
);
89 packet_count
+= h
- (packet_count
% h
);
90 rmctx
.nb_packets
= packet_count
;
95 memset(pkt
.data
,0,sizeof(pkt
.data
));
96 rm_get_packet(fd
, &rmctx
, &pkt
);
97 DEBUGF("total frames = %d packet count = %d output counter = %d \n",rmctx
.audio_pkt_cnt
*(fs
/sps
), packet_count
,rmctx
.audio_pkt_cnt
);
98 for(i
= 0; i
< rmctx
.audio_pkt_cnt
*(fs
/sps
) ; i
++)
100 /* output raw audio frames that are sent to the decoder into separate files */
101 #ifdef DUMP_RAW_FRAMES
102 snprintf(filename
,sizeof(filename
),"dump%d.raw",++x
);
103 fd_out
= open(filename
,O_WRONLY
|O_CREAT
|O_APPEND
);
104 write(fd_out
,pkt
.data
+i
*sps
,sps
);
108 memcpy(inbuf
,pkt
.data
+i
*sps
,sps
);
109 nb_frames
= cook_decode_frame(&rmctx
,&q
, outbuf
, &datasize
, inbuf
, rmctx
.block_align
);
110 rmctx
.frame_number
++;
111 write(fd_dec
,outbuf
,datasize
);
113 packet_count
-= rmctx
.audio_pkt_cnt
;
114 rmctx
.audio_pkt_cnt
= 0;
116 close_wav(fd_dec
,&rmctx
);