Sound Engine

Simple Sound Engine for Windows

At the moment Red  has no sound, so for the Apps in my Red Apps section I had to improvise ....
I called the Rebol interpreter from within my Red exe to handle sound effects etc ....

This was not an ideal way to do it and though it worked ok, it was a bit messy .... 
So I needed to think of an easier, simpler way to handle sound until Red gets its own ....
There's been talk of bindings, but I personally have not found one that works yet ....
By using 'Call' from your Red program there are a few ways to do it ....  Calling Poweshell(Media.Soundplayer) .... Or calling a VBS script .... but all are a bit of a wrangle to use .... For example, You call powershell that runs soundplayer that plays an .mp3 file and 
then you need to kill powershell, so taskKill.exe is needed .... so not ideal ....

'sndEngine.exe' is my way of adding sound to Red exe's with the minimal of fuss ....
Nothing fancy here, just a very simple way to play .mp3 files .... 

Once compiled, the script below will play/stop a background wav file ....
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Red [ title: "Test Sound Engine" Author: "Alan Brack" needs: view ]
#include %system/library/call/call.red
view [ title: "Test Sound Effect Engine"
       button "Play Sound" [call "start /min sndengine.exe" write %flag.dat "sound"]
       button "Stop Sound" [write %flag.dat "stop"]      
     ] 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;    
 
;;;; Important Notes:
;;;; Script needs to be compiled for it to run ;;;;  
;;;; The'system folder' from the 'Red_master.zip' must be in your Red script folder for compilation ;;;;
   

Here's how to play sound effects ....
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Red [ title: "Test Sound Engine" Author: "Alan Brack" needs: view ]
#include %system/library/call/call.red
view [ title: "Test Sound Effect Engine"
       below
       text font-color red "Play two Sound Effects"       
       button "Play Sound Effect 1" [call "start /min sndengine.exe" write %flag.dat "effect1"]
       button "Play Sound Effect 2" [call "start /min sndengine.exe" write %flag.dat "effect2"]     
     ] 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Play music and sound effects together ....
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Red [ title: "Test Sound Engine" Author: "Alan B" needs: view ]
#include %system/library/call/call.red
view [ title: "Test Sound Effect Engine"
       below
       text font-color red "Buttons to Play two Sound Effects"       
       button "Play Sound Effect 1" [call "start /min sndengine.exe" write %flag.dat "effect1"]
       button "Play Sound Effect 2" [call "start /min sndengine.exe" write %flag.dat "effect2"]
       text font-color red "Buttons to Play Music and Stop Music"
       across
       button "Play Sound" [call "start /min sndengine.exe" write %flag.dat "sound"]
       button "Stop Sound" [write %flag.dat "stop"]      
     ] 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Will only play .mp3 files .... and only one music wav and two sound effects can be used per script ....
your music file should be re-named to 'go_sound1.mp3'  and copied to your red script folder  ....
your sound effects files should be re-named to 'go_effect1.mp3' and 'go_effect2.mp3' and copied to your folder ....
Make sure the 'sndEngine.exe' is also in your folder and thats it .... The scripts above show you how ....

Here's  my 'sndEngine.exe' and a couple of demo's .... mySoundEngine

Note:
The Windows shell is called to run the 'sndEngine.exe', so you get a slight flicker of the cmd window .... 
To eliminate this completely, do this: 
From within your program folder, hold the shift key and right click, then from the
menu choose 'Open Command Wndow Here'  In the cmd window, right click on the top title bar and choose 'Properties',
then click the 'Colours' tab and change the Opacity slider to minimum (30%) .... Now  'OK' the change .... 
Close the cmd window from the bottom task bar .... Now no flicker ....