From 16e1e247638aa0da5541aa78fb141e60744d56a0 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Thu, 4 Aug 2011 15:03:15 +0200 Subject: Handle sample rates and channels. --- decoders/ffmpeg_decoder.cpp | 2 ++ decoders/mpg123_decoder.cpp | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'decoders') diff --git a/decoders/ffmpeg_decoder.cpp b/decoders/ffmpeg_decoder.cpp index 630e38e..7b7397f 100644 --- a/decoders/ffmpeg_decoder.cpp +++ b/decoders/ffmpeg_decoder.cpp @@ -14,6 +14,8 @@ DecoderFFmpeg::DecoderFFmpeg(const std::string& filename) { av_dump_format(lavf_ctx, 0, filename.c_str(), 0); lavc_ctx = lavf_ctx->streams[0]->codec; + samplerate = lavc_ctx->sample_rate; + channels = lavc_ctx->channels; codec = avcodec_find_decoder(lavc_ctx->codec_id); std::cerr << "Opening decoder: " << avcodec_open(lavc_ctx, codec) << std::endl; diff --git a/decoders/mpg123_decoder.cpp b/decoders/mpg123_decoder.cpp index ec6f490..13e9861 100644 --- a/decoders/mpg123_decoder.cpp +++ b/decoders/mpg123_decoder.cpp @@ -17,8 +17,15 @@ DecoderMpg123::DecoderMpg123(const std::string& filename) { throw std::runtime_error(mpg123_plain_strerror(error)); } + long rate; + int channels, enc; + mpg123_getformat(handle, &rate, &channels, &enc); + std::cout << boost::format("mpg123: %li Hz, %i channels, encoding value %i") % rate % channels % enc << std::endl; + this->samplerate = rate; + this->channels = channels; + mpg123_format_none(handle); - mpg123_format(handle, 44100, 2, MPG123_ENC_SIGNED_16); + mpg123_format(handle, rate, channels, MPG123_ENC_SIGNED_16); } DecoderMpg123::~DecoderMpg123() { -- cgit v1.2.3