~ubuntu-branches/ubuntu/utopic/libav/utopic

« back to all changes in this revision

Viewing changes to libavresample/audio_convert.c

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler
  • Date: 2012-12-21 15:32:13 UTC
  • mto: (1.2.18)
  • mto: This revision was merged to the branch mainline in revision 34.
  • Revision ID: package-import@ubuntu.com-20121221153213-fudzrugjzivtv0wp
Tags: upstream-9~beta3
ImportĀ upstreamĀ versionĀ 9~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include "libavutil/samplefmt.h"
30
30
#include "audio_convert.h"
31
31
#include "audio_data.h"
 
32
#include "dither.h"
 
33
#include "internal.h"
32
34
 
33
35
enum ConvFuncType {
34
36
    CONV_FUNC_TYPE_FLAT,
46
48
 
47
49
struct AudioConvert {
48
50
    AVAudioResampleContext *avr;
 
51
    DitherContext *dc;
49
52
    enum AVSampleFormat in_fmt;
50
53
    enum AVSampleFormat out_fmt;
51
54
    int channels;
246
249
    SET_CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL)
247
250
}
248
251
 
 
252
void ff_audio_convert_free(AudioConvert **ac)
 
253
{
 
254
    if (!*ac)
 
255
        return;
 
256
    ff_dither_free(&(*ac)->dc);
 
257
    av_freep(ac);
 
258
}
 
259
 
249
260
AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr,
250
261
                                     enum AVSampleFormat out_fmt,
251
262
                                     enum AVSampleFormat in_fmt,
252
 
                                     int channels)
 
263
                                     int channels, int sample_rate)
253
264
{
254
265
    AudioConvert *ac;
255
266
    int in_planar, out_planar;
263
274
    ac->in_fmt   = in_fmt;
264
275
    ac->channels = channels;
265
276
 
 
277
    if (avr->dither_method != AV_RESAMPLE_DITHER_NONE          &&
 
278
        av_get_packed_sample_fmt(out_fmt) == AV_SAMPLE_FMT_S16 &&
 
279
        av_get_bytes_per_sample(in_fmt) > 2) {
 
280
        ac->dc = ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate);
 
281
        if (!ac->dc) {
 
282
            av_free(ac);
 
283
            return NULL;
 
284
        }
 
285
        return ac;
 
286
    }
 
287
 
266
288
    in_planar  = av_sample_fmt_is_planar(in_fmt);
267
289
    out_planar = av_sample_fmt_is_planar(out_fmt);
268
290
 
284
306
    return ac;
285
307
}
286
308
 
287
 
int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in, int len)
 
309
int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in)
288
310
{
289
311
    int use_generic = 1;
 
312
    int len         = in->nb_samples;
 
313
 
 
314
    if (ac->dc) {
 
315
        /* dithered conversion */
 
316
        av_dlog(ac->avr, "%d samples - audio_convert: %s to %s (dithered)\n",
 
317
                len, av_get_sample_fmt_name(ac->in_fmt),
 
318
                av_get_sample_fmt_name(ac->out_fmt));
 
319
 
 
320
        return ff_convert_dither(ac->dc, out, in);
 
321
    }
290
322
 
291
323
    /* determine whether to use the optimized function based on pointer and
292
324
       samples alignment in both the input and output */