60 unsigned long currentFrame = 0;
61 std::vector<char> data;
62 bool playingRepeat =
false;
64 template <
class Archive>
65 void serialize(Archive& archive) {
82#if !defined(__ANDROID__) && !defined(SMALL3D_IOS)
84#elif defined(__ANDROID__)
85 oboe::AudioStreamBuilder *streamBuilder;
86 oboe::AudioStream *stream;
87#elif defined(SMALL3D_IOS)
88static ALCdevice *openalDevice;
89static ALCcontext *openalContext;
94 static bool noOutputDevice;
96 static unsigned int numInstances;
98#if !defined(SMALL3D_IOS) && !defined(__ANDROID__)
99 static PaDeviceIndex defaultOutput;
100 static int audioCallback(
const void *inputBuffer,
void *outputBuffer,
101 unsigned long framesPerBuffer,
102 const PaStreamCallbackTimeInfo *timeInfo,
103 PaStreamCallbackFlags statusFlags,
105#elif defined(__ANDROID__)
107 class AudioCallbackClass :
public oboe::AudioStreamDataCallback {
109 SoundData *soundData;
111 AudioCallbackClass(SoundData *soundData) {
112 this->soundData = soundData;
114 oboe::DataCallbackResult onAudioReady(oboe::AudioStream *audioStream,
void *audioData,
117 auto *out =
static_cast<SAMPLE_DATATYPE*
>(audioData);
119 if (soundData->currentFrame * SAMPLES_PER_FRAME >= soundData->samples) {
120 if (soundData->repeat) {
121 soundData->currentFrame = 0;
125 memset(out, 0, WORD_SIZE * numFrames * SAMPLES_PER_FRAME * soundData->channels);
126 return oboe::DataCallbackResult::Stop;
130 memcpy(out, &soundData->data.data()[WORD_SIZE * soundData->currentFrame *
131 SAMPLES_PER_FRAME * soundData->channels],
132 WORD_SIZE * numFrames * SAMPLES_PER_FRAME * soundData->channels);
134 soundData->currentFrame += numFrames;
136 return oboe::DataCallbackResult::Continue;
140 AudioCallbackClass audioCallbackObject;
144 void load(
const std::string& soundFilePath);
157 explicit Sound(
const std::string& soundFilePath);
168 void play(
const bool repeat=
false);
206 void saveBinary(
const std::string& binaryFilePath);