comparison audioconvert.c @ 7459:283eeda62184 libavcodec

Modify av_audio_convert() to use AVAudioConvert context struct; add av_audio_convert_alloc() and av_audio_convert_free() support functions.
author pross
date Fri, 01 Aug 2008 13:53:18 +0000
parents eb63aa50bf85
children 1302ec81afc0
comparison
equal deleted inserted replaced
7458:eb63aa50bf85 7459:283eeda62184
68 SampleFmtInfo info= sample_fmt_info[sample_fmt]; 68 SampleFmtInfo info= sample_fmt_info[sample_fmt];
69 snprintf (buf, buf_size, "%-6s" " %2d ", info.name, info.bits); 69 snprintf (buf, buf_size, "%-6s" " %2d ", info.name, info.bits);
70 } 70 }
71 } 71 }
72 72
73 int av_audio_convert(void *maybe_dspcontext_or_something_av_convert_specific, 73 struct AVAudioConvert {
74 void *out[6], int out_stride[6], enum SampleFormat out_fmt, 74 int in_channels, out_channels;
75 void * in[6], int in_stride[6], enum SampleFormat in_fmt, int len){ 75 int fmt_pair;
76 };
77
78 AVAudioConvert *av_audio_convert_alloc(enum SampleFormat out_fmt, int out_channels,
79 enum SampleFormat in_fmt, int in_channels,
80 const const float *matrix, int flags)
81 {
82 AVAudioConvert *ctx;
83 if (in_channels!=out_channels)
84 return NULL; /* FIXME: not supported */
85 ctx = av_malloc(sizeof(AVAudioConvert));
86 if (!ctx)
87 return NULL;
88 ctx->in_channels = in_channels;
89 ctx->out_channels = out_channels;
90 ctx->fmt_pair = out_fmt + SAMPLE_FMT_NB*in_fmt;
91 return ctx;
92 }
93
94 void av_audio_convert_free(AVAudioConvert *ctx)
95 {
96 av_free(ctx);
97 }
98
99 int av_audio_convert(AVAudioConvert *ctx,
100 void * const out[6], const int out_stride[6],
101 const void * const in[6], const int in_stride[6], int len)
102 {
76 int ch; 103 int ch;
77 const int isize= FFMIN( in_fmt+1, 4);
78 const int osize= FFMIN(out_fmt+1, 4);
79 const int fmt_pair= out_fmt + 5*in_fmt;
80 104
81 //FIXME optimize common cases 105 //FIXME optimize common cases
82 106
83 for(ch=0; ch<6; ch++){ 107 for(ch=0; ch<ctx->out_channels; ch++){
84 const int is= in_stride[ch] * isize; 108 const int is= in_stride[ch];
85 const int os= out_stride[ch] * osize; 109 const int os= out_stride[ch];
86 uint8_t *pi= in[ch]; 110 uint8_t *pi= in[ch];
87 uint8_t *po= out[ch]; 111 uint8_t *po= out[ch];
88 uint8_t *end= po + os; 112 uint8_t *end= po + os*len;
89 if(!out[ch]) 113 if(!out[ch])
90 continue; 114 continue;
91 115
92 #define CONV(ofmt, otype, ifmt, expr)\ 116 #define CONV(ofmt, otype, ifmt, expr)\
93 if(fmt_pair == ofmt + 5*ifmt){\ 117 if(ctx->fmt_pair == ofmt + SAMPLE_FMT_NB*ifmt){\
94 do{\ 118 do{\
95 *(otype*)po = expr; pi += is; po += os;\ 119 *(otype*)po = expr; pi += is; po += os;\
96 }while(po < end);\ 120 }while(po < end);\
97 } 121 }
98 122