diff options
author | Nils Wallménius <nils@rockbox.org> | 2011-06-02 14:59:15 +0000 |
---|---|---|
committer | Nils Wallménius <nils@rockbox.org> | 2011-06-02 14:59:15 +0000 |
commit | 4909e09267ad1f2638d48d91b4b273d5508ec380 (patch) | |
tree | 768a0131e0b7e4d66f7e5130fb27ce3f85b1f8ae /apps/codecs/libcook/main.c | |
parent | b58d3656d79e5f9752a22d55c139294412084e4f (diff) | |
download | rockbox-4909e09267ad1f2638d48d91b4b273d5508ec380.tar.gz rockbox-4909e09267ad1f2638d48d91b4b273d5508ec380.zip |
FS#12141 by Sean Bartell
Some of these were found with http://www.samba.org/junkcode/#findstatic. Changes of note:
* The old MDCT has been removed.
* Makefile.test files that create test programs for libatrac, libcook, and libffmpegFLAC have been removed, as they don't work. My project will have a replacement that works with all codecs.
* I've tried not to remove anything useful. CLIP_TO_15 was removed from libtremor because there's another copy (also commented) in codeclib.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29945 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/libcook/main.c')
-rw-r--r-- | apps/codecs/libcook/main.c | 190 |
1 files changed, 0 insertions, 190 deletions
diff --git a/apps/codecs/libcook/main.c b/apps/codecs/libcook/main.c deleted file mode 100644 index 928cad298e..0000000000 --- a/apps/codecs/libcook/main.c +++ /dev/null | |||
@@ -1,190 +0,0 @@ | |||
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 <inttypes.h> | ||
23 | #include <sys/stat.h> | ||
24 | #include <fcntl.h> | ||
25 | #include <unistd.h> | ||
26 | #include <string.h> | ||
27 | |||
28 | #include "../librm/rm.h" | ||
29 | #include "cook.h" | ||
30 | |||
31 | //#define DUMP_RAW_FRAMES | ||
32 | |||
33 | #define DATA_HEADER_SIZE 18 /* size of DATA chunk header in a rm file */ | ||
34 | static unsigned char wav_header[44]={ | ||
35 | 'R','I','F','F',// 0 - ChunkID | ||
36 | 0,0,0,0, // 4 - ChunkSize (filesize-8) | ||
37 | 'W','A','V','E',// 8 - Format | ||
38 | 'f','m','t',' ',// 12 - SubChunkID | ||
39 | 16,0,0,0, // 16 - SubChunk1ID // 16 for PCM | ||
40 | 1,0, // 20 - AudioFormat (1=Uncompressed) | ||
41 | 2,0, // 22 - NumChannels | ||
42 | 0,0,0,0, // 24 - SampleRate in Hz | ||
43 | 0,0,0,0, // 28 - Byte Rate (SampleRate*NumChannels*(BitsPerSample/8) | ||
44 | 4,0, // 32 - BlockAlign (== NumChannels * BitsPerSample/8) | ||
45 | 16,0, // 34 - BitsPerSample | ||
46 | 'd','a','t','a',// 36 - Subchunk2ID | ||
47 | 0,0,0,0 // 40 - Subchunk2Size | ||
48 | }; | ||
49 | |||
50 | int open_wav(char* filename) { | ||
51 | int fd,res; | ||
52 | |||
53 | fd=open(filename,O_CREAT|O_WRONLY|O_TRUNC,S_IRUSR|S_IWUSR); | ||
54 | if (fd >= 0) { | ||
55 | res = write(fd,wav_header,sizeof(wav_header)); | ||
56 | } | ||
57 | |||
58 | return(fd); | ||
59 | } | ||
60 | |||
61 | void close_wav(int fd, RMContext *rmctx, COOKContext *q) { | ||
62 | int x,res; | ||
63 | int filesize; | ||
64 | int bytes_per_sample = 2; | ||
65 | int samples_per_frame = q->samples_per_frame; | ||
66 | int nb_channels = rmctx->nb_channels; | ||
67 | int sample_rate = rmctx->sample_rate; | ||
68 | int nb_frames = rmctx->audio_framesize/rmctx->block_align * rmctx->nb_packets - 2; // first 2 frames have no valid audio; skipped in output | ||
69 | |||
70 | filesize= samples_per_frame*bytes_per_sample*nb_frames +44; | ||
71 | printf("Filesize = %d\n",filesize); | ||
72 | |||
73 | // ChunkSize | ||
74 | x=filesize-8; | ||
75 | wav_header[4]=(x&0xff); | ||
76 | wav_header[5]=(x&0xff00)>>8; | ||
77 | wav_header[6]=(x&0xff0000)>>16; | ||
78 | wav_header[7]=(x&0xff000000)>>24; | ||
79 | |||
80 | // Number of channels | ||
81 | wav_header[22]=nb_channels; | ||
82 | |||
83 | // Samplerate | ||
84 | wav_header[24]=sample_rate&0xff; | ||
85 | wav_header[25]=(sample_rate&0xff00)>>8; | ||
86 | wav_header[26]=(sample_rate&0xff0000)>>16; | ||
87 | wav_header[27]=(sample_rate&0xff000000)>>24; | ||
88 | |||
89 | // ByteRate | ||
90 | x=sample_rate*bytes_per_sample*nb_channels; | ||
91 | wav_header[28]=(x&0xff); | ||
92 | wav_header[29]=(x&0xff00)>>8; | ||
93 | wav_header[30]=(x&0xff0000)>>16; | ||
94 | wav_header[31]=(x&0xff000000)>>24; | ||
95 | |||
96 | // BlockAlign | ||
97 | wav_header[32]=rmctx->block_align;//2*rmctx->nb_channels; | ||
98 | |||
99 | // Bits per sample | ||
100 | wav_header[34]=16; | ||
101 | |||
102 | // Subchunk2Size | ||
103 | x=filesize-44; | ||
104 | wav_header[40]=(x&0xff); | ||
105 | wav_header[41]=(x&0xff00)>>8; | ||
106 | wav_header[42]=(x&0xff0000)>>16; | ||
107 | wav_header[43]=(x&0xff000000)>>24; | ||
108 | |||
109 | lseek(fd,0,SEEK_SET); | ||
110 | res = write(fd,wav_header,sizeof(wav_header)); | ||
111 | close(fd); | ||
112 | } | ||
113 | |||
114 | int main(int argc, char *argv[]) | ||
115 | { | ||
116 | int fd, fd_dec; | ||
117 | int res, datasize,i; | ||
118 | int nb_frames = 0; | ||
119 | #ifdef DUMP_RAW_FRAMES | ||
120 | char filename[15]; | ||
121 | int fd_out; | ||
122 | #endif | ||
123 | int32_t outbuf[2048]; | ||
124 | uint16_t fs,sps,h; | ||
125 | uint32_t packet_count; | ||
126 | COOKContext q; | ||
127 | RMContext rmctx; | ||
128 | RMPacket pkt; | ||
129 | |||
130 | memset(&q,0,sizeof(COOKContext)); | ||
131 | memset(&rmctx,0,sizeof(RMContext)); | ||
132 | memset(&pkt,0,sizeof(RMPacket)); | ||
133 | |||
134 | if (argc != 2) { | ||
135 | DEBUGF("Incorrect number of arguments\n"); | ||
136 | return -1; | ||
137 | } | ||
138 | |||
139 | fd = open(argv[1],O_RDONLY); | ||
140 | if (fd < 0) { | ||
141 | DEBUGF("Error opening file %s\n", argv[1]); | ||
142 | return -1; | ||
143 | } | ||
144 | |||
145 | /* copy the input rm file to a memory buffer */ | ||
146 | uint8_t * filebuf = (uint8_t *)calloc((int)filesize(fd),sizeof(uint8_t)); | ||
147 | res = read(fd,filebuf,filesize(fd)); | ||
148 | |||
149 | fd_dec = open_wav("output.wav"); | ||
150 | if (fd_dec < 0) { | ||
151 | DEBUGF("Error creating output file\n"); | ||
152 | return -1; | ||
153 | } | ||
154 | res = real_parse_header(fd, &rmctx); | ||
155 | packet_count = rmctx.nb_packets; | ||
156 | rmctx.audio_framesize = rmctx.block_align; | ||
157 | rmctx.block_align = rmctx.sub_packet_size; | ||
158 | fs = rmctx.audio_framesize; | ||
159 | sps= rmctx.block_align; | ||
160 | h = rmctx.sub_packet_h; | ||
161 | cook_decode_init(&rmctx,&q); | ||
162 | |||
163 | /* change the buffer pointer to point at the first audio frame */ | ||
164 | advance_buffer(&filebuf, rmctx.data_offset+ DATA_HEADER_SIZE); | ||
165 | while(packet_count) | ||
166 | { | ||
167 | rm_get_packet(&filebuf, &rmctx, &pkt); | ||
168 | //DEBUGF("total frames = %d packet count = %d output counter = %d \n",rmctx.audio_pkt_cnt*(fs/sps), packet_count,rmctx.audio_pkt_cnt); | ||
169 | for(i = 0; i < rmctx.audio_pkt_cnt*(fs/sps) ; i++) | ||
170 | { | ||
171 | /* output raw audio frames that are sent to the decoder into separate files */ | ||
172 | #ifdef DUMP_RAW_FRAMES | ||
173 | snprintf(filename,sizeof(filename),"dump%d.raw",++x); | ||
174 | fd_out = open(filename,O_WRONLY|O_CREAT|O_APPEND, 0666); | ||
175 | write(fd_out,pkt.frames[i],sps); | ||
176 | close(fd_out); | ||
177 | #endif | ||
178 | nb_frames = cook_decode_frame(&rmctx,&q, outbuf, &datasize, pkt.frames[i] , rmctx.block_align); | ||
179 | rmctx.frame_number++; | ||
180 | res = write(fd_dec,outbuf,datasize); | ||
181 | } | ||
182 | packet_count -= rmctx.audio_pkt_cnt; | ||
183 | rmctx.audio_pkt_cnt = 0; | ||
184 | } | ||
185 | close_wav(fd_dec, &rmctx, &q); | ||
186 | close(fd); | ||
187 | |||
188 | |||
189 | return 0; | ||
190 | } | ||