// // Created by david on 01.02.2026. // #ifndef LOCKSTEP_PLAYBACKENGINE_H #define LOCKSTEP_PLAYBACKENGINE_H #include "StepListener.h" #include "MixingPlayer.h" #include "RubberBandStretcher.h" #include "mp3file.h" #include "AudioCallback.h" #include #include #include #include /** 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: PlaybackEngine(std::string filesDir, int resid); virtual ~PlaybackEngine(); /** Play a beat sound. */ virtual void playBeat(); void playMusic(int fd); private: RubberBand::RubberBandStretcher stretcher; MixingPlayer *mPlayer; std::string mFilesDir; std::unique_ptr musicFile; std::atomic haveMusicFile; std::unique_ptr musicFeed; std::atomic exitMusicFeedThread; int android_fd; std::atomic haveTimeRatio; double timeRatio; void initRubberBand(); void closeRubberBand(); void closeMusicFile(); void musicFeedThread(); }; #endif //LOCKSTEP_PLAYBACKENGINE_H