fix: play with rate of mp3 file

This commit is contained in:
2026-03-22 07:37:27 +01:00
parent b14ea02694
commit b0f6d6d5c9
3 changed files with 16 additions and 1 deletions

View File

@@ -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

View File

@@ -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<MusicProvider>(&stretcher));
}

View File

@@ -46,6 +46,8 @@ private:
std::unique_ptr<std::thread> musicFeed;
std::atomic<bool> exitMusicFeedThread;
int android_fd;
std::atomic<bool> haveTimeRatio;
double timeRatio;
void initRubberBand();
void closeRubberBand();
void closeMusicFile();