It is currently Sun Jul 22, 2018 9:33 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Problems with some type of WAVE files on MacOS?
PostPosted: Mon Apr 02, 2018 10:17 am 
Offline
PureBasic Team
PureBasic Team
User avatar

Joined: Fri Apr 25, 2003 6:14 pm
Posts: 1562
Location: Germany (Saxony, Deutscheinsiedel)
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:
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)


Top
 Profile  
Reply with quote  
 Post subject: Re: Problems with some type of WAVE files on MacOS?
PostPosted: Mon Apr 02, 2018 1:07 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu May 30, 2013 4:39 pm
Posts: 384
I copied the samples into a new wave file, but it is still crashing here on OSX 10.7 and PB 5.42.


Top
 Profile  
Reply with quote  
 Post subject: Re: Problems with some type of WAVE files on MacOS?
PostPosted: Mon Apr 02, 2018 8:34 pm 
Offline
New User
New User
User avatar

Joined: Fri Feb 02, 2018 10:33 pm
Posts: 7
Location: New Jersey
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 Sierra 10.12.6 & Windows 7, PB 4.62


Top
 Profile  
Reply with quote  
 Post subject: Re: Problems with some type of WAVE files on MacOS?
PostPosted: Mon Apr 02, 2018 9:29 pm 
Offline
PureBasic Team
PureBasic Team
User avatar

Joined: Fri Apr 25, 2003 6:14 pm
Posts: 1562
Location: Germany (Saxony, Deutscheinsiedel)
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)


Top
 Profile  
Reply with quote  
 Post subject: Re: Problems with some type of WAVE files on MacOS?
PostPosted: Wed Apr 04, 2018 9:51 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1519
Location: Germany
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):
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:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Problems with some type of WAVE files on MacOS?
PostPosted: Wed Apr 04, 2018 11:10 pm 
Offline
PureBasic Team
PureBasic Team
User avatar

Joined: Fri Apr 25, 2003 6:14 pm
Posts: 1562
Location: Germany (Saxony, Deutscheinsiedel)
@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)


Top
 Profile  
Reply with quote  
 Post subject: Re: Problems with some type of WAVE files on MacOS?
PostPosted: Thu Apr 05, 2018 8:03 am 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1519
Location: Germany
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:


Top
 Profile  
Reply with quote  
 Post subject: Re: Problems with some type of WAVE files on MacOS?
PostPosted: Thu Apr 05, 2018 8:41 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13330
Location: France
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.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye