1 #ifndef INCLUDE_AL_SOUNDFILE_HPP
2 #define INCLUDE_AL_SOUNDFILE_HPP
17 std::vector<float> data;
20 long long int frameCount = 0;
35 bool open(
const char* path);
36 float* getFrame(
long long int frame);
40 unsigned int newSampleRate);
45 long long int frame = 0;
63 void getFrames(uint64_t numFrames,
float* buffer,
int bufferLength);
78 bool isOpen() {
return mImpl !=
nullptr; }
88 bool open(
const char* path);
92 uint64_t
getFrames(uint64_t numFrames,
float* buffer);
103 std::atomic<bool> pauseSignal;
104 std::atomic<bool> loopSignal;
105 std::atomic<bool> rewindSignal;
121 bool open(
const char* path) {
122 bool ret = soundFile.open(path);
123 player.soundFile = &soundFile;
127 void setPlay() { pauseSignal.store(
false); }
128 void setPause() { pauseSignal.store(
true); }
129 void togglePause() { pauseSignal.store(!pauseSignal.load()); }
131 void setRewind() { rewindSignal.store(
true); }
133 void setLoop() { loopSignal.store(
true); }
134 void setNoLoop() { loopSignal.store(
false); }
136 void getFrames(
int numFrames,
float* buffer,
int bufferLength) {
137 player.pause = pauseSignal.load();
138 player.loop = loopSignal.load();
139 if (rewindSignal.exchange(
false)) {
142 player.getFrames(numFrames, buffer, bufferLength);
The SoundFileStreaming class provides reading soundifle directly from disk one buffer at a time.
uint64_t getFrames(uint64_t numFrames, float *buffer)
Read interleaved frames into preallocated buffer;.
uint64_t totalFrames()
Total number of frames in file. Call after open has returned true.
void close()
Close file and cleanup.
uint32_t sampleRate()
Sampling rate of file. Call after open has returned true.
bool open(const char *path)
Open file for reading.
uint16_t numChannels()
Number of channels in file. Call after open has returned true.
Read sound file and store the data in float array (interleaved)
Soundfile player class with thread-safe access to playback controls.