return 0;
}
- m_rtAudio->setErrorCallback([](RtAudioErrorType type, const std::string& msg) {
- u::log::print("[KA] RtAudio error %d: %s\n", type, msg.c_str());
- });
-
u::log::print("[KA] Opening device out=%d, in=%d, samplerate=%d\n",
conf.soundDeviceOut, conf.soundDeviceIn, conf.samplerate);
#endif
- m_callbackInfo = {
- /* kernelAudio = */ this,
- /* ready = */ true,
- /* withJack = */ getAPI() == G_SYS_API_JACK,
- /* outBuf = */ nullptr, // filled later on in audio callback
- /* inBuf = */ nullptr, // filled later on in audio callback
- /* bufferSize = */ 0, // filled later on in audio callback
- /* channelsOutCount = */ m_channelsOutCount,
- /* channelsInCount = */ m_channelsInCount};
-
- RtAudioErrorType res = m_rtAudio->openStream(
- &outParams, // output params
- conf.soundDeviceIn != -1 ? &inParams : nullptr, // input params if inDevice is selected
- RTAUDIO_FLOAT32, // audio format
- m_realSampleRate, // sample rate
- &m_realBufferSize, // buffer size in byte
- &audioCallback, // audio callback
- &m_callbackInfo, // user data passed to callback
- &options);
-
- if (res == RtAudioErrorType::RTAUDIO_NO_ERROR)
+ try
{
+ m_callbackInfo = {
+ /* kernelAudio = */ this,
+ /* ready = */ true,
+ /* withJack = */ getAPI() == G_SYS_API_JACK,
+ /* outBuf = */ nullptr, // filled later on in audio callback
+ /* inBuf = */ nullptr, // filled later on in audio callback
+ /* bufferSize = */ 0, // filled later on in audio callback
+ /* channelsOutCount = */ m_channelsOutCount,
+ /* channelsInCount = */ m_channelsInCount};
+
+ m_rtAudio->openStream(
+ &outParams, // output params
+ conf.soundDeviceIn != -1 ? &inParams : nullptr, // input params if inDevice is selected
+ RTAUDIO_FLOAT32, // audio format
+ m_realSampleRate, // sample rate
+ &m_realBufferSize, // buffer size in byte
+ &audioCallback, // audio callback
+ &m_callbackInfo, // user data passed to callback
+ &options);
m_ready = true;
return 1;
}
- else
+ catch (RtAudioError& e)
{
+ u::log::print("[KA] RtAudio init error: %s\n", e.getMessage());
closeDevice();
return 0;
}
int KernelAudio::startStream()
{
- if (m_rtAudio->startStream() == RtAudioErrorType::RTAUDIO_NO_ERROR)
+ try
{
- u::log::print("[KA] Start stream - latency = %lu\n", m_rtAudio->getStreamLatency());
+ m_rtAudio->startStream();
+ u::log::print("[KA] latency = %lu\n", m_rtAudio->getStreamLatency());
return 1;
}
- return 0;
+ catch (RtAudioError& e)
+ {
+ u::log::print("[KA] Start stream error: %s\n", e.getMessage());
+ return 0;
+ }
}
/* -------------------------------------------------------------------------- */
int KernelAudio::stopStream()
{
- if (m_rtAudio->stopStream() == RtAudioErrorType::RTAUDIO_NO_ERROR)
+ try
{
- u::log::print("[KA] Stop stream\n");
+ m_rtAudio->stopStream();
return 1;
}
- return 0;
+ catch (RtAudioError& /*e*/)
+ {
+ u::log::print("[KA] Stop stream error\n");
+ return 0;
+ }
}
/* -------------------------------------------------------------------------- */
m::KernelAudio::Device KernelAudio::fetchDevice(size_t deviceIndex) const
{
- RtAudio::DeviceInfo info = m_rtAudio->getDeviceInfo(deviceIndex);
+ try
+ {
+ RtAudio::DeviceInfo info = m_rtAudio->getDeviceInfo(deviceIndex);
- if (!info.probed)
+ if (!info.probed)
+ {
+ u::log::print("[KA] Can't probe device %d\n", deviceIndex);
+ return {deviceIndex};
+ }
+
+ return {
+ deviceIndex,
+ true,
+ info.name,
+ static_cast<int>(info.outputChannels),
+ static_cast<int>(info.inputChannels),
+ static_cast<int>(info.duplexChannels),
+ info.isDefaultOutput,
+ info.isDefaultInput,
+ u::vector::cast<int>(info.sampleRates)};
+ }
+ catch (RtAudioError& e)
{
- u::log::print("[KA] Can't probe device %d\n", deviceIndex);
- return {deviceIndex};
+ u::log::print("[KA] Error fetching device %d: %s\n", deviceIndex, e.getMessage());
+ return {0};
}
-
- return {
- deviceIndex,
- true,
- info.name,
- static_cast<int>(info.outputChannels),
- static_cast<int>(info.inputChannels),
- static_cast<int>(info.duplexChannels),
- info.isDefaultOutput,
- info.isDefaultInput,
- u::vector::cast<int>(info.sampleRates)};
}
/* -------------------------------------------------------------------------- */