summaryrefslogtreecommitdiffstats
path: root/apps
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
parent694b3b734f8b1cddb323b29e74929a35bb5cd9ef (diff)
downloadrockbox-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')
-rw-r--r--apps/codecs/libcook/main.c18
-rw-r--r--apps/codecs/libcook/rm.c73
-rw-r--r--apps/codecs/libcook/rm.h5
3 files changed, 86 insertions, 10 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 @@
# 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);
}
diff --git a/apps/codecs/libcook/rm.c b/apps/codecs/libcook/rm.c
index 92b6428462..b2ccfc2480 100644
--- a/apps/codecs/libcook/rm.c
+++ b/apps/codecs/libcook/rm.c
@@ -38,6 +38,21 @@
#endif
/* Some Rockbox-like functions (these should be implemented in metadata_common.[ch] */
+static uint8_t get_uint8(uint8_t *buf)
+{
+ return (uint8_t)buf[0];
+}
+
+static uint16_t get_uint16be(uint8_t *buf)
+{
+ return (uint16_t)((buf[0] << 8)|buf[1]);
+}
+
+static uint32_t get_uint32be(uint8_t *buf)
+{
+ return (uint32_t)((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]);
+}
+
static int read_uint8(int fd, uint8_t* buf)
{
unsigned char tmp[1];
@@ -79,6 +94,11 @@ off_t filesize(int fd)
}
}
+void advance_buffer(uint8_t **buf, int val)
+{
+ *buf += val;
+}
+
int read_cook_extradata(int fd, RMContext *rmctx) {
read_uint32be(fd, &rmctx->cook_version);
read_uint16be(fd, &rmctx->samples_pf_pc);
@@ -273,7 +293,6 @@ int real_parse_header(int fd, RMContext *rmctx)
uint32_t duration;
uint32_t preroll;
uint32_t index_offset;
- uint32_t data_offset;
uint16_t num_streams;
uint16_t flags = 0;
@@ -331,7 +350,7 @@ int real_parse_header(int fd, RMContext *rmctx)
read_uint32be(fd, &duration);
read_uint32be(fd, &preroll);
read_uint32be(fd, &index_offset);
- read_uint32be(fd, &data_offset);
+ read_uint32be(fd, &rmctx->data_offset);
read_uint16be(fd, &num_streams);
read_uint16be(fd, &rmctx->flags);
skipped += 40;
@@ -344,7 +363,7 @@ int real_parse_header(int fd, RMContext *rmctx)
printf(" duration = %d\n",duration);
printf(" preroll = %d\n",preroll);
printf(" index_offset = %d\n",index_offset);
- printf(" data_offset = %d\n",data_offset);
+ printf(" data_offset = %d\n",rmctx->data_offset);
printf(" num_streams = %d\n",num_streams);
printf(" flags=0x%04x\n",flags);
break;
@@ -474,6 +493,54 @@ void rm_get_packet(int fd,RMContext *rmctx, RMPacket *pkt)
//return pkt->data;
}
+
+/**
+ * Another version of rm_get_packet which reads from a memory buffer
+ * instead of readind from a file descriptor.
+ **/
+void rm_get_packet_membuf(uint8_t **filebuf,RMContext *rmctx, RMPacket *pkt)
+{
+ uint8_t unknown;
+ uint16_t x, place;
+ uint16_t sps = rmctx->sub_packet_size;
+ uint16_t h = rmctx->sub_packet_h;
+ uint16_t y = rmctx->sub_packet_cnt;
+ uint16_t w = rmctx->audio_framesize;
+ do
+ {
+ y = rmctx->sub_packet_cnt;
+ pkt->version = get_uint16be(*filebuf);
+ pkt->length = get_uint16be(*filebuf+2);
+ pkt->stream_number = get_uint16be(*filebuf+4);
+ pkt->timestamp = get_uint32be(*filebuf+6);
+ DEBUGF(" version = %d\n"
+ " length = %d\n"
+ " stream = %d\n"
+ " timestamp= %d\n",pkt->version,pkt->length,pkt->stream_number,pkt->timestamp);
+
+ unknown = get_uint8(*filebuf+10);
+ pkt->flags = get_uint8(*filebuf+11);
+
+ if(pkt->version == 1)
+ unknown = get_uint8(*filebuf+10);
+
+ if (pkt->flags & 2) /* keyframe */
+ y = rmctx->sub_packet_cnt = 0;
+ if (!y) /* if keyframe update playback elapsed time */
+ rmctx->audiotimestamp = pkt->timestamp;
+
+ advance_buffer(filebuf,12);
+
+ for(x = 0 ; x < w/sps; x++)
+ {
+ place = sps*(h*x+((h+1)/2)*(y&1)+(y>>1));
+ pkt->frames[place/sps] = *filebuf;
+ advance_buffer(filebuf,sps);
+ }
+ rmctx->audio_pkt_cnt++;
+ }while(++(rmctx->sub_packet_cnt) < h);
+}
+
#ifdef DEBUG
void dump_rm_context(RMContext *rmctx)
{
diff --git a/apps/codecs/libcook/rm.h b/apps/codecs/libcook/rm.h
index 8e2ebe8a16..bdd03f3db2 100644
--- a/apps/codecs/libcook/rm.h
+++ b/apps/codecs/libcook/rm.h
@@ -27,6 +27,7 @@
typedef struct rm_packet
{
uint8_t data[30000]; /* Reordered data. No malloc, hence the size */
+ uint8_t *frames[100]; /* Pointers to ordered audio frames in buffer */
uint16_t version;
uint16_t length;
uint32_t timestamp;
@@ -44,6 +45,7 @@ typedef struct rm_context
int audio_pkt_cnt; /* Output packet counter*/
/* Stream Variables */
+ uint32_t data_offset;
uint32_t audiotimestamp; /* Audio packet timestamp*/
uint16_t sub_packet_cnt; /* Subpacket counter, used while reading */
uint16_t sub_packet_size, sub_packet_h, coded_framesize; /* Descrambling parameters from container */
@@ -75,4 +77,7 @@ int open_wav(char* filename);
void close_wav(int fd, RMContext *rmctx);
int real_parse_header(int fd, RMContext *rmctx);
void rm_get_packet(int fd,RMContext *rmctx, RMPacket *pkt);
+void rm_get_packet_membuf(uint8_t **filebuf,RMContext *rmctx, RMPacket *pkt);
+off_t filesize(int fd);
+void advance_buffer(uint8_t **buf, int val);
#endif