summaryrefslogtreecommitdiff
path: root/apps/codecs/libcook/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/libcook/main.c')
-rw-r--r--apps/codecs/libcook/main.c114
1 files changed, 114 insertions, 0 deletions
diff --git a/apps/codecs/libcook/main.c b/apps/codecs/libcook/main.c
new file mode 100644
index 0000000000..2f85295fb5
--- /dev/null
+++ b/apps/codecs/libcook/main.c
@@ -0,0 +1,114 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2009 Mohamed Tarek
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include <stdint.h>
22#include <sys/types.h>
23#include <sys/stat.h>
24#include <fcntl.h>
25#include <unistd.h>
26
27#include "rm2wav.h"
28#include "cook.h"
29
30//#define DUMP_RAW_FRAMES
31#define DEBUGF(message,args ...) av_log(NULL,AV_LOG_ERROR,message,## args)
32int main(int argc, char *argv[])
33{
34 int fd, fd_dec;
35 int res, datasize,x,i;
36 int nb_frames = 0;
37#ifdef DUMP_RAW_FRAMES
38 char filename[15];
39 int fd_out;
40#endif
41 int16_t outbuf[2048];
42 uint8_t inbuf[1024];
43 uint16_t fs,sps,h;
44 uint32_t packet_count;
45 COOKContext q;
46 RMContext rmctx;
47 RMPacket pkt;
48
49 memset(&q,0,sizeof(COOKContext));
50 memset(&rmctx,0,sizeof(RMContext));
51 memset(&pkt,0,sizeof(RMPacket));
52
53 if (argc != 2) {
54 DEBUGF("Incorrect number of arguments\n");
55 return -1;
56 }
57
58 fd = open(argv[1],O_RDONLY);
59 if (fd < 0) {
60 DEBUGF("Error opening file %s\n", argv[1]);
61 return -1;
62 }
63
64 fd_dec = open_wav("output.wav");
65 if (fd_dec < 0) {
66 DEBUGF("Error creating output file\n");
67 return -1;
68 }
69 res = real_parse_header(fd, &rmctx);
70 packet_count = rmctx.nb_packets;
71 rmctx.audio_framesize = rmctx.block_align;
72 rmctx.block_align = rmctx.sub_packet_size;
73 fs = rmctx.audio_framesize;
74 sps= rmctx.block_align;
75 h = rmctx.sub_packet_h;
76 cook_decode_init(&rmctx,&q);
77 av_log(NULL,AV_LOG_ERROR,"nb_frames = %d\n",nb_frames);
78 x = 0;
79 if(packet_count % h)
80 {
81 packet_count += h - (packet_count % h);
82 rmctx.nb_packets = packet_count;
83 }
84 while(packet_count)
85 {
86
87 memset(pkt.data,0,sizeof(pkt.data));
88 rm_get_packet(fd, &rmctx, &pkt);
89 DEBUGF("total frames = %d packet count = %d output counter = %d \n",rmctx.audio_pkt_cnt*(fs/sps), packet_count,rmctx.audio_pkt_cnt);
90 for(i = 0; i < rmctx.audio_pkt_cnt*(fs/sps) ; i++)
91 {
92 /* output raw audio frames that are sent to the decoder into separate files */
93 #ifdef DUMP_RAW_FRAMES
94 snprintf(filename,sizeof(filename),"dump%d.raw",++x);
95 fd_out = open(filename,O_WRONLY|O_CREAT|O_APPEND);
96 write(fd_out,pkt.data+i*sps,sps);
97 close(fd_out);
98 #endif
99
100 memcpy(inbuf,pkt.data+i*sps,sps);
101 nb_frames = cook_decode_frame(&rmctx,&q, outbuf, &datasize, inbuf , rmctx.block_align);
102 rmctx.frame_number++;
103 write(fd_dec,outbuf,datasize);
104 }
105 packet_count -= rmctx.audio_pkt_cnt;
106 rmctx.audio_pkt_cnt = 0;
107 }
108 cook_decode_close(&q);
109 close_wav(fd_dec,&rmctx);
110 close(fd);
111
112
113 return 0;
114}