NULL
};
-static byte reservoir_[FLAC__MAX_BLOCK_SIZE * 2 * 2 * 2]; /* *2 for max bytes-per-sample, *2 for max channels, another *2 for overflow */
-#ifdef RESERVOIR_TEST
#define SAMPLES_PER_WRITE 512
+static byte reservoir_[FLAC__MAX_BLOCK_SIZE * 2 * 2 * 2]; /* *2 for max bytes-per-sample, *2 for max channels, another *2 for overflow */
static byte output_[FLAC__MAX_BLOCK_SIZE * 2 * 2]; /* *2 for max bytes-per-sample, *2 for max channels */
-#endif
static unsigned reservoir_samples_;
static FLAC__FileDecoder *decoder_;
static file_info_struct file_info_;
}
}
-#ifndef RESERVOIR_TEST
-void *play_loop_(void *arg)
-{
-
- (void)arg;
-
- while(file_info_.is_playing) {
- if(!file_info_.eof) {
- (void)FLAC__file_decoder_process_one_frame(decoder_);
- if(reservoir_samples_ > 0) {
- unsigned bytes = reservoir_samples_ * ((file_info_.bits_per_sample+7)/8) * file_info_.channels;
- flac_ip.add_vis_pcm(flac_ip.output->written_time(), file_info_.sample_format, file_info_.channels, bytes, reservoir_);
- while(flac_ip.output->buffer_free() < (int)bytes && file_info_.is_playing && file_info_.seek_to_in_sec == -1)
- xmms_usleep(10000);
- if(file_info_.is_playing && file_info_.seek_to_in_sec == -1)
- flac_ip.output->write_audio(reservoir_, bytes);
- reservoir_samples_ = 0;
- }
- else {
- file_info_.eof = true;
- xmms_usleep(10000);
- }
- }
- else
- xmms_usleep(10000);
- if (file_info_.seek_to_in_sec != -1) {
- const double distance = (double)file_info_.seek_to_in_sec * 1000.0 / (double)file_info_.length_in_msec;
- unsigned target_sample = (unsigned)(distance * (double)file_info_.total_samples);
- if(FLAC__file_decoder_seek_absolute(decoder_, (uint64)target_sample)) {
- flac_ip.output->flush(file_info_.seek_to_in_sec * 1000);
- file_info_.seek_to_in_sec = -1;
- file_info_.eof = false;
- }
- }
-
- }
- if(decoder_ && decoder_->state != FLAC__FILE_DECODER_UNINITIALIZED)
- FLAC__file_decoder_finish(decoder_);
-
- /* are these two calls necessary? */
- flac_ip.output->buffer_free();
- flac_ip.output->buffer_free();
-
- pthread_exit(NULL);
- return 0; /* to silence the compiler warning about not returning a value */
-}
-#else
void *play_loop_(void *arg)
{
pthread_exit(NULL);
return 0; /* to silence the compiler warning about not returning a value */
}
-#endif
bool decoder_init_(const char *filename)
{
return true;
}
-#ifndef RESERVOIR_TEST
-FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__FileDecoder *decoder, const FLAC__Frame *frame, const int32 *buffer[], void *client_data)
-{
- file_info_struct *file_info = (file_info_struct *)client_data;
- const unsigned bps = file_info->bits_per_sample, channels = file_info->channels, wide_samples = frame->header.blocksize;
- unsigned wide_sample, sample, channel;
- int8 *scbuffer = (int8*)reservoir_;
- int16 *ssbuffer = (int16*)reservoir_;
-
- (void)decoder;
-
- if(file_info->abort_flag)
- return FLAC__STREAM_DECODER_WRITE_ABORT;
-
- if(bps == 8) {
- for(sample = wide_sample = 0; wide_sample < wide_samples; wide_sample++)
- for(channel = 0; channel < channels; channel++, sample++)
- scbuffer[sample] = (int8)buffer[channel][wide_sample];
- }
- else if(bps == 16) {
- for(sample = wide_sample = 0; wide_sample < wide_samples; wide_sample++)
- for(channel = 0; channel < channels; channel++, sample++)
- ssbuffer[sample] = (int16)buffer[channel][wide_sample];
- }
- else {
- file_info->abort_flag = true;
- return FLAC__STREAM_DECODER_WRITE_ABORT;
- }
-
- reservoir_samples_ = wide_samples;
-
- return FLAC__STREAM_DECODER_WRITE_CONTINUE;
-}
-#else
FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__FileDecoder *decoder, const FLAC__Frame *frame, const int32 *buffer[], void *client_data)
{
file_info_struct *file_info = (file_info_struct *)client_data;
return FLAC__STREAM_DECODER_WRITE_CONTINUE;
}
-#endif
void metadata_callback_(const FLAC__FileDecoder *decoder, const FLAC__StreamMetaData *metadata, void *client_data)
{