To simplify things, I consolidated a couple of scripts that I used in that demo and here is the code:
-- sound handles
sndFire = -1;
sndBirds = {};
sndAmbient = -1;
local firstTime = 1;
function auplayer_init(e)
ocAUCreate();
sndFire = ocAULoadSound("audiobank/other/fire.wav");
ocAUSetSoundRange(sndFire, 50.0, 500.0);
sndAmbient = ocAULoadSound("audiobank/atmospheric/Desert.wav");
ocAUSetSound2D(sndAmbient);
ocAUSetSoundVolume(sndAmbient, 25.0);
for i=1,8,1 do
sndBirds[i] = ocAULoadSound("audiobank/other/bird" .. i .. ".wav");
ocAUSetSoundRange(sndBirds[i], 50.0, 750.0);
end
end
function auplayer_main(e)
if firstTime == 1 then
ocAUSetSoundPosition(sndFire, g_Entity[e]['x'], g_Entity[e]['y'], g_Entity[e]['z']);
ocAULoopSound(sndFire);
ocAULoopSound(sndAmbient);
firstTime = 0;
end
-- Update player listener position
ocAUSetListenerPosition(g_PlayerPosX, g_PlayerPosY, g_PlayerPosZ);
ocAUSetListenerAngle(g_PlayerAngY);
-- every few seconds randomize a bird sound
if GetTimer(e) > 3000 then
if math.random(100) < 40 then
idx = math.random(1,8);
ocAUSetSoundPosition(sndBirds[idx], math.random(300,500) + g_PlayerPosX, math.random(300,500) + g_PlayerPosY, math.random(300,500) + g_PlayerPosZ);
ocAUPlaySound(sndBirds[idx]);
end
StartTimer(e);
end
end
function auplayer_exit(e)
ocAUDestroy();
end
I attached this script to the firepit entity and set Physics Always On.
System Specs: OS - Windows 7 Home Premium 64-bit SP1, CPU - AMD Phenom II X4 945, 3.0Ghz, RAM - 8Gb DDR3, GFX Card - 2048MB NVIDIA GeForce GT 640, FPSC-R Version - Beta 1.0085