This is my first post on Stackoverflow, I hope I'm doing this right.
I'm new to C++.
I've been playing with RtAudio and Qt (on linux, desktop and raspberry pi).
Backend is ALSA.
Audio out went fine both on my desktop computer (RME Fireface UCX in ClassCompilant mode and on the Raspberry Pi 3 with HifiBerry and PiSound)
Lately, I tried to add audio input support to my program. I read the duplex tutorial on RtAudio website, and tried to implement it inside my code.
As soon as I added the input StreamParameters
to openStream
I got a very cracky sound.
Although, StreamStatus is ok in the callback...
I tried to create an empty C++ project, and simply copy the RtAudio tutorial. Sadly, the problem remains...
I added this to my project file in Qt Creator
LIBS += -lpthread -lasound
I think my issue is similar to this one, but I couldn't find how (or if) it was solved
I tried different buffer sizes (from 64 to 4096 and more), the cracks are less audible, but still present when buffer size increases
Do you know anything that should be done regarding RtAudio in duplex mode that might solve this ? It seems that buffer size is not the same when in duplex mode.
edit :
Out of curiosity (and despair), I tried even lower buffer sizes with the canonical example from RtAudio help : it turns out using buffer size 1, 2, 4 and 8 frames removes the cracks...
As soon as I use 16 frames, sound is awful
Even 15 frames works, I really don't get what's going on
Code Sample :
RtAudio::StreamOptions options;
options.flags |= RTAUDIO_SCHEDULE_REALTIME;
RtAudio::StreamParameters params_in, params_out;
params_in.deviceId = 3;
params_in.nChannels = 2;
params_out.deviceId = 3;
params_out.nChannels = 2;
When output only, it works :
try {
audio.openStream(
¶ms_out,
NULL,
RTAUDIO_SINT16,
48000,
&buffer_frames,
&inout,
(void *) &buffer_bytes,
&options
);
}
catch (RtAudioError& e) {
std::cout << "Error while opening stream" << std::endl;
e.printMessage();
exit(0);
}
Cracks appear when changing NULL
to ¶ms_in
:
try {
audio.openStream(
¶ms_out,
¶ms_in,
RTAUDIO_SINT16,
48000,
&buffer_frames,
&inout,
(void *) &buffer_bytes,
&options
);
}
catch (RtAudioError& e) {
std::cout << "Error while opening stream" << std::endl;
e.printMessage();
exit(0);
}
Thank you for your help