Author Topic: WASAPI, 96kHz file played in slow speed  (Read 242 times)

MikaelS

  • Posts: 198
WASAPI, 96kHz file played in slow speed
« on: 31 Oct '17 - 18:21 »
Hello,

I have a problem that's hopefully simple, it feels like I just have overseen something.

I init Wasapi with the channel information, e.g. freq = 96000, chans = 2.
After that I create a mixer with the same frequency and channels and finally I add my stream to the mixer and start to play it.

Everything works well, BUT, the file played too slow.

If I play a standard MP3 (44100 kHz file) it works like it should.

Any hints what I might have missed?

Thanks in advance.

PS: I use BASS.NET and the most recent versions of BASS and it's addons.
« Last Edit: 1 Nov '17 - 08:30 by MikaelS »

Ian @ un4seen

  • Administrator
  • Posts: 20433
Re: WASAPI, 96kHz file played in slow speed
« Reply #1 on: 1 Nov '17 - 16:27 »
Are you using the BASS_WASAPI_AUTOFORMAT flag in your BASS_WASAPI_Init call? If so, it may be that the output isn't actually using the sample rate that you requested (because the device doesn't support it). You can use BASS_WASAPI_GetInfo afterwards to confirm what the sample rate is.

MikaelS

  • Posts: 198
Re: WASAPI, 96kHz file played in slow speed
« Reply #2 on: 2 Nov '17 - 17:55 »
Thanks Ian.
I tried to remove the AUTOFORMAT flag, but that resulted in that I could not initialize BASSWasapi. I got a BASS_ERROR_FORMAT.

So, to simplify the question, is there any way I can play the 96kHz file in correct speed (via downsampling or such) ?

Ian @ un4seen

  • Administrator
  • Posts: 20433
Re: WASAPI, 96kHz file played in slow speed
« Reply #3 on: 2 Nov '17 - 18:05 »
Yes, you just need to create the mixer with the same rate as the WASAPI output (rather than the source file), by using the "freq" value from BASS_WASAPI_GetInfo in the BASS_Mixer_StreamCreate call (do the same with the "chans" value too).

MikaelS

  • Posts: 198
Re: WASAPI, 96kHz file played in slow speed
« Reply #4 on: 2 Nov '17 - 19:43 »
Thanks Ian.
I tried this but unfortunately the problem remains.
Freqs from BASS_WASAPI_GetInfo returned 44100, chans 2.

I injected this into the BASS_Mixer_StreamCreate call, but still the song is playing in slow speed. 
I'm a bit confused now :)

Ian @ un4seen

  • Administrator
  • Posts: 20433
Re: WASAPI, 96kHz file played in slow speed
« Reply #5 on: 3 Nov '17 - 16:53 »
Are you sure that is being done on the correct mixer, ie. the one that is feeding the output device? For comparison, please try playing the file with the pre-compiled CONTEST.EXE example included in the BASSWASAPI package (C\BIN folder) and see if you get the same problem with that. If your app is using shared mode then use the "-s" option with the CONTEST.EXE example for the same.

MikaelS

  • Posts: 198
Re: WASAPI, 96kHz file played in slow speed
« Reply #6 on: 6 Nov '17 - 09:08 »
Thanks for the reply and sorry for my delayed reply.

I have tested with the contest application and there the file is played in correct speed.
I will have to analyse my code again..

I assume that I need to init WASAPI to properly change frequency?

Ian @ un4seen

  • Administrator
  • Posts: 20433
Re: WASAPI, 96kHz file played in slow speed
« Reply #7 on: 6 Nov '17 - 17:06 »
I assume that I need to init WASAPI to properly change frequency?

I'm not entirely sure what you mean. If you're using shared mode WASAPI, it won't be possible to change the output device's sample rate. If you're referring to the audio file's sample rate changing, there is no need to reinitialize the WASAPI device or recreate the mixer then. You can just plug the new file into the same mixer.

MikaelS

  • Posts: 198
Re: WASAPI, 96kHz file played in slow speed
« Reply #8 on: 6 Nov '17 - 18:35 »
Quote
If you're using shared mode WASAPI, it won't be possible to change the output device's sample rate

Yes, that was what I ment. Sorry for being unclear and thanks for the help.