Problems with some type of WAVE files on MacOS?

Mac OSX specific forum
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2056
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Problems with some type of WAVE files on MacOS?

Post by Andre »

Hi friends,

I used several sound effects for my project from free resources on the internet.
While all is running fine on Windows, I noticed problems with some WAVE files on MacOS.

With this PB example code:

Code: Select all

If InitSound() = 0
  MessageRequester("Error", "Sound system is not available",  0)
  End
EndIf

SoundFileName$ = OpenFileRequester("Choose a .wav file", "", "Wave files|*.wav",0)
If SoundFileName$
  If LoadSound(5, SoundFileName$)
    PlaySound(5);, #PB_Sound_Loop)
    MessageRequester("Sound", "Playing the sound (loop)..."+#LF$+"Click to quit..", 0)
  Else
    MessageRequester("Error", "Can't load the sound.", 0)
  EndIf
EndIf
End   
I get an invalid memory-access error at the call of LoadSound(), when trying to load/play the WAVE file from this resources:
http://soundbible.com/1964-Small-Crowd-Applause.html (SMALL_CROWD_APPLAUSE-Yannick_Lemieux-1268806408.wav)
(interesting is, that with activated #PB_Sound_Loop flag this memory access error isn't occurring, but a "wrong" sounding effect is playing then...)

This one also don't sound correctly (but don't crash with the memory access error):
Laugh - Kid_Laugh-Mike_Koenig-1673908713.wav / http://soundbible.com/2026-Kid-Laugh.html

Anyone knows more about incompatibilities with WAV sound loading on MacOS?
If so, can you suggest some (free) tools for converting into a 'right' format (specific WAV type?) which is playing well on Windows and MacOS?

Btw. other sound files are working well on MacOS, like this one:
Applause2 - Applause-SoundBible.com-151138312.wav / http://soundbible.com/988-Applause.html
Cheer - 5_Sec_Crowd_Cheer-Mike_Koenig-1562033255.wav / http://soundbible.com/1700-5-Sec-Crowd-Cheer.html
Doing - NFF-doing.wav / http://www.noiseforfun.com/2012-sound-effects/doing/
Frog - NFF-frog.wav / http://www.noiseforfun.com/2012-sound-effects/frog/
Honest - NFF-honest.wav / http://www.noiseforfun.com/2012-sound-effects/honest/
TickTock - Tick Tock-SoundBible.com-1165545065.wav / http://soundbible.com/1258-Tick-Tock.html
Wrong - NFF-wrong-02.wav / http://www.noiseforfun.com/2012-sound-effects/wrong-02/
Yay - 1_person_cheering-Jett_Rifkin-1851518140.wav / http://soundbible.com/2103-1-Person-Cheering.html

Thank you for any help! :D
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
Wolfram
Enthusiast
Enthusiast
Posts: 567
Joined: Thu May 30, 2013 4:39 pm

Re: Problems with some type of WAVE files on MacOS?

Post by Wolfram »

I copied the samples into a new wave file, but it is still crashing here on OSX 10.7 and PB 5.42.
macOS Catalina 10.15.7
User avatar
robertfern
User
User
Posts: 23
Joined: Fri Feb 02, 2018 10:33 pm
Location: New Jersey

Re: Problems with some type of WAVE files on MacOS?

Post by robertfern »

The Mac version of PB can't be more than 16bit 44.1khz audio
The sample sound file you showed is 24bit at 48Khz.

You need to convert it!

or you could use cocoamessage() to play all sound files Mac can handle

Sorry.
Mac OSX Ventura & Windows 10, PB 6.04
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2056
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: Problems with some type of WAVE files on MacOS?

Post by Andre »

Thank you both for testing and the hint, Robert!
So I have an idea, what to try next... :)

But as it seems to be a PB limitation, also Fred should take a look.
Either something at the PB implementation of LoadSound() / PlaySound() can be improved, or there must be added a note about it in the MacOS docs...
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Problems with some type of WAVE files on MacOS?

Post by Shardik »

The PureBasic documentation for the sound library states that Windows is utilizing DirectX and Linux SDL (unfortunately nothing is stated for MacOS although I presume that MacOS also utilizes SDL):
[color=#0040FF]PureBasic documentation for sound library[/color] wrote:Overview

The PureBasic sound system provides an easy way to have sound inside application or game. It uses special functions to get the maximum speed of available hardware. It uses DirectX on Windows. On Linux, it requires the SDL library.
If MacOS is indeed utilizing the SDL library for sound functions, the problem with André's WAV files seems to be that they are 24 bit samples which are not supported by SDL as you may see in their list of possible audio format values.

By the way: to see the parameters of a WAV file on MacOS you may load the WAV file into the QuickTime player and list the WAV file infos by clicking in the menu on "Fenster" (english: Window) and then selecting "Filminformationen einblenden" (english: list video informations).

Using the MacOS Cocoa function NSSound you may also play 24 bit WAV files as demonstrated in the following example code which I have tested successfully on these systems:
- MacOS 10.6.8 'Snow Leopard' with PB 5.46 x86 in both ASCII and Unicode mode and with PB 5.62 x86
- MacOS 10.13.4 'Sierra' with PB 5.62 x86 and x64

You may even click on both buttons in rapid succession and mix both sounds. Before trying the example code you have to modify the path to both WAV files:

Code: Select all

EnableExplicit

Define SelectedGadget.I

Dim Filename.S(1)

Filename(0) = "/FilePathTo/Small_Crowd_Applause-Yannick_Lemieux-1268806408.wav"
Filename(1) = "/FilePathTo/Kid_Laugh-Mike_Koenig-1673908713.wav"

Procedure PlaySoundFile(Filename.S)
  Protected Sound.I

  If FileSize(Filename) > 0
    ; ----- Load sound
    Sound = CocoaMessage(0, CocoaMessage(0, 0, "NSSound alloc"),
      "initWithContentsOfFile:$", @Filename, "byReference:", #YES)

    If Sound
      ; ----- Play sound
      CocoaMessage(0, Sound, "play")
    EndIf
  EndIf
EndProcedure

OpenWindow(0, 270, 100, 200, 70, "Play sound file")
ButtonGadget(0, 10, 10, WindowWidth(0) - 20, 25, "Small crowd applause")
ButtonGadget(1, 10, 40, WindowWidth(0) - 20, 25, "Kid laugh")

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      SelectedGadget = EventGadget()

      If SelectedGadget <= 1
        PlaySoundFile(Filename(SelectedGadget))
      EndIf
  EndSelect
ForEver
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2056
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: Problems with some type of WAVE files on MacOS?

Post by Andre »

@Shardik: Thank you very much, for the additional informations and the example code (workaround)! :D

I'm not on MacOS right now to test it, but the solution seems to be easy enough, so that Fred could switch also natively (for the Sound lib) to such MacOS system commands... or isn't it that easy? :wink:
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Problems with some type of WAVE files on MacOS?

Post by Shardik »

Andre wrote:I'm not on MacOS right now to test it, but the solution seems to be easy enough, so that Fred could switch also natively (for the Sound lib) to such MacOS system commands... or isn't it that easy? :wink:
Unfortunately it isn't that easy. If you take a look into the command index of PureBasic's sound library you will see that it contains 17 functions which would have to be implemented in PureBasic to be usable cross-platform. So it would be much easier to use my workaround or to simply convert the few (somehow exotic) 24 bit sound samples into 16 bit samples... :wink:
Fred
Administrator
Administrator
Posts: 16617
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Problems with some type of WAVE files on MacOS?

Post by Fred »

PB uses CoreAudio directly on OS X with a custom mixer, that's why it's not very flexible. Some more info should be added on the doc to tells which formats are supported.
User avatar
Piero
Enthusiast
Enthusiast
Posts: 281
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Problems with some type of WAVE files on MacOS?

Post by Piero »

I had all kind of problems with sounds...
Now (PB 6.02) I strangely must avoid sounds from some audio editing apps, even if I save with the right Khz etc.
Anyway exporting from Ocenaudio or Audacity works well

This also may help (to include sound data directly into your PB app):
viewtopic.php?p=596189#p596189
User avatar
Piero
Enthusiast
Enthusiast
Posts: 281
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Problems with some type of WAVE files on MacOS?

Post by Piero »

...hope this also may help:
These Applescripts (saved as apps) will create copies of dropped files in ogg or wav format via Terminal (ffmpeg must be installed)

Code: Select all

-- audio/video to ogg

on open tf
	tell application "Terminal" to activate
	repeat with i in tf
		tell application "Terminal" to do script "ffmpeg -i " & quoted form of POSIX path of i & " " & quoted form of (((characters 1 thru -((offset of "." in (the reverse of (characters of (POSIX path of i))) as text) + 1) of (POSIX path of i)) as text) & "_pbo.ogg")
	end repeat
end open

Code: Select all

-- audio/video to PB wav

on open tf
	tell application "Terminal" to activate
	repeat with i in tf
		tell application "Terminal" to do script "ffmpeg -i " & quoted form of POSIX path of i & "  -c:a pcm_s16le -ar 44100 " & quoted form of (((characters 1 thru -((offset of "." in (the reverse of (characters of (POSIX path of i))) as text) + 1) of (POSIX path of i)) as text) & "_pbw.wav")
	end repeat
end open
Post Reply