fix: play with rate of mp3 file
This commit is contained in:
1
TODO.md
1
TODO.md
@@ -3,6 +3,7 @@
|
|||||||
* analyze the (secondly or so) noise beeps in the mp3 playback
|
* analyze the (secondly or so) noise beeps in the mp3 playback
|
||||||
- introduced with this commit
|
- introduced with this commit
|
||||||
- is it librubberband, my failure to feed it properly (buffer exhaustion), or sth else?
|
- 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
|
* correct sampling rate of libmpg123 vs. 48000 Hz using librubberband
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,9 @@ PlaybackEngine::PlaybackEngine(std::string filesDir, int resid):
|
|||||||
mFilesDir(filesDir),
|
mFilesDir(filesDir),
|
||||||
haveMusicFile(false),
|
haveMusicFile(false),
|
||||||
exitMusicFeedThread(false),
|
exitMusicFeedThread(false),
|
||||||
android_fd(0)
|
android_fd(0),
|
||||||
|
haveTimeRatio(false),
|
||||||
|
timeRatio(1.0)
|
||||||
{
|
{
|
||||||
LOGI("PlaybackEngine()");
|
LOGI("PlaybackEngine()");
|
||||||
LOGI("NDK LOG_LEVEL=%d", LOG_LEVEL);
|
LOGI("NDK LOG_LEVEL=%d", LOG_LEVEL);
|
||||||
@@ -162,6 +164,12 @@ void PlaybackEngine::musicFeedThread() {
|
|||||||
|
|
||||||
// thread 2: polling for decoding more mp3 -> process() -- getSamplesRequired()
|
// thread 2: polling for decoding more mp3 -> process() -- getSamplesRequired()
|
||||||
while(!exitMusicFeedThread.load()) {
|
while(!exitMusicFeedThread.load()) {
|
||||||
|
|
||||||
|
if(haveTimeRatio.load()) {
|
||||||
|
stretcher.setTimeRatio(timeRatio);
|
||||||
|
haveTimeRatio.store(false);
|
||||||
|
}
|
||||||
|
|
||||||
// do work ...
|
// do work ...
|
||||||
size_t num_samples = stretcher.getSamplesRequired();
|
size_t num_samples = stretcher.getSamplesRequired();
|
||||||
|
|
||||||
@@ -260,6 +268,10 @@ void PlaybackEngine::playMusic(int fd) {
|
|||||||
|
|
||||||
android_fd = fd;
|
android_fd = fd;
|
||||||
musicFile.reset(mp3file_open_fd(android_fd, 0));
|
musicFile.reset(mp3file_open_fd(android_fd, 0));
|
||||||
|
if(musicFile) {
|
||||||
|
timeRatio = ((double) 48000) / ((double) musicFile->rate);
|
||||||
|
haveTimeRatio.store(true);
|
||||||
|
}
|
||||||
haveMusicFile.store(true);
|
haveMusicFile.store(true);
|
||||||
mPlayer->setMusic(std::make_shared<MusicProvider>(&stretcher));
|
mPlayer->setMusic(std::make_shared<MusicProvider>(&stretcher));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ private:
|
|||||||
std::unique_ptr<std::thread> musicFeed;
|
std::unique_ptr<std::thread> musicFeed;
|
||||||
std::atomic<bool> exitMusicFeedThread;
|
std::atomic<bool> exitMusicFeedThread;
|
||||||
int android_fd;
|
int android_fd;
|
||||||
|
std::atomic<bool> haveTimeRatio;
|
||||||
|
double timeRatio;
|
||||||
void initRubberBand();
|
void initRubberBand();
|
||||||
void closeRubberBand();
|
void closeRubberBand();
|
||||||
void closeMusicFile();
|
void closeMusicFile();
|
||||||
|
|||||||
Reference in New Issue
Block a user