2005-06-07 18:53:01 +00:00
|
|
|
|
/***************************************************************************
|
|
|
|
|
* __________ __ ___.
|
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
|
* $Id$
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2002 Bj<EFBFBD>rn Stenberg
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2005-06-22 19:41:30 +00:00
|
|
|
|
#include "codec.h"
|
2005-06-07 18:53:01 +00:00
|
|
|
|
|
|
|
|
|
#include <codecs/libFLAC/include/FLAC/seekable_stream_decoder.h>
|
2005-07-28 18:43:33 +00:00
|
|
|
|
#include <codecs/libFLAC/include/FLAC/format.h>
|
|
|
|
|
#include <codecs/libFLAC/include/FLAC/metadata.h>
|
2005-06-07 18:53:01 +00:00
|
|
|
|
#include "playback.h"
|
|
|
|
|
#include "lib/codeclib.h"
|
2005-06-26 19:41:29 +00:00
|
|
|
|
#include "dsp.h"
|
2005-06-07 18:53:01 +00:00
|
|
|
|
|
|
|
|
|
#define FLAC_MAX_SUPPORTED_BLOCKSIZE 4608
|
|
|
|
|
#define FLAC_MAX_SUPPORTED_CHANNELS 2
|
|
|
|
|
|
2005-06-09 09:47:04 +00:00
|
|
|
|
static uint32_t samplesdone;
|
2005-06-07 18:53:01 +00:00
|
|
|
|
|
2005-07-28 18:43:33 +00:00
|
|
|
|
static FLAC__StreamMetadata *stream_info;
|
|
|
|
|
static FLAC__StreamMetadata *seek_table;
|
|
|
|
|
unsigned int metadata_length;
|
|
|
|
|
|
2005-06-07 18:53:01 +00:00
|
|
|
|
/* Called when the FLAC decoder needs some FLAC data to decode */
|
|
|
|
|
FLAC__SeekableStreamDecoderReadStatus flac_read_handler(const FLAC__SeekableStreamDecoder *dec,
|
|
|
|
|
FLAC__byte buffer[], unsigned *bytes, void *data)
|
2005-09-07 02:22:26 +00:00
|
|
|
|
{
|
|
|
|
|
struct codec_api* ci = (struct codec_api*)data;
|
2005-06-07 18:53:01 +00:00
|
|
|
|
(void)dec;
|
|
|
|
|
|
|
|
|
|
*bytes=(unsigned)(ci->read_filebuf(buffer,*bytes));
|
|
|
|
|
|
2005-06-07 20:09:53 +00:00
|
|
|
|
if (*bytes==0) {
|
2005-09-07 02:22:26 +00:00
|
|
|
|
return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
|
2005-06-07 20:09:53 +00:00
|
|
|
|
} else {
|
2005-09-07 02:22:26 +00:00
|
|
|
|
return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
|
2005-06-07 18:53:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static unsigned char pcmbuf[FLAC_MAX_SUPPORTED_BLOCKSIZE*FLAC_MAX_SUPPORTED_CHANNELS*2] IDATA_ATTR;
|
|
|
|
|
|
|
|
|
|
/* Called when the FLAC decoder has some decoded PCM data to write */
|
|
|
|
|
FLAC__StreamDecoderWriteStatus flac_write_handler(const FLAC__SeekableStreamDecoder *dec,
|
2005-09-07 02:22:26 +00:00
|
|
|
|
const FLAC__Frame *frame,
|
2005-07-28 18:43:33 +00:00
|
|
|
|
const FLAC__int32 * const buf[],
|
|
|
|
|
void *data)
|
2005-06-07 18:53:01 +00:00
|
|
|
|
{
|
2005-09-07 02:22:26 +00:00
|
|
|
|
struct codec_api* ci = (struct codec_api*)data;
|
|
|
|
|
(void)dec;
|
|
|
|
|
unsigned int c_samp, c_chan, d_samp;
|
|
|
|
|
uint32_t data_size = frame->header.blocksize * frame->header.channels * 2; /* Assume 16-bit words */
|
|
|
|
|
uint32_t samples = frame->header.blocksize;
|
|
|
|
|
int yieldcounter = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (samples*frame->header.channels > (FLAC_MAX_SUPPORTED_BLOCKSIZE*FLAC_MAX_SUPPORTED_CHANNELS)) {
|
|
|
|
|
// ERROR!!!
|
|
|
|
|
DEBUGF("ERROR: samples*frame->header.channels=%d\n",samples*frame->header.channels);
|
|
|
|
|
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
(void)dec;
|
|
|
|
|
for (c_samp = d_samp = 0; c_samp < samples; c_samp++) {
|
|
|
|
|
for(c_chan = 0; c_chan < frame->header.channels; c_chan++, d_samp++) {
|
|
|
|
|
pcmbuf[d_samp*2] = (buf[c_chan][c_samp]&0xff00)>>8;
|
|
|
|
|
pcmbuf[(d_samp*2)+1] = buf[c_chan][c_samp]&0xff;
|
|
|
|
|
if (yieldcounter++ == 100) {
|
|
|
|
|
ci->yield();
|
|
|
|
|
yieldcounter = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
samplesdone+=samples;
|
|
|
|
|
ci->set_elapsed(samplesdone/(ci->id3->frequency/1000));
|
2005-06-09 20:01:09 +00:00
|
|
|
|
|
2005-09-07 02:22:26 +00:00
|
|
|
|
ci->yield();
|
|
|
|
|
while (!ci->pcmbuf_insert(pcmbuf, data_size))
|
|
|
|
|
ci->yield();
|
2005-06-07 18:53:01 +00:00
|
|
|
|
|
2005-09-07 02:22:26 +00:00
|
|
|
|
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
|
2005-06-07 18:53:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void flac_metadata_handler(const FLAC__SeekableStreamDecoder *dec,
|
|
|
|
|
const FLAC__StreamMetadata *meta, void *data)
|
|
|
|
|
{
|
2005-07-28 18:43:33 +00:00
|
|
|
|
/* Ignore metadata for now... */
|
|
|
|
|
(void)dec;
|
|
|
|
|
(void)data;
|
|
|
|
|
|
|
|
|
|
metadata_length += meta->length;
|
|
|
|
|
|
|
|
|
|
if ( meta->type == FLAC__METADATA_TYPE_STREAMINFO ) {
|
2005-09-07 02:22:26 +00:00
|
|
|
|
stream_info = FLAC__metadata_object_clone( meta );
|
|
|
|
|
if ( stream_info == NULL ) {
|
|
|
|
|
//return CODEC_ERROR;
|
|
|
|
|
}
|
2005-07-28 18:43:33 +00:00
|
|
|
|
} else if ( meta->type == FLAC__METADATA_TYPE_SEEKTABLE ) {
|
2005-09-07 02:22:26 +00:00
|
|
|
|
seek_table = FLAC__metadata_object_clone( meta );
|
|
|
|
|
if ( seek_table == NULL ) {
|
|
|
|
|
//return CODEC_ERROR;
|
|
|
|
|
}
|
2005-07-28 18:43:33 +00:00
|
|
|
|
}
|
2005-06-07 18:53:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void flac_error_handler(const FLAC__SeekableStreamDecoder *dec,
|
|
|
|
|
FLAC__StreamDecoderErrorStatus status, void *data)
|
|
|
|
|
{
|
|
|
|
|
(void)dec;
|
|
|
|
|
(void)status;
|
|
|
|
|
(void)data;
|
|
|
|
|
}
|
|
|
|
|
|
2005-09-07 02:22:26 +00:00
|
|
|
|
FLAC__SeekableStreamDecoderSeekStatus flac_seek_handler(const FLAC__SeekableStreamDecoder *decoder,
|
|
|
|
|
FLAC__uint64 absolute_byte_offset,
|
|
|
|
|
void *client_data)
|
2005-06-07 18:53:01 +00:00
|
|
|
|
{
|
2005-07-28 18:43:33 +00:00
|
|
|
|
(void)decoder;
|
|
|
|
|
struct codec_api* ci = (struct codec_api*)client_data;
|
2005-06-07 18:53:01 +00:00
|
|
|
|
|
2005-07-28 18:43:33 +00:00
|
|
|
|
if (ci->seek_buffer(absolute_byte_offset)) {
|
2005-09-07 02:22:26 +00:00
|
|
|
|
return FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK;
|
2005-07-28 18:43:33 +00:00
|
|
|
|
} else {
|
2005-09-07 02:22:26 +00:00
|
|
|
|
return FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;
|
2005-07-28 18:43:33 +00:00
|
|
|
|
}
|
2005-06-07 18:53:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-09-07 02:22:26 +00:00
|
|
|
|
FLAC__SeekableStreamDecoderTellStatus flac_tell_handler(const FLAC__SeekableStreamDecoder *decoder,
|
|
|
|
|
FLAC__uint64 *absolute_byte_offset, void *client_data)
|
2005-06-07 18:53:01 +00:00
|
|
|
|
{
|
2005-07-28 18:43:33 +00:00
|
|
|
|
struct codec_api* ci = (struct codec_api*)client_data;
|
2005-06-07 18:53:01 +00:00
|
|
|
|
|
2005-07-28 18:43:33 +00:00
|
|
|
|
(void)decoder;
|
2005-09-07 02:22:26 +00:00
|
|
|
|
*absolute_byte_offset = ci->curpos;
|
|
|
|
|
return FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK;
|
2005-06-07 18:53:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-09-07 02:22:26 +00:00
|
|
|
|
FLAC__SeekableStreamDecoderLengthStatus flac_length_handler(const FLAC__SeekableStreamDecoder *decoder,
|
|
|
|
|
FLAC__uint64 *stream_length, void *client_data)
|
2005-06-07 18:53:01 +00:00
|
|
|
|
{
|
2005-07-28 18:43:33 +00:00
|
|
|
|
struct codec_api* ci = (struct codec_api*)client_data;
|
2005-06-07 18:53:01 +00:00
|
|
|
|
|
2005-07-28 18:43:33 +00:00
|
|
|
|
(void)decoder;
|
2005-09-07 02:22:26 +00:00
|
|
|
|
*stream_length = ci->filesize;
|
|
|
|
|
return FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK;
|
2005-06-07 18:53:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-09-07 02:22:26 +00:00
|
|
|
|
FLAC__bool flac_eof_handler(const FLAC__SeekableStreamDecoder *decoder,
|
|
|
|
|
void *client_data)
|
2005-06-07 18:53:01 +00:00
|
|
|
|
{
|
2005-07-28 18:43:33 +00:00
|
|
|
|
struct codec_api* ci = (struct codec_api*)client_data;
|
2005-06-07 18:53:01 +00:00
|
|
|
|
|
2005-07-28 18:43:33 +00:00
|
|
|
|
(void)decoder;
|
|
|
|
|
if (ci->curpos >= ci->filesize) {
|
2005-09-07 02:22:26 +00:00
|
|
|
|
return true;
|
2005-07-28 18:43:33 +00:00
|
|
|
|
} else {
|
2005-09-07 02:22:26 +00:00
|
|
|
|
return false;
|
2005-07-28 18:43:33 +00:00
|
|
|
|
}
|
2005-06-07 18:53:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifndef SIMULATOR
|
|
|
|
|
extern char iramcopy[];
|
|
|
|
|
extern char iramstart[];
|
|
|
|
|
extern char iramend[];
|
|
|
|
|
#endif
|
|
|
|
|
|
2005-09-07 02:22:26 +00:00
|
|
|
|
FLAC__uint64 find_sample_number(struct codec_api *ci, size_t offset)
|
2005-07-28 18:43:33 +00:00
|
|
|
|
{
|
|
|
|
|
FLAC__StreamMetadata_SeekPoint *points;
|
|
|
|
|
FLAC__uint64 prev_sample, next_sample;
|
|
|
|
|
size_t prev_offset, next_offset;
|
|
|
|
|
int percent;
|
|
|
|
|
|
2005-09-07 02:22:26 +00:00
|
|
|
|
if (offset >= (ci->id3->filesize - metadata_length)) {
|
2005-07-28 18:43:33 +00:00
|
|
|
|
return stream_info->data.stream_info.total_samples;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
prev_offset = 0;
|
|
|
|
|
prev_sample = 0;
|
2005-09-07 02:22:26 +00:00
|
|
|
|
next_offset = ci->id3->filesize - metadata_length;
|
2005-07-28 18:43:33 +00:00
|
|
|
|
next_sample = stream_info->data.stream_info.total_samples;
|
|
|
|
|
|
2005-09-07 02:22:26 +00:00
|
|
|
|
if (seek_table) {
|
2005-07-28 18:43:33 +00:00
|
|
|
|
int left, right, middle;
|
|
|
|
|
|
2005-09-07 02:22:26 +00:00
|
|
|
|
middle = 0; /* Silence compiler warnings */
|
2005-07-28 18:43:33 +00:00
|
|
|
|
points = seek_table->data.seek_table.points;
|
|
|
|
|
left = 0;
|
|
|
|
|
right = seek_table->data.seek_table.num_points - 1;
|
|
|
|
|
|
|
|
|
|
/* Do a binary search to find the matching seek point */
|
2005-09-07 02:22:26 +00:00
|
|
|
|
while (left <= right) {
|
2005-07-28 18:43:33 +00:00
|
|
|
|
middle = (left + right) / 2;
|
|
|
|
|
|
2005-09-07 02:22:26 +00:00
|
|
|
|
if ((FLAC__uint64)offset < points[middle].stream_offset) {
|
2005-07-28 18:43:33 +00:00
|
|
|
|
right = middle - 1;
|
2005-09-07 02:22:26 +00:00
|
|
|
|
} else if ((FLAC__uint64)offset > points[middle].stream_offset) {
|
2005-07-28 18:43:33 +00:00
|
|
|
|
left = middle + 1;
|
|
|
|
|
} else {
|
|
|
|
|
return points[middle].sample_number;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Didn't find a matching seek point, so get the sample numbers of the
|
|
|
|
|
* seek points to the left and right of offset to make our guess more
|
|
|
|
|
* accurate. Accuracy depends on how close these sample numbers are to
|
|
|
|
|
* each other.
|
|
|
|
|
*/
|
2005-09-07 02:22:26 +00:00
|
|
|
|
if ((unsigned)left >= seek_table->data.seek_table.num_points) {
|
2005-07-28 18:43:33 +00:00
|
|
|
|
prev_offset = points[middle].stream_offset;
|
|
|
|
|
prev_sample = points[middle].sample_number;
|
2005-09-07 02:22:26 +00:00
|
|
|
|
} else if (right < 0) {
|
2005-07-28 18:43:33 +00:00
|
|
|
|
next_offset = points[middle].stream_offset;
|
|
|
|
|
next_sample = points[middle].sample_number;
|
|
|
|
|
} else {
|
|
|
|
|
middle--;
|
|
|
|
|
prev_offset = points[middle].stream_offset;
|
|
|
|
|
prev_sample = points[middle].sample_number;
|
|
|
|
|
next_offset = points[middle+1].stream_offset;
|
|
|
|
|
next_sample = points[middle+1].sample_number;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Either there's no seek table or we didn't find our seek point, so now we
|
|
|
|
|
* have to guess.
|
|
|
|
|
*/
|
|
|
|
|
percent = ((offset - prev_offset) * 100) / (next_offset - prev_offset);
|
|
|
|
|
return (FLAC__uint64)(percent * (next_sample - prev_sample) / 100 + prev_sample);
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-22 19:41:30 +00:00
|
|
|
|
/* this is the codec entry point */
|
2005-06-22 19:55:09 +00:00
|
|
|
|
enum codec_status codec_start(struct codec_api* api)
|
2005-06-07 18:53:01 +00:00
|
|
|
|
{
|
2005-06-22 19:41:30 +00:00
|
|
|
|
struct codec_api* ci = api;
|
|
|
|
|
FLAC__SeekableStreamDecoder* flacDecoder;
|
2005-07-28 18:43:33 +00:00
|
|
|
|
FLAC__uint64 offset;
|
2005-06-07 18:53:01 +00:00
|
|
|
|
|
2005-09-07 02:22:26 +00:00
|
|
|
|
TEST_CODEC_API(ci);
|
2005-06-07 18:53:01 +00:00
|
|
|
|
|
|
|
|
|
#ifndef SIMULATOR
|
2005-09-07 02:22:26 +00:00
|
|
|
|
ci->memcpy(iramstart, iramcopy, iramend-iramstart);
|
2005-06-07 18:53:01 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2005-07-28 18:43:33 +00:00
|
|
|
|
ci->configure(CODEC_SET_FILEBUF_LIMIT, (int *)(1024*1024*10));
|
|
|
|
|
ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512));
|
|
|
|
|
ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*1024));
|
2005-06-07 18:53:01 +00:00
|
|
|
|
|
2005-07-28 18:43:33 +00:00
|
|
|
|
ci->configure(CODEC_DSP_ENABLE, (bool *)true);
|
|
|
|
|
ci->configure(DSP_DITHER, (bool *)false);
|
|
|
|
|
ci->configure(DSP_SET_STEREO_MODE, (int *)STEREO_INTERLEAVED);
|
|
|
|
|
ci->configure(DSP_SET_SAMPLE_DEPTH, (int *)(16));
|
2005-06-26 19:41:29 +00:00
|
|
|
|
|
2005-09-07 02:22:26 +00:00
|
|
|
|
next_track:
|
2005-07-28 18:43:33 +00:00
|
|
|
|
metadata_length = 0;
|
|
|
|
|
seek_table = NULL;
|
|
|
|
|
stream_info = NULL;
|
2005-06-07 18:53:01 +00:00
|
|
|
|
|
2005-07-28 18:43:33 +00:00
|
|
|
|
if (codec_init(api)) {
|
2005-09-07 02:22:26 +00:00
|
|
|
|
return CODEC_ERROR;
|
2005-07-28 18:43:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-09-07 02:22:26 +00:00
|
|
|
|
while (!ci->taginfo_ready)
|
|
|
|
|
ci->yield();
|
2005-06-26 19:41:29 +00:00
|
|
|
|
|
2005-09-07 02:22:26 +00:00
|
|
|
|
ci->configure(DSP_SET_FREQUENCY, (long *)(ci->id3->frequency));
|
2005-07-28 18:43:33 +00:00
|
|
|
|
codec_set_replaygain(ci->id3);
|
2005-06-26 19:41:29 +00:00
|
|
|
|
|
2005-07-28 18:43:33 +00:00
|
|
|
|
/* Create a decoder instance */
|
2005-09-07 02:22:26 +00:00
|
|
|
|
flacDecoder = FLAC__seekable_stream_decoder_new();
|
2005-07-28 18:43:33 +00:00
|
|
|
|
|
|
|
|
|
/* Set up the decoder and the callback functions - this must be done before init */
|
|
|
|
|
|
|
|
|
|
/* The following are required for stream_decoder and higher */
|
|
|
|
|
FLAC__seekable_stream_decoder_set_client_data(flacDecoder,ci);
|
|
|
|
|
FLAC__seekable_stream_decoder_set_write_callback(flacDecoder, flac_write_handler);
|
|
|
|
|
FLAC__seekable_stream_decoder_set_read_callback(flacDecoder, flac_read_handler);
|
|
|
|
|
FLAC__seekable_stream_decoder_set_metadata_callback(flacDecoder, flac_metadata_handler);
|
|
|
|
|
FLAC__seekable_stream_decoder_set_error_callback(flacDecoder, flac_error_handler);
|
|
|
|
|
FLAC__seekable_stream_decoder_set_metadata_respond_all(flacDecoder);
|
|
|
|
|
|
|
|
|
|
/* The following are only for the seekable_stream_decoder */
|
|
|
|
|
FLAC__seekable_stream_decoder_set_seek_callback(flacDecoder, flac_seek_handler);
|
|
|
|
|
FLAC__seekable_stream_decoder_set_tell_callback(flacDecoder, flac_tell_handler);
|
|
|
|
|
FLAC__seekable_stream_decoder_set_length_callback(flacDecoder, flac_length_handler);
|
|
|
|
|
FLAC__seekable_stream_decoder_set_eof_callback(flacDecoder, flac_eof_handler);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* QUESTION: What do we do when the init fails? */
|
|
|
|
|
if (FLAC__seekable_stream_decoder_init(flacDecoder)) {
|
2005-09-07 02:22:26 +00:00
|
|
|
|
return CODEC_ERROR;
|
2005-06-07 18:53:01 +00:00
|
|
|
|
}
|
2005-06-18 20:57:01 +00:00
|
|
|
|
|
2005-07-28 18:43:33 +00:00
|
|
|
|
/* The first thing to do is to parse the metadata */
|
|
|
|
|
FLAC__seekable_stream_decoder_process_until_end_of_metadata(flacDecoder);
|
2005-06-18 20:57:01 +00:00
|
|
|
|
|
2005-09-07 02:22:26 +00:00
|
|
|
|
if (ci->id3->offset && stream_info) {
|
|
|
|
|
FLAC__uint64 sample;
|
2005-07-28 18:43:33 +00:00
|
|
|
|
|
2005-09-07 02:22:26 +00:00
|
|
|
|
sample = find_sample_number(ci, ci->id3->offset - metadata_length);
|
|
|
|
|
ci->advance_buffer(ci->id3->offset);
|
|
|
|
|
FLAC__seekable_stream_decoder_seek_absolute(flacDecoder, sample);
|
|
|
|
|
FLAC__seekable_stream_decoder_get_decode_position(flacDecoder, &offset);
|
|
|
|
|
ci->set_offset(offset);
|
|
|
|
|
samplesdone = (uint32_t)sample;
|
|
|
|
|
ci->set_elapsed(sample/(ci->id3->frequency/1000));
|
2005-07-28 18:43:33 +00:00
|
|
|
|
} else {
|
2005-09-07 02:22:26 +00:00
|
|
|
|
samplesdone = 0;
|
|
|
|
|
ci->set_elapsed(0);
|
2005-06-18 20:57:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-07-28 18:43:33 +00:00
|
|
|
|
/* The main decoder loop */
|
2005-09-07 02:22:26 +00:00
|
|
|
|
while (FLAC__seekable_stream_decoder_get_state(flacDecoder) != FLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM) {
|
|
|
|
|
ci->yield();
|
2005-07-28 18:43:33 +00:00
|
|
|
|
if (ci->stop_codec || ci->reload_codec) {
|
2005-09-07 02:22:26 +00:00
|
|
|
|
break;
|
2005-07-28 18:43:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ci->seek_time) {
|
|
|
|
|
int sample_loc;
|
|
|
|
|
|
|
|
|
|
sample_loc = ci->seek_time/1000 * ci->id3->frequency;
|
2005-09-07 02:22:26 +00:00
|
|
|
|
if (FLAC__seekable_stream_decoder_seek_absolute(flacDecoder, sample_loc)) {
|
|
|
|
|
samplesdone = sample_loc;
|
|
|
|
|
ci->set_elapsed(samplesdone/(ci->id3->frequency/1000));
|
2005-07-28 18:43:33 +00:00
|
|
|
|
}
|
|
|
|
|
ci->seek_time = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FLAC__seekable_stream_decoder_process_single(flacDecoder);
|
|
|
|
|
FLAC__seekable_stream_decoder_get_decode_position(flacDecoder, &offset);
|
|
|
|
|
ci->set_offset(offset);
|
|
|
|
|
}
|
2005-06-07 18:53:01 +00:00
|
|
|
|
|
2005-07-28 18:43:33 +00:00
|
|
|
|
/* Flush the libFLAC buffers */
|
|
|
|
|
FLAC__seekable_stream_decoder_finish(flacDecoder);
|
2005-06-07 20:09:53 +00:00
|
|
|
|
|
2005-07-28 18:43:33 +00:00
|
|
|
|
if (ci->request_next_track()) {
|
2005-09-07 02:22:26 +00:00
|
|
|
|
if (stream_info) {
|
|
|
|
|
FLAC__metadata_object_delete(stream_info);
|
2005-07-28 18:43:33 +00:00
|
|
|
|
}
|
2005-09-07 02:22:26 +00:00
|
|
|
|
if (seek_table) {
|
|
|
|
|
FLAC__metadata_object_delete(seek_table);
|
2005-07-28 18:43:33 +00:00
|
|
|
|
}
|
|
|
|
|
metadata_length = 0;
|
|
|
|
|
goto next_track;
|
|
|
|
|
}
|
2005-06-07 18:53:01 +00:00
|
|
|
|
|
2005-07-28 18:43:33 +00:00
|
|
|
|
return CODEC_OK;
|
2005-06-07 18:53:01 +00:00
|
|
|
|
}
|