Working with multichannel output in NAudio I noticed a bug in the ASIOSampleConvertor: the ConvertorFloatToIntGeneric is using a float pointer instead of a int pointer as it should.
Corrected code:
public static void ConvertorFloatToIntGeneric(IntPtr inputInterleavedBuffer, IntPtr[] asioOutputBuffers, int nbChannels, int nbSamples)
{
unsafe
{
float* inputSamples = (float*)inputInterleavedBuffer;
int*[] samples = new int*[nbChannels]; // <- here stood float*
for (int i = 0; i < nbChannels; i++)
{
samples[i] = (int*)asioOutputBuffers[i]; // <- here stood float*
}
for (int i = 0; i < nbSamples; i++)
{
for (int j = 0; j < nbChannels; j++)
{
*samples[j]++ = clampToInt(*inputSamples++);
}
}
}
}
Comments: thanks for reporting this. testing ASIO is a pain as not all soundcards use all the sample converters. What soundcard are you using? And have you tested this in an x86 and/or x64 app?
Corrected code:
public static void ConvertorFloatToIntGeneric(IntPtr inputInterleavedBuffer, IntPtr[] asioOutputBuffers, int nbChannels, int nbSamples)
{
unsafe
{
float* inputSamples = (float*)inputInterleavedBuffer;
int*[] samples = new int*[nbChannels]; // <- here stood float*
for (int i = 0; i < nbChannels; i++)
{
samples[i] = (int*)asioOutputBuffers[i]; // <- here stood float*
}
for (int i = 0; i < nbSamples; i++)
{
for (int j = 0; j < nbChannels; j++)
{
*samples[j]++ = clampToInt(*inputSamples++);
}
}
}
}
Comments: thanks for reporting this. testing ASIO is a pain as not all soundcards use all the sample converters. What soundcard are you using? And have you tested this in an x86 and/or x64 app?