From 17d51938d23c5f60f1ae0f4944724944c1b9dfdd Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Thu, 29 Sep 2011 04:55:53 +0200 Subject: [PATCH] swr_test: test planar audio Signed-off-by: Michael Niedermayer --- libswresample/swresample_test.c | 61 ++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 12 deletions(-) diff --git a/libswresample/swresample_test.c b/libswresample/swresample_test.c index e8683cd5dd..61e1b09367 100644 --- a/libswresample/swresample_test.c +++ b/libswresample/swresample_test.c @@ -28,7 +28,16 @@ #define ASSERT_LEVEL 2 -static double get(const void *p, int index, enum AVSampleFormat f){ +static double get(const uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f){ + const uint8_t *p; + if(f>=0x100){ + f&=0xFF; + p= a[ch]; + }else{ + p= a[0]; + index= ch + index*ch_count; + } + switch(f){ case AV_SAMPLE_FMT_U8 : return ((const uint8_t*)p)[index]/255.0*2-1.0; case AV_SAMPLE_FMT_S16: return ((const int16_t*)p)[index]/32767.0; @@ -39,7 +48,15 @@ static double get(const void *p, int index, enum AVSampleFormat f){ } } -static void set(void *p, int index, enum AVSampleFormat f, double v){ +static void set(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f, double v){ + uint8_t *p; + if(f>=0x100){ + f&=0xFF; + p= a[ch]; + }else{ + p= a[0]; + index= ch + index*ch_count; + } switch(f){ case AV_SAMPLE_FMT_U8 : ((uint8_t*)p)[index]= (v+1.0)*255.0/2; break; case AV_SAMPLE_FMT_S16: ((int16_t*)p)[index]= v*32767; break; @@ -68,6 +85,19 @@ AV_CH_LAYOUT_7POINT1_WIDE , 0 }; +static void setup_array(uint8_t *out[SWR_CH_MAX], uint8_t *in, enum AVSampleFormat format, int samples){ + if(format >= 0x100){ + int i; + int plane_size= av_get_bytes_per_sample(format&0xFF)*samples; + format&=0xFF; + for(i=0; i) failed\n"); if(swr_init(backw_ctx) < 0) @@ -108,14 +143,16 @@ int main(int argc, char **argv){ if(!backw_ctx) fprintf(stderr, "Failed to init backw_ctx\n"); //FIXME test planar + setup_array(ain , array_in , in_sample_fmt+planar_in , SAMPLES); + setup_array(amid, array_mid, out_sample_fmt+planar_out, 3*SAMPLES); + setup_array(aout, array_out, in_sample_fmt , SAMPLES); for(ch=0; ch