78
73
FLAC__bool has_replaygain;
79
74
double replay_scale;
80
75
DitherContext dither_context;
83
typedef FLAC__StreamDecoderWriteStatus (*WriteCallback) (const void *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
84
typedef void (*MetadataCallback) (const void *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
85
typedef void (*ErrorCallback) (const void *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
89
void* (*new_decoder) (void);
90
FLAC__bool (*set_md5_checking) (void *decoder, FLAC__bool value);
91
FLAC__bool (*set_source) (void *decoder, const char* source);
92
FLAC__bool (*set_metadata_ignore_all) (void *decoder);
93
FLAC__bool (*set_metadata_respond) (void *decoder, FLAC__MetadataType type);
94
FLAC__bool (*set_write_callback) (void *decoder, WriteCallback value);
95
FLAC__bool (*set_metadata_callback) (void *decoder, MetadataCallback value);
96
FLAC__bool (*set_error_callback) (void *decoder, ErrorCallback value);
97
FLAC__bool (*set_client_data) (void *decoder, void *value);
98
FLAC__bool (*decoder_init) (void *decoder);
99
void (*safe_decoder_finish) (void *decoder);
100
void (*safe_decoder_delete) (void *decoder);
101
FLAC__bool (*process_until_end_of_metadata) (void *decoder);
102
FLAC__bool (*process_single) (void *decoder);
103
FLAC__bool (*is_eof) (void *decoder);
106
#define NUM_DECODER_TYPES 2
112
static void FLAC_XMMS__init();
78
static void FLAC_XMMS__init(void);
113
79
static int FLAC_XMMS__is_our_file(char *filename);
114
80
static void FLAC_XMMS__play_file(char *filename);
115
static void FLAC_XMMS__stop();
81
static void FLAC_XMMS__stop(void);
116
82
static void FLAC_XMMS__pause(short p);
117
83
static void FLAC_XMMS__seek(int time);
118
static int FLAC_XMMS__get_time();
119
static void FLAC_XMMS__cleanup();
84
static int FLAC_XMMS__get_time(void);
85
static void FLAC_XMMS__cleanup(void);
120
86
static void FLAC_XMMS__get_song_info(char *filename, char **title, int *length);
122
88
static void *play_loop_(void *arg);
124
static FLAC__bool safe_decoder_init_(const char *filename, void **decoderp, decoder_funcs_t const ** fnsp);
125
static void file_decoder_safe_decoder_finish_(void *decoder);
126
static void file_decoder_safe_decoder_delete_(void *decoder);
127
static FLAC__StreamDecoderWriteStatus write_callback_(const void *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
128
static void metadata_callback_(const void *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
129
static void error_callback_(const void *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
90
static FLAC__bool safe_decoder_init_(const char *filename, FLAC__StreamDecoder *decoder);
91
static void safe_decoder_finish_(FLAC__StreamDecoder *decoder);
92
static void safe_decoder_delete_(FLAC__StreamDecoder *decoder);
131
static void init_decoder_func_tables();
132
static decoder_t source_to_decoder_type (const char *source);
94
static FLAC__StreamDecoderReadStatus http_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
95
static FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
96
static void metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
97
static void error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
134
99
InputPlugin flac_ip =
316
291
if(decoder_ == 0)
319
if(!safe_decoder_init_(filename, &decoder_, &decoder_func_table_))
294
if(!safe_decoder_init_(filename, decoder_))
322
if(file_info_.has_replaygain && flac_cfg.output.replaygain.enable) {
297
if(stream_data_.has_replaygain && flac_cfg.output.replaygain.enable) {
323
298
if(flac_cfg.output.resolution.replaygain.bps_out == 8) {
324
file_info_.sample_format = FMT_U8;
325
file_info_.sample_format_bytes_per_sample = 1;
299
stream_data_.sample_format = FMT_U8;
300
stream_data_.sample_format_bytes_per_sample = 1;
327
302
else if(flac_cfg.output.resolution.replaygain.bps_out == 16) {
328
file_info_.sample_format = (is_big_endian_host_) ? FMT_S16_BE : FMT_S16_LE;
329
file_info_.sample_format_bytes_per_sample = 2;
303
stream_data_.sample_format = (is_big_endian_host_) ? FMT_S16_BE : FMT_S16_LE;
304
stream_data_.sample_format_bytes_per_sample = 2;
332
307
/*@@@ need some error here like wa2: MessageBox(mod_.hMainWindow, "ERROR: plugin can only handle 8/16-bit samples\n", "ERROR: plugin can only handle 8/16-bit samples", 0); */
333
308
fprintf(stderr, "libxmms-flac: can't handle %d bit output\n", flac_cfg.output.resolution.replaygain.bps_out);
334
decoder_func_table_ -> safe_decoder_finish(decoder_);
309
safe_decoder_finish_(decoder_);
339
if(file_info_.bits_per_sample == 8) {
340
file_info_.sample_format = FMT_U8;
341
file_info_.sample_format_bytes_per_sample = 1;
314
if(stream_data_.bits_per_sample == 8) {
315
stream_data_.sample_format = FMT_U8;
316
stream_data_.sample_format_bytes_per_sample = 1;
343
else if(file_info_.bits_per_sample == 16 || (file_info_.bits_per_sample == 24 && flac_cfg.output.resolution.normal.dither_24_to_16)) {
344
file_info_.sample_format = (is_big_endian_host_) ? FMT_S16_BE : FMT_S16_LE;
345
file_info_.sample_format_bytes_per_sample = 2;
318
else if(stream_data_.bits_per_sample == 16 || (stream_data_.bits_per_sample == 24 && flac_cfg.output.resolution.normal.dither_24_to_16)) {
319
stream_data_.sample_format = (is_big_endian_host_) ? FMT_S16_BE : FMT_S16_LE;
320
stream_data_.sample_format_bytes_per_sample = 2;
348
323
/*@@@ need some error here like wa2: MessageBox(mod_.hMainWindow, "ERROR: plugin can only handle 8/16-bit samples\n", "ERROR: plugin can only handle 8/16-bit samples", 0); */
349
fprintf(stderr, "libxmms-flac: can't handle %d bit output\n", file_info_.bits_per_sample);
350
decoder_func_table_ -> safe_decoder_finish(decoder_);
324
fprintf(stderr, "libxmms-flac: can't handle %d bit output\n", stream_data_.bits_per_sample);
325
safe_decoder_finish_(decoder_);
354
FLAC__replaygain_synthesis__init_dither_context(&file_info_.dither_context, file_info_.sample_format_bytes_per_sample * 8, flac_cfg.output.resolution.replaygain.noise_shaping);
355
file_info_.is_playing = true;
329
FLAC__replaygain_synthesis__init_dither_context(&stream_data_.dither_context, stream_data_.sample_format_bytes_per_sample * 8, flac_cfg.output.resolution.replaygain.noise_shaping);
330
stream_data_.is_playing = true;
357
if(flac_ip.output->open_audio(file_info_.sample_format, file_info_.sample_rate, file_info_.channels) == 0) {
332
if(flac_ip.output->open_audio(stream_data_.sample_format, stream_data_.sample_rate, stream_data_.channels) == 0) {
358
333
audio_error_ = true;
359
decoder_func_table_ -> safe_decoder_finish(decoder_);
334
safe_decoder_finish_(decoder_);
363
file_info_.title = flac_format_song_title(filename);
364
flac_ip.set_info(file_info_.title, file_info_.length_in_msec, file_info_.sample_rate * file_info_.channels * file_info_.bits_per_sample, file_info_.sample_rate, file_info_.channels);
338
stream_data_.title = flac_format_song_title(filename);
339
flac_ip.set_info(stream_data_.title, stream_data_.length_in_msec, stream_data_.sample_rate * stream_data_.channels * stream_data_.bits_per_sample, stream_data_.sample_rate, stream_data_.channels);
366
file_info_.seek_to_in_sec = -1;
367
file_info_.play_thread_open = true;
341
stream_data_.seek_to_in_sec = -1;
342
stream_data_.play_thread_open = true;
368
343
pthread_create(&decode_thread_, NULL, play_loop_, NULL);
371
void FLAC_XMMS__stop()
346
void FLAC_XMMS__stop(void)
373
if(file_info_.is_playing) {
374
file_info_.is_playing = false;
375
if(file_info_.play_thread_open) {
376
file_info_.play_thread_open = false;
348
if(stream_data_.is_playing) {
349
stream_data_.is_playing = false;
350
if(stream_data_.play_thread_open) {
351
stream_data_.play_thread_open = false;
377
352
pthread_join(decode_thread_, NULL);
379
354
flac_ip.output->close_audio();
380
decoder_func_table_ -> safe_decoder_finish (decoder_);
355
safe_decoder_finish_(decoder_);
499
483
bitrate_history_[(bh_index_w + BITRATE_HIST_SIZE - 1) % BITRATE_HIST_SIZE] =
500
484
decode_position > decode_position_last && written_time > written_time_last ?
501
485
8000 * (decode_position - decode_position_last) / (written_time - written_time_last) :
502
file_info_.sample_rate * file_info_.channels * file_info_.bits_per_sample;
486
stream_data_.sample_rate * stream_data_.channels * stream_data_.bits_per_sample;
503
487
decode_position_last = decode_position;
504
488
written_time_last = written_time;
508
file_info_.eof = true;
492
stream_data_.eof = true;
509
493
xmms_usleep(10000);
513
497
xmms_usleep(10000);
514
if(decoder_func_table_->seekable && file_info_.seek_to_in_sec != -1) {
515
const double distance = (double)file_info_.seek_to_in_sec * 1000.0 / (double)file_info_.length_in_msec;
516
unsigned target_sample = (unsigned)(distance * (double)file_info_.total_samples);
517
if(FLAC__file_decoder_seek_absolute(decoder_, (FLAC__uint64)target_sample)) {
518
flac_ip.output->flush(file_info_.seek_to_in_sec * 1000);
498
if(!stream_data_.is_http_source && stream_data_.seek_to_in_sec != -1) {
499
const double distance = (double)stream_data_.seek_to_in_sec * 1000.0 / (double)stream_data_.length_in_msec;
500
FLAC__uint64 target_sample = (FLAC__uint64)(distance * (double)stream_data_.total_samples);
501
if(stream_data_.total_samples > 0 && target_sample >= stream_data_.total_samples)
502
target_sample = stream_data_.total_samples - 1;
503
if(FLAC__stream_decoder_seek_absolute(decoder_, target_sample)) {
504
flac_ip.output->flush(stream_data_.seek_to_in_sec * 1000);
519
505
bh_index_last_w = bh_index_last_o = flac_ip.output->output_time() / BITRATE_HIST_SEGMENT_MSEC % BITRATE_HIST_SIZE;
520
if(!FLAC__file_decoder_get_decode_position(decoder_, &decode_position_frame))
506
if(!FLAC__stream_decoder_get_decode_position(decoder_, &decode_position_frame))
521
507
decode_position_frame = 0;
522
file_info_.seek_to_in_sec = -1;
523
file_info_.eof = false;
524
sample_buffer_first_ = sample_buffer_last_ = 0;
508
stream_data_.eof = false;
509
sample_buffer_first_ = sample_buffer_last_ = 0;
511
else if(FLAC__stream_decoder_get_state(decoder_) == FLAC__STREAM_DECODER_SEEK_ERROR) {
512
/*@@@ this should probably be a dialog */
513
fprintf(stderr, "libxmms-flac: SEEK ERROR\n");
514
FLAC__stream_decoder_flush(decoder_);
515
stream_data_.eof = false;
516
sample_buffer_first_ = sample_buffer_last_ = 0;
518
stream_data_.seek_to_in_sec = -1;
528
521
/* display the right bitrate from history */
529
522
unsigned bh_index_o = flac_ip.output->output_time() / BITRATE_HIST_SEGMENT_MSEC % BITRATE_HIST_SIZE;
530
523
if(bh_index_o != bh_index_last_o && bh_index_o != bh_index_last_w && bh_index_o != (bh_index_last_w + 1) % BITRATE_HIST_SIZE) {
531
524
bh_index_last_o = bh_index_o;
532
flac_ip.set_info(file_info_.title, file_info_.length_in_msec, bitrate_history_[bh_index_o], file_info_.sample_rate, file_info_.channels);
525
flac_ip.set_info(stream_data_.title, stream_data_.length_in_msec, bitrate_history_[bh_index_o], stream_data_.sample_rate, stream_data_.channels);
537
decoder_func_table_ -> safe_decoder_finish(decoder_);
530
safe_decoder_finish_(decoder_);
539
532
/* are these two calls necessary? */
540
533
flac_ip.output->buffer_free();
541
534
flac_ip.output->buffer_free();
543
g_free(file_info_.title);
536
g_free(stream_data_.title);
545
538
pthread_exit(NULL);
546
539
return 0; /* to silence the compiler warning about not returning a value */
549
/*********** File decoder functions */
551
static FLAC__bool file_decoder_init (void *decoder)
553
return FLAC__file_decoder_init( (FLAC__FileDecoder*) decoder) == FLAC__FILE_DECODER_OK;
556
static void file_decoder_safe_decoder_finish_(void *decoder)
558
if(decoder && FLAC__file_decoder_get_state((FLAC__FileDecoder *) decoder) != FLAC__FILE_DECODER_UNINITIALIZED)
559
FLAC__file_decoder_finish((FLAC__FileDecoder *) decoder);
562
static void file_decoder_safe_decoder_delete_(void *decoder)
542
FLAC__bool safe_decoder_init_(const char *filename, FLAC__StreamDecoder *decoder)
547
safe_decoder_finish_(decoder);
549
FLAC__stream_decoder_set_md5_checking(decoder, false);
550
FLAC__stream_decoder_set_metadata_ignore_all(decoder);
551
FLAC__stream_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_STREAMINFO);
552
FLAC__stream_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT);
553
if(stream_data_.is_http_source) {
554
flac_http_open(filename, 0);
555
if(FLAC__stream_decoder_init_stream(decoder, http_read_callback_, /*seek_callback=*/0, /*tell_callback=*/0, /*length_callback=*/0, /*eof_callback=*/0, write_callback_, metadata_callback_, error_callback_, /*client_data=*/&stream_data_) != FLAC__STREAM_DECODER_INIT_STATUS_OK)
559
if(FLAC__stream_decoder_init_file(decoder, filename, write_callback_, metadata_callback_, error_callback_, /*client_data=*/&stream_data_) != FLAC__STREAM_DECODER_INIT_STATUS_OK)
563
if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder))
569
void safe_decoder_finish_(FLAC__StreamDecoder *decoder)
571
if(decoder && FLAC__stream_decoder_get_state(decoder) != FLAC__STREAM_DECODER_UNINITIALIZED)
572
(void)FLAC__stream_decoder_finish(decoder);
573
if(stream_data_.is_http_source)
577
void safe_decoder_delete_(FLAC__StreamDecoder *decoder)
565
file_decoder_safe_decoder_finish_(decoder);
566
FLAC__file_decoder_delete( (FLAC__FileDecoder *) decoder);
580
safe_decoder_finish_(decoder);
581
FLAC__stream_decoder_delete(decoder);
570
static FLAC__bool file_decoder_is_eof(void *decoder)
572
return FLAC__file_decoder_get_state((FLAC__FileDecoder *) decoder) == FLAC__FILE_DECODER_END_OF_FILE;
575
static const decoder_funcs_t FILE_DECODER_FUNCTIONS = {
577
(void* (*) (void)) FLAC__file_decoder_new,
578
(FLAC__bool (*) (void *, FLAC__bool)) FLAC__file_decoder_set_md5_checking,
579
(FLAC__bool (*) (void *, const char*)) FLAC__file_decoder_set_filename,
580
(FLAC__bool (*) (void *)) FLAC__file_decoder_set_metadata_ignore_all,
581
(FLAC__bool (*) (void *, FLAC__MetadataType)) FLAC__file_decoder_set_metadata_respond,
582
(FLAC__bool (*) (void *, WriteCallback)) FLAC__file_decoder_set_write_callback,
583
(FLAC__bool (*) (void *, MetadataCallback)) FLAC__file_decoder_set_metadata_callback,
584
(FLAC__bool (*) (void *, ErrorCallback)) FLAC__file_decoder_set_error_callback,
585
(FLAC__bool (*) (void *, void *)) FLAC__file_decoder_set_client_data,
586
(FLAC__bool (*) (void *)) file_decoder_init,
587
(void (*) (void *)) file_decoder_safe_decoder_finish_,
588
(void (*) (void *)) file_decoder_safe_decoder_delete_,
589
(FLAC__bool (*) (void *)) FLAC__file_decoder_process_until_end_of_metadata,
590
(FLAC__bool (*) (void *)) FLAC__file_decoder_process_single,
594
/*********** HTTP decoder functions */
598
static FLAC__bool http_decoder_set_md5_checking (void *decoder, FLAC__bool value)
601
// operation unsupported
602
return FLAC__stream_decoder_get_state ((const FLAC__StreamDecoder *) decoder) ==
603
FLAC__STREAM_DECODER_UNINITIALIZED;
606
static FLAC__bool http_decoder_set_url (void *decoder, const char* url)
609
url_ = g_strdup (url);
613
static FLAC__StreamDecoderReadStatus http_decoder_read_callback (const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data)
617
*bytes = flac_http_read (buffer, *bytes);
585
FLAC__StreamDecoderReadStatus http_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
589
*bytes = flac_http_read(buffer, *bytes);
618
590
return *bytes ? FLAC__STREAM_DECODER_READ_STATUS_CONTINUE : FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
621
static FLAC__bool http_decoder_init (void *decoder)
623
flac_http_open (url_, 0);
625
FLAC__stream_decoder_set_read_callback (decoder, http_decoder_read_callback);
626
return FLAC__stream_decoder_init( (FLAC__StreamDecoder*) decoder) == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA;
629
static void http_decoder_safe_decoder_finish_(void *decoder)
631
if(decoder && FLAC__stream_decoder_get_state((FLAC__StreamDecoder *) decoder) != FLAC__STREAM_DECODER_UNINITIALIZED) {
632
FLAC__stream_decoder_finish((FLAC__StreamDecoder *) decoder);
637
static void http_decoder_safe_decoder_delete_(void *decoder)
640
http_decoder_safe_decoder_finish_(decoder);
641
FLAC__stream_decoder_delete( (FLAC__StreamDecoder *) decoder);
645
static FLAC__bool http_decoder_is_eof(void *decoder)
647
return FLAC__stream_decoder_get_state((FLAC__StreamDecoder *) decoder) == FLAC__STREAM_DECODER_END_OF_STREAM;
650
static const decoder_funcs_t HTTP_DECODER_FUNCTIONS = {
652
(void* (*) (void)) FLAC__stream_decoder_new,
653
http_decoder_set_md5_checking,
654
(FLAC__bool (*) (void *, const char*)) http_decoder_set_url,
655
(FLAC__bool (*) (void *)) FLAC__stream_decoder_set_metadata_ignore_all,
656
(FLAC__bool (*) (void *, FLAC__MetadataType)) FLAC__stream_decoder_set_metadata_respond,
657
(FLAC__bool (*) (void *, WriteCallback)) FLAC__stream_decoder_set_write_callback,
658
(FLAC__bool (*) (void *, MetadataCallback)) FLAC__stream_decoder_set_metadata_callback,
659
(FLAC__bool (*) (void *, ErrorCallback)) FLAC__stream_decoder_set_error_callback,
660
(FLAC__bool (*) (void *, void *)) FLAC__stream_decoder_set_client_data,
661
(FLAC__bool (*) (void *)) http_decoder_init,
662
(void (*) (void *)) http_decoder_safe_decoder_finish_,
663
(void (*) (void *)) http_decoder_safe_decoder_delete_,
664
(FLAC__bool (*) (void *)) FLAC__stream_decoder_process_until_end_of_metadata,
665
(FLAC__bool (*) (void *)) FLAC__stream_decoder_process_single,
669
static decoder_funcs_t const *decoder_func_table_;
671
static void init_decoder_func_tables()
673
DECODER_FUNCS [DECODER_FILE] = & FILE_DECODER_FUNCTIONS;
674
DECODER_FUNCS [DECODER_HTTP] = & HTTP_DECODER_FUNCTIONS;
677
static decoder_t source_to_decoder_type (const char *source)
679
return strncasecmp(source, "http://", 7) ? DECODER_FILE : DECODER_HTTP;
682
static void change_decoder_if_needed (decoder_t new_decoder_type, void **decoderp, decoder_funcs_t const ** fntabp)
684
const decoder_funcs_t *new_fn_table = DECODER_FUNCS [new_decoder_type];
685
if (*fntabp != new_fn_table) {
686
(*fntabp)->safe_decoder_delete(*decoderp);
687
*fntabp = new_fn_table;
688
*decoderp = new_fn_table -> new_decoder();
692
FLAC__bool safe_decoder_init_(const char *filename, void **decoderp, decoder_funcs_t const ** fntabp)
694
if(decoderp == 0 || *decoderp == 0)
697
(*fntabp)->safe_decoder_finish(*decoderp);
699
change_decoder_if_needed(source_to_decoder_type(filename), decoderp, fntabp);
702
decoder_funcs_t const *fntab = *fntabp;
703
void *decoder = *decoderp;
708
fntab -> set_md5_checking(decoder, false);
709
fntab -> set_source(decoder, filename);
710
fntab -> set_metadata_ignore_all(decoder);
711
fntab -> set_metadata_respond(decoder, FLAC__METADATA_TYPE_STREAMINFO);
712
fntab -> set_metadata_respond(decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT);
713
fntab -> set_write_callback(decoder, write_callback_);
714
fntab -> set_metadata_callback(decoder, metadata_callback_);
715
fntab -> set_error_callback(decoder, error_callback_);
716
fntab -> set_client_data(decoder, &file_info_);
717
if(!fntab -> decoder_init(decoder))
720
if(!fntab -> process_until_end_of_metadata(decoder))
727
FLAC__StreamDecoderWriteStatus write_callback_(const void *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
729
file_info_struct *file_info = (file_info_struct *)client_data;
730
const unsigned channels = file_info->channels, wide_samples = frame->header.blocksize;
731
const unsigned bits_per_sample = file_info->bits_per_sample;
593
FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
595
stream_data_struct *stream_data = (stream_data_struct *)client_data;
596
const unsigned channels = stream_data->channels, wide_samples = frame->header.blocksize;
597
const unsigned bits_per_sample = stream_data->bits_per_sample;
732
598
FLAC__byte *sample_buffer_start;
736
if(file_info->abort_flag)
602
if(stream_data->abort_flag)
737
603
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
739
if((sample_buffer_last_ + wide_samples) > (SAMPLE_BUFFER_SIZE / (channels * file_info->sample_format_bytes_per_sample))) {
740
memmove(sample_buffer_, sample_buffer_ + sample_buffer_first_ * channels * file_info->sample_format_bytes_per_sample, (sample_buffer_last_ - sample_buffer_first_) * channels * file_info->sample_format_bytes_per_sample);
605
if((sample_buffer_last_ + wide_samples) > (SAMPLE_BUFFER_SIZE / (channels * stream_data->sample_format_bytes_per_sample))) {
606
memmove(sample_buffer_, sample_buffer_ + sample_buffer_first_ * channels * stream_data->sample_format_bytes_per_sample, (sample_buffer_last_ - sample_buffer_first_) * channels * stream_data->sample_format_bytes_per_sample);
741
607
sample_buffer_last_ -= sample_buffer_first_;
742
608
sample_buffer_first_ = 0;
744
sample_buffer_start = sample_buffer_ + sample_buffer_last_ * channels * file_info->sample_format_bytes_per_sample;
745
if(file_info->has_replaygain && flac_cfg.output.replaygain.enable) {
610
sample_buffer_start = sample_buffer_ + sample_buffer_last_ * channels * stream_data->sample_format_bytes_per_sample;
611
if(stream_data->has_replaygain && flac_cfg.output.replaygain.enable) {
746
612
FLAC__replaygain_synthesis__apply_gain(
747
613
sample_buffer_start,
748
614
!is_big_endian_host_,
749
file_info->sample_format_bytes_per_sample == 1, /* unsigned_data_out */
615
stream_data->sample_format_bytes_per_sample == 1, /* unsigned_data_out */
754
file_info->sample_format_bytes_per_sample * 8,
755
file_info->replay_scale,
620
stream_data->sample_format_bytes_per_sample * 8,
621
stream_data->replay_scale,
756
622
flac_cfg.output.replaygain.hard_limit,
757
623
flac_cfg.output.resolution.replaygain.dither,
758
&file_info->dither_context
624
&stream_data->dither_context
761
627
else if(is_big_endian_host_) {