Author Topic: C# Bass audio sample rate changes playback speed  (Read 517 times)

Zongo

  • Posts: 4
Hey all!

I currently have a small project for which I use ManagedBass. Actually it's pretty much done, only I have the problem that the sample rate of the audio files should always be at 44100Hz to play correctly, but most of my audio files are 48000Hz, which makes the songs play at a lower pitch and generally too slow. When the sample rate is below 44100Hz, it's the other way around (higher pitch, faster playback speed). I can't figure out why this is.

Here is a trimmed down portion of my code:

Code: [Select]
Bass.Init();

int h = Bass.CreateStream(FileName, 0, 0, BassFlags.Decode);

if (h == 0) return false;

int tStream = BassFx.TempoCreate(h, BassFlags.FxFreeSource);

if (tStream == 0) return false;
Handle = tStream;

Bass.ChannelPlay(Handle);


Ian @ un4seen

  • Administrator
  • Posts: 26172
Re: C# Bass audio sample rate changes playback speed
« Reply #1 on: 4 Aug '23 - 16:30 »
BASS will automatically convert the file's format to the output device's format during playback, so that it plays at the correct speed.

I notice you're using BASS_FX tempo processing. Perhaps you're changing the rate through that, eg. using the BASS_ATTRIB_TEMPO_FREQ option? Does it still sound wrong if you remove that stuff and just play the file directly?

Zongo

  • Posts: 4
Re: C# Bass audio sample rate changes playback speed
« Reply #2 on: 4 Aug '23 - 17:38 »
It doesn't fix the problem when I do it like so:

Code: [Select]
Bass.Init();

int h = Bass.CreateStream(FileName, 0, 0, BassFlags.Default);

Bass.ChannelPlay(h);

Ian @ un4seen

  • Administrator
  • Posts: 26172
Re: C# Bass audio sample rate changes playback speed
« Reply #3 on: 4 Aug '23 - 17:51 »
That's strange. For comparison, please try playing the same file with one of the pre-compiled examples included in the BASS package (C\BIN folder) and with non-BASS software (eg. Windows Media Player) on the same system. If the problem happens with BASS and not the other software, then please upload (or link) an affected file to have a look at here:

   ftp.un4seen.com/incoming/

Zongo

  • Posts: 4
Re: C# Bass audio sample rate changes playback speed
« Reply #4 on: 4 Aug '23 - 18:23 »
I don't know where I can find pre-compiled examples, but Windows Media Player, XMPlay and all other playback software I have play it correctly.

Here are the files + a demonstration video:
https://mega.nz/folder/ZwYQxADB#zXbBddvA40URTI2x4NQhug

Zongo

  • Posts: 4
Re: C# Bass audio sample rate changes playback speed
« Reply #5 on: 4 Aug '23 - 19:25 »
I found the problem. After creating a new .Net project it seemed to be fixed, then I looked very closely at my Load function and found that I was calling a function that set the frequency at the beginning of a song to 44100Hz. I use a modified version of the MediaPlayer class from ManagedBass, because the original had quite a lot of wrong stuff in it, including that. I have now removed the line and now it works. Well then, thanks for the answer, without it I would not have come to the idea to prepare a new project for demonstration ^^