Skip to content
Snippets Groups Projects
Commit 83b02b0e authored by BERTHAUT Florent's avatar BERTHAUT Florent
Browse files

Added check on channels number

parent 733c0d8b
No related branches found
No related tags found
No related merge requests found
...@@ -58,22 +58,30 @@ int Gdpd::init(int nbInputs, int nbOutputs, int sampleRate, int bufferSize) { ...@@ -58,22 +58,30 @@ int Gdpd::init(int nbInputs, int nbOutputs, int sampleRate, int bufferSize) {
Godot::print("There are no available sound devices."); Godot::print("There are no available sound devices.");
} }
RtAudio::StreamParameters outParams, inParams; RtAudio::StreamParameters outParams, inpParams;
unsigned int sr = m_audio.getDeviceInfo(outParams.deviceId).preferredSampleRate; inpParams.deviceId = m_audio.getDefaultInputDevice();
outParams.deviceId = m_audio.getDefaultOutputDevice(); outParams.deviceId = m_audio.getDefaultOutputDevice();
inParams.deviceId = m_audio.getDefaultInputDevice(); RtAudio::DeviceInfo inpInfo = m_audio.getDeviceInfo(inpParams.deviceId);
outParams.nChannels = m_nbInputs = nbInputs; RtAudio::DeviceInfo outInfo = m_audio.getDeviceInfo(outParams.deviceId);
inParams.nChannels = m_nbOutputs = nbOutputs;
m_bufferFrames = bufferSize; unsigned int sr = outInfo.preferredSampleRate;
inpParams.nChannels = m_nbInputs
= std::min<int>(nbInputs, inpInfo.inputChannels);
outParams.nChannels = m_nbOutputs
= std::min<int>(nbOutputs, outInfo.outputChannels);
print("Output channels = "+std::to_string(outParams.nChannels));
print("Input channels = "+std::to_string(inpParams.nChannels));
m_bufferFrames = std::max<int>(64, bufferSize);
RtAudio::StreamOptions options; RtAudio::StreamOptions options;
options.streamName = "gdpd"; options.streamName = "gdpd";
options.flags = RTAUDIO_SCHEDULE_REALTIME; options.flags = RTAUDIO_SCHEDULE_REALTIME;
if(m_audio.getCurrentApi() != RtAudio::MACOSX_CORE) { if(m_audio.getCurrentApi() != RtAudio::MACOSX_CORE) {
options.flags |= RTAUDIO_MINIMIZE_LATENCY; // CoreAudio doesn't seem to like this options.flags |= RTAUDIO_MINIMIZE_LATENCY;
} }
try { try {
m_audio.openStream(&outParams, &inParams, RTAUDIO_FLOAT32, m_audio.openStream(&outParams, &inpParams, RTAUDIO_FLOAT32,
sr, &m_bufferFrames, &audioCallback, sr, &m_bufferFrames, &audioCallback,
this, &options); this, &options);
m_audio.startStream(); m_audio.startStream();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment