2026-02-01 02:54:05 +01:00
|
|
|
//
|
|
|
|
|
// Created by david on 01.02.2026.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#ifndef LOCKSTEP_PLAYBACKENGINE_H
|
|
|
|
|
#define LOCKSTEP_PLAYBACKENGINE_H
|
|
|
|
|
|
2026-03-04 01:31:35 +01:00
|
|
|
#include "StepListener.h"
|
2026-03-03 14:19:56 +01:00
|
|
|
#include "MixingPlayer.h"
|
2026-03-20 23:17:34 +01:00
|
|
|
#include "RubberBandStretcher.h"
|
|
|
|
|
#include "mp3file.h"
|
|
|
|
|
#include "AudioCallback.h"
|
2026-03-03 12:04:17 +01:00
|
|
|
#include <string>
|
2026-03-20 23:17:34 +01:00
|
|
|
#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;
|
|
|
|
|
};
|
2026-02-01 02:54:05 +01:00
|
|
|
|
2026-03-04 01:31:35 +01:00
|
|
|
class PlaybackEngine : public StepListener {
|
2026-02-01 02:54:05 +01:00
|
|
|
public:
|
2026-03-03 14:19:56 +01:00
|
|
|
PlaybackEngine(std::string filesDir, int resid);
|
2026-02-01 02:54:05 +01:00
|
|
|
virtual ~PlaybackEngine();
|
2026-03-04 01:31:35 +01:00
|
|
|
/** Play a beat sound. */
|
|
|
|
|
virtual void playBeat();
|
2026-03-19 19:17:57 +01:00
|
|
|
void playMusic(int fd);
|
2026-02-01 02:54:05 +01:00
|
|
|
private:
|
2026-03-20 23:17:34 +01:00
|
|
|
RubberBand::RubberBandStretcher stretcher;
|
2026-03-03 14:19:56 +01:00
|
|
|
MixingPlayer *mPlayer;
|
2026-03-03 12:04:17 +01:00
|
|
|
std::string mFilesDir;
|
2026-03-20 23:17:34 +01:00
|
|
|
std::unique_ptr<MP3File> musicFile;
|
|
|
|
|
std::atomic<bool> haveMusicFile;
|
|
|
|
|
std::unique_ptr<std::thread> musicFeed;
|
|
|
|
|
std::atomic<bool> exitMusicFeedThread;
|
|
|
|
|
int android_fd;
|
2026-03-22 07:37:27 +01:00
|
|
|
std::atomic<bool> haveTimeRatio;
|
|
|
|
|
double timeRatio;
|
2026-03-20 23:17:34 +01:00
|
|
|
void initRubberBand();
|
|
|
|
|
void closeRubberBand();
|
|
|
|
|
void closeMusicFile();
|
|
|
|
|
void musicFeedThread();
|
2026-02-01 02:54:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif //LOCKSTEP_PLAYBACKENGINE_H
|