From adc857ecd7dd7e38ebf0b47ffba09debb386486a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gl=C3=B6ckner?= Date: Sat, 13 Jul 2024 09:46:48 +0200 Subject: [PATCH] AudioConverter: fix output buffer size calculation --- src/media/UAudioConverter.pas | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) 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;