# HG changeset patch # User Paula Stanciu # Date 1218118779 -10800 # Node ID 66f53425a5dda1825bb535ce74efce9ec3e5e603 # Parent d332994acaa989410f91ef9bb9bcc34bb1f1a2a4# Parent a9917a9cde99a716aa76a4e5bb6df23dd556fe07 Automated merge with ssh://paula@hg.atheme.org//hg/audacious-plugins diff -r a9917a9cde99 -r 66f53425a5dd buildsys.mk.in --- a/buildsys.mk.in Thu Aug 07 17:19:07 2008 +0300 +++ b/buildsys.mk.in Thu Aug 07 17:19:39 2008 +0300 @@ -102,7 +102,7 @@ case $$i in \ *.o) \ test $$i -nt .deps && regen=1; \ - deps="$${deps%.o}.dep $$i"; \ + deps="$${deps} $${i%.o}.dep"; \ ;; \ esac; \ done; \ diff -r a9917a9cde99 -r 66f53425a5dd src/filewriter/Makefile --- a/src/filewriter/Makefile Thu Aug 07 17:19:07 2008 +0300 +++ b/src/filewriter/Makefile Thu Aug 07 17:19:39 2008 +0300 @@ -4,7 +4,8 @@ wav.c \ mp3.c \ vorbis.c \ - flac.c + flac.c \ + convert.c include ../../buildsys.mk include ../../extra.mk @@ -13,4 +14,4 @@ CFLAGS += ${PLUGIN_CFLAGS} CPPFLAGS += ${PLUGIN_CPPFLAGS} ${GLIB_CFLAGS} ${GTK_CFLAGS} ${MOWGLI_CFLAGS} ${FILEWRITER_CFLAGS} ${OGG_VORBIS_CFLAGS} -I../.. -LIBS += ${GTK_LIBS} ${FILEWRITER_LIBS} +LIBS += ${GTK_LIBS} ${FILEWRITER_LIBS} -lSAD diff -r a9917a9cde99 -r 66f53425a5dd src/filewriter/convert.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/filewriter/convert.c Thu Aug 07 17:19:39 2008 +0300 @@ -0,0 +1,64 @@ +#include "convert.h" + +static SAD_dither_t *sad_state = NULL; +gpointer convert_output = NULL; +static gsize convert_output_length = 0; +static gint nch; +static AFormat in_fmt; +static AFormat out_fmt; + +gboolean convert_init(AFormat input_fmt, AFormat output_fmt, gint channels) +{ + gint ret; + SAD_buffer_format input_sad_fmt; + SAD_buffer_format output_sad_fmt; + + + input_sad_fmt.sample_format = aud_sadfmt_from_afmt(input_fmt); + if (input_sad_fmt.sample_format < 0) return FALSE; + input_sad_fmt.fracbits = FMT_FRACBITS(input_fmt); + input_sad_fmt.channels = channels; + input_sad_fmt.channels_order = SAD_CHORDER_INTERLEAVED; + input_sad_fmt.samplerate = 0; + + output_sad_fmt.sample_format = aud_sadfmt_from_afmt(output_fmt); + if (output_sad_fmt.sample_format < 0) return FALSE; + output_sad_fmt.fracbits = FMT_FRACBITS(output_fmt); + output_sad_fmt.channels = channels; + output_sad_fmt.channels_order = SAD_CHORDER_INTERLEAVED; + output_sad_fmt.samplerate = 0; + + sad_state = SAD_dither_init(&input_sad_fmt, &output_sad_fmt, &ret); + if (sad_state == NULL) { + AUDDBG("ditherer init failed\n"); + return FALSE; + } + + in_fmt = input_fmt; + out_fmt = output_fmt; + nch = channels; + + SAD_dither_set_dither(sad_state, FALSE); + return TRUE; +} + +gint convert_process(gpointer ptr, gint length) +{ + gint frames, len; + frames = length / nch / FMT_SIZEOF(in_fmt); + len = frames * nch * FMT_SIZEOF(out_fmt); + + if (convert_output == NULL || convert_output_length < len) + { + convert_output_length = len; + convert_output = aud_smart_realloc(convert_output, &convert_output_length); + } + + SAD_dither_process_buffer(sad_state, ptr, convert_output, frames); + return len; +} + +void convert_free(void) +{ + if (sad_state != NULL) {SAD_dither_free(sad_state); sad_state = NULL;} +} diff -r a9917a9cde99 -r 66f53425a5dd src/filewriter/convert.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/filewriter/convert.h Thu Aug 07 17:19:39 2008 +0300 @@ -0,0 +1,14 @@ +#ifndef CONVERT_H +#define CONVERT_H + +#include "filewriter.h" + +gpointer convert_output; + +gboolean convert_init(AFormat input_fmt, AFormat output_fmt, gint channels); + +gint convert_process(gpointer ptr, gint length); + +void convert_free(void); + +#endif diff -r a9917a9cde99 -r 66f53425a5dd src/filewriter/filewriter.c --- a/src/filewriter/filewriter.c Thu Aug 07 17:19:07 2008 +0300 +++ b/src/filewriter/filewriter.c Thu Aug 07 17:19:39 2008 +0300 @@ -22,6 +22,7 @@ #include "filewriter.h" #include "plugins.h" +#include "convert.h" struct format_info input; @@ -261,75 +262,20 @@ if (!output_file) return 0; + convert_init(fmt, plugin.format_required, nch); + rv = (plugin.open)(); return rv; } -static void convert_buffer(gpointer buffer, gint length) -{ - gint i; - - if (input.format == FMT_S8) - { - guint8 *ptr1 = buffer; - gint8 *ptr2 = buffer; - - for (i = 0; i < length; i++) - *(ptr1++) = *(ptr2++) ^ 128; - } - if (input.format == FMT_S16_BE) - { - gint16 *ptr = buffer; - - for (i = 0; i < length >> 1; i++, ptr++) - *ptr = GUINT16_SWAP_LE_BE(*ptr); - } - if (input.format == FMT_S16_NE) - { - gint16 *ptr = buffer; - - for (i = 0; i < length >> 1; i++, ptr++) - *ptr = GINT16_TO_LE(*ptr); - } - if (input.format == FMT_U16_BE) - { - gint16 *ptr1 = buffer; - guint16 *ptr2 = buffer; - - for (i = 0; i < length >> 1; i++, ptr2++) - *(ptr1++) = GINT16_TO_LE(GUINT16_FROM_BE(*ptr2) ^ 32768); - } - if (input.format == FMT_U16_LE) - { - gint16 *ptr1 = buffer; - guint16 *ptr2 = buffer; - - for (i = 0; i < length >> 1; i++, ptr2++) - *(ptr1++) = GINT16_TO_LE(GUINT16_FROM_LE(*ptr2) ^ 32768); - } - if (input.format == FMT_U16_NE) - { - gint16 *ptr1 = buffer; - guint16 *ptr2 = buffer; - - for (i = 0; i < length >> 1; i++, ptr2++) - *(ptr1++) = GINT16_TO_LE((*ptr2) ^ 32768); - } -} - static void file_write(void *ptr, gint length) { - if (input.format == FMT_S8 || input.format == FMT_S16_BE || - input.format == FMT_U16_LE || input.format == FMT_U16_BE || - input.format == FMT_U16_NE) - convert_buffer(ptr, length); -#ifdef WORDS_BIGENDIAN - if (input.format == FMT_S16_NE) - convert_buffer(ptr, length); -#endif + int len; - plugin.write(ptr, length); + len = convert_process(ptr, length); + + plugin.write(convert_output, len); } static gint file_write_output(void *ptr, gint length) @@ -340,6 +286,7 @@ static void file_close(void) { plugin.close(); + convert_free(); if (output_file) { diff -r a9917a9cde99 -r 66f53425a5dd src/filewriter/filewriter.h --- a/src/filewriter/filewriter.h Thu Aug 07 17:19:07 2008 +0300 +++ b/src/filewriter/filewriter.h Thu Aug 07 17:19:39 2008 +0300 @@ -37,6 +37,8 @@ #include #include +#include + struct format_info { AFormat format; int frequency; @@ -65,6 +67,7 @@ gint (*free)(void); gint (*playing)(void); gint (*get_written_time)(void); + AFormat format_required; }; #endif diff -r a9917a9cde99 -r 66f53425a5dd src/filewriter/flac.c --- a/src/filewriter/flac.c Thu Aug 07 17:19:07 2008 +0300 +++ b/src/filewriter/flac.c Thu Aug 07 17:19:39 2008 +0300 @@ -44,7 +44,8 @@ flac_close, flac_free, flac_playing, - flac_get_written_time + flac_get_written_time, + FMT_S16_NE }; static FLAC__StreamEncoder *flac_encoder; diff -r a9917a9cde99 -r 66f53425a5dd src/filewriter/mp3.c --- a/src/filewriter/mp3.c Thu Aug 07 17:19:07 2008 +0300 +++ b/src/filewriter/mp3.c Thu Aug 07 17:19:39 2008 +0300 @@ -50,7 +50,8 @@ mp3_close, mp3_free, mp3_playing, - mp3_get_written_time + mp3_get_written_time, + FMT_S16_NE }; static GtkWidget *configure_win = NULL; diff -r a9917a9cde99 -r 66f53425a5dd src/filewriter/vorbis.c --- a/src/filewriter/vorbis.c Thu Aug 07 17:19:07 2008 +0300 +++ b/src/filewriter/vorbis.c Thu Aug 07 17:19:39 2008 +0300 @@ -47,7 +47,8 @@ vorbis_close, vorbis_free, vorbis_playing, - vorbis_get_written_time + vorbis_get_written_time, + FMT_S16_NE }; static float v_base_quality = 0.5; diff -r a9917a9cde99 -r 66f53425a5dd src/filewriter/wav.c --- a/src/filewriter/wav.c Thu Aug 07 17:19:07 2008 +0300 +++ b/src/filewriter/wav.c Thu Aug 07 17:19:39 2008 +0300 @@ -40,7 +40,8 @@ wav_close, wav_free, wav_playing, - wav_get_written_time + wav_get_written_time, + FMT_S16_LE }; diff -r a9917a9cde99 -r 66f53425a5dd src/icecast/Makefile --- a/src/icecast/Makefile Thu Aug 07 17:19:07 2008 +0300 +++ b/src/icecast/Makefile Thu Aug 07 17:19:39 2008 +0300 @@ -2,7 +2,8 @@ SRCS = icecast.c \ ../filewriter/mp3.o \ - ../filewriter/vorbis.o + ../filewriter/vorbis.o \ + ../filewriter/convert.o include ../../buildsys.mk include ../../extra.mk @@ -11,4 +12,4 @@ CFLAGS += ${PLUGIN_CFLAGS} ${SHOUT_CFLAGS} CPPFLAGS += ${PLUGIN_CPPFLAGS} ${GLIB_CFLAGS} ${GTK_CFLAGS} ${PANGO_CFLAGS} ${MOWGLI_CFLAGS} ${DBUS_CFLAGS} ${FILEWRITER_CFLAGS} ${OGG_VORBIS_CFLAGS} ${SHOUT_CFLAGS} -I../../intl -I../.. -LIBS += ${GTK_LIBS} ${FILEWRITER_LIBS} ${SHOUT_LIBS} +LIBS += ${GTK_LIBS} ${FILEWRITER_LIBS} ${SHOUT_LIBS} -lSAD diff -r a9917a9cde99 -r 66f53425a5dd src/icecast/icecast.c --- a/src/icecast/icecast.c Thu Aug 07 17:19:07 2008 +0300 +++ b/src/icecast/icecast.c Thu Aug 07 17:19:39 2008 +0300 @@ -24,6 +24,7 @@ #include "../filewriter/filewriter.h" #include "../filewriter/plugins.h" +#include "../filewriter/convert.h" #include struct format_info input; @@ -325,76 +326,21 @@ } } + convert_init(fmt, plugin.format_required, nch); + rv = (plugin.open)(); g_debug("ICE_OPEN"); return rv; } -static void convert_buffer(gpointer buffer, gint length) -{ - gint i; - - if (input.format == FMT_S8) - { - guint8 *ptr1 = buffer; - gint8 *ptr2 = buffer; - - for (i = 0; i < length; i++) - *(ptr1++) = *(ptr2++) ^ 128; - } - if (input.format == FMT_S16_BE) - { - gint16 *ptr = buffer; - - for (i = 0; i < length >> 1; i++, ptr++) - *ptr = GUINT16_SWAP_LE_BE(*ptr); - } - if (input.format == FMT_S16_NE) - { - gint16 *ptr = buffer; - - for (i = 0; i < length >> 1; i++, ptr++) - *ptr = GINT16_TO_LE(*ptr); - } - if (input.format == FMT_U16_BE) - { - gint16 *ptr1 = buffer; - guint16 *ptr2 = buffer; - - for (i = 0; i < length >> 1; i++, ptr2++) - *(ptr1++) = GINT16_TO_LE(GUINT16_FROM_BE(*ptr2) ^ 32768); - } - if (input.format == FMT_U16_LE) - { - gint16 *ptr1 = buffer; - guint16 *ptr2 = buffer; - - for (i = 0; i < length >> 1; i++, ptr2++) - *(ptr1++) = GINT16_TO_LE(GUINT16_FROM_LE(*ptr2) ^ 32768); - } - if (input.format == FMT_U16_NE) - { - gint16 *ptr1 = buffer; - guint16 *ptr2 = buffer; - - for (i = 0; i < length >> 1; i++, ptr2++) - *(ptr1++) = GINT16_TO_LE((*ptr2) ^ 32768); - } -} - static void ice_write(void *ptr, gint length) { - if (input.format == FMT_S8 || input.format == FMT_S16_BE || - input.format == FMT_U16_LE || input.format == FMT_U16_BE || - input.format == FMT_U16_NE) - convert_buffer(ptr, length); -#ifdef WORDS_BIGENDIAN - if (input.format == FMT_S16_NE) - convert_buffer(ptr, length); -#endif + int len; - plugin.write(ptr, length); + len = convert_process(ptr, length); + + plugin.write(convert_output, length); } static gint ice_real_write(void* ptr, gint length) @@ -435,6 +381,7 @@ static gboolean ice_real_close(gpointer data) { plugin.close(); + convert_free(); if (shout) { diff -r a9917a9cde99 -r 66f53425a5dd src/skins/plugin.c --- a/src/skins/plugin.c Thu Aug 07 17:19:07 2008 +0300 +++ b/src/skins/plugin.c Thu Aug 07 17:19:39 2008 +0300 @@ -106,15 +106,15 @@ gboolean skins_cleanup(void) { if (plugin_is_active == TRUE) { + gtk_widget_hide(mainwin); + gtk_widget_hide(equalizerwin); + gtk_widget_hide(playlistwin); skins_cfg_save(); cleanup_skins(); skins_free_paths(); ui_main_evlistener_dissociate(); ui_playlist_evlistener_dissociate(); skins_cfg_free(); - gtk_widget_destroy(mainwin); - gtk_widget_destroy(equalizerwin); - gtk_widget_destroy(playlistwin); ui_manager_destroy(); mainwin = NULL; equalizerwin = NULL;