diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2010-10-13 19:04:46 +0200 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2010-10-13 19:04:46 +0200 |
commit | af96e1ce92c751f92cdb862985d1abe7362a6e59 (patch) | |
tree | becd9199f426f2b53cca4f40eba443e8a6e94196 /decoders/decoder_mpg123.c | |
parent | 18399d8f41e0154af266f43fd4a05420cb335aa7 (diff) |
Resample files when transcoding to mp3 using libsamplerate.
Diffstat (limited to 'decoders/decoder_mpg123.c')
-rw-r--r-- | decoders/decoder_mpg123.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/decoders/decoder_mpg123.c b/decoders/decoder_mpg123.c index 50391f4..41d25c1 100644 --- a/decoders/decoder_mpg123.c +++ b/decoders/decoder_mpg123.c @@ -3,7 +3,7 @@ #include <mpg123.h> #include <stdio.h> -static gboolean mpg123_decoder_init(gpointer *data) { +static gboolean mpg123_decoder_init(struct decoder *decoder) { mpg123_handle *handle; int error; @@ -24,14 +24,14 @@ static gboolean mpg123_decoder_init(gpointer *data) { mpg123_format_none(handle); mpg123_format(handle, 44100, 2, MPG123_ENC_SIGNED_16); - *data = handle; + decoder->data = handle; return TRUE; } -static gssize mpg123_decoder_decode(gpointer data, GInputStream *input, +static gssize mpg123_decoder_decode(struct decoder *decoder, GInputStream *input, GOutputStream *output, GError **error) { - mpg123_handle *handle = data; + mpg123_handle *handle = decoder->data; gssize size; int ret; const int inbuf_size = 0x400*8; @@ -55,6 +55,18 @@ static gssize mpg123_decoder_decode(gpointer data, GInputStream *input, mpg123_getformat(handle, &rate, &channels, &enc); g_debug("New format: %li Hz, %i channels, encoding value %i", rate, channels, enc); ret = mpg123_read(handle, outbuf, outbuf_size, (size_t*)&size); + decoder->rate = rate; + /* TODO: mpg123 uses native byte order, add endian check here */ + /* assuming little endian for now... */ + switch(enc) { + case MPG123_ENC_SIGNED_16: + decoder->format = AUDIO_FORMAT_S16LE; + break; + default: + *error = g_error_new(decoder_quark(), DECODER_CODE_ERROR, g_strdup("unknown audio format")); + return -1; + } + decoder->channels = channels; } if(ret != MPG123_OK && ret != MPG123_DONE && ret != MPG123_NEW_FORMAT @@ -68,8 +80,8 @@ static gssize mpg123_decoder_decode(gpointer data, GInputStream *input, return size; } -static void mpg123_decoder_close(gpointer data) { - mpg123_handle *handle = data; +static void mpg123_decoder_close(struct decoder *decoder) { + mpg123_handle *handle = decoder->data; mpg123_close(handle); mpg123_delete(handle); } |