xplatform Why just a beep()

Share your advanced PureBasic knowledge/code with the community.
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

xplatform Why just a beep()

Post by collectordave »

Edited from Original:

After suggestions about create sound and a little more thought I asked myself 'Why Just A Beep?'

Many different sounds can be created with SoundEasy.pbi so reprogrammed to this:

Code: Select all

InitSound()

IncludeFile "SoundEasy.pbi"

Enumeration Warnings
  #Beep
EndEnumeration 


Procedure SoundWarning(Warning.i)
  
  Define CurrentSound.i
  
  InitSound()
  
  Select Warning
      
    Case #Beep

      CurrentSound = CreateSound(#PB_Any, 1000, 0.5) 

  EndSelect

  PlaySound(CurrentSound)

  
  While SoundStatus(CurrentSound) <> #PB_Sound_Stopped : Wend

  FreeSound(CurrentSound)

EndProcedure


SoundWarning(#Beep)

Delay(1000)
Imagination is the only limit here.

If anyone creates a sound with SoundEasy post here with the title for your sound and I can add to the code above.

We could end up with a whole library of sounds far exceeding the lowly beep.

collectordave
Last edited by collectordave on Mon Aug 12, 2019 6:31 am, edited 1 time in total.
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: xplatform Beep No API

Post by collectordave »

Just thought of something need to use freesound()

Modyfied code below:-

Code: Select all

Procedure Beep(Duration.i)
  
 ;Duration maximum 500 milliseconds 
 
InitSound()

CurrentSound = LoadSound(#PB_Any, "Beep.wav")

PlaySound(CurrentSound)

Delay(Duration)

FreeSound(CurrentSound)

EndProcedure

Beep(500)

Delay (300)

Beep(100)
CD
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
User avatar
blueb
Addict
Addict
Posts: 1041
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: xplatform Beep No API

Post by blueb »

Looks interesting Dave.

If you're looking for something that allows you to add
sounds to your programs without any external sound files
you might check out BasicallyPure's CreateSound() command in:
SoundEasy.pbi (appears to be cross platform)

viewtopic.php?p=405772#p405772
- It was too lonely at the top.

System : PB 6.10 Beta 9 (x64) and Win Pro 11 (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: xplatform Beep No API

Post by collectordave »

Rewritten with no external file.

Duration now in seconds.

Code: Select all

IncludeFile "SoundEasy.pbi"

Procedure Beep(Duration.f)
  
  Define CurrentSound.i
  
  InitSound()
  
  CurrentSound = CreateSound(#PB_Any, 1000, Duration) 

  PlaySound(CurrentSound)

  While SoundStatus(CurrentSound) <> #PB_Sound_Stopped : Wend

  FreeSound(CurrentSound)

EndProcedure

Beep(0.5)

Delay (1000)

Beep(1.5)
You now only need this and the soundeasy.pbi
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: xplatform Why just a beep()

Post by collectordave »

Original Post edited with new ideas.

If the code in the first post could be run in a thread it would also not block application running.

So:-

SoundWarning(#Beep) ;As a thread
Messagerequester()

Would be Ok.

CD
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
Post Reply