ASIO:How to retrieve the sampling rate of a device

Started by YAN HONG,

YAN HONG

Hi all,

I wrote a test code to obtain the sampling rate of devices driven by ASIO and check if the sampling rate is consistent with the audio sampling rate.

void Error(const char* es)
{
    char mes[200];
    sprintf_s(mes, "%s(error code: %d---%d)", es, BASS_ErrorGetCode(), BASS_ASIO_ErrorGetCode());
    printf("%s\n",mes);
}

if (!BASS_Init(-1, 44100, 0, 0, NULL))
{
    Error("BASS_Init");
}
DWORD asio_device = BASS_ASIO_GetDevice();
if (asio_device != BASS_NODEVICE)
{
        BASS_ASIO_Init(asio_device, 0);
}
else
{
       
        Error("Can't BASS_ASIO_Init");
}
printf("BASS_ASIO_GetRate == %d\n", BASS_ASIO_GetRate());
HSTREAM stream = BASS_StreamCreateFile(FALSE, "test.wav", 0, 0, BASS_SAMPLE_FLOAT | BASS_STREAM_DECODE | BASS_ASYNCFILE);
if (!stream)
 {
        Error("Can't play Stream");
}
BASS_CHANNELINFO info;
BASS_ChannelGetInfo(stream, &info);
printf("BASS Channel rate = %d \n", info.freq);
if (!BASS_ASIO_ChannelSetRate(FALSE, 0, info.freq))
{
        Error("BASS_ASIO_ChannelSetRate");
}     
if (!BASS_ASIO_CheckRate(info.freq))
{
        Error("BASS_ASIO_CheckRate");
}   
printf("BASS_ASIO_GetRate again == %d\n", BASS_ASIO_GetRate());

This is my test execution result.

BASS_ASIO_GetRate == 0
BASS Channel rate = 44100
BASS_ASIO_GetRate again == 0

Why did I print BASS_ASIO_GetRate twice, but the result is 0?

Ian @ un4seen

BASS_ASIO_GetRate returns a "double" floating-point value, while your printf call is expecting an integer. Please try changing "%d" to "%g".

YAN HONG

Yes,it works.I didn't notice the returned data type.Thanks ;D

YAN HONG

Hi Ian,I was wondering if there is a function I can call to clear the ASIO buffer?

Ian @ un4seen