2010-05-09 21:42:09 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Mohamed Tarek
|
|
|
|
*
|
|
|
|
* 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"
|
2010-06-21 10:48:34 +00:00
|
|
|
#include "libasf/asf.h"
|
|
|
|
#include "libwmapro/wmaprodec.h"
|
2010-05-09 21:42:09 +00:00
|
|
|
|
|
|
|
CODEC_HEADER
|
|
|
|
|
2011-06-01 10:28:26 +00:00
|
|
|
static int32_t *dec[2]; /* pointers to the output buffers in WMAProDecodeCtx in
|
|
|
|
wmaprodec.c */
|
2010-06-21 10:48:34 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
|
2010-05-09 21:42:09 +00:00
|
|
|
/* this is the codec entry point */
|
2011-04-27 03:08:23 +00:00
|
|
|
enum codec_status codec_main(enum codec_entry_call_reason reason)
|
|
|
|
{
|
|
|
|
if (reason == CODEC_LOAD) {
|
|
|
|
/* Generic codec initialisation */
|
|
|
|
ci->configure(DSP_SET_SAMPLE_DEPTH, WMAPRO_DSP_SAMPLE_DEPTH);
|
|
|
|
}
|
|
|
|
|
|
|
|
return CODEC_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this is called for each file to process */
|
|
|
|
enum codec_status codec_run(void)
|
2010-05-09 21:42:09 +00:00
|
|
|
{
|
2010-06-21 10:48:34 +00:00
|
|
|
uint32_t elapsedtime;
|
|
|
|
asf_waveformatex_t wfx; /* Holds the stream properties */
|
|
|
|
int res; /* Return values from asf_read_packet() and decode_packet() */
|
|
|
|
uint8_t* audiobuf; /* Pointer to the payload of one wma pro packet */
|
|
|
|
int audiobufsize; /* Payload size */
|
|
|
|
int packetlength = 0; /* Logical packet size (minus the header size) */
|
|
|
|
int outlen = 0; /* Number of bytes written to the output buffer */
|
2014-11-28 21:43:56 +00:00
|
|
|
unsigned int pktcnt = 0; /* Count of the packets played */
|
2010-07-29 22:18:04 +00:00
|
|
|
uint8_t *data; /* Pointer to decoder input buffer */
|
|
|
|
int size; /* Size of the input frame to the decoder */
|
2011-04-27 03:08:23 +00:00
|
|
|
intptr_t param;
|
2010-06-21 10:48:34 +00:00
|
|
|
|
2013-07-14 11:59:39 +00:00
|
|
|
elapsedtime = ci->id3->elapsed;
|
|
|
|
|
2011-02-20 15:27:10 +00:00
|
|
|
restart_track:
|
2010-06-21 10:48:34 +00:00
|
|
|
if (codec_init()) {
|
|
|
|
LOGF("(WMA PRO) Error: Error initialising codec\n");
|
2011-04-27 03:08:23 +00:00
|
|
|
return CODEC_ERROR;
|
2010-06-21 10:48:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy the format metadata we've stored in the id3 TOC field. This
|
|
|
|
saves us from parsing it again here. */
|
|
|
|
memcpy(&wfx, ci->id3->toc, sizeof(wfx));
|
|
|
|
|
2013-05-05 04:48:40 +00:00
|
|
|
ci->configure(DSP_SET_FREQUENCY, wfx.rate);
|
2010-06-21 10:48:34 +00:00
|
|
|
ci->configure(DSP_SET_STEREO_MODE, wfx.channels == 1 ?
|
2010-07-26 22:03:20 +00:00
|
|
|
STEREO_MONO : STEREO_NONINTERLEAVED);
|
2010-06-21 10:48:34 +00:00
|
|
|
codec_set_replaygain(ci->id3);
|
|
|
|
|
2010-07-15 05:38:09 +00:00
|
|
|
if (decode_init(&wfx) < 0) {
|
2010-06-21 10:48:34 +00:00
|
|
|
LOGF("(WMA PRO) Error: Unsupported or corrupt file\n");
|
2011-04-27 03:08:23 +00:00
|
|
|
return CODEC_ERROR;
|
2010-06-21 10:48:34 +00:00
|
|
|
}
|
|
|
|
|
2013-07-14 11:59:39 +00:00
|
|
|
if (elapsedtime) {
|
|
|
|
elapsedtime = asf_seek(elapsedtime, &wfx);
|
|
|
|
if (elapsedtime < 1)
|
|
|
|
return CODEC_OK;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Now advance the file position to the first frame */
|
|
|
|
ci->seek_buffer(ci->id3->first_frame_offset);
|
|
|
|
}
|
2010-06-21 10:48:34 +00:00
|
|
|
|
2013-07-14 11:59:39 +00:00
|
|
|
ci->set_elapsed(elapsedtime);
|
2010-06-21 10:48:34 +00:00
|
|
|
|
|
|
|
/* The main decoding loop */
|
|
|
|
|
|
|
|
while (pktcnt < wfx.numpackets)
|
2011-05-01 11:42:41 +00:00
|
|
|
{
|
2017-12-07 18:21:57 +00:00
|
|
|
long action = ci->get_command(¶m);
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
if (action == CODEC_ACTION_HALT)
|
|
|
|
break;
|
2010-06-21 10:48:34 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Deal with any pending seek requests */
|
|
|
|
if (action == CODEC_ACTION_SEEK_TIME) {
|
|
|
|
if (param == 0) {
|
|
|
|
ci->set_elapsed(0);
|
2010-06-21 10:48:34 +00:00
|
|
|
ci->seek_complete();
|
2013-07-14 11:59:39 +00:00
|
|
|
elapsedtime = 0;
|
2010-06-21 10:48:34 +00:00
|
|
|
goto restart_track; /* Pretend you never saw this... */
|
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
elapsedtime = asf_seek(param, &wfx);
|
2010-06-21 10:48:34 +00:00
|
|
|
if (elapsedtime < 1){
|
2011-04-27 03:08:23 +00:00
|
|
|
ci->set_elapsed(0);
|
2010-06-21 10:48:34 +00:00
|
|
|
ci->seek_complete();
|
2011-04-27 03:08:23 +00:00
|
|
|
break;
|
2010-06-21 10:48:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ci->set_elapsed(elapsedtime);
|
|
|
|
ci->seek_complete();
|
|
|
|
}
|
|
|
|
|
|
|
|
res = asf_read_packet(&audiobuf, &audiobufsize, &packetlength, &wfx);
|
|
|
|
|
|
|
|
if (res < 0) {
|
2011-04-27 03:08:23 +00:00
|
|
|
LOGF("(WMA PRO) Warning: asf_read_packet returned %d", res);
|
|
|
|
return CODEC_ERROR;
|
2010-06-21 10:48:34 +00:00
|
|
|
} else {
|
2010-07-15 05:38:09 +00:00
|
|
|
data = audiobuf;
|
|
|
|
size = audiobufsize;
|
2010-06-21 10:48:34 +00:00
|
|
|
pktcnt++;
|
|
|
|
|
|
|
|
/* We now loop on the packet, decoding and outputting the subframes
|
|
|
|
* one-by-one. For more information about how wma pro structures its
|
|
|
|
* audio frames, see libwmapro/wmaprodec.c */
|
2010-07-15 05:38:09 +00:00
|
|
|
while(size > 0)
|
2010-06-21 10:48:34 +00:00
|
|
|
{
|
2010-07-26 22:03:20 +00:00
|
|
|
res = decode_packet(&wfx, dec, &outlen, data, size);
|
2010-07-17 09:55:38 +00:00
|
|
|
if(res < 0) {
|
|
|
|
LOGF("(WMA PRO) Error: decode_packet returned %d", res);
|
2011-04-27 03:08:23 +00:00
|
|
|
return CODEC_ERROR;
|
2010-07-17 09:55:38 +00:00
|
|
|
}
|
2010-07-15 05:38:09 +00:00
|
|
|
data += res;
|
|
|
|
size -= res;
|
2010-06-21 10:48:34 +00:00
|
|
|
if(outlen) {
|
|
|
|
ci->yield ();
|
2010-08-03 22:59:03 +00:00
|
|
|
outlen /= (wfx.channels);
|
2010-07-26 22:03:20 +00:00
|
|
|
ci->pcmbuf_insert(dec[0], dec[1], outlen );
|
2010-06-21 10:48:34 +00:00
|
|
|
elapsedtime += outlen*10/(wfx.rate/100);
|
|
|
|
ci->set_elapsed(elapsedtime);
|
|
|
|
ci->yield ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Advance to the next logical packet */
|
|
|
|
ci->advance_buffer(packetlength);
|
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
return CODEC_OK;
|
2010-05-09 21:42:09 +00:00
|
|
|
}
|
|
|
|
|