SoundLength Error

Just starting out? Need help? Post your questions and find answers here.
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

SoundLength Error

Post by chris319 »

I am successfully loading and playing a .wav sound file, yet I get a "division by zero" error when I call SoundLength().

What's going on?
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: SoundLength Error

Post by Mijikai »

What PB Version are you using?
A small runnable example would be nice.
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Re: SoundLength Error

Post by chris319 »

Version 5.73 LTS x64

Code: Select all

InitSound()

soundOpen = LoadSound(1, "D:\My Music\Beautiful Music\A Summer Place.wav")

If soundOpen <> 0: Debug "Sound opened OK": EndIf

Debug SoundLength(1)

FreeSound(1)
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: SoundLength Error

Post by kenmo »

Sounds like a bug in the SoundLength() function.

It would be useful to share the problematic WAV, if possible. Or even just the WAV header, as viewed in hex editor etc.

Probably whatever program wrote the WAV wrote invalid or incomplete header data, OR it's a variant of the WAV format which PureBasic doesn't support.

Either way: The PB function should fail gracefully (return 0 or -1?) not a hard crash attempting to divide by zero.
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Re: SoundLength Error

Post by chris319 »

Probably whatever program wrote the WAV wrote invalid or incomplete header data, OR it's a variant of the WAV format which PureBasic doesn't support.
That's pretty much it.

There are two types of WAVE FORMAT. Either one can be present in a .wav file. They are both 100% supported by Microsoft, not proprietary.

WAVEFORMATEX is the old, legacy format.

WAVEFORMATEXTENSIBLE is the new format which accommodates more than 2 channels and bit depths greater than 16 bits.

I had created my wav files using the new wave format at 24 bits, causing PB SoundLength() to fail.

I re-made the files as old-style, 16-bit files and the SoundLength() function worked OK.
Post Reply