-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace OpenAL by PortAudio #1040
Changes from 6 commits
c91116e
6d432ec
0a40d6e
c2c3477
d23827e
02f11e5
ac2742d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,28 @@ | ||||||
#include <iostream> | ||||||
|
||||||
#include <stdio.h> | ||||||
|
||||||
#include <cubos/core/al/audio_device.hpp> | ||||||
|
||||||
int main() | ||||||
{ | ||||||
auto audio = cubos::core::al::AudioDevice::create(); | ||||||
|
||||||
std::vector<cubos::core::al::DeviceInfo> devices; | ||||||
audio->enumerateDevices(devices, true); | ||||||
|
||||||
audio->init([](void* outputBuffer, unsigned long framesPerBuffer, unsigned long, void*) -> int { | ||||||
float* out = static_cast<float*>(outputBuffer); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
for (unsigned int i = 0; i < framesPerBuffer; i++) | ||||||
{ | ||||||
*out++ = 0.5f * static_cast<float>(std::sin(2.0 * 3.141592653589793 * 440.0 * i / 44100.0)); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
return 0; | ||||||
}); | ||||||
audio->start(); | ||||||
|
||||||
std::cout << "press enter to stop the sound"; | ||||||
std::cin.get(); | ||||||
|
||||||
audio->stop(); | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,28 @@ | ||
#include "oal_audio_device.hpp" | ||
#include "port_audio_device.hpp" | ||
|
||
using namespace cubos::core::al; | ||
|
||
std::shared_ptr<AudioDevice> AudioDevice::create(const std::string& specifier) | ||
std::shared_ptr<AudioDevice> AudioDevice::create(int deviceIndex) | ||
{ | ||
return std::make_shared<OALAudioDevice>(specifier); | ||
return std::make_shared<PortAudioDevice>(deviceIndex); | ||
} | ||
|
||
void AudioDevice::enumerateDevices(std::vector<std::string>& devices) | ||
int AudioDevice::deviceCount() | ||
{ | ||
OALAudioDevice::enumerateDevices(devices); | ||
return PortAudioDevice::deviceCount(); | ||
} | ||
|
||
void AudioDevice::enumerateDevices(std::vector<DeviceInfo>& devices, bool debug) | ||
{ | ||
PortAudioDevice::enumerateDevices(devices, debug); | ||
} | ||
|
||
DeviceInfo AudioDevice::deviceInfo(int deviceIndex) | ||
{ | ||
return PortAudioDevice::deviceInfo(deviceIndex); | ||
} | ||
|
||
void AudioDevice::printDeviceInformation(int deviceIndex) | ||
{ | ||
return PortAudioDevice::printDeviceInformation(deviceIndex); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inclusion of deprecated C++ header
stdio.h
; consider usingcstdio
instead