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 @@ -2118,7 +2118,15 @@ uint32_t AudioFlinger::MixerThread::prepareTracks_l(const SortedVector< wp<Track
21182118 if (t->sampleRate () == (int )mSampleRate ) {
21192119 minFrames = mFrameCount ;
21202120 } else {
2121- minFrames = (mFrameCount * t->sampleRate ()) / mSampleRate + 1 ;
2121+ // +1 for rounding and +1 for additional sample needed for interpolation
2122+ minFrames = (mFrameCount * t->sampleRate ()) / mSampleRate + 1 + 1 ;
2123+ // add frames already consumed but not yet released by the resampler
2124+ // because cblk->framesReady() will include these frames
2125+ minFrames += mAudioMixer ->getUnreleasedFrames (track->name ());
2126+ // the minimum track buffer size is normally twice the number of frames necessary
2127+ // to fill one buffer and the resampler should not leave more than one buffer worth
2128+ // of unreleased frames after each pass, but just in case...
2129+ LOG_ASSERT (minFrames <= cblk->frameCount );
21222130 }
21232131 }
21242132 if ((cblk->framesReady () >= minFrames) && track->isReady () &&
Original file line number Diff line number Diff line change @@ -329,6 +329,23 @@ void AudioMixer::track_t::adjustVolumeRamp(bool aux)
329329 }
330330}
331331
332+ size_t AudioMixer::track_t::getUnreleasedFrames ()
333+ {
334+ if (resampler != NULL ) {
335+ return resampler->getUnreleasedFrames ();
336+ }
337+ return 0 ;
338+ }
339+
340+ size_t AudioMixer::getUnreleasedFrames (int name)
341+ {
342+ name -= TRACK0;
343+ if (uint32_t (name) < MAX_NUM_TRACKS) {
344+ track_t & track (mState .tracks [name]);
345+ return track.getUnreleasedFrames ();
346+ }
347+ return 0 ;
348+ }
332349
333350void AudioMixer::setBufferProvider (AudioBufferProvider* buffer)
334351{
Original file line number Diff line number Diff line change @@ -88,6 +88,8 @@ class AudioMixer
8888
8989 uint32_t trackNames () const { return mTrackNames ; }
9090
91+ size_t getUnreleasedFrames (int name);
92+
9193private:
9294
9395 enum {
@@ -159,6 +161,7 @@ class AudioMixer
159161 bool doesResample () const ;
160162 void resetResampler ();
161163 void adjustVolumeRamp (bool aux);
164+ size_t getUnreleasedFrames ();
162165 };
163166
164167 // 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