--------------------------- --------------------------- -- Tutorial: Sound engine. Test 1 -- Starting up the sound engine. -- -- Copyright (c) 2006-2008 Capricorn 76 Pty. Ltd. --------------------------- --------------------------- --------------------------- --------------------------- -- PROGRAM STARTS HERE --------------------------- --------------------------- --------------------------- -- Initialise the sound engine, ask it to detect the sound driver --------------------------- local soundInitialised = ISound:init( 'AUTO_DETECT_SOUND', -- Instead of using hard-coded strings, we could IApp:load('constantsSoundDrivers.e76script') and use the pre-defined constants. 20, -- Frame rate for sound updating (how many times a sec the 3D position is updated when viewing a 3D scene) 0, -- Thread priority. The sound engine runs in a different thread to the graphics engine. This controls its thread priority level compared to other threads in the system. false); -- Silent errors are off, so ScriptENGINE will raise an error is something's not right if (soundInitialised) then --------------------------- -- Open the console, so we can communicate with user --------------------------- IApp:showConsoleWindow(); print('Sound engine intialised:', ISound:getCurrentDriverName()); --------------------------- -- Sleep for 5 seconds --------------------------- IApp:sleep(5000); --------------------------- -- Close the engine, the window will close, and the program will terminate --------------------------- ISound:destroy(); end
--------------------------- --------------------------- -- Tutorial: Sound engine. Test 2 -- Starting up the sound engine, loading and playing a sound -- -- Copyright (c) 2006-2008 Capricorn 76 Pty. Ltd. --------------------------- --------------------------- --------------------------- --------------------------- -- PROGRAM STARTS HERE --------------------------- --------------------------- --------------------------- -- Initialise the sound engine, ask it to detect the sound driver --------------------------- local soundInitialised = ISound:init( 'AUTO_DETECT_SOUND', -- Instead of using hard-coded strings, we could IApp:load('constantsSoundDrivers.e76script') and use the pre-defined constants. 20, -- Frame rate for sound updating (how many times a sec the 3D position is updated when viewing a 3D scene) 0, -- Thread priority. The sound engine runs in a different thread to the graphics engine. This controls its thread priority level compared to other threads in the system. false); -- Silent errors are off, so ScriptENGINE will raise an error is something's not right if (soundInitialised) then --------------------------- -- Open the console, so we can communicate with user --------------------------- IApp:showConsoleWindow(); print('Sound engine intialised:', ISound:getCurrentDriverName()); --------------------------- -- Load and play sound --------------------------- local soundId = ISound:load('testSound', 'sfx.wav'); if (soundId) then --------------------------- -- Play sound --------------------------- ISound:setLooping(soundId, true); -- Turn on looping, sound will keep on looping till we stop it, or close down the engine ISound:play(soundId); -- This is not a streamed sound, so we don't have to worry about the streaming parameters --------------------------- -- Sleep for 5 seconds --------------------------- IApp:sleep(3000); end --------------------------- -- Close the engine, the window will close, and the program will terminate --------------------------- ISound:destroy(); end
--------------------------- --------------------------- -- Tutorial: Sound engine. Test 3 -- Starting up the sound engine, loading and playing a 3D sound while moving it -- -- Copyright (c) 2006-2008 Capricorn 76 Pty. Ltd. --------------------------- --------------------------- --------------------------- --------------------------- -- PROGRAM STARTS HERE --------------------------- --------------------------- IApp:loadScript(IApp:getExeFilePath() .. './Constants/constantsSoundDrivers.e76script'); --------------------------- -- Initialise the sound engine, ask it to detect the sound driver --------------------------- local soundInitialised = ISound:init( 'AUTO_DETECT_SOUND', -- Instead of using hard-coded strings, we could IApp:load('constantsSoundDrivers.e76script') and use the pre-defined constants. 20, -- Frame rate for sound updating (how many times a sec the 3D position is updated when viewing a 3D scene) 0, -- Thread priority. The sound engine runs in a different thread to the graphics engine. This controls its thread priority level compared to other threads in the system. false); -- Silent errors are off, so ScriptENGINE will raise an error is something's not right if (soundInitialised) then --------------------------- -- Open the console, so we can communicate with user --------------------------- IApp:showConsoleWindow(); --------------------------- -- Setup the 3D distance model. -- We want the -- (more info about distance models can be found in OpenAL's documentation.) --------------------------- ISound:setDistanceModel(SOUND_DISTANCE_INVERSE_CLAMPED); print('Sound engine intialised:', ISound:getCurrentDriverName()); --------------------------- -- Load and play sound --------------------------- local soundId = ISound:load('testSound', 'sfx3d.wav'); if (soundId) then --------------------------- -- Play sound --------------------------- ISound:setLooping(soundId, true); -- Turn on looping, sound will keep on looping till we stop it, or close down the engine ISound:setPosition(soundId, '0 0 -50'); ISound:setReferenceDistance(1); -- The min distance at which the sound will get no louder ISound:setMaxDistance(100); -- The max distance at which the sound cannot be heard ISound:setRolloffFactor(soundId, 0.1); -- The rolloff factor affect the attentuation applied to a 3D sound as the distance changes from the listener ISound:play(soundId); -- This is not a streamed sound, so we don't have to worry about the streaming parameters --------------------------- -- Go into a loop moving the sound's 3D position. -- We could create a periodic thread that runs in the background, moving the position of the sound. -- If we also had the graphics engine running, we could subscribe to the subscribeTickPeriodic event. --------------------------- local i; for i = -50, 50 do ISound:setPosition(soundId, IMisc:vectorCreate(0, 0, i)); IApp:sleep(200); print('Sound position:', i); end end --------------------------- -- Close the engine, the window will close, and the program will terminate --------------------------- ISound:destroy(); end
Copyright © 2006-23 Sep 2009 Capricorn 76 Pty. Ltd. (created on Wed Sep 23 16:49:12 2009)