Closed X1l10on88 closed 1 year ago
The original version of your issue had the following code:
char *out = (char*)outputBuffer;
for (int i = 0; i < amount_of_data_to_play_now; i++)
{
*out++ = ((char*)oData->data)[i]; // left channel
*out++ = ((char*)oData->data)[i]; // right channel
}
Can you try like this, but replace char
with short
? Assuming your audio buffer format is RTAUDIO_SINT16
. If you're using RTAUDIO_FLOAT32
then you should use float
, etc.
You can see an example of this in the playback tutorial where a double
is used because the audio format is RTAUDIO_FLOAT64
.
Thank you for your answer, the solution was even more straightforward, I had to set the flag for non-interleaved play:
// In the constructor
if(fake_stereo == true && channels == 1){
options.flags = RTAUDIO_NONINTERLEAVED;
oParams.nChannels = 2;
}
and now my callback function looks like this:
//Play modes
if(fake_stereo == false && channels == 1){
memcpy(outputBuffer, oData->data, amount_of_data_to_play_now);
} else if( fake_stereo == true && channels == 1 ){
memcpy(outputBuffer, oData->data, amount_of_data_to_play_now);
memcpy((char*)outputBuffer+amount_of_data_to_play_now, oData->data, amount_of_data_to_play_now);
}
Hello,
I have found myself embarked in the "issue" that mono is played only on the left channel, for then finding out it is by design: https://github.com/thestk/rtaudio/issues/243.
In the comment of the previous issue, there is a generic indication that I should open the stream with 2 channels and copy the mono audio in both, but there is no code example or really mention of how.
Here is my attempt which almost works, but it distorts the audio: