summaryrefslogtreecommitdiffstats
path: root/apps/codecs/alac.c
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2011-04-27 03:08:23 +0000
committerMichael Sevakis <jethead71@rockbox.org>2011-04-27 03:08:23 +0000
commitc537d5958e8b421ac4f9bef6c8b9e7425a6cf167 (patch)
tree7ed36518fb6524da7bbd913ba7619b85b5d15d23 /apps/codecs/alac.c
parentdcf0f8de4a37ff1d2ea510aef75fa67977a8bdcc (diff)
downloadrockbox-c537d5958e8b421ac4f9bef6c8b9e7425a6cf167.tar.gz
rockbox-c537d5958e8b421ac4f9bef6c8b9e7425a6cf167.zip
Commit FS#12069 - Playback rework - first stages. Gives as thorough as possible a treatment of codec management, track change and metadata logic as possible while maintaining fairly narrow focus and not rewriting everything all at once. Please see the rockbox-dev mail archive on 2011-04-25 (Playback engine rework) for a more thorough manifest of what was addressed. Plugins and codecs become incompatible.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29785 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/alac.c')
-rw-r--r--apps/codecs/alac.c188
1 files changed, 93 insertions, 95 deletions
diff --git a/apps/codecs/alac.c b/apps/codecs/alac.c
index cd9129a278..82bda264c3 100644
--- a/apps/codecs/alac.c
+++ b/apps/codecs/alac.c
@@ -32,116 +32,114 @@ CODEC_HEADER
static int32_t outputbuffer[ALAC_MAX_CHANNELS][ALAC_BLOCKSIZE] IBSS_ATTR;
/* this is the codec entry point */
-enum codec_status codec_main(void)
+enum codec_status codec_main(enum codec_entry_call_reason reason)
{
- size_t n;
- demux_res_t demux_res;
- stream_t input_stream;
- uint32_t samplesdone;
- uint32_t elapsedtime;
- int samplesdecoded;
- unsigned int i;
- unsigned char* buffer;
- alac_file alac;
- int retval;
-
- /* Generic codec initialisation */
- ci->configure(DSP_SET_STEREO_MODE, STEREO_NONINTERLEAVED);
- ci->configure(DSP_SET_SAMPLE_DEPTH, ALAC_OUTPUT_DEPTH-1);
-
- next_track:
- retval = CODEC_OK;
-
- /* Clean and initialize decoder structures */
- memset(&demux_res , 0, sizeof(demux_res));
- if (codec_init()) {
- LOGF("ALAC: Error initialising codec\n");
- retval = CODEC_ERROR;
- goto exit;
- }
-
- if (codec_wait_taginfo() != 0)
- goto done;
-
- ci->configure(DSP_SWITCH_FREQUENCY, ci->id3->frequency);
- codec_set_replaygain(ci->id3);
+ if (reason == CODEC_LOAD) {
+ /* Generic codec initialisation */
+ ci->configure(DSP_SET_STEREO_MODE, STEREO_NONINTERLEAVED);
+ ci->configure(DSP_SET_SAMPLE_DEPTH, ALAC_OUTPUT_DEPTH-1);
+ }
- stream_create(&input_stream,ci);
+ return CODEC_OK;
+}
- /* Read from ci->id3->offset before calling qtmovie_read. */
- samplesdone = (uint32_t)(((uint64_t)(ci->id3->offset) * ci->id3->frequency) /
- (ci->id3->bitrate*128));
-
- /* if qtmovie_read returns successfully, the stream is up to
- * the movie data, which can be used directly by the decoder */
- if (!qtmovie_read(&input_stream, &demux_res)) {
- LOGF("ALAC: Error initialising file\n");
- retval = CODEC_ERROR;
- goto done;
- }
-
- /* initialise the sound converter */
- create_alac(demux_res.sound_sample_size, demux_res.num_channels,&alac);
- alac_set_info(&alac, demux_res.codecdata);
-
- /* Set i for first frame, seek to desired sample position for resuming. */
- i=0;
- if (samplesdone > 0) {
- if (m4a_seek(&demux_res, &input_stream, samplesdone,
- &samplesdone, (int*) &i)) {
- elapsedtime = (samplesdone * 10) / (ci->id3->frequency / 100);
- ci->set_elapsed(elapsedtime);
- } else {
- samplesdone = 0;
+/* this is called for each file to process */
+enum codec_status codec_run(void)
+{
+ size_t n;
+ demux_res_t demux_res;
+ stream_t input_stream;
+ uint32_t samplesdone;
+ uint32_t elapsedtime = 0;
+ int samplesdecoded;
+ unsigned int i;
+ unsigned char* buffer;
+ alac_file alac;
+ intptr_t param;
+
+ /* Clean and initialize decoder structures */
+ memset(&demux_res , 0, sizeof(demux_res));
+ if (codec_init()) {
+ LOGF("ALAC: Error initialising codec\n");
+ return CODEC_ERROR;
}
- }
- /* The main decoding loop */
- while (i < demux_res.num_sample_byte_sizes) {
- ci->yield();
- if (ci->stop_codec || ci->new_track) {
- break;
+ ci->configure(DSP_SWITCH_FREQUENCY, ci->id3->frequency);
+ codec_set_replaygain(ci->id3);
+
+ ci->seek_buffer(0);
+
+ stream_create(&input_stream,ci);
+
+ /* Read from ci->id3->offset before calling qtmovie_read. */
+ samplesdone = (uint32_t)(((uint64_t)(ci->id3->offset) * ci->id3->frequency) /
+ (ci->id3->bitrate*128));
+
+ /* if qtmovie_read returns successfully, the stream is up to
+ * the movie data, which can be used directly by the decoder */
+ if (!qtmovie_read(&input_stream, &demux_res)) {
+ LOGF("ALAC: Error initialising file\n");
+ return CODEC_ERROR;
}
- /* Deal with any pending seek requests */
- if (ci->seek_time) {
- if (m4a_seek(&demux_res, &input_stream,
- ((ci->seek_time-1)/10) * (ci->id3->frequency/100),
- &samplesdone, (int *)&i)) {
- elapsedtime=(samplesdone*10)/(ci->id3->frequency/100);
- ci->set_elapsed(elapsedtime);
- }
- ci->seek_complete();
+ /* initialise the sound converter */
+ create_alac(demux_res.sound_sample_size, demux_res.num_channels,&alac);
+ alac_set_info(&alac, demux_res.codecdata);
+
+ /* Set i for first frame, seek to desired sample position for resuming. */
+ i=0;
+ if (samplesdone > 0) {
+ if (m4a_seek(&demux_res, &input_stream, samplesdone,
+ &samplesdone, (int*) &i)) {
+ elapsedtime = (samplesdone * 10) / (ci->id3->frequency / 100);
+ ci->set_elapsed(elapsedtime);
+ } else {
+ samplesdone = 0;
+ }
}
- /* Request the required number of bytes from the input buffer */
- buffer=ci->request_buffer(&n, ALAC_BYTE_BUFFER_SIZE);
+ /* The main decoding loop */
+ while (i < demux_res.num_sample_byte_sizes) {
+ enum codec_command_action action = ci->get_command(&param);
+
+ if (action == CODEC_ACTION_HALT)
+ break;
- /* Decode one block - returned samples will be host-endian */
- ci->yield();
- samplesdecoded=alac_decode_frame(&alac, buffer, outputbuffer, ci->yield);
+ /* Request the required number of bytes from the input buffer */
+ buffer=ci->request_buffer(&n, ALAC_BYTE_BUFFER_SIZE);
- /* Advance codec buffer by amount of consumed bytes */
- ci->advance_buffer(alac.bytes_consumed);
+ /* Deal with any pending seek requests */
+ if (action == CODEC_ACTION_SEEK_TIME) {
+ if (m4a_seek(&demux_res, &input_stream,
+ (param/10) * (ci->id3->frequency/100),
+ &samplesdone, (int *)&i)) {
+ elapsedtime=(samplesdone*10)/(ci->id3->frequency/100);
+ }
+ ci->set_elapsed(elapsedtime);
+ ci->seek_complete();
+ }
- /* Output the audio */
- ci->yield();
- ci->pcmbuf_insert(outputbuffer[0], outputbuffer[1], samplesdecoded);
+ /* Request the required number of bytes from the input buffer */
+ buffer=ci->request_buffer(&n, ALAC_BYTE_BUFFER_SIZE);
- /* Update the elapsed-time indicator */
- samplesdone+=samplesdecoded;
- elapsedtime=(samplesdone*10)/(ci->id3->frequency/100);
- ci->set_elapsed(elapsedtime);
+ /* Decode one block - returned samples will be host-endian */
+ samplesdecoded=alac_decode_frame(&alac, buffer, outputbuffer, ci->yield);
+ ci->yield();
- i++;
- }
+ /* Advance codec buffer by amount of consumed bytes */
+ ci->advance_buffer(alac.bytes_consumed);
-done:
- LOGF("ALAC: Decoded %lu samples\n",(unsigned long)samplesdone);
+ /* Output the audio */
+ ci->pcmbuf_insert(outputbuffer[0], outputbuffer[1], samplesdecoded);
- if (ci->request_next_track())
- goto next_track;
+ /* Update the elapsed-time indicator */
+ samplesdone+=samplesdecoded;
+ elapsedtime=(samplesdone*10)/(ci->id3->frequency/100);
+ ci->set_elapsed(elapsedtime);
+
+ i++;
+ }
-exit:
- return retval;
+ LOGF("ALAC: Decoded %lu samples\n",(unsigned long)samplesdone);
+ return CODEC_OK;
}