feat: play music through librubberband

This commit is contained in:
2026-03-20 23:17:34 +01:00
parent 5b26203533
commit b14ea02694
8 changed files with 314 additions and 7 deletions

View File

@@ -7,7 +7,28 @@
#include "StepListener.h"
#include "MixingPlayer.h"
#include "RubberBandStretcher.h"
#include "mp3file.h"
#include "AudioCallback.h"
#include <string>
#include <thread>
#include <memory>
#include <atomic>
/** Provides music through a regular callback to oboe. Called from separate oboe thread. */
class MusicProvider : public AudioCallbackProvider {
public:
explicit MusicProvider(RubberBand::RubberBandStretcher *stretcher);
~MusicProvider() override;
/** Called from separate oboe thread. */
void onAudioReady(float *data, int32_t frames) override;
private:
const size_t num_buf_samples = 48000;
RubberBand::RubberBandStretcher *stretcher;
float *buf;
int idebug;
};
class PlaybackEngine : public StepListener {
public:
@@ -17,8 +38,18 @@ public:
virtual void playBeat();
void playMusic(int fd);
private:
RubberBand::RubberBandStretcher stretcher;
MixingPlayer *mPlayer;
std::string mFilesDir;
std::unique_ptr<MP3File> musicFile;
std::atomic<bool> haveMusicFile;
std::unique_ptr<std::thread> musicFeed;
std::atomic<bool> exitMusicFeedThread;
int android_fd;
void initRubberBand();
void closeRubberBand();
void closeMusicFile();
void musicFeedThread();
};
#endif //LOCKSTEP_PLAYBACKENGINE_H