diff mbox

[FFmpeg-devel] swresample/swresample: do not use s32p internally by default when resampling

Message ID 20170316054310.22561-1-mfcc64@gmail.com
State Accepted
Commit c52638cca255737eb060dcdedf5be4414e622e82
Headers show

Commit Message

Muhammad Faiz March 16, 2017, 5:43 a.m. UTC
use fltp when doing s32 -> s32 resampling
because s32p has no simd optimization

benchmark:
old 17.913s
new  7.584s (use fma3)

Signed-off-by: Muhammad Faiz <mfcc64@gmail.com>
---
 libswresample/swresample.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

wm4 March 16, 2017, 6:01 a.m. UTC | #1
On Thu, 16 Mar 2017 12:43:10 +0700
Muhammad Faiz <mfcc64@gmail.com> wrote:

> use fltp when doing s32 -> s32 resampling
> because s32p has no simd optimization
> 
> benchmark:
> old 17.913s
> new  7.584s (use fma3)
> 
> Signed-off-by: Muhammad Faiz <mfcc64@gmail.com>
> ---
>  libswresample/swresample.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/libswresample/swresample.c b/libswresample/swresample.c
> index f2e6600..74c96dc 100644
> --- a/libswresample/swresample.c
> +++ b/libswresample/swresample.c
> @@ -223,6 +223,8 @@ av_cold int swr_init(struct SwrContext *s){
>          }else if(   av_get_planar_sample_fmt(s-> in_sample_fmt) == AV_SAMPLE_FMT_S32P
>                   && av_get_planar_sample_fmt(s->out_sample_fmt) == AV_SAMPLE_FMT_S32P
>                   && !s->rematrix
> +                 && s->out_sample_rate == s->in_sample_rate
> +                 && !(s->flags & SWR_FLAG_RESAMPLE)
>                   && s->engine != SWR_ENGINE_SOXR){
>              s->int_sample_fmt= AV_SAMPLE_FMT_S32P;
>          }else if(av_get_bytes_per_sample(s->in_sample_fmt) <= 4){

Wouldn't going over float lose bits? I guess most times, s32 is
actually 24 bit padded (since we have no 24 bit format). But it could
be true 32 bit as well (with all bits used). Or does it use double, or
am I missing something else?
Muhammad Faiz March 16, 2017, 10 a.m. UTC | #2
On Thu, Mar 16, 2017 at 1:01 PM, wm4 <nfxjfg@googlemail.com> wrote:
> On Thu, 16 Mar 2017 12:43:10 +0700
> Muhammad Faiz <mfcc64@gmail.com> wrote:
>
>> use fltp when doing s32 -> s32 resampling
>> because s32p has no simd optimization
>>
>> benchmark:
>> old 17.913s
>> new  7.584s (use fma3)
>>
>> Signed-off-by: Muhammad Faiz <mfcc64@gmail.com>
>> ---
>>  libswresample/swresample.c | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/libswresample/swresample.c b/libswresample/swresample.c
>> index f2e6600..74c96dc 100644
>> --- a/libswresample/swresample.c
>> +++ b/libswresample/swresample.c
>> @@ -223,6 +223,8 @@ av_cold int swr_init(struct SwrContext *s){
>>          }else if(   av_get_planar_sample_fmt(s-> in_sample_fmt) == AV_SAMPLE_FMT_S32P
>>                   && av_get_planar_sample_fmt(s->out_sample_fmt) == AV_SAMPLE_FMT_S32P
>>                   && !s->rematrix
>> +                 && s->out_sample_rate == s->in_sample_rate
>> +                 && !(s->flags & SWR_FLAG_RESAMPLE)
>>                   && s->engine != SWR_ENGINE_SOXR){
>>              s->int_sample_fmt= AV_SAMPLE_FMT_S32P;
>>          }else if(av_get_bytes_per_sample(s->in_sample_fmt) <= 4){
>
> Wouldn't going over float lose bits?

Yes, of course. But when resampling with default opt, aliasing happens at
about -90dB which is only 15 bits. Keeping 32 bits has no point at all.

> I guess most times, s32 is
> actually 24 bit padded (since we have no 24 bit format). But it could
> be true 32 bit as well (with all bits used). Or does it use double, or
> am I missing something else?

Using double is overkill, i think.
wm4 March 16, 2017, 6:14 p.m. UTC | #3
On Thu, 16 Mar 2017 17:00:17 +0700
Muhammad Faiz <mfcc64@gmail.com> wrote:

> On Thu, Mar 16, 2017 at 1:01 PM, wm4 <nfxjfg@googlemail.com> wrote:
> > On Thu, 16 Mar 2017 12:43:10 +0700
> > Muhammad Faiz <mfcc64@gmail.com> wrote:
> >  
> >> use fltp when doing s32 -> s32 resampling
> >> because s32p has no simd optimization
> >>
> >> benchmark:
> >> old 17.913s
> >> new  7.584s (use fma3)
> >>
> >> Signed-off-by: Muhammad Faiz <mfcc64@gmail.com>
> >> ---
> >>  libswresample/swresample.c | 2 ++
> >>  1 file changed, 2 insertions(+)
> >>
> >> diff --git a/libswresample/swresample.c b/libswresample/swresample.c
> >> index f2e6600..74c96dc 100644
> >> --- a/libswresample/swresample.c
> >> +++ b/libswresample/swresample.c
> >> @@ -223,6 +223,8 @@ av_cold int swr_init(struct SwrContext *s){
> >>          }else if(   av_get_planar_sample_fmt(s-> in_sample_fmt) == AV_SAMPLE_FMT_S32P
> >>                   && av_get_planar_sample_fmt(s->out_sample_fmt) == AV_SAMPLE_FMT_S32P
> >>                   && !s->rematrix
> >> +                 && s->out_sample_rate == s->in_sample_rate
> >> +                 && !(s->flags & SWR_FLAG_RESAMPLE)
> >>                   && s->engine != SWR_ENGINE_SOXR){
> >>              s->int_sample_fmt= AV_SAMPLE_FMT_S32P;
> >>          }else if(av_get_bytes_per_sample(s->in_sample_fmt) <= 4){  
> >
> > Wouldn't going over float lose bits?  
> 
> Yes, of course. But when resampling with default opt, aliasing happens at
> about -90dB which is only 15 bits. Keeping 32 bits has no point at all.
> 
> > I guess most times, s32 is
> > actually 24 bit padded (since we have no 24 bit format). But it could
> > be true 32 bit as well (with all bits used). Or does it use double, or
> > am I missing something else?  
> 
> Using double is overkill, i think.

From my naive point of view this seems ok, then.
Muhammad Faiz March 18, 2017, 7:10 a.m. UTC | #4
On Fri, Mar 17, 2017 at 1:14 AM, wm4 <nfxjfg@googlemail.com> wrote:
> On Thu, 16 Mar 2017 17:00:17 +0700
> Muhammad Faiz <mfcc64@gmail.com> wrote:
>
>> On Thu, Mar 16, 2017 at 1:01 PM, wm4 <nfxjfg@googlemail.com> wrote:
>> > On Thu, 16 Mar 2017 12:43:10 +0700
>> > Muhammad Faiz <mfcc64@gmail.com> wrote:
>> >
>> >> use fltp when doing s32 -> s32 resampling
>> >> because s32p has no simd optimization
>> >>
>> >> benchmark:
>> >> old 17.913s
>> >> new  7.584s (use fma3)
>> >>
>> >> Signed-off-by: Muhammad Faiz <mfcc64@gmail.com>
>> >> ---
>> >>  libswresample/swresample.c | 2 ++
>> >>  1 file changed, 2 insertions(+)
>> >>
>> >> diff --git a/libswresample/swresample.c b/libswresample/swresample.c
>> >> index f2e6600..74c96dc 100644
>> >> --- a/libswresample/swresample.c
>> >> +++ b/libswresample/swresample.c
>> >> @@ -223,6 +223,8 @@ av_cold int swr_init(struct SwrContext *s){
>> >>          }else if(   av_get_planar_sample_fmt(s-> in_sample_fmt) == AV_SAMPLE_FMT_S32P
>> >>                   && av_get_planar_sample_fmt(s->out_sample_fmt) == AV_SAMPLE_FMT_S32P
>> >>                   && !s->rematrix
>> >> +                 && s->out_sample_rate == s->in_sample_rate
>> >> +                 && !(s->flags & SWR_FLAG_RESAMPLE)
>> >>                   && s->engine != SWR_ENGINE_SOXR){
>> >>              s->int_sample_fmt= AV_SAMPLE_FMT_S32P;
>> >>          }else if(av_get_bytes_per_sample(s->in_sample_fmt) <= 4){
>> >
>> > Wouldn't going over float lose bits?
>>
>> Yes, of course. But when resampling with default opt, aliasing happens at
>> about -90dB which is only 15 bits. Keeping 32 bits has no point at all.
>>
>> > I guess most times, s32 is
>> > actually 24 bit padded (since we have no 24 bit format). But it could
>> > be true 32 bit as well (with all bits used). Or does it use double, or
>> > am I missing something else?
>>
>> Using double is overkill, i think.
>
> From my naive point of view this seems ok, then.

Applied

Thank's
diff mbox

Patch

diff --git a/libswresample/swresample.c b/libswresample/swresample.c
index f2e6600..74c96dc 100644
--- a/libswresample/swresample.c
+++ b/libswresample/swresample.c
@@ -223,6 +223,8 @@  av_cold int swr_init(struct SwrContext *s){
         }else if(   av_get_planar_sample_fmt(s-> in_sample_fmt) == AV_SAMPLE_FMT_S32P
                  && av_get_planar_sample_fmt(s->out_sample_fmt) == AV_SAMPLE_FMT_S32P
                  && !s->rematrix
+                 && s->out_sample_rate == s->in_sample_rate
+                 && !(s->flags & SWR_FLAG_RESAMPLE)
                  && s->engine != SWR_ENGINE_SOXR){
             s->int_sample_fmt= AV_SAMPLE_FMT_S32P;
         }else if(av_get_bytes_per_sample(s->in_sample_fmt) <= 4){