summaryrefslogtreecommitdiff
path: root/apps/codecs/libcook/main.c
diff options
context:
space:
mode:
authorMohamed Tarek <mt@rockbox.org>2009-05-22 20:23:38 +0000
committerMohamed Tarek <mt@rockbox.org>2009-05-22 20:23:38 +0000
commitb63028d80ae665688a2202a2eaeb2e01e10ab520 (patch)
tree762cec22804a554c97983ccbe4a818eca899d528 /apps/codecs/libcook/main.c
parent694b3b734f8b1cddb323b29e74929a35bb5cd9ef (diff)
downloadrockbox-b63028d80ae665688a2202a2eaeb2e01e10ab520.zip
rockbox-b63028d80ae665688a2202a2eaeb2e01e10ab520.tar.gz
rockbox-b63028d80ae665688a2202a2eaeb2e01e10ab520.tar.bz2
rockbox-b63028d80ae665688a2202a2eaeb2e01e10ab520.tar.xz
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.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/apps/codecs/libcook/main.c b/apps/codecs/libcook/main.c
index b0b2829..3557b15 100644
--- a/apps/codecs/libcook/main.c
+++ b/apps/codecs/libcook/main.c
@@ -37,6 +37,7 @@
# endif
#endif
+#define DATA_HEADER_SIZE 18 /* size of DATA chunk header in a rm file */
static unsigned char wav_header[44]={
'R','I','F','F',// 0 - ChunkID
0,0,0,0, // 4 - ChunkSize (filesize-8)
@@ -127,7 +128,6 @@ int main(int argc, char *argv[])
int fd_out;
#endif
int16_t outbuf[2048];
- uint8_t inbuf[1024];
uint16_t fs,sps,h;
uint32_t packet_count;
COOKContext q;
@@ -149,6 +149,10 @@ int main(int argc, char *argv[])
return -1;
}
+ /* copy the input rm file to a memory buffer */
+ uint8_t * filebuf = (uint8_t *)calloc((int)filesize(fd),sizeof(uint8_t));
+ read(fd,filebuf,filesize(fd));
+
fd_dec = open_wav("output.wav");
if (fd_dec < 0) {
DEBUGF("Error creating output file\n");
@@ -169,11 +173,12 @@ int main(int argc, char *argv[])
packet_count += h - (packet_count % h);
rmctx.nb_packets = packet_count;
}
+
+ /* change the buffer pointer to point at the first audio frame */
+ advance_buffer(&filebuf, rmctx.data_offset+ DATA_HEADER_SIZE);
while(packet_count)
{
-
- memset(pkt.data,0,sizeof(pkt.data));
- rm_get_packet(fd, &rmctx, &pkt);
+ rm_get_packet_membuf(&filebuf, &rmctx, &pkt);
DEBUGF("total frames = %d packet count = %d output counter = %d \n",rmctx.audio_pkt_cnt*(fs/sps), packet_count,rmctx.audio_pkt_cnt);
for(i = 0; i < rmctx.audio_pkt_cnt*(fs/sps) ; i++)
{
@@ -181,12 +186,11 @@ int main(int argc, char *argv[])
#ifdef DUMP_RAW_FRAMES
snprintf(filename,sizeof(filename),"dump%d.raw",++x);
fd_out = open(filename,O_WRONLY|O_CREAT|O_APPEND);
- write(fd_out,pkt.data+i*sps,sps);
+ write(fd_out,pkt.frames[i],sps);
close(fd_out);
#endif
- memcpy(inbuf,pkt.data+i*sps,sps);
- nb_frames = cook_decode_frame(&rmctx,&q, outbuf, &datasize, inbuf , rmctx.block_align);
+ nb_frames = cook_decode_frame(&rmctx,&q, outbuf, &datasize, pkt.frames[i] , rmctx.block_align);
rmctx.frame_number++;
write(fd_dec,outbuf,datasize);
}