2008-07-26 15:16:10 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
2008-07-26 15:32:08 +00:00
|
|
|
* $Id$
|
2008-07-26 15:16:10 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Dominik Wenger
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "codeclib.h"
|
2008-11-05 13:30:58 +00:00
|
|
|
#include "libasap/asap.h"
|
2008-07-26 15:16:10 +00:00
|
|
|
|
|
|
|
CODEC_HEADER
|
|
|
|
|
2008-07-27 14:47:43 +00:00
|
|
|
#define CHUNK_SIZE (1024*2)
|
2008-07-26 15:16:10 +00:00
|
|
|
|
2008-07-27 14:47:43 +00:00
|
|
|
static byte samples[CHUNK_SIZE] IBSS_ATTR; /* The sample buffer */
|
2011-05-15 13:40:02 +00:00
|
|
|
static ASAP_State asap IBSS_ATTR; /* asap codec state */
|
2008-07-26 15:16:10 +00:00
|
|
|
|
2011-04-27 12:52:11 +00:00
|
|
|
/* this is the codec entry point */
|
|
|
|
enum codec_status codec_main(enum codec_entry_call_reason reason)
|
|
|
|
{
|
|
|
|
/* Nothing to do */
|
|
|
|
return CODEC_OK;
|
|
|
|
(void)reason;
|
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* this is called for each file to process */
|
|
|
|
enum codec_status codec_run(void)
|
2008-07-26 15:16:10 +00:00
|
|
|
{
|
|
|
|
int n_bytes;
|
|
|
|
int song;
|
|
|
|
int duration;
|
|
|
|
char* module;
|
2008-07-28 19:20:40 +00:00
|
|
|
int bytesPerSample =2;
|
2011-04-27 03:08:23 +00:00
|
|
|
intptr_t param;
|
2008-07-28 19:20:40 +00:00
|
|
|
|
2008-07-26 15:16:10 +00:00
|
|
|
if (codec_init()) {
|
|
|
|
DEBUGF("codec init failed\n");
|
|
|
|
return CODEC_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
codec_set_replaygain(ci->id3);
|
|
|
|
|
|
|
|
int bytes_done =0;
|
2008-07-26 15:41:50 +00:00
|
|
|
size_t filesize;
|
2008-07-26 15:16:10 +00:00
|
|
|
ci->seek_buffer(0);
|
|
|
|
module = ci->request_buffer(&filesize, ci->filesize);
|
|
|
|
if (!module || (size_t)filesize < (size_t)ci->filesize)
|
|
|
|
{
|
|
|
|
DEBUGF("loading error\n");
|
|
|
|
return CODEC_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*Init ASAP */
|
|
|
|
if (!ASAP_Load(&asap, ci->id3->path, module, filesize))
|
|
|
|
{
|
|
|
|
DEBUGF("%s: format not supported",ci->id3->path);
|
|
|
|
return CODEC_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make use of 44.1khz */
|
|
|
|
ci->configure(DSP_SET_FREQUENCY, 44100);
|
|
|
|
/* Sample depth is 16 bit little endian */
|
|
|
|
ci->configure(DSP_SET_SAMPLE_DEPTH, 16);
|
|
|
|
/* Stereo or Mono output ? */
|
2011-05-15 13:40:02 +00:00
|
|
|
if(asap.module_info->channels ==1)
|
2008-07-28 19:20:40 +00:00
|
|
|
{
|
2008-07-26 15:16:10 +00:00
|
|
|
ci->configure(DSP_SET_STEREO_MODE, STEREO_MONO);
|
2008-07-28 19:20:40 +00:00
|
|
|
bytesPerSample = 2;
|
|
|
|
}
|
2008-07-26 15:16:10 +00:00
|
|
|
else
|
2008-07-28 19:20:40 +00:00
|
|
|
{
|
2008-07-26 15:16:10 +00:00
|
|
|
ci->configure(DSP_SET_STEREO_MODE, STEREO_INTERLEAVED);
|
2008-07-28 19:20:40 +00:00
|
|
|
bytesPerSample = 4;
|
|
|
|
}
|
2008-07-26 15:16:10 +00:00
|
|
|
/* reset eleapsed */
|
|
|
|
ci->set_elapsed(0);
|
|
|
|
|
2011-05-15 13:40:02 +00:00
|
|
|
song = asap.module_info->default_song;
|
|
|
|
duration = asap.module_info->durations[song];
|
2008-07-26 15:16:10 +00:00
|
|
|
if (duration < 0)
|
|
|
|
duration = 180 * 1000;
|
|
|
|
|
2010-02-08 16:48:56 +00:00
|
|
|
/* set id3 length, because metadata parse might not have done it */
|
|
|
|
ci->id3->length = duration;
|
|
|
|
|
2008-07-26 15:16:10 +00:00
|
|
|
ASAP_PlaySong(&asap, song, duration);
|
|
|
|
ASAP_MutePokeyChannels(&asap, 0);
|
|
|
|
|
|
|
|
/* The main decoder loop */
|
|
|
|
while (1) {
|
2011-04-27 03:08:23 +00:00
|
|
|
enum codec_command_action action = ci->get_command(¶m);
|
|
|
|
|
|
|
|
if (action == CODEC_ACTION_HALT)
|
2008-07-26 15:16:10 +00:00
|
|
|
break;
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (action == CODEC_ACTION_SEEK_TIME) {
|
|
|
|
/* New time is ready in param */
|
|
|
|
|
2008-07-26 15:16:10 +00:00
|
|
|
/* seek to pos */
|
2011-04-27 03:08:23 +00:00
|
|
|
ASAP_Seek(&asap,param);
|
2008-07-26 15:16:10 +00:00
|
|
|
/* update bytes_done */
|
2011-04-27 03:08:23 +00:00
|
|
|
bytes_done = param*44.1*2;
|
|
|
|
/* update elapsed */
|
|
|
|
ci->set_elapsed((bytes_done / 2) / 44.1);
|
2008-07-26 15:16:10 +00:00
|
|
|
/* seek ready */
|
|
|
|
ci->seek_complete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Generate a buffer full of Audio */
|
|
|
|
#ifdef ROCKBOX_LITTLE_ENDIAN
|
|
|
|
n_bytes = ASAP_Generate(&asap, samples, sizeof(samples), ASAP_FORMAT_S16_LE);
|
|
|
|
#else
|
|
|
|
n_bytes = ASAP_Generate(&asap, samples, sizeof(samples), ASAP_FORMAT_S16_BE);
|
|
|
|
#endif
|
|
|
|
|
2008-07-28 19:20:40 +00:00
|
|
|
ci->pcmbuf_insert(samples, NULL, n_bytes /bytesPerSample);
|
2008-07-26 15:16:10 +00:00
|
|
|
|
|
|
|
bytes_done += n_bytes;
|
|
|
|
ci->set_elapsed((bytes_done / 2) / 44.1);
|
|
|
|
|
|
|
|
if(n_bytes != sizeof(samples))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CODEC_OK;
|
|
|
|
}
|