2005-02-16 12:56:00 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
2005-02-16 15:13:39 +00:00
|
|
|
* Copyright (C) 2005 Dave Chapman
|
2005-02-16 12:56:00 +00:00
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "plugin.h"
|
|
|
|
|
2005-02-18 16:28:52 +00:00
|
|
|
#if (CONFIG_HWCODEC == MASNONE)
|
|
|
|
/* software codec platforms */
|
2005-02-16 12:56:00 +00:00
|
|
|
|
|
|
|
#include <inttypes.h> /* Needed by a52.h */
|
|
|
|
|
2005-02-26 11:02:18 +00:00
|
|
|
#include <codecs/liba52/config-a52.h>
|
2005-02-16 12:56:00 +00:00
|
|
|
#include <codecs/liba52/a52.h>
|
|
|
|
|
2005-02-16 18:51:21 +00:00
|
|
|
#include "lib/xxx2wav.h" /* Helper functions common to test decoders */
|
2005-02-16 15:13:39 +00:00
|
|
|
|
2005-02-16 18:51:21 +00:00
|
|
|
static struct plugin_api* rb;
|
2005-02-16 15:13:39 +00:00
|
|
|
|
2005-02-16 12:56:00 +00:00
|
|
|
#ifdef WORDS_BIGENDIAN
|
2005-05-07 22:41:17 +00:00
|
|
|
#define LE_S16(x) ( (uint16_t) ( ((uint16_t)(x) >> 8) | ((uint16_t)(x) << 8) ) )
|
2005-02-16 12:56:00 +00:00
|
|
|
#else
|
2005-05-07 22:41:17 +00:00
|
|
|
#define LE_S16(x) (x)
|
2005-02-16 12:56:00 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
static float gain = 1;
|
|
|
|
static a52_state_t * state;
|
|
|
|
|
|
|
|
static inline int16_t convert (int32_t i)
|
|
|
|
{
|
|
|
|
i >>= 15;
|
|
|
|
return (i > 32767) ? 32767 : ((i < -32768) ? -32768 : i);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ao_play(file_info_struct* file_info,sample_t* samples,int flags) {
|
|
|
|
int i;
|
|
|
|
static int16_t int16_samples[256*2];
|
|
|
|
|
|
|
|
flags &= A52_CHANNEL_MASK | A52_LFE;
|
|
|
|
|
|
|
|
if (flags==A52_STEREO) {
|
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
int16_samples[2*i] = LE_S16(convert (samples[i]));
|
|
|
|
int16_samples[2*i+1] = LE_S16(convert (samples[i+256]));
|
|
|
|
}
|
|
|
|
} else {
|
2005-02-25 00:46:41 +00:00
|
|
|
DEBUGF("ERROR: unsupported format: %d\n",flags);
|
2005-02-16 12:56:00 +00:00
|
|
|
}
|
|
|
|
|
2005-02-16 15:13:39 +00:00
|
|
|
/* FIX: Buffer the disk write to write larger amounts at one */
|
2005-02-16 12:56:00 +00:00
|
|
|
i=rb->write(file_info->outfile,int16_samples,256*2*2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void a52_decode_data (file_info_struct* file_info, uint8_t * start, uint8_t * end)
|
|
|
|
{
|
|
|
|
static uint8_t buf[3840];
|
|
|
|
static uint8_t * bufptr = buf;
|
|
|
|
static uint8_t * bufpos = buf + 7;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sample_rate and flags are static because this routine could
|
|
|
|
* exit between the a52_syncinfo() and the ao_setup(), and we want
|
|
|
|
* to have the same values when we get back !
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int sample_rate;
|
|
|
|
static int flags;
|
|
|
|
int bit_rate;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
len = end - start;
|
|
|
|
if (!len)
|
|
|
|
break;
|
|
|
|
if (len > bufpos - bufptr)
|
|
|
|
len = bufpos - bufptr;
|
|
|
|
memcpy (bufptr, start, len);
|
|
|
|
bufptr += len;
|
|
|
|
start += len;
|
|
|
|
if (bufptr == bufpos) {
|
|
|
|
if (bufpos == buf + 7) {
|
|
|
|
int length;
|
|
|
|
|
|
|
|
length = a52_syncinfo (buf, &flags, &sample_rate, &bit_rate);
|
|
|
|
if (!length) {
|
2005-02-25 00:46:41 +00:00
|
|
|
DEBUGF("skip\n");
|
2005-02-16 12:56:00 +00:00
|
|
|
for (bufptr = buf; bufptr < buf + 6; bufptr++)
|
|
|
|
bufptr[0] = bufptr[1];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
bufpos = buf + length;
|
|
|
|
} else {
|
|
|
|
// The following two defaults are taken from audio_out_oss.c:
|
|
|
|
level_t level;
|
|
|
|
sample_t bias;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* This is the configuration for the downmixing: */
|
|
|
|
flags=A52_STEREO|A52_ADJUST_LEVEL|A52_LFE;
|
|
|
|
level=(1 << 26);
|
|
|
|
bias=0;
|
|
|
|
|
|
|
|
level = (level_t) (level * gain);
|
|
|
|
|
|
|
|
if (a52_frame (state, buf, &flags, &level, bias))
|
|
|
|
goto error;
|
2005-02-16 15:13:39 +00:00
|
|
|
file_info->frames_decoded++;
|
2005-02-16 12:56:00 +00:00
|
|
|
|
2005-02-16 15:13:39 +00:00
|
|
|
/* We assume this never changes */
|
|
|
|
file_info->samplerate=sample_rate;
|
2005-02-16 12:56:00 +00:00
|
|
|
|
|
|
|
// An A52 frame consists of 6 blocks of 256 samples
|
|
|
|
// So we decode and output them one block at a time
|
|
|
|
for (i = 0; i < 6; i++) {
|
|
|
|
if (a52_block (state)) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
ao_play (file_info, a52_samples (state),flags);
|
|
|
|
file_info->current_sample+=256;
|
|
|
|
}
|
|
|
|
bufptr = buf;
|
|
|
|
bufpos = buf + 7;
|
|
|
|
continue;
|
|
|
|
error:
|
2005-02-25 00:46:41 +00:00
|
|
|
DEBUGF("error\n");
|
2005-02-16 12:56:00 +00:00
|
|
|
bufptr = buf;
|
|
|
|
bufpos = buf + 7;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-16 15:13:39 +00:00
|
|
|
|
|
|
|
#define BUFFER_SIZE 4096
|
|
|
|
|
2005-06-11 14:44:35 +00:00
|
|
|
#ifdef USE_IRAM
|
|
|
|
extern char iramcopy[];
|
|
|
|
extern char iramstart[];
|
|
|
|
extern char iramend[];
|
|
|
|
#endif
|
|
|
|
|
2005-02-16 12:56:00 +00:00
|
|
|
/* this is the plugin entry point */
|
|
|
|
enum plugin_status plugin_start(struct plugin_api* api, void* file)
|
|
|
|
{
|
2005-02-16 18:51:21 +00:00
|
|
|
file_info_struct file_info;
|
|
|
|
|
2005-02-16 15:13:39 +00:00
|
|
|
/* Generic plugin initialisation */
|
2005-02-16 12:56:00 +00:00
|
|
|
|
2005-02-16 15:13:39 +00:00
|
|
|
TEST_PLUGIN_API(api);
|
2005-02-16 12:56:00 +00:00
|
|
|
rb = api;
|
|
|
|
|
2005-06-11 14:44:35 +00:00
|
|
|
#ifdef USE_IRAM
|
|
|
|
rb->memcpy(iramstart, iramcopy, iramend-iramstart);
|
|
|
|
#endif
|
|
|
|
|
2005-02-16 15:13:39 +00:00
|
|
|
/* This function sets up the buffers and reads the file into RAM */
|
2005-02-16 12:56:00 +00:00
|
|
|
|
2005-02-16 18:51:21 +00:00
|
|
|
if (local_init(file,"/ac3test.wav",&file_info,api)) {
|
2005-02-16 12:56:00 +00:00
|
|
|
return PLUGIN_ERROR;
|
|
|
|
}
|
|
|
|
|
2005-02-16 15:13:39 +00:00
|
|
|
/* Intialise the A52 decoder and check for success */
|
|
|
|
state = a52_init (0); // Parameter is "accel"
|
2005-02-16 12:56:00 +00:00
|
|
|
|
|
|
|
if (state == NULL) {
|
2005-02-16 15:13:39 +00:00
|
|
|
rb->splash(HZ*2, true, "a52_init failed");
|
2005-02-16 12:56:00 +00:00
|
|
|
return PLUGIN_ERROR;
|
|
|
|
}
|
|
|
|
|
2005-02-16 15:13:39 +00:00
|
|
|
/* The main decoding loop */
|
|
|
|
|
|
|
|
file_info.start_tick=*(rb->current_tick);
|
2005-02-16 16:06:06 +00:00
|
|
|
rb->button_clear_queue();
|
|
|
|
|
2005-02-16 12:56:00 +00:00
|
|
|
while (file_info.curpos < file_info.filesize) {
|
2005-02-16 15:13:39 +00:00
|
|
|
|
2005-02-16 12:56:00 +00:00
|
|
|
if ((file_info.curpos+BUFFER_SIZE) < file_info.filesize) {
|
2005-02-16 15:13:39 +00:00
|
|
|
a52_decode_data(&file_info,&filebuf[file_info.curpos],&filebuf[file_info.curpos+BUFFER_SIZE]);
|
2005-02-16 12:56:00 +00:00
|
|
|
file_info.curpos+=BUFFER_SIZE;
|
|
|
|
} else {
|
2005-02-16 15:13:39 +00:00
|
|
|
a52_decode_data(&file_info,&filebuf[file_info.curpos],&filebuf[file_info.filesize-1]);
|
2005-02-16 12:56:00 +00:00
|
|
|
file_info.curpos=file_info.filesize;
|
|
|
|
}
|
|
|
|
|
2005-02-16 15:13:39 +00:00
|
|
|
display_status(&file_info);
|
2005-02-16 12:56:00 +00:00
|
|
|
|
|
|
|
if (rb->button_get(false)!=BUTTON_NONE) {
|
|
|
|
close_wav(&file_info);
|
|
|
|
return PLUGIN_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close_wav(&file_info);
|
|
|
|
|
2005-02-16 15:13:39 +00:00
|
|
|
/* Cleanly close and exit */
|
|
|
|
|
|
|
|
//NOT NEEDED: a52_free (state);
|
|
|
|
|
2005-02-16 12:56:00 +00:00
|
|
|
rb->splash(HZ*2, true, "FINISHED!");
|
|
|
|
return PLUGIN_OK;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_HWCODEC == MASNONE */
|