[libav-api] using libav to resample, alias effects

Jieyun Fu jieyunfu at gmail.com
Thu Apr 21 00:35:28 CEST 2011


Hi all,

I realized that when I am writing my own code to upsample a piece of audio
from 8000Hz to 22050Hz, I always get some alias effects: the sound got buzzy
(with some zee, zee in the background) and looking at the spectrogram we can
see the frequency mirrors around 8K Hz, which is a classical alias effects.

If I use ffmpeg binaries, I don't have this problem. But I do need to use
Libav to achieve that. You guys can download the original raw waveform and
the converted raw waveform from (
http://dl.dropbox.com/u/4363247/ffmpeg/before.raw and
http://dl.dropbox.com/u/4363247/ffmpeg/after.raw)

There are two APIs to resample the audio but both produce these alias
effects. Please let me know if I am missing anything.

    newsize = (long) size * 22050 / 8000.0;
    ReSampleContext* context = av_audio_resample_init(1, 1, // out channels,
in channels
                                     22050, 8000,
                                     SAMPLE_FMT_S16, SAMPLE_FMT_S16,
                                     16, 0, 0, 0.8);
    int audio_resample_rc = audio_resample(context,
(short*)converted_samples, (short*)samples, size / 2);
    if (context)
        audio_resample_close(context);

and

        int out_rate = 22050;
        audio_cntx = av_resample_init( out_rate,    // out rate
            RATE,   // in rate
            16, // filter length
            0,  // phase count
            0,  // linear FIR filter
            0.8 );  // cutoff frequency
        assert( audio_cntx && "Failed to create resampling context!" );

        int samples_consumed = 0;
        int samples_output = av_resample( audio_cntx,
            (short*)out_buffer,
            (short*)in_buffer,
            &samples_consumed,
            bytes_read / 2,
            40000 * 4 / 2,
            0 );
        av_resample_close( audio_cntx );

Jieyun
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libav.org/pipermail/libav-api/attachments/20110420/32e41ff2/attachment.htm>


More information about the libav-api mailing list