33 if (code1 == AL_NO_ERROR) {
51 const char *device_names =
alcGetString(
nullptr, ALC_ALL_DEVICES_SPECIFIER);
53 device_names =
alcGetString(
nullptr, ALC_DEVICE_SPECIFIER);
57 for (
const char *device_name = device_names; device_name[0];
58 device_name += strlen(device_name) + 1) {
59 log(
"al: device found \"%s\"", device_name);
63 const char *defname =
alcGetString(0, ALC_DEFAULT_DEVICE_SPECIFIER);
68 log(
"al: Default sound device not present");
87 ALfloat listenerOri[] = {0.f, 1.f, 0.f, 0.f, 0.f, -1.f};
98 float x = cos(pitch) * cos(yaw);
99 float y = sin(yaw) * cos(pitch);
100 float z = -sin(pitch);
102 ALfloat listenerOri[] = {-
x,
y,
z, 0.f, 0.f, 1.f};
121 alGetSourcei(track->source_id, AL_SOURCE_STATE, &status);
122 if (status == AL_PLAYING) {
127 int num_processed_buffers = 0;
128 int num_queued_buffers = 0;
130 &num_processed_buffers);
131 alGetSourcei(track->source_id, AL_BUFFERS_QUEUED, &num_queued_buffers);
133 for (
int i = 0; i < num_processed_buffers; ++i) {
134 unsigned int buffer_id;
174 int bytes_per_sample) {
175 Assert(bytes_per_sample == 2,
176 "OpenALSoundProvider: unsupported sample size: %u",
180 switch (num_channels) {
182 sound_format = AL_FORMAT_MONO16;
185 sound_format = AL_FORMAT_STEREO16;
189 switch (num_channels) {
204 Error(
"Unsupported number of audio channels: %u", num_channels);
207 unsigned int al_source = -1;
213 alSourcei(al_source, AL_LOOPING, AL_FALSE);
227 int num_samples,
const void *
samples,
233 int bytes_per_sample = 2;
235 int num_processed_buffers = 0;
237 &num_processed_buffers);
238 if (num_processed_buffers > 0) {
239 unsigned int *processed_buffer_ids =
240 new unsigned int[num_processed_buffers];
242 processed_buffer_ids);
244 log(
"OpenAL: Faile to get played buffers.");
248 log(
"OpenAL: Faile to delete played buffers.");
251 delete[] processed_buffer_ids;
254 unsigned int al_buffer;
257 num_samples * bytes_per_sample,
buffer->sample_rate);
271 if (status != AL_PLAYING) {
281 }
while (status == AL_PLAYING);
287 int num_channels,
int sample_rate,
const void *
data,
size_t size) {
289 switch (num_channels) {
291 sound_format = AL_FORMAT_MONO16;
295 sound_format = AL_FORMAT_STEREO16;
300 switch (num_channels) {
315 Error(
"Unsupported number of audio channels: %u", num_channels);
325 alSourcei(al_source, AL_LOOPING, AL_FALSE);
345 alSourcei(al_source, AL_BUFFER, al_buffer);
362 if (status == AL_PLAYING) {
375 float track_offset = 0;
377 log(
"playing: %.4f/%.4f\n", track_offset, track_length);
380 }
while (status == AL_PLAYING);
390 if (
bRunning.load(std::memory_order_acquire)) {
395 void Start(
int interval, std::function<
void(
void)>
func) {
396 if (
bRunning.load(std::memory_order_acquire)) {
399 bRunning.store(
true, std::memory_order_release);
401 while (
bRunning.load(std::memory_order_acquire)) {
403 std::this_thread::sleep_for(
404 std::chrono::milliseconds(interval));
410 bRunning.store(
false, std::memory_order_release);
417 return (
bRunning.load(std::memory_order_acquire) &&
438 virtual bool Pause();
506 if (status == AL_PLAYING) {
595 ALint num_processed_buffers = 0;
597 if (num_processed_buffers <= 0) {
601 ALuint *processed_buffer_ids =
new ALuint[num_processed_buffers];
603 log(
"OpenAL: Faile to get played buffers.");
605 for (
ALint i = 0; i < num_processed_buffers; i++) {
609 log(
"OpenAL: Faile to unqueue played buffer.");
616 log(
"OpenAL: Faile to delete played buffer.");
621 delete[] processed_buffer_ids;
658 std::shared_ptr<AudioTrackS16> track = std::make_shared<AudioTrackS16>();
661 if (!track->Open(
source)) {
665 return std::dynamic_pointer_cast<IAudioTrack, AudioTrackS16>(track);
679 virtual bool SetPosition(
float x,
float y,
float z,
float max_dist);
746 unsigned int num_channels = data_source->GetChannelCount();
747 switch (num_channels) {
756 switch (num_channels) {
771 Error(
"Unsupported number of audio channels: %u", num_channels);
835 if (status == AL_PLAYING) {
874 std::shared_ptr<AudioSample16> sample = std::make_shared<AudioSample16>();
877 if (!sample->Open(
source)) {
881 return std::dynamic_pointer_cast<IAudioSample, AudioSample16>(sample);