summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndree Buschmann <AndreeBuschmann@t-online.de>2011-04-16 19:08:50 +0000
committerAndree Buschmann <AndreeBuschmann@t-online.de>2011-04-16 19:08:50 +0000
commit19f9fd0f5feaf329a6e386eb859e0700b6e8dcc6 (patch)
tree257873f6803c480dbdf8fd7669e7f120cd1b79d5
parente4dd514e6ffed290f07eff20b586b704008d0a8a (diff)
downloadrockbox-19f9fd0f5feaf329a6e386eb859e0700b6e8dcc6.tar.gz
rockbox-19f9fd0f5feaf329a6e386eb859e0700b6e8dcc6.zip
Refactor alac decoder as preparation for upcoming m4a changes. The alac decoder does not need to use get_sample_info() to gather frame size or the number of consumed bytes.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29724 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/codecs/alac.c21
-rw-r--r--apps/codecs/libalac/alac.c9
-rw-r--r--apps/codecs/libalac/decomp.h1
3 files changed, 15 insertions, 16 deletions
diff --git a/apps/codecs/alac.c b/apps/codecs/alac.c
index 3721f04f1f..428fc59836 100644
--- a/apps/codecs/alac.c
+++ b/apps/codecs/alac.c
@@ -35,8 +35,6 @@ enum codec_status codec_main(void)
35 stream_t input_stream; 35 stream_t input_stream;
36 uint32_t samplesdone; 36 uint32_t samplesdone;
37 uint32_t elapsedtime; 37 uint32_t elapsedtime;
38 uint32_t sample_duration;
39 uint32_t sample_byte_size;
40 int samplesdecoded; 38 int samplesdecoded;
41 unsigned int i; 39 unsigned int i;
42 unsigned char* buffer; 40 unsigned char* buffer;
@@ -112,18 +110,9 @@ enum codec_status codec_main(void)
112 ci->seek_complete(); 110 ci->seek_complete();
113 } 111 }
114 112
115 /* Lookup the length (in samples and bytes) of block i */
116 if (!get_sample_info(&demux_res, i, &sample_duration,
117 &sample_byte_size)) {
118 LOGF("ALAC: Error in get_sample_info\n");
119 retval = CODEC_ERROR;
120 goto done;
121 }
122
123 /* Request the required number of bytes from the input buffer */ 113 /* Request the required number of bytes from the input buffer */
124 114 buffer=ci->request_buffer(&n, demux_res.sample_byte_size[i]);
125 buffer=ci->request_buffer(&n,sample_byte_size); 115 if (n!=demux_res.sample_byte_size[i]) {
126 if (n!=sample_byte_size) {
127 retval = CODEC_ERROR; 116 retval = CODEC_ERROR;
128 goto done; 117 goto done;
129 } 118 }
@@ -132,15 +121,15 @@ enum codec_status codec_main(void)
132 ci->yield(); 121 ci->yield();
133 samplesdecoded=alac_decode_frame(&alac, buffer, outputbuffer, ci->yield); 122 samplesdecoded=alac_decode_frame(&alac, buffer, outputbuffer, ci->yield);
134 123
135 /* Advance codec buffer n bytes */ 124 /* Advance codec buffer by amount of consumed bytes */
136 ci->advance_buffer(n); 125 ci->advance_buffer(alac.bytes_consumed);
137 126
138 /* Output the audio */ 127 /* Output the audio */
139 ci->yield(); 128 ci->yield();
140 ci->pcmbuf_insert(outputbuffer[0], outputbuffer[1], samplesdecoded); 129 ci->pcmbuf_insert(outputbuffer[0], outputbuffer[1], samplesdecoded);
141 130
142 /* Update the elapsed-time indicator */ 131 /* Update the elapsed-time indicator */
143 samplesdone+=sample_duration; 132 samplesdone+=samplesdecoded;
144 elapsedtime=(samplesdone*10)/(ci->id3->frequency/100); 133 elapsedtime=(samplesdone*10)/(ci->id3->frequency/100);
145 ci->set_elapsed(elapsedtime); 134 ci->set_elapsed(elapsedtime);
146 135
diff --git a/apps/codecs/libalac/alac.c b/apps/codecs/libalac/alac.c
index a7d7448b97..38fd6e1cdf 100644
--- a/apps/codecs/libalac/alac.c
+++ b/apps/codecs/libalac/alac.c
@@ -1108,10 +1108,14 @@ int alac_decode_frame(alac_file *alac,
1108{ 1108{
1109 int channels; 1109 int channels;
1110 int outputsamples; 1110 int outputsamples;
1111 int input_buffer_start;
1111 1112
1112 /* setup the stream */ 1113 /* setup the stream */
1113 alac->input_buffer = inbuffer; 1114 alac->input_buffer = inbuffer;
1114 alac->input_buffer_bitaccumulator = 0; 1115 alac->input_buffer_bitaccumulator = 0;
1116
1117 /* save to gather byte consumption */
1118 input_buffer_start = (int)alac->input_buffer;
1115 1119
1116 channels = readbits(alac, 3); 1120 channels = readbits(alac, 3);
1117 1121
@@ -1127,6 +1131,11 @@ int alac_decode_frame(alac_file *alac,
1127 default: /* Unsupported */ 1131 default: /* Unsupported */
1128 return -1; 1132 return -1;
1129 } 1133 }
1134
1135 /* calculate consumed bytes */
1136 alac->bytes_consumed = (int)alac->input_buffer - input_buffer_start;
1137 alac->bytes_consumed += (alac->input_buffer_bitaccumulator>5) ? 2 : 1;
1138
1130 return outputsamples; 1139 return outputsamples;
1131} 1140}
1132 1141
diff --git a/apps/codecs/libalac/decomp.h b/apps/codecs/libalac/decomp.h
index bd476804cd..d7abd4db34 100644
--- a/apps/codecs/libalac/decomp.h
+++ b/apps/codecs/libalac/decomp.h
@@ -20,6 +20,7 @@ typedef struct
20 int samplesize; 20 int samplesize;
21 int numchannels; 21 int numchannels;
22 int bytespersample; 22 int bytespersample;
23 int bytes_consumed;
23 24
24 /* stuff from setinfo */ 25 /* stuff from setinfo */
25 uint32_t setinfo_max_samples_per_frame; /* 0x1000 = 4096 */ /* max samples per frame? */ 26 uint32_t setinfo_max_samples_per_frame; /* 0x1000 = 4096 */ /* max samples per frame? */