diff --git a/TODO.md b/TODO.md index a921bb8..d2972fa 100644 --- a/TODO.md +++ b/TODO.md @@ -3,6 +3,7 @@ * analyze the (secondly or so) noise beeps in the mp3 playback - introduced with this commit - is it librubberband, my failure to feed it properly (buffer exhaustion), or sth else? + - the sizes of my buffers? * correct sampling rate of libmpg123 vs. 48000 Hz using librubberband diff --git a/app/src/main/cpp/PlaybackEngine.cpp b/app/src/main/cpp/PlaybackEngine.cpp index 134b04f..f56f656 100644 --- a/app/src/main/cpp/PlaybackEngine.cpp +++ b/app/src/main/cpp/PlaybackEngine.cpp @@ -80,7 +80,9 @@ PlaybackEngine::PlaybackEngine(std::string filesDir, int resid): mFilesDir(filesDir), haveMusicFile(false), exitMusicFeedThread(false), - android_fd(0) + android_fd(0), + haveTimeRatio(false), + timeRatio(1.0) { LOGI("PlaybackEngine()"); LOGI("NDK LOG_LEVEL=%d", LOG_LEVEL); @@ -162,6 +164,12 @@ void PlaybackEngine::musicFeedThread() { // thread 2: polling for decoding more mp3 -> process() -- getSamplesRequired() while(!exitMusicFeedThread.load()) { + + if(haveTimeRatio.load()) { + stretcher.setTimeRatio(timeRatio); + haveTimeRatio.store(false); + } + // do work ... size_t num_samples = stretcher.getSamplesRequired(); @@ -260,6 +268,10 @@ void PlaybackEngine::playMusic(int fd) { android_fd = fd; musicFile.reset(mp3file_open_fd(android_fd, 0)); + if(musicFile) { + timeRatio = ((double) 48000) / ((double) musicFile->rate); + haveTimeRatio.store(true); + } haveMusicFile.store(true); mPlayer->setMusic(std::make_shared(&stretcher)); } diff --git a/app/src/main/cpp/PlaybackEngine.h b/app/src/main/cpp/PlaybackEngine.h index 9546326..a743a3a 100644 --- a/app/src/main/cpp/PlaybackEngine.h +++ b/app/src/main/cpp/PlaybackEngine.h @@ -46,6 +46,8 @@ private: std::unique_ptr musicFeed; std::atomic exitMusicFeedThread; int android_fd; + std::atomic haveTimeRatio; + double timeRatio; void initRubberBand(); void closeRubberBand(); void closeMusicFile();