Patch by Mohamed Tarek from FS #10182. Remove floating point code (FFT, MDCT, etc...
[kugel-rb.git] / apps / codecs / libcook / main.c
blob40e2fd8a4f3ebc577b86233e453f3d34099e4511
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$ main.c 20898 2009-05-09 23:24:02Z dave $
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 ****************************************************************************/
21 #include <stdint.h>
22 #include <sys/types.h>
23 #include <sys/stat.h>
24 #include <fcntl.h>
25 #include <unistd.h>
27 #include "rm2wav.h"
28 #include "cook.h"
30 //#define DUMP_RAW_FRAMES
31 #define DEBUGF(message,args ...) av_log(NULL,AV_LOG_ERROR,message,## args)
32 int main(int argc, char *argv[])
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;
49 memset(&q,0,sizeof(COOKContext));
50 memset(&rmctx,0,sizeof(RMContext));
51 memset(&pkt,0,sizeof(RMPacket));
53 if (argc != 2) {
54 DEBUGF("Incorrect number of arguments\n");
55 return -1;
58 fd = open(argv[1],O_RDONLY);
59 if (fd < 0) {
60 DEBUGF("Error opening file %s\n", argv[1]);
61 return -1;
64 fd_dec = open_wav("output.wav");
65 if (fd_dec < 0) {
66 DEBUGF("Error creating output file\n");
67 return -1;
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)
81 packet_count += h - (packet_count % h);
82 rmctx.nb_packets = packet_count;
84 while(packet_count)
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++)
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
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);
105 packet_count -= rmctx.audio_pkt_cnt;
106 rmctx.audio_pkt_cnt = 0;
108 cook_decode_close(&q);
109 close_wav(fd_dec,&rmctx);
110 close(fd);
113 return 0;