diff --git a/src/media/UAudioConverter.pas b/src/media/UAudioConverter.pas index ca61f774a..6fb89597a 100644 --- a/src/media/UAudioConverter.pas +++ b/src/media/UAudioConverter.pas @@ -270,8 +270,7 @@ function TAudioConverter_SWResample.Init(SrcFormatInfo: TAudioFormatInfo; av_opt_set_sample_fmt(SwrContext, 'out_sample_fmt', DstFormat, 0); swr_init(SwrContext); // calculate ratio - Ratio := (dstFormatInfo.Channels / srcFormatInfo.Channels) * - (dstFormatInfo.SampleRate / srcFormatInfo.SampleRate); + Ratio := srcFormatInfo.GetRatio(dstFormatInfo); Result := true; end; @@ -320,7 +319,7 @@ function TAudioConverter_SWResample.Convert(InputBuffer: PByteArray; OutputBuffe end; InputSampleCount := InputSize div SrcFormatInfo.FrameSize; - OutputSampleCount := GetOutputBufferSize(InputSampleCount); + OutputSampleCount := GetOutputBufferSize(InputSize) div DstFormatInfo.FrameSize; InBufPtr := Pcuint8(@InputBuffer[0]); OutBufPtr := Pcuint8(@OutputBuffer[0]); OutputSampleCount:= swr_convert(SwrContext, OutBufPtr, OutputSampleCount, @@ -328,7 +327,7 @@ function TAudioConverter_SWResample.Convert(InputBuffer: PByteArray; OutputBuffe if (OutputSampleCount < 0) then begin Log.LogError('swr_convert failed ' + inttostr(OutputSampleCount), 'TAudioConverter_SWResample.Init'); - OutputSampleCount := GetOutputBufferSize(InputSampleCount); + OutputSampleCount := GetOutputBufferSize(InputSize) div DstFormatInfo.FrameSize; end; Result := OutputSampleCount * DstFormatInfo.FrameSize; end; @@ -410,8 +409,7 @@ function TAudioConverter_FFmpeg.Init(SrcFormatInfo: TAudioFormatInfo; end; // calculate ratio - Ratio := (dstFormatInfo.Channels / srcFormatInfo.Channels) * - (dstFormatInfo.SampleRate / srcFormatInfo.SampleRate); + Ratio := srcFormatInfo.GetRatio(dstFormatInfo); Result := true; end;