On Fri, Nov 08, 2002 at 07:12:35PM -0800, Josh Coalson
wrote:> Yeah, it's useful, so now there is a
> FLAC__seekable_stream_decoder_get_decode_position() and
> FLAC__file_decoder_get_decode_position(). I haven't documented
> them yet but you can see an example in
> src/metaflac/operations_shorthand_seektable.c where I use it
> during seektable creation.
Ok, here is patch for "current bitrate" displaying in xmms plugin and
fix for the artist/performer thing.
Attached is also automake/autoconf patch, so i can compile flac again, but
i'm not sure about it...
--
Miroslav Lichvar
-------------- next part --------------
--- src/plugin_xmms/plugin.c.orig 2002-11-07 18:40:44.000000000 +0100
+++ src/plugin_xmms/plugin.c 2002-11-09 17:28:45.000000000 +0100
@@ -58,6 +58,7 @@
unsigned channels;
unsigned sample_rate;
unsigned length_in_msec;
+ gchar *title;
AFormat sample_format;
int seek_to_in_sec;
FLAC__bool has_replaygain;
@@ -114,6 +115,10 @@
#define SAMPLES_PER_WRITE 512
static FLAC__int32 reservoir_[FLAC__MAX_BLOCK_SIZE * 2/*for overflow*/ *
FLAC_PLUGIN__MAX_SUPPORTED_CHANNELS];
static FLAC__byte sample_buffer_[SAMPLES_PER_WRITE *
FLAC_PLUGIN__MAX_SUPPORTED_CHANNELS * (24/8)]; /* (24/8) for max bytes per
sample */
+#define BITRATE_HIST_SEGMENT_MSEC 500
+/* 500ms * 50 = 25s should be enough */
+#define BITRATE_HIST_SIZE 50
+static unsigned bitrate_history[BITRATE_HIST_SIZE];
static unsigned wide_samples_in_reservoir_ = 0;
static FLAC__FileDecoder *decoder_ = 0;
static file_info_struct file_info_;
@@ -188,7 +193,6 @@
void FLAC_XMMS__play_file(char *filename)
{
FILE *f;
- gchar *ret;
wide_samples_in_reservoir_ = 0;
audio_error_ = false;
@@ -219,10 +223,8 @@
return;
}
- ret = flac_format_song_title(filename);
- flac_ip.set_info(ret, file_info_.length_in_msec, file_info_.sample_rate *
file_info_.channels * file_info_.bits_per_sample, file_info_.sample_rate,
file_info_.channels);
-
- g_free(ret);
+ file_info_.title = flac_format_song_title(filename);
+ 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);
file_info_.seek_to_in_sec = -1;
file_info_.play_thread_open = true;
@@ -304,6 +306,10 @@
void *play_loop_(void *arg)
{
+ unsigned written_time_last = 0, bh_index_last_w = 0, bh_index_last_o =
BITRATE_HIST_SIZE;
+ FLAC__uint64 decode_position_last = 0;
+
+
(void)arg;
while(file_info_.is_playing) {
@@ -326,7 +332,8 @@
const unsigned n = min(wide_samples_in_reservoir_, SAMPLES_PER_WRITE);
const unsigned delta = n * channels;
int bytes;
- unsigned i;
+ unsigned i, written_time, bh_index_w, bh_index_o;
+ FLAC__uint64 decode_position;
if(flac_cfg.output.replaygain.enable && file_info_.has_replaygain)
{
bytes = (int)FLAC__plugin_common__apply_gain(
@@ -365,6 +372,27 @@
xmms_usleep(10000);
if(file_info_.is_playing && file_info_.seek_to_in_sec == -1)
flac_ip.output->write_audio(sample_buffer_, bytes);
+
+ /* compute current bitrate */
+
+ written_time = flac_ip.output->written_time();
+ bh_index_w = written_time / BITRATE_HIST_SEGMENT_MSEC % BITRATE_HIST_SIZE ;
+ bh_index_o = flac_ip.output->output_time() / BITRATE_HIST_SEGMENT_MSEC %
BITRATE_HIST_SIZE ;
+ if(bh_index_w != bh_index_last_w && wide_samples_in_reservoir_ <
SAMPLES_PER_WRITE) {
+ bh_index_last_w = bh_index_w;
+ if(!FLAC__file_decoder_get_decode_position(decoder_,
&decode_position))
+ decode_position = 0;
+
+ bitrate_history[(bh_index_w + BITRATE_HIST_SIZE - 1) % BITRATE_HIST_SIZE]
= decode_position > decode_position_last && written_time >
written_time_last ? 8000 * (decode_position - decode_position_last) /
(written_time - written_time_last) : file_info_.sample_rate *
file_info_.channels * file_info_.bits_per_sample;
+ decode_position_last = decode_position;
+ written_time_last = written_time;
+ }
+
+ /* display the right bitrate from history */
+ if(bh_index_o != bh_index_last_o && bh_index_last_w != bh_index_o)
{
+ bh_index_last_o = bh_index_o;
+ flac_ip.set_info(file_info_.title, file_info_.length_in_msec,
bitrate_history[bh_index_o], file_info_.sample_rate, file_info_.channels);
+ }
}
else {
file_info_.eof = true;
@@ -378,6 +406,7 @@
unsigned target_sample = (unsigned)(distance *
(double)file_info_.total_samples);
if(FLAC__file_decoder_seek_absolute(decoder_, (FLAC__uint64)target_sample))
{
flac_ip.output->flush(file_info_.seek_to_in_sec * 1000);
+ bh_index_last_w = bh_index_last_o = file_info_.seek_to_in_sec * 1000 /
BITRATE_HIST_SEGMENT_MSEC % BITRATE_HIST_SIZE;
file_info_.seek_to_in_sec = -1;
file_info_.eof = false;
wide_samples_in_reservoir_ = 0;
@@ -390,6 +419,8 @@
/* are these two calls necessary? */
flac_ip.output->buffer_free();
flac_ip.output->buffer_free();
+
+ g_free(file_info_.title);
pthread_exit(NULL);
return 0; /* to silence the compiler warning about not returning a value */
-------------- next part --------------
--- src/plugin_xmms/wrap_id3.c.orig 2002-11-07 18:40:44.000000000 +0100
+++ src/plugin_xmms/wrap_id3.c 2002-11-09 11:41:23.000000000 +0100
@@ -98,6 +98,8 @@
XMMS_NEW_TITLEINPUT(input);
input->performer = local__getstr(tag.performer);
+ if (!input->performer)
+ input->performer = local__getstr(tag.composer);
input->album_name = local__getstr(tag.album);
input->track_name = local__getstr(tag.title);
input->track_number = local__getnum(tag.track_number);
-------------- next part --------------
Index: configure.in
==================================================================RCS file:
/cvsroot/flac/flac/configure.in,v
retrieving revision 1.64
diff -u -r1.64 configure.in
--- configure.in 7 Nov 2002 05:14:02 -0000 1.64
+++ configure.in 9 Nov 2002 16:51:46 -0000
@@ -230,7 +230,7 @@
AM_PATH_XMMS(0.9.5.1, , AC_MSG_WARN([*** XMMS >= 0.9.5.1 not installed -
xmms support will not be built]))
AM_CONDITIONAL(FLaC__HAS_XMMS, test x$XMMS_INPUT_PLUGIN_DIR != x)
-SHARE_LIBS='$(top_builddir)/src/share/libgrabbag.a
$(top_builddir)/src/share/libgain_analysis.a
$(top_builddir)/src/share/libgetopt.a $(top_builddir)/src/share/libutf8.a'
+SHARE_LIBS='$(top_builddir)/src/share/grabbag/libgrabbag.a
$(top_builddir)/src/share/gain_analysis/libgain_analysis.a
$(top_builddir)/src/share/getopt/libgetopt.a
$(top_builddir)/src/share/utf8/libutf8.a'
dnl check for i18n(internationalization); these are from libiconv/gettext
AM_ICONV
Index: src/flac/Makefile.am
==================================================================RCS file:
/cvsroot/flac/flac/src/flac/Makefile.am,v
retrieving revision 1.19
diff -u -r1.19 Makefile.am
--- src/flac/Makefile.am 30 Oct 2002 06:28:09 -0000 1.19
+++ src/flac/Makefile.am 9 Nov 2002 16:51:49 -0000
@@ -38,4 +38,4 @@
encode.h \
vorbiscomment.h
-flac_LDADD = $(NEED_OGGFLAC_LIB) $(top_builddir)/src/libFLAC/libFLAC.la
@OGG_LIBS@ @SHARE_LIBS@ @LIBICONV@ -lm
+flac_LDADD = $(NEED_OGGFLAC_LIB) @SHARE_LIBS@
$(top_builddir)/src/libFLAC/libFLAC.la @OGG_LIBS@ @LIBICONV@ -lm
Index: src/plugin_xmms/Makefile.am
==================================================================RCS file:
/cvsroot/flac/flac/src/plugin_xmms/Makefile.am,v
retrieving revision 1.17
diff -u -r1.17 Makefile.am
--- src/plugin_xmms/Makefile.am 16 Oct 2002 22:06:06 -0000 1.17
+++ src/plugin_xmms/Makefile.am 9 Nov 2002 16:51:49 -0000
@@ -52,5 +52,5 @@
# for fix info see:
# http://lists.freshrpms.net/pipermail/rpm-list/2002-April/000746.html
# the workaround is the extra '-L$(top_builddir)/src/libFLAC/.libs'
-libxmms_flac_la_LIBADD = $(top_builddir)/src/plugin_common/libplugin_common.a
$(top_builddir)/src/libFLAC/libFLAC.la -L$(top_builddir)/src/libFLAC/.libs
@XMMS_LIBS@ @ID3LIB_LIBS@
+libxmms_flac_la_LIBADD = @SHARE_LIBS@
$(top_builddir)/src/plugin_common/libplugin_common.a
$(top_builddir)/src/libFLAC/libFLAC.la -L$(top_builddir)/src/libFLAC/.libs
@XMMS_LIBS@ @ID3LIB_LIBS@
libxmms_flac_la_LDFLAGS = -module -avoid-version
Index: src/test_libFLAC/Makefile.am
==================================================================RCS file:
/cvsroot/flac/flac/src/test_libFLAC/Makefile.am,v
retrieving revision 1.7
diff -u -r1.7 Makefile.am
--- src/test_libFLAC/Makefile.am 7 Nov 2002 05:07:30 -0000 1.7
+++ src/test_libFLAC/Makefile.am 9 Nov 2002 16:51:53 -0000
@@ -25,7 +25,7 @@
noinst_PROGRAMS = test_libFLAC
test_libFLAC_LDADD = \
- $(top_builddir)/src/share/grabbag/grabbag.la \
+ $(top_builddir)/src/share/grabbag/libgrabbag.a \
$(top_builddir)/src/libFLAC/libFLAC.la \
-lm
test_libFLAC_SOURCES = \
Index: src/test_libFLAC++/Makefile.am
==================================================================RCS file:
/cvsroot/flac/flac/src/test_libFLAC++/Makefile.am,v
retrieving revision 1.8
diff -u -r1.8 Makefile.am
--- src/test_libFLAC++/Makefile.am 7 Nov 2002 05:07:31 -0000 1.8
+++ src/test_libFLAC++/Makefile.am 9 Nov 2002 16:51:53 -0000
@@ -25,7 +25,7 @@
noinst_PROGRAMS = test_libFLAC++
test_libFLAC___LDADD = \
- $(top_builddir)/src/share/grabbag/grabbag.la \
+ $(top_builddir)/src/share/grabbag/libgrabbag.a \
$(top_builddir)/src/libFLAC++/libFLAC++.la \
$(top_builddir)/src/libFLAC/libFLAC.la \
-lm
Index: src/test_libOggFLAC/Makefile.am
==================================================================RCS file:
/cvsroot/flac/flac/src/test_libOggFLAC/Makefile.am,v
retrieving revision 1.7
diff -u -r1.7 Makefile.am
--- src/test_libOggFLAC/Makefile.am 7 Nov 2002 05:07:31 -0000 1.7
+++ src/test_libOggFLAC/Makefile.am 9 Nov 2002 16:51:53 -0000
@@ -25,7 +25,7 @@
noinst_PROGRAMS = test_libOggFLAC
test_libOggFLAC_LDADD = \
- $(top_builddir)/src/share/grabbag/grabbag.la \
+ $(top_builddir)/src/share/grabbag/libgrabbag.a \
$(top_builddir)/src/libOggFLAC/libOggFLAC.la \
$(top_builddir)/src/libFLAC/libFLAC.la \
@OGG_LIBS@ \
Index: src/test_libOggFLAC++/Makefile.am
==================================================================RCS file:
/cvsroot/flac/flac/src/test_libOggFLAC++/Makefile.am,v
retrieving revision 1.6
diff -u -r1.6 Makefile.am
--- src/test_libOggFLAC++/Makefile.am 7 Nov 2002 05:07:31 -0000 1.6
+++ src/test_libOggFLAC++/Makefile.am 9 Nov 2002 16:51:53 -0000
@@ -25,7 +25,7 @@
noinst_PROGRAMS = test_libOggFLAC++
test_libOggFLAC___LDADD = \
- $(top_builddir)/src/share/grabbag/grabbag.la \
+ $(top_builddir)/src/share/grabbag/libgrabbag.a \
$(top_builddir)/src/libOggFLAC++/libOggFLAC++.la \
$(top_builddir)/src/libOggFLAC/libOggFLAC.la \
$(top_builddir)/src/libFLAC/libFLAC.la \