File tree Expand file tree Collapse file tree 4 files changed +30
-1
lines changed
Expand file tree Collapse file tree 4 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -2111,7 +2111,15 @@ uint32_t AudioFlinger::MixerThread::prepareTracks_l(const SortedVector< wp<Track
21112111 if (t->sampleRate () == (int )mSampleRate ) {
21122112 minFrames = mFrameCount ;
21132113 } else {
2114- minFrames = (mFrameCount * t->sampleRate ()) / mSampleRate + 1 ;
2114+ // +1 for rounding and +1 for additional sample needed for interpolation
2115+ minFrames = (mFrameCount * t->sampleRate ()) / mSampleRate + 1 + 1 ;
2116+ // add frames already consumed but not yet released by the resampler
2117+ // because cblk->framesReady() will include these frames
2118+ minFrames += mAudioMixer ->getUnreleasedFrames (track->name ());
2119+ // the minimum track buffer size is normally twice the number of frames necessary
2120+ // to fill one buffer and the resampler should not leave more than one buffer worth
2121+ // of unreleased frames after each pass, but just in case...
2122+ LOG_ASSERT (minFrames <= cblk->frameCount );
21152123 }
21162124 }
21172125 if ((cblk->framesReady () >= minFrames) && track->isReady () &&
Original file line number Diff line number Diff line change @@ -331,6 +331,23 @@ void AudioMixer::track_t::adjustVolumeRamp(bool aux)
331331 }
332332}
333333
334+ size_t AudioMixer::track_t::getUnreleasedFrames ()
335+ {
336+ if (resampler != NULL ) {
337+ return resampler->getUnreleasedFrames ();
338+ }
339+ return 0 ;
340+ }
341+
342+ size_t AudioMixer::getUnreleasedFrames (int name)
343+ {
344+ name -= TRACK0;
345+ if (uint32_t (name) < MAX_NUM_TRACKS) {
346+ track_t & track (mState .tracks [name]);
347+ return track.getUnreleasedFrames ();
348+ }
349+ return 0 ;
350+ }
334351
335352status_t AudioMixer::setBufferProvider (AudioBufferProvider* buffer)
336353{
Original file line number Diff line number Diff line change @@ -91,6 +91,8 @@ class AudioMixer
9191
9292 static void ditherAndClamp (int32_t * out, int32_t const *sums, size_t c);
9393
94+ size_t getUnreleasedFrames (int name);
95+
9496private:
9597
9698 enum {
@@ -167,6 +169,7 @@ class AudioMixer
167169 bool doesResample () const ;
168170 void resetResampler ();
169171 void adjustVolumeRamp (bool aux);
172+ size_t getUnreleasedFrames ();
170173 };
171174
172175 // pad to 32-bytes to fill cache line
Original file line number Diff line number Diff line change @@ -54,6 +54,7 @@ class AudioResampler {
5454 AudioBufferProvider* provider) = 0;
5555
5656 virtual void reset ();
57+ virtual size_t getUnreleasedFrames () { return mInputIndex ; }
5758
5859protected:
5960 // number of bits for phase fraction - 30 bits allows nearly 2x downsampling
You can’t perform that action at this time.
0 commit comments