static void xmms_replaygain_destroy (xmms_xform_t *xform) { xmms_config_property_t *cfgv; g_return_if_fail (xform); g_free (xmms_xform_private_data_get (xform)); cfgv = xmms_xform_config_lookup (xform, "mode"); xmms_config_property_callback_remove (cfgv, xmms_replaygain_config_changed, xform); cfgv = xmms_xform_config_lookup (xform, "use_anticlip"); xmms_config_property_callback_remove (cfgv, xmms_replaygain_config_changed, xform); cfgv = xmms_xform_config_lookup (xform, "preamp"); xmms_config_property_callback_remove (cfgv, xmms_replaygain_config_changed, xform); cfgv = xmms_xform_config_lookup (xform, "enabled"); xmms_config_property_callback_remove (cfgv, xmms_replaygain_config_changed, xform); }
/* * Private stuff */ static CdIo_t * open_cd (xmms_xform_t *xform) { CdIo_t *cdio; xmms_config_property_t *val; const gchar *device; const gchar *accessmode; cdio_log_set_handler (log_handler); val = xmms_xform_config_lookup (xform, "device"); device = xmms_config_property_get_string (val); val = xmms_xform_config_lookup (xform, "accessmode"); accessmode = xmms_config_property_get_string (val); XMMS_DBG ("Trying to open device '%s', using '%s' access mode.", device, accessmode); if (g_ascii_strcasecmp (accessmode, "default") == 0) { cdio = cdio_open (device, DRIVER_UNKNOWN); } else { cdio = cdio_open_am (device, DRIVER_UNKNOWN, accessmode); } if (!cdio) { xmms_log_error ("Failed to open device '%s'.", device); } else { cdio_set_speed (cdio, 1); xmms_log_info ("Opened device '%s'.", device); } return cdio; }
static gboolean xmms_vocoder_init (xmms_xform_t *xform) { xmms_vocoder_data_t *priv; xmms_config_property_t *config; g_return_val_if_fail (xform, FALSE); priv = g_new0 (xmms_vocoder_data_t, 1); priv->winsize = 2048; priv->channels = xmms_xform_indata_get_int (xform, XMMS_STREAM_TYPE_FMT_CHANNELS); priv->bufsize = priv->winsize * priv->channels; priv->iobuf = g_malloc (priv->bufsize * sizeof (gint16)); priv->procbuf = g_malloc (priv->bufsize * sizeof (pvocoder_sample_t)); priv->resbuf = g_malloc (priv->bufsize * sizeof (gfloat)); priv->outbuf = g_string_new (NULL); priv->pvoc = pvocoder_init (priv->winsize, priv->channels); g_return_val_if_fail (priv->pvoc, FALSE); priv->resampler = src_new (SRC_LINEAR, priv->channels, NULL); g_return_val_if_fail (priv->resampler, FALSE); xmms_xform_private_data_set (xform, priv); config = xmms_xform_config_lookup (xform, "enabled"); g_return_val_if_fail (config, FALSE); xmms_config_property_callback_set (config, xmms_vocoder_config_changed, priv); priv->enabled = !!xmms_config_property_get_int (config); config = xmms_xform_config_lookup (xform, "speed"); g_return_val_if_fail (config, FALSE); xmms_config_property_callback_set (config, xmms_vocoder_config_changed, priv); priv->speed = (gfloat) xmms_config_property_get_int (config) / 100.0; config = xmms_xform_config_lookup (xform, "pitch"); g_return_val_if_fail (config, FALSE); xmms_config_property_callback_set (config, xmms_vocoder_config_changed, priv); priv->pitch = 100.0 / (gfloat) xmms_config_property_get_int (config); config = xmms_xform_config_lookup (xform, "attack_detection"); g_return_val_if_fail (config, FALSE); xmms_config_property_callback_set (config, xmms_vocoder_config_changed, priv); priv->attack_detection = !!xmms_config_property_get_int (config); pvocoder_set_scale (priv->pvoc, priv->speed * priv->pitch); pvocoder_set_attack_detection (priv->pvoc, priv->attack_detection); priv->resdata.data_in = NULL; priv->resdata.input_frames = 0; priv->resdata.data_out = priv->resbuf; priv->resdata.output_frames = priv->winsize; priv->resdata.src_ratio = priv->pitch; priv->resdata.end_of_input = 0; xmms_xform_outdata_type_copy (xform); return TRUE; }
static void xmms_vocoder_destroy (xmms_xform_t *xform) { xmms_vocoder_data_t *data; xmms_config_property_t *config; g_return_if_fail (xform); data = xmms_xform_private_data_get (xform); g_return_if_fail (data); config = xmms_xform_config_lookup (xform, "enabled"); xmms_config_property_callback_remove (config, xmms_vocoder_config_changed, data); config = xmms_xform_config_lookup (xform, "speed"); xmms_config_property_callback_remove (config, xmms_vocoder_config_changed, data); config = xmms_xform_config_lookup (xform, "pitch"); xmms_config_property_callback_remove (config, xmms_vocoder_config_changed, data); config = xmms_xform_config_lookup (xform, "attack_detection"); xmms_config_property_callback_remove (config, xmms_vocoder_config_changed, data); pvocoder_close (data->pvoc); src_delete (data->resampler); g_string_free (data->outbuf, TRUE); g_free (data->resbuf); g_free (data->procbuf); g_free (data->iobuf); g_free (data); }
static gboolean xmms_magic_plugin_init (xmms_xform_t *xform) { xmms_magic_checker_t c; gchar *res; const gchar *url; xmms_config_property_t *cv; c.xform = xform; c.read = c.offset = 0; c.alloc = 128; /* start with a 128 bytes buffer */ c.buf = g_malloc (c.alloc); cv = xmms_xform_config_lookup (xform, "dumpcount"); c.dumpcount = xmms_config_property_get_int (cv); url = xmms_xform_indata_find_str (xform, XMMS_STREAM_TYPE_URL); res = xmms_magic_match (&c, url); if (res) { xmms_xform_metadata_set_str (xform, XMMS_MEDIALIB_ENTRY_PROPERTY_MIME, res); xmms_xform_outdata_type_add (xform, XMMS_STREAM_TYPE_MIMETYPE, res, XMMS_STREAM_TYPE_END); } g_free (c.buf); return !!res; }
static void xmms_modplug_destroy (xmms_xform_t *xform) { xmms_modplug_data_t *data; xmms_config_property_t *cfgv; int i; g_return_if_fail (xform); data = xmms_xform_private_data_get (xform); g_return_if_fail (data); if (data->buffer) g_string_free (data->buffer, TRUE); if (data->mod) ModPlug_Unload (data->mod); for (i = 0; i < G_N_ELEMENTS (config_params); i++) { cfgv = xmms_xform_config_lookup (xform, config_params[i].key); xmms_config_property_callback_remove (cfgv, xmms_modplug_config_changed, data); } g_free (data); }
static gboolean xmms_normalize_init (xmms_xform_t *xform) { xmms_config_property_t *cfgv; xmms_normalize_data_t *data; int i; g_return_val_if_fail (xform, FALSE); data = g_new0 (xmms_normalize_data_t, 1); for (i = 0; i < G_N_ELEMENTS (config_params); i++) { cfgv = xmms_xform_config_lookup (xform, config_params[i].key); xmms_config_property_callback_set (cfgv, xmms_normalize_config_changed, data); xmms_normalize_config_changed (XMMS_OBJECT (cfgv), NULL, data); } xmms_xform_outdata_type_copy (xform); data->dirty = FALSE; data->compress = compress_new (data->use_anticlip, data->target, data->max_gain, data->smooth, data->buckets); xmms_xform_private_data_set (xform, data); return TRUE; }
static void xmms_normalize_destroy (xmms_xform_t *xform) { xmms_normalize_data_t *data; xmms_config_property_t *cfgv; int i; g_return_if_fail (xform); data = xmms_xform_private_data_get (xform); g_return_if_fail (data); compress_free (data->compress); for (i = 0; i < G_N_ELEMENTS (config_params); i++) { cfgv = xmms_xform_config_lookup (xform, config_params[i].key); xmms_config_property_callback_remove (cfgv, xmms_normalize_config_changed, data); } g_free (data); }
static gboolean xmms_cdda_browse (xmms_xform_t *xform, const gchar *url, xmms_error_t *error) { track_t track_count, t; gchar cdda_url[XMMS_PATH_MAX]; xmms_config_property_t *val; const gchar *device; gchar *disc_id; g_return_val_if_fail (xform, FALSE); val = xmms_xform_config_lookup (xform, "device"); device = xmms_config_property_get_string (val); if (!get_disc_ids (device, &disc_id, 0, &track_count)) { return FALSE; } for (t = 1; t <= track_count; t++) { gchar trackno[3]; g_snprintf (cdda_url, XMMS_PATH_MAX, "cdda://%s/%d", disc_id, t); XMMS_DBG ("Adding '%s'.", cdda_url); g_snprintf (trackno, sizeof (trackno), "%d", t); xmms_xform_browse_add_symlink (xform, trackno, cdda_url); xmms_xform_browse_add_entry_property_int (xform, "intsort", t); } g_free (disc_id); return TRUE; }
static gboolean xmms_ringbuf_plugin_init (xmms_xform_t *xform) { xmms_config_property_t *config; xmms_ringbuf_priv_t *priv; gint buffer_size; priv = g_new0 (xmms_ringbuf_priv_t, 1); xmms_xform_private_data_set (xform, priv); config = xmms_xform_config_lookup (xform, "buffersize"); buffer_size = xmms_config_property_get_int (config); g_cond_init (&priv->state_cond); g_mutex_init (&priv->state_lock); g_mutex_init (&priv->buffer_lock); priv->state = STATE_WANT_BUFFER; priv->buffer = xmms_ringbuf_new (MAX (4096, buffer_size)); priv->thread = g_thread_new ("x2 ringbuf", xmms_ringbuf_xform_thread, xform); xmms_xform_outdata_type_copy (xform); return TRUE; }
static gint xmms_id3v1_get_tags (xmms_xform_t *xform) { xmms_config_property_t *config; gint enabled; xmms_error_t err; gint64 res; guchar buf[128]; gint ret = 0; config = xmms_xform_config_lookup (xform, "id3v1_enable"); g_return_val_if_fail (config, -1); enabled = xmms_config_property_get_int (config); if (!enabled) { XMMS_DBG ("ID3v1 tags disabled."); return 0; } xmms_error_reset (&err); res = xmms_xform_seek (xform, -128, XMMS_XFORM_SEEK_END, &err); if (res == -1) { XMMS_DBG ("Couldn't seek - not getting id3v1 tag"); return 0; } if (xmms_xform_read (xform, buf, 128, &err) == 128) { if (xmms_id3v1_parse (xform, buf)) { ret = 128; } } else { XMMS_DBG ("Read of 128 bytes failed?!"); xmms_error_reset (&err); } res = xmms_xform_seek (xform, 0, XMMS_XFORM_SEEK_SET, &err); if (res == -1) { XMMS_DBG ("Couldn't seek after getting id3 tag?!? very bad"); return -1; } return ret; }
static void xmms_eq_destroy (xmms_xform_t *xform) { xmms_config_property_t *config; gpointer priv; gchar buf[16]; gint i; g_return_if_fail (xform); priv = xmms_xform_private_data_get (xform); config = xmms_xform_config_lookup (xform, "enabled"); xmms_config_property_callback_remove (config, xmms_eq_config_changed, priv); config = xmms_xform_config_lookup (xform, "bands"); xmms_config_property_callback_remove (config, xmms_eq_config_changed, priv); config = xmms_xform_config_lookup (xform, "extra_filtering"); xmms_config_property_callback_remove (config, xmms_eq_config_changed, priv); config = xmms_xform_config_lookup (xform, "use_legacy"); xmms_config_property_callback_remove (config, xmms_eq_config_changed, priv); config = xmms_xform_config_lookup (xform, "preamp"); xmms_config_property_callback_remove (config, xmms_eq_gain_changed, priv); for (i=0; i<EQ_BANDS_LEGACY; i++) { g_snprintf (buf, sizeof (buf), "legacy%d", i); config = xmms_xform_config_lookup (xform, buf); xmms_config_property_callback_remove (config, xmms_eq_gain_changed, priv); } for (i=0; i<EQ_MAX_BANDS; i++) { g_snprintf (buf, sizeof (buf), "gain%02d", i); config = xmms_xform_config_lookup (xform, buf); xmms_config_property_callback_remove (config, xmms_eq_gain_changed, priv); } g_free (priv); }
static gboolean xmms_cdda_init (xmms_xform_t *xform) { CdIo_t *cdio = NULL; cdrom_drive_t *drive = NULL; const gchar *url; gchar **url_data = NULL; gchar *url_end; xmms_cdda_data_t *data; guint playtime; lsn_t first_lsn; track_t track; gchar *disc_id = NULL; gchar *cddb_id = NULL; xmms_config_property_t *val; const gchar *device; const gchar *metakey; gboolean ret = TRUE; g_return_val_if_fail (xform, FALSE); url = xmms_xform_indata_get_str (xform, XMMS_STREAM_TYPE_URL); if (g_ascii_strcasecmp (url, "cdda://") == 0) { xmms_xform_outdata_type_add (xform, XMMS_STREAM_TYPE_MIMETYPE, "application/x-xmms2-playlist-entries", XMMS_STREAM_TYPE_END); return TRUE; } val = xmms_xform_config_lookup (xform, "device"); device = xmms_config_property_get_string (val); if (!get_disc_ids (device, &disc_id, &cddb_id, 0)) { return FALSE; } url += 7; url_data = g_strsplit (url, "/", 2); if (g_ascii_strcasecmp (url_data[0], disc_id)) { xmms_log_error ("Wrong disc inserted."); ret = FALSE; goto end; } if (url_data[1] == NULL) { xmms_log_error ("Missing track number."); ret = FALSE; goto end; } track = strtol (url_data[1], &url_end, 10); if (url_data[1] == url_end) { xmms_log_error ("Invalid track, need a number."); ret = FALSE; goto end; } cdio = open_cd (xform); if (!cdio) { ret = FALSE; goto end; } drive = cdio_cddap_identify_cdio (cdio, 1, NULL); if (!drive) { xmms_log_error ("Failed to identify drive."); ret = FALSE; goto end; } if (cdio_cddap_open (drive)) { xmms_log_error ("Unable to open disc."); ret = FALSE; goto end; } first_lsn = cdio_cddap_track_firstsector (drive, track); if (first_lsn == -1) { xmms_log_error ("No such track."); ret = FALSE; goto end; } data = g_new (xmms_cdda_data_t, 1); data->cdio = cdio; data->drive = drive; data->track = track; data->first_lsn = first_lsn; data->last_lsn = cdio_cddap_track_lastsector (drive, data->track); data->current_lsn = first_lsn; data->buf_used = CDIO_CD_FRAMESIZE_RAW; playtime = (data->last_lsn - data->first_lsn) * 1000.0 / CDIO_CD_FRAMES_PER_SEC; metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_DURATION; xmms_xform_metadata_set_int (xform, metakey, playtime); metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_BITRATE; xmms_xform_metadata_set_int (xform, metakey, 141120); xmms_xform_metadata_set_str (xform, "disc_id", url_data[0]); xmms_xform_metadata_set_str (xform, "cddb_id", cddb_id); metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_TRACKNR; xmms_xform_metadata_set_int (xform, metakey, track); xmms_xform_private_data_set (xform, data); xmms_xform_outdata_type_add (xform, XMMS_STREAM_TYPE_MIMETYPE, "audio/pcm", XMMS_STREAM_TYPE_FMT_FORMAT, XMMS_SAMPLE_FORMAT_S16, XMMS_STREAM_TYPE_FMT_CHANNELS, 2, XMMS_STREAM_TYPE_FMT_SAMPLERATE, 44100, XMMS_STREAM_TYPE_END); end: /* These are to be destroyed in every cases... */ g_free (cddb_id); g_free (disc_id); g_strfreev (url_data); /* destroy cdio/drive in case of failure */ if (!ret) { if (drive) { cdio_cddap_close_no_free_cdio (drive); } if (cdio) { cdio_destroy (cdio); } } return ret; }
static gboolean xmms_gme_init (xmms_xform_t *xform) { xmms_gme_data_t *data; gme_err_t init_error; GString *file_contents; /* The raw data from the file. */ gme_info_t *metadata = NULL; xmms_config_property_t *val; int loops; int maxlength; const char *subtune_str; int subtune = 0; long fadelen = -1; int samplerate; double stereodepth; g_return_val_if_fail (xform, FALSE); data = g_new0 (xmms_gme_data_t, 1); xmms_xform_private_data_set (xform, data); val = xmms_xform_config_lookup (xform, "samplerate"); samplerate = xmms_config_property_get_int (val); if (samplerate < 1) samplerate = GME_DEFAULT_SAMPLE_RATE; data->samplerate = samplerate; xmms_xform_outdata_type_add (xform, XMMS_STREAM_TYPE_MIMETYPE, "audio/pcm", /* PCM samples */ XMMS_STREAM_TYPE_FMT_FORMAT, XMMS_SAMPLE_FORMAT_S16, /* 16-bit signed */ XMMS_STREAM_TYPE_FMT_CHANNELS, 2, /* stereo */ XMMS_STREAM_TYPE_FMT_SAMPLERATE, samplerate, XMMS_STREAM_TYPE_END); file_contents = g_string_new (""); for (;;) { xmms_error_t error; gchar buf[4096]; gint ret; ret = xmms_xform_read (xform, buf, sizeof (buf), &error); if (ret == -1) { XMMS_DBG ("Error reading emulated music data"); return FALSE; } if (ret == 0) { break; } g_string_append_len (file_contents, buf, ret); } init_error = gme_open_data (file_contents->str, file_contents->len, &data->emu, samplerate); g_string_free (file_contents, TRUE); if (init_error) { XMMS_DBG ("gme_open_data returned an error: %s", init_error); return FALSE; } if (xmms_xform_metadata_get_str (xform, "subtune", &subtune_str)) { subtune = strtol (subtune_str, NULL, 10); XMMS_DBG ("Setting subtune to %d", subtune); if ((subtune < 0 || subtune > gme_track_count (data->emu))) { XMMS_DBG ("Invalid subtune index"); return FALSE; } } else { xmms_xform_metadata_set_int (xform, XMMS_MEDIALIB_ENTRY_PROPERTY_SUBTUNES, gme_track_count (data->emu)); } /* * Get metadata here */ init_error = gme_track_info (data->emu, &metadata, subtune); if (init_error) { XMMS_DBG ("Couldn't get GME track info: %s", init_error); init_error = ""; } else { xmms_xform_metadata_set_str (xform, XMMS_MEDIALIB_ENTRY_PROPERTY_TITLE, metadata->song); xmms_xform_metadata_set_str (xform, XMMS_MEDIALIB_ENTRY_PROPERTY_ARTIST, metadata->author); xmms_xform_metadata_set_str (xform, XMMS_MEDIALIB_ENTRY_PROPERTY_ALBUM, metadata->game); xmms_xform_metadata_set_str (xform, XMMS_MEDIALIB_ENTRY_PROPERTY_COMMENT, metadata->comment); xmms_xform_metadata_set_str (xform, XMMS_MEDIALIB_ENTRY_PROPERTY_YEAR, metadata->copyright); xmms_xform_metadata_set_str (xform, XMMS_MEDIALIB_ENTRY_PROPERTY_GENRE, metadata->system); /* I mapped genre to the system type */ val = xmms_xform_config_lookup (xform, "loops"); loops = xmms_config_property_get_int (val); XMMS_DBG ("intro_length = %d, loops = %d, loop_length = %d", metadata->intro_length, loops, metadata->loop_length); if (metadata->intro_length > 0) { if ((loops > 0) && (metadata->loop_length > 0)) { fadelen = metadata->intro_length + loops * metadata->loop_length; XMMS_DBG ("fadelen now = %ld", fadelen); } else { fadelen = metadata->length; XMMS_DBG ("fadelen now = %ld", fadelen); } } } val = xmms_xform_config_lookup (xform, "maxlength"); maxlength = xmms_config_property_get_int (val); XMMS_DBG ("maxlength = %d seconds", maxlength); if (maxlength > 0 && (fadelen < 0 || (maxlength * 1000L < fadelen))) { fadelen = maxlength * 1000L; XMMS_DBG ("fadelen now = %ld", fadelen); } XMMS_DBG ("gme.fadelen = %ld", fadelen); val = xmms_xform_config_lookup (xform, "stereodepth"); stereodepth = xmms_config_property_get_float (val); if (stereodepth >= 0.0 && stereodepth <= 1.0) { XMMS_DBG ("Setting stereo depth to %f.", stereodepth); gme_set_stereo_depth (data->emu, stereodepth); } else { XMMS_DBG ("gme.stereodepth = %f out of range 0.0 - 1.0; not setting.", stereodepth); } init_error = gme_start_track (data->emu, subtune); if (init_error) { XMMS_DBG ("gme_start_track returned an error: %s", init_error); gme_free_info (metadata); return FALSE; } if (fadelen > 0) { XMMS_DBG ("Setting song length and fade length..."); xmms_xform_metadata_set_int (xform, XMMS_MEDIALIB_ENTRY_PROPERTY_DURATION, fadelen); gme_set_fade (data->emu, fadelen); } gme_free_info (metadata); return TRUE; }
static gboolean xmms_replaygain_init (xmms_xform_t *xform) { xmms_replaygain_data_t *data; xmms_config_property_t *cfgv; xmms_sample_format_t fmt; g_return_val_if_fail (xform, FALSE); data = g_new0 (xmms_replaygain_data_t, 1); g_return_val_if_fail (data, FALSE); xmms_xform_private_data_set (xform, data); cfgv = xmms_xform_config_lookup (xform, "mode"); xmms_config_property_callback_set (cfgv, xmms_replaygain_config_changed, xform); data->mode = parse_mode (xmms_config_property_get_string (cfgv)); cfgv = xmms_xform_config_lookup (xform, "use_anticlip"); xmms_config_property_callback_set (cfgv, xmms_replaygain_config_changed, xform); data->use_anticlip = !!xmms_config_property_get_int (cfgv); cfgv = xmms_xform_config_lookup (xform, "preamp"); xmms_config_property_callback_set (cfgv, xmms_replaygain_config_changed, xform); data->preamp = pow (10.0, atof (xmms_config_property_get_string (cfgv)) / 20.0); cfgv = xmms_xform_config_lookup (xform, "enabled"); xmms_config_property_callback_set (cfgv, xmms_replaygain_config_changed, xform); data->enabled = !!xmms_config_property_get_int (cfgv); xmms_xform_outdata_type_copy (xform); compute_gain (xform, data); fmt = xmms_xform_indata_get_int (xform, XMMS_STREAM_TYPE_FMT_FORMAT); switch (fmt) { case XMMS_SAMPLE_FORMAT_S8: data->apply = apply_s8; break; case XMMS_SAMPLE_FORMAT_U8: data->apply = apply_u8; break; case XMMS_SAMPLE_FORMAT_S16: data->apply = apply_s16; break; case XMMS_SAMPLE_FORMAT_U16: data->apply = apply_u16; break; case XMMS_SAMPLE_FORMAT_S32: data->apply = apply_s32; break; case XMMS_SAMPLE_FORMAT_U32: data->apply = apply_u32; break; case XMMS_SAMPLE_FORMAT_FLOAT: data->apply = apply_float; break; case XMMS_SAMPLE_FORMAT_DOUBLE: data->apply = apply_double; break; default: /* we shouldn't ever get here, since we told the daemon * earlier about this list of supported formats. */ g_assert_not_reached (); break; } return TRUE; }
static void xmms_sid_get_songlength (xmms_xform_t *xform) { xmms_config_property_t *config; const gchar *tmp, *md5sum, *songlength_path; gint subtune = 1; GIOChannel* io; GString *buf; g_return_if_fail (xform); config = xmms_xform_config_lookup (xform, "songlength_path"); g_return_if_fail (config); songlength_path = xmms_config_property_get_string (config); if (!songlength_path[0]) return; if (xmms_xform_metadata_get_str (xform, "subtune", &tmp)) { subtune = atoi (tmp); } if (!xmms_xform_metadata_get_str (xform, "HVSCfingerprint", &md5sum)) { return; } io = g_io_channel_new_file (songlength_path, "r", NULL); if (!io) { xmms_log_error ("Unable to load songlengths database '%s'", songlength_path); return; } buf = g_string_new (""); while (g_io_channel_read_line_string (io, buf, NULL, NULL) == G_IO_STATUS_NORMAL) { if (buf->len > 33 && g_ascii_strncasecmp (buf->str, md5sum, 32) == 0) { gint cur = 0; gchar *b; b = buf->str + 33; while (*b) { gint min, sec; /* read timestamp */ if (sscanf (b, "%d:%d", &min, &sec) != 2) { /* no more timestamps on this line */ break; } else { cur++; } if (cur == subtune) { const gchar *metakey; gchar ms_str[10 + 1]; /* LONG_MAX in str, \w NULL */ glong ms; ms = (min * 60 + sec) * 1000; metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_DURATION; xmms_xform_metadata_set_int (xform, metakey, ms); if (g_snprintf (ms_str, 10 + 1, "%ld", ms) > 0) { metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_STARTMS; xmms_xform_metadata_set_str (xform, metakey, "0"); metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_STOPMS; xmms_xform_metadata_set_str (xform, metakey, ms_str); } goto done; } /* forward to next possible timestamp */ b = strchr (b, ' '); if (!b) { /* no more timestamps on this line */ break; } b++; } } } xmms_log_info ("Couldn't find sid tune in songlength.txt"); done: g_io_channel_unref (io); }
static gboolean xmms_speex_init (xmms_xform_t *xform) { gint pe; xmms_config_property_t *val; xmms_speex_data_t *data; xmms_error_t error; g_return_val_if_fail (xform, FALSE); data = g_new0 (xmms_speex_data_t, 1); g_return_val_if_fail (data, FALSE); xmms_xform_private_data_set (xform, data); ogg_sync_init (&data->sync_state); speex_bits_init (&data->speex_bits); /* Find the speex header */ while (42) { gint ret; data->ogg_data = ogg_sync_buffer (&data->sync_state, 1024); ret = xmms_xform_read (xform, data->ogg_data, 1024, &error); ogg_sync_wrote (&data->sync_state, ret); if (ret <= 0) { return FALSE; } if (ogg_sync_pageout (&data->sync_state, &data->ogg_page) == 1) { break; } } ogg_stream_init (&data->stream_state, ogg_page_serialno (&data->ogg_page)); if (ogg_stream_pagein (&data->stream_state, &data->ogg_page) < 0) { return FALSE; } if (ogg_stream_packetout (&data->stream_state, &data->ogg_packet) != 1) { return FALSE; } data->speexheader = speex_packet_to_header ((char *)data->ogg_packet.packet, data->ogg_packet.bytes); data->speex_state = speex_decoder_init (speex_mode_list[data->speexheader->mode]); val = xmms_xform_config_lookup (xform, "perceptual_enhancer"); pe = xmms_config_property_get_int (val); speex_decoder_ctl (data->speex_state, SPEEX_SET_ENH, &pe); ogg_sync_pageout (&data->sync_state, &data->ogg_page); ogg_stream_pagein (&data->stream_state, &data->ogg_page); ogg_stream_packetout (&data->stream_state, &data->ogg_packet); data->samples_buf = g_new (gint16, data->speexheader->frames_per_packet * data->speexheader->frame_size * data->speexheader->nb_channels); data->samples_start = data->samples_buf; data->samples_count = 0; xmms_speex_read_metadata (xform, data); xmms_xform_outdata_type_add (xform, XMMS_STREAM_TYPE_MIMETYPE, "audio/pcm", XMMS_STREAM_TYPE_FMT_FORMAT, XMMS_SAMPLE_FORMAT_S16, XMMS_STREAM_TYPE_FMT_CHANNELS, data->speexheader->nb_channels, XMMS_STREAM_TYPE_FMT_SAMPLERATE, data->speexheader->rate, XMMS_STREAM_TYPE_END); return TRUE; }
static gboolean xmms_modplug_init (xmms_xform_t *xform) { xmms_modplug_data_t *data; const gchar *metakey; gint filesize; xmms_config_property_t *cfgv; gint i; g_return_val_if_fail (xform, FALSE); data = g_new0 (xmms_modplug_data_t, 1); xmms_xform_private_data_set (xform, data); for (i = 0; i < G_N_ELEMENTS (config_params); i++) { cfgv = xmms_xform_config_lookup (xform, config_params[i].key); xmms_config_property_callback_set (cfgv, xmms_modplug_config_changed, data); xmms_modplug_config_changed (XMMS_OBJECT (cfgv), NULL, data); } /* mFrequency and mResamplingMode are set in config_changed */ data->settings.mChannels = 2; data->settings.mBits = 16; ModPlug_SetSettings (&data->settings); xmms_xform_outdata_type_add (xform, XMMS_STREAM_TYPE_MIMETYPE, "audio/pcm", XMMS_STREAM_TYPE_FMT_FORMAT, XMMS_SAMPLE_FORMAT_S16, XMMS_STREAM_TYPE_FMT_CHANNELS, 2, XMMS_STREAM_TYPE_FMT_SAMPLERATE, data->settings.mFrequency, XMMS_STREAM_TYPE_END); data->buffer = g_string_new (""); for (;;) { xmms_error_t error; gchar buf[4096]; gint ret; ret = xmms_xform_read (xform, buf, sizeof (buf), &error); if (ret == -1) { XMMS_DBG ("Error reading mod"); return FALSE; } if (ret == 0) { break; } g_string_append_len (data->buffer, buf, ret); } data->mod = ModPlug_Load (data->buffer->str, data->buffer->len); if (!data->mod) { XMMS_DBG ("Error loading mod"); return FALSE; } metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_SIZE; if (xmms_xform_metadata_get_int (xform, metakey, &filesize)) { metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_DURATION; xmms_xform_metadata_set_int (xform, metakey, ModPlug_GetLength (data->mod)); } metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_TITLE; xmms_xform_metadata_set_str (xform, metakey, ModPlug_GetName (data->mod)); return TRUE; }
static gboolean xmms_id3v1_parse (xmms_xform_t *xform, guchar *buf) { xmms_config_property_t *config; const char *encoding; const gchar *metakey; xmmsv_t *bb; unsigned char data[32]; bb = xmmsv_new_bitbuffer_ro (buf, 128); xmmsv_bitbuffer_get_data (bb, data, 3); if (memcmp (data, "TAG", 3) != 0) { xmmsv_unref (bb); return FALSE; } XMMS_DBG ("Found ID3v1 TAG!"); config = xmms_xform_config_lookup (xform, "id3v1_encoding"); g_return_val_if_fail (config, FALSE); encoding = xmms_config_property_get_string (config); metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_TITLE; xmmsv_bitbuffer_get_data (bb, data, 30); xmms_id3v1_set (xform, metakey, data, 30, encoding); metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_ARTIST; xmmsv_bitbuffer_get_data (bb, data, 30); xmms_id3v1_set (xform, metakey, data, 30, encoding); metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_ALBUM; xmmsv_bitbuffer_get_data (bb, data, 30); xmms_id3v1_set (xform, metakey, data, 30, encoding); metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_YEAR; xmmsv_bitbuffer_get_data (bb, data, 4); xmms_id3v1_set (xform, metakey, data, 4, encoding); xmmsv_bitbuffer_get_data (bb, data, 30); /* v1.1 */ if (data[28] == '\0' && data[29]) { metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_COMMENT; xmms_id3v1_set (xform, metakey, data, 28, encoding); metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_TRACKNR; if (!xmms_xform_metadata_has_val (xform, metakey)) { xmms_xform_metadata_set_int (xform, metakey, data[29]); } } else { metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_COMMENT; xmms_id3v1_set (xform, metakey, data, 30, encoding); } xmmsv_bitbuffer_get_data (bb, data, 1); metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_GENRE; if (data[0] >= G_N_ELEMENTS (id3_genres)) { xmms_xform_metadata_set_str (xform, metakey, "Unknown"); } else { xmms_xform_metadata_set_str (xform, metakey, id3_genres[data[0]]); } xmmsv_unref (bb); return TRUE; }
static gboolean xmms_eq_init (xmms_xform_t *xform) { xmms_equalizer_data_t *priv; xmms_config_property_t *config; gint i, j, srate; gfloat gain; g_return_val_if_fail (xform, FALSE); priv = g_new0 (xmms_equalizer_data_t, 1); g_return_val_if_fail (priv, FALSE); xmms_xform_private_data_set (xform, priv); config = xmms_xform_config_lookup (xform, "enabled"); g_return_val_if_fail (config, FALSE); xmms_config_property_callback_set (config, xmms_eq_config_changed, priv); priv->enabled = !!xmms_config_property_get_int (config); config = xmms_xform_config_lookup (xform, "bands"); g_return_val_if_fail (config, FALSE); xmms_config_property_callback_set (config, xmms_eq_config_changed, priv); priv->bands = xmms_config_property_get_int (config); config = xmms_xform_config_lookup (xform, "extra_filtering"); g_return_val_if_fail (config, FALSE); xmms_config_property_callback_set (config, xmms_eq_config_changed, priv); priv->extra_filtering = xmms_config_property_get_int (config); config = xmms_xform_config_lookup (xform, "use_legacy"); g_return_val_if_fail (config, FALSE); xmms_config_property_callback_set (config, xmms_eq_config_changed, priv); priv->use_legacy = xmms_config_property_get_int (config); config = xmms_xform_config_lookup (xform, "preamp"); g_return_val_if_fail (config, FALSE); xmms_config_property_callback_set (config, xmms_eq_gain_changed, priv); gain = xmms_config_property_get_float (config); for (i=0; i<EQ_CHANNELS; i++) { set_preamp (i, xmms_eq_gain_scale (gain, TRUE)); } for (i=0; i<EQ_BANDS_LEGACY; i++) { gchar buf[16]; g_snprintf (buf, sizeof (buf), "legacy%d", i); config = xmms_xform_config_lookup (xform, buf); g_return_val_if_fail (config, FALSE); priv->legacy[i] = config; xmms_config_property_callback_set (config, xmms_eq_gain_changed, priv); gain = xmms_config_property_get_float (config); if (priv->use_legacy) { for (j = 0; j < EQ_CHANNELS; j++) { set_gain (i, j, xmms_eq_gain_scale (gain, FALSE)); } } } for (i=0; i<EQ_MAX_BANDS; i++) { gchar buf[16]; g_snprintf (buf, sizeof (buf), "gain%02d", i); config = xmms_xform_config_lookup (xform, buf); g_return_val_if_fail (config, FALSE); priv->gain[i] = config; xmms_config_property_callback_set (config, xmms_eq_gain_changed, priv); gain = xmms_config_property_get_float (config); if (!priv->use_legacy) { for (j = 0; j < EQ_CHANNELS; j++) { set_gain (i, j, xmms_eq_gain_scale (gain, FALSE)); } } } init_iir (); srate = xmms_xform_indata_get_int (xform, XMMS_STREAM_TYPE_FMT_SAMPLERATE); if (priv->use_legacy) { config_iir (srate, EQ_BANDS_LEGACY, 1); } else { config_iir (srate, priv->bands, 0); } xmms_xform_outdata_type_copy (xform); XMMS_DBG ("Equalizer initialized successfully!"); return TRUE; }