remove id3 support from the plugins
[flac.git] / src / plugin_xmms / plugin.c
index 9d64738..bdb1e4a 100644 (file)
@@ -1,5 +1,5 @@
 /* libxmms-flac - XMMS FLAC input plugin
- * Copyright (C) 2000,2001,2002,2003  Josh Coalson
+ * Copyright (C) 2000,2001,2002,2003,2004  Josh Coalson
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
 #include "FLAC/all.h"
 #include "plugin_common/all.h"
 #include "share/grabbag.h"
+#include "share/replaygain_synthesis.h"
 #include "configure.h"
-#include "wrap_id3.h"
 #include "charset.h"
+#include "tag.h"
 
 #ifdef min
 #undef min
 #endif
 #define min(x,y) ((x)<(y)?(x):(y))
 
+/* adjust for compilers that can't understand using LLU suffix for uint64_t literals */
+#ifdef _MSC_VER
+#define FLAC__U64L(x) x
+#else
+#define FLAC__U64L(x) x##LLU
+#endif
+
 extern void FLAC_XMMS__file_info_box(char *filename);
 
 typedef struct {
@@ -123,6 +131,7 @@ static FLAC__FileDecoder *decoder_ = 0;
 static file_info_struct file_info_;
 static pthread_t decode_thread_;
 static FLAC__bool audio_error_ = false;
+static FLAC__bool is_big_endian_host_;
 
 #define BITRATE_HIST_SEGMENT_MSEC 500
 /* 500ms * 50 = 25s should be enough */
@@ -139,6 +148,9 @@ InputPlugin *get_iplugin_info()
 void FLAC_XMMS__init()
 {
        ConfigFile *cfg;
+       FLAC__uint32 test = 1;
+       is_big_endian_host_ = (*((FLAC__byte*)(&test)))? false : true;
 
        flac_cfg.title.tag_override = FALSE;
        g_free(flac_cfg.title.tag_format);
@@ -155,9 +167,6 @@ void FLAC_XMMS__init()
 
        xmms_cfg_read_boolean(cfg, "flac", "title.convert_char_set", &flac_cfg.title.convert_char_set);
 
-       if(!xmms_cfg_read_string(cfg, "flac", "title.file_char_set", &flac_cfg.title.file_char_set))
-               flac_cfg.title.file_char_set = FLAC_plugin__charset_get_current();
-
        if(!xmms_cfg_read_string(cfg, "flac", "title.user_char_set", &flac_cfg.title.user_char_set))
                flac_cfg.title.user_char_set = FLAC_plugin__charset_get_current();
 
@@ -225,7 +234,7 @@ void FLAC_XMMS__play_file(char *filename)
                        file_info_.sample_format_bytes_per_sample = 1;
                }
                else if(flac_cfg.output.resolution.replaygain.bps_out == 16) {
-                       file_info_.sample_format = FMT_S16_LE;
+                       file_info_.sample_format = (is_big_endian_host_) ? FMT_S16_BE : FMT_S16_LE;
                        file_info_.sample_format_bytes_per_sample = 2;
                }
                else {
@@ -241,7 +250,7 @@ void FLAC_XMMS__play_file(char *filename)
                        file_info_.sample_format_bytes_per_sample = 1;
                }
                else if(file_info_.bits_per_sample == 16 || (file_info_.bits_per_sample == 24 && flac_cfg.output.resolution.normal.dither_24_to_16)) {
-                       file_info_.sample_format = FMT_S16_LE;
+                       file_info_.sample_format = (is_big_endian_host_) ? FMT_S16_BE : FMT_S16_LE;
                        file_info_.sample_format_bytes_per_sample = 2;
                }
                else {
@@ -251,7 +260,7 @@ void FLAC_XMMS__play_file(char *filename)
                        return;
                }
        }
-       FLAC__plugin_common__init_dither_context(&file_info_.dither_context, file_info_.sample_format_bytes_per_sample * 8, flac_cfg.output.resolution.replaygain.noise_shaping);
+       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);
        file_info_.is_playing = true;
 
        if(flac_ip.output->open_audio(file_info_.sample_format, file_info_.sample_rate, file_info_.channels) == 0) {
@@ -497,18 +506,30 @@ FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__FileDecoder *decoder,
                sample_buffer_first_ = 0;
        }
        sample_buffer_start = sample_buffer_ + sample_buffer_last_ * channels * file_info->sample_format_bytes_per_sample;
-       if(file_info_.has_replaygain && flac_cfg.output.replaygain.enable) {
-               FLAC__plugin_common__apply_gain(
+       if(file_info->has_replaygain && flac_cfg.output.replaygain.enable) {
+               FLAC__replaygain_synthesis__apply_gain(
                                sample_buffer_start,
+                               !is_big_endian_host_,
+                               file_info->sample_format_bytes_per_sample == 1, /* unsigned_data_out */
                                buffer,
                                wide_samples,
                                channels,
                                bits_per_sample,
                                file_info->sample_format_bytes_per_sample * 8,
-                               file_info_.replay_scale,
+                               file_info->replay_scale,
                                flac_cfg.output.replaygain.hard_limit,
                                flac_cfg.output.resolution.replaygain.dither,
-                               &file_info_.dither_context
+                               &file_info->dither_context
+               );
+       }
+       else if(is_big_endian_host_) {
+               FLAC__plugin_common__pack_pcm_signed_big_endian(
+                       sample_buffer_start,
+                       buffer,
+                       wide_samples,
+                       channels,
+                       bits_per_sample,
+                       file_info->sample_format_bytes_per_sample * 8
                );
        }
        else {
@@ -532,18 +553,18 @@ void metadata_callback_(const FLAC__FileDecoder *decoder, const FLAC__StreamMeta
        file_info_struct *file_info = (file_info_struct *)client_data;
        (void)decoder;
        if(metadata->type == FLAC__METADATA_TYPE_STREAMINFO) {
-               FLAC__ASSERT(metadata->data.stream_info.total_samples < 0x100000000); /* this plugin can only handle < 4 gigasamples */
+               FLAC__ASSERT(metadata->data.stream_info.total_samples < FLAC__U64L(0x100000000)); /* this plugin can only handle < 4 gigasamples */
                file_info->total_samples = (unsigned)(metadata->data.stream_info.total_samples&0xffffffff);
                file_info->bits_per_sample = metadata->data.stream_info.bits_per_sample;
                file_info->channels = metadata->data.stream_info.channels;
                file_info->sample_rate = metadata->data.stream_info.sample_rate;
-               file_info->length_in_msec = file_info->total_samples * 10 / (file_info->sample_rate / 100);
+               file_info->length_in_msec = (FLAC__uint64)file_info->total_samples * 10 / (file_info->sample_rate / 100);
        }
        else if(metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
                double gain, peak;
                if(grabbag__replaygain_load_from_vorbiscomment(metadata, flac_cfg.output.replaygain.album_mode, &gain, &peak)) {
-                       file_info_.has_replaygain = true;
-                       file_info_.replay_scale = grabbag__replaygain_compute_scale_factor(peak, gain, (double)flac_cfg.output.replaygain.preamp, /*prevent_clipping=*/!flac_cfg.output.replaygain.hard_limit);
+                       file_info->has_replaygain = true;
+                       file_info->replay_scale = grabbag__replaygain_compute_scale_factor(peak, gain, (double)flac_cfg.output.replaygain.preamp, /*prevent_clipping=*/!flac_cfg.output.replaygain.hard_limit);
                }
        }
 }