forked from len0rd/rockbox
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
This commit is contained in:
parent
694b3b734f
commit
b63028d80a
3 changed files with 86 additions and 10 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue