-
Notifications
You must be signed in to change notification settings - Fork 14
/
playback.h
38 lines (31 loc) · 932 Bytes
/
playback.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef PLAYBACK_H
#define PLAYBACK_H
#include <fstream>
#include <vector>
#include "signal_type.h"
// Reads a recording file (see record.cpp to generate such files) into memory
// and replays the signal in a loop through the "next()" method.
//
// This is useful when debugging/testing new pedals as you don't need to keep
// your guitar around. You can just make a recording and then loop it back
// through the effects loop.
class Playback {
public:
Playback(const std::string& filename) {
std::ifstream stream(filename);
SignalType signal;
while (stream >> signal) {
frames_.push_back(signal);
}
}
SignalType next() {
auto signal = frames_[next_frame_];
next_frame_ = (next_frame_ + 1) % frames_.size();
return signal;
}
const std::vector<SignalType>& frames() { return frames_; }
private:
std::vector<SignalType> frames_;
int next_frame_ = 0;
};
#endif /* PLAYBACK_H */