diff options
author | Mohamed Tarek <mt@rockbox.org> | 2009-05-22 20:23:38 +0000 |
---|---|---|
committer | Mohamed Tarek <mt@rockbox.org> | 2009-05-22 20:23:38 +0000 |
commit | b63028d80ae665688a2202a2eaeb2e01e10ab520 (patch) | |
tree | 762cec22804a554c97983ccbe4a818eca899d528 /apps/codecs/libcook/main.c | |
parent | 694b3b734f8b1cddb323b29e74929a35bb5cd9ef (diff) | |
download | rockbox-b63028d80ae665688a2202a2eaeb2e01e10ab520.tar.gz rockbox-b63028d80ae665688a2202a2eaeb2e01e10ab520.zip |
Modify the test program to read audio frames from a memory buffer rather
than a file descriptor, to make the decoding process as much similar
as to how it should be in rockbox.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21042 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/libcook/main.c')
-rw-r--r-- | apps/codecs/libcook/main.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/apps/codecs/libcook/main.c b/apps/codecs/libcook/main.c index b0b2829f25..3557b15524 100644 --- a/apps/codecs/libcook/main.c +++ b/apps/codecs/libcook/main.c | |||
@@ -37,6 +37,7 @@ | |||
37 | # endif | 37 | # endif |
38 | #endif | 38 | #endif |
39 | 39 | ||
40 | #define DATA_HEADER_SIZE 18 /* size of DATA chunk header in a rm file */ | ||
40 | static unsigned char wav_header[44]={ | 41 | static unsigned char wav_header[44]={ |
41 | 'R','I','F','F',// 0 - ChunkID | 42 | 'R','I','F','F',// 0 - ChunkID |
42 | 0,0,0,0, // 4 - ChunkSize (filesize-8) | 43 | 0,0,0,0, // 4 - ChunkSize (filesize-8) |
@@ -127,7 +128,6 @@ int main(int argc, char *argv[]) | |||
127 | int fd_out; | 128 | int fd_out; |
128 | #endif | 129 | #endif |
129 | int16_t outbuf[2048]; | 130 | int16_t outbuf[2048]; |
130 | uint8_t inbuf[1024]; | ||
131 | uint16_t fs,sps,h; | 131 | uint16_t fs,sps,h; |
132 | uint32_t packet_count; | 132 | uint32_t packet_count; |
133 | COOKContext q; | 133 | COOKContext q; |
@@ -149,6 +149,10 @@ int main(int argc, char *argv[]) | |||
149 | return -1; | 149 | return -1; |
150 | } | 150 | } |
151 | 151 | ||
152 | /* copy the input rm file to a memory buffer */ | ||
153 | uint8_t * filebuf = (uint8_t *)calloc((int)filesize(fd),sizeof(uint8_t)); | ||
154 | read(fd,filebuf,filesize(fd)); | ||
155 | |||
152 | fd_dec = open_wav("output.wav"); | 156 | fd_dec = open_wav("output.wav"); |
153 | if (fd_dec < 0) { | 157 | if (fd_dec < 0) { |
154 | DEBUGF("Error creating output file\n"); | 158 | DEBUGF("Error creating output file\n"); |
@@ -169,11 +173,12 @@ int main(int argc, char *argv[]) | |||
169 | packet_count += h - (packet_count % h); | 173 | packet_count += h - (packet_count % h); |
170 | rmctx.nb_packets = packet_count; | 174 | rmctx.nb_packets = packet_count; |
171 | } | 175 | } |
176 | |||
177 | /* change the buffer pointer to point at the first audio frame */ | ||
178 | advance_buffer(&filebuf, rmctx.data_offset+ DATA_HEADER_SIZE); | ||
172 | while(packet_count) | 179 | while(packet_count) |
173 | { | 180 | { |
174 | 181 | rm_get_packet_membuf(&filebuf, &rmctx, &pkt); | |
175 | memset(pkt.data,0,sizeof(pkt.data)); | ||
176 | rm_get_packet(fd, &rmctx, &pkt); | ||
177 | DEBUGF("total frames = %d packet count = %d output counter = %d \n",rmctx.audio_pkt_cnt*(fs/sps), packet_count,rmctx.audio_pkt_cnt); | 182 | DEBUGF("total frames = %d packet count = %d output counter = %d \n",rmctx.audio_pkt_cnt*(fs/sps), packet_count,rmctx.audio_pkt_cnt); |
178 | for(i = 0; i < rmctx.audio_pkt_cnt*(fs/sps) ; i++) | 183 | for(i = 0; i < rmctx.audio_pkt_cnt*(fs/sps) ; i++) |
179 | { | 184 | { |
@@ -181,12 +186,11 @@ int main(int argc, char *argv[]) | |||
181 | #ifdef DUMP_RAW_FRAMES | 186 | #ifdef DUMP_RAW_FRAMES |
182 | snprintf(filename,sizeof(filename),"dump%d.raw",++x); | 187 | snprintf(filename,sizeof(filename),"dump%d.raw",++x); |
183 | fd_out = open(filename,O_WRONLY|O_CREAT|O_APPEND); | 188 | fd_out = open(filename,O_WRONLY|O_CREAT|O_APPEND); |
184 | write(fd_out,pkt.data+i*sps,sps); | 189 | write(fd_out,pkt.frames[i],sps); |
185 | close(fd_out); | 190 | close(fd_out); |
186 | #endif | 191 | #endif |
187 | 192 | ||
188 | memcpy(inbuf,pkt.data+i*sps,sps); | 193 | nb_frames = cook_decode_frame(&rmctx,&q, outbuf, &datasize, pkt.frames[i] , rmctx.block_align); |
189 | nb_frames = cook_decode_frame(&rmctx,&q, outbuf, &datasize, inbuf , rmctx.block_align); | ||
190 | rmctx.frame_number++; | 194 | rmctx.frame_number++; |
191 | write(fd_dec,outbuf,datasize); | 195 | write(fd_dec,outbuf,datasize); |
192 | } | 196 | } |