@@ -69,31 +69,32 @@ bool AudioTransform::init( const Frame& srcFrame, const Frame& dstFrame )
69
69
return true ;
70
70
}
71
71
72
- void AudioTransform::initFrames ( const Frame& srcFrame , Frame& dstFrame )
72
+ void AudioTransform::updateOutputFrame ( const size_t nbInputSamples , Frame& dstFrame ) const
73
73
{
74
- const AudioFrame& src = static_cast <const AudioFrame&>( srcFrame );
75
74
AudioFrame& dst = static_cast <AudioFrame&>( dstFrame );
76
75
77
76
// resize buffer of output frame
78
77
const int dstSampleSize = av_get_bytes_per_sample ( dst.desc ().getSampleFormat () );
79
- const size_t bufferSizeNeeded = src. getNbSamples () * dst.desc ().getChannels () * dstSampleSize;
78
+ const size_t bufferSizeNeeded = nbInputSamples * dst.desc ().getChannels () * dstSampleSize;
80
79
if ( bufferSizeNeeded > dstFrame.getSize () )
81
80
dstFrame.resize ( bufferSizeNeeded );
82
81
83
82
// set nbSamples of output frame
84
- dst.setNbSamples ( src.getNbSamples () );
85
-
86
- _nbSamplesOfPreviousFrame = src.getNbSamples ();
83
+ dst.setNbSamples ( nbInputSamples );
87
84
}
88
85
89
86
void AudioTransform::convert ( const Frame& srcFrame, Frame& dstFrame )
90
87
{
91
88
if ( ! _isInit )
92
89
_isInit = init ( srcFrame, dstFrame );
93
90
91
+ // if number of samples change from previous frame
94
92
const AudioFrame& srcAudioFrame = static_cast <const AudioFrame&>( srcFrame );
95
93
if ( srcAudioFrame.getNbSamples () != _nbSamplesOfPreviousFrame )
96
- initFrames ( srcFrame, dstFrame );
94
+ {
95
+ updateOutputFrame ( srcAudioFrame.getNbSamples (), dstFrame );
96
+ _nbSamplesOfPreviousFrame = srcAudioFrame.getNbSamples ();
97
+ }
97
98
98
99
const unsigned char * srcData = srcFrame.getData ();
99
100
unsigned char * dstData = dstFrame.getData ();
0 commit comments