00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00028 #include "avcodec.h"
00029
00030 int av_audio_convert(void *maybe_dspcontext_or_something_av_convert_specific,
00031 void *out[6], int out_stride[6], enum SampleFormat out_fmt,
00032 void * in[6], int in_stride[6], enum SampleFormat in_fmt, int len){
00033 int ch;
00034 const int isize= FFMIN( in_fmt+1, 4);
00035 const int osize= FFMIN(out_fmt+1, 4);
00036 const int fmt_pair= out_fmt + 5*in_fmt;
00037
00038
00039
00040 for(ch=0; ch<6; ch++){
00041 const int is= in_stride[ch] * isize;
00042 const int os= out_stride[ch] * osize;
00043 uint8_t *pi= in[ch];
00044 uint8_t *po= out[ch];
00045 uint8_t *end= po + os;
00046 if(!out[ch])
00047 continue;
00048
00049 #define CONV(ofmt, otype, ifmt, expr)\
00050 if(fmt_pair == ofmt + 5*ifmt){\
00051 do{\
00052 *(otype*)po = expr; pi += is; po += os;\
00053 }while(po < end);\
00054 }
00055
00056
00057
00058
00059 CONV(SAMPLE_FMT_U8 , uint8_t, SAMPLE_FMT_U8 , *(uint8_t*)pi)
00060 else CONV(SAMPLE_FMT_S16, int16_t, SAMPLE_FMT_U8 , (*(uint8_t*)pi - 0x80)<<8)
00061 else CONV(SAMPLE_FMT_S32, int32_t, SAMPLE_FMT_U8 , (*(uint8_t*)pi - 0x80)<<24)
00062 else CONV(SAMPLE_FMT_FLT, float , SAMPLE_FMT_U8 , (*(uint8_t*)pi - 0x80)*(1.0 / (1<<7)))
00063 else CONV(SAMPLE_FMT_U8 , uint8_t, SAMPLE_FMT_S16, (*(int16_t*)pi>>8) + 0x80)
00064 else CONV(SAMPLE_FMT_S16, int16_t, SAMPLE_FMT_S16, *(int16_t*)pi)
00065 else CONV(SAMPLE_FMT_S32, int32_t, SAMPLE_FMT_S16, *(int16_t*)pi<<16)
00066 else CONV(SAMPLE_FMT_FLT, float , SAMPLE_FMT_S16, *(int16_t*)pi*(1.0 / (1<<15)))
00067 else CONV(SAMPLE_FMT_U8 , uint8_t, SAMPLE_FMT_S32, (*(int32_t*)pi>>24) + 0x80)
00068 else CONV(SAMPLE_FMT_S16, int16_t, SAMPLE_FMT_S32, *(int32_t*)pi>>16)
00069 else CONV(SAMPLE_FMT_S32, int32_t, SAMPLE_FMT_S32, *(int32_t*)pi)
00070 else CONV(SAMPLE_FMT_FLT, float , SAMPLE_FMT_S32, *(int32_t*)pi*(1.0 / (1<<31)))
00071 else CONV(SAMPLE_FMT_U8 , uint8_t, SAMPLE_FMT_FLT, lrintf(*(float*)pi * (1<<7)) + 0x80)
00072 else CONV(SAMPLE_FMT_S16, int16_t, SAMPLE_FMT_FLT, lrintf(*(float*)pi * (1<<15)))
00073 else CONV(SAMPLE_FMT_S32, int32_t, SAMPLE_FMT_FLT, lrintf(*(float*)pi * (1<<31)))
00074 else CONV(SAMPLE_FMT_FLT, float , SAMPLE_FMT_FLT, *(float*)pi)
00075 else return -1;
00076 }
00077 return 0;
00078 }