Author Topic: ASIO:How to retrieve the sampling rate of a device  (Read 115 times)

YAN HONG

  • Posts: 4
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.

Code: [Select]
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);
}

Code: [Select]
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.

Code: [Select]
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?
« Last Edit: 5 Sep '24 - 11:01 by YAN HONG »

Ian @ un4seen

  • Administrator
  • Posts: 26079
Re: ASIO:How to retrieve the sampling rate of a device
« Reply #1 on: 5 Sep '24 - 18:07 »
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

  • Posts: 4
Re: ASIO:How to retrieve the sampling rate of a device
« Reply #2 on: 6 Sep '24 - 02:50 »
Yes,it works.I didn't notice the returned data type.Thanks ;D

YAN HONG

  • Posts: 4
Re: ASIO:How to retrieve the sampling rate of a device
« Reply #3 on: 6 Sep '24 - 07:22 »
Hi Ian,I was wondering if there is a function I can call to clear the ASIO buffer?

Ian @ un4seen

  • Administrator
  • Posts: 26079
Re: ASIO:How to retrieve the sampling rate of a device
« Reply #4 on: 6 Sep '24 - 14:12 »
Please clarify what buffer(s) you want to clear and when.