[SOLVED] Loading audio into a table issues

Hello all!

I’m trying to load my audio into a table for later user. I’m using Director so I’m declaring my audio in my main.lua as a global for later use. I’m having issues where it sets the volume ACROSS THE BOARD instead of individually:

audioTable = {}  
  
local theFiles = {"SFX/echo\_affirm.wav","SFX/echo\_affirm1.wav","SFX/techy\_affirm.wav","SFX/techy\_affirm1.wav","SFX/chatter1.wav","SFX/chatter2.wav","SFX/chatter3.wav","SFX/chatter4.wav","SFX/chatter5.wav" }  
  
for i=1,#theFiles do  
 audioTable[i] = audio.loadSound(theFiles[i])  
end  
  
battleMusic = audio.loadStream( "SFX/ShadowsApproach.mp3" )  
battleMusicChannel = audio.play( battleMusic, { channel=1, loops=-1 } )   
audio.setVolume( 0.00, { battleMusicChannel } ) -- set the volume on channel 1  
  
altMusic1 = audio.loadStream( "SFX/TheJourney\_noDrums.mp3" )  
altMusic1Channel = audio.play( altMusic1, { channel=2, loops=-1 } )   
audio.setVolume( 0.00, { altMusic1Channel } ) -- set the volume on channel 1  
  
altMusic2 = audio.loadStream( "SFX/Wishful\_noDrums.mp3" )  
altMusic2Channel = audio.play( altMusic2, { channel=3, loops=-1 } )   
audio.setVolume( 0.00, { altMusic2Channel } ) -- set the volume on channel 1  

and then in one of my later screens I’m doing:

 local tempValue = mRand(5,9)  
 local tempChannel = audio.play(audioTable[tempValue])  
 audio.setVolume( 1.00, { tempChannel } ) -- set the volume on channel 1  
 tutorialCount = tutorialCount + 1  
 audio.fade({ channel=battleMusicChannel, time=1000, volume=0.0 } )  
 audio.fade({ channel=altMusic2Channel, time=5000, volume=0.35 } )  

But all I end up getting is EVERYTHING, ALL OF MY SOUNDS played back at full volume, none of the fading took place, etc. Works fine with just my music files (the loadStreams) but not my wav’s (the loadSounds).

How are others handling multiple sound effects? You can’t tell me that EVRYONE is naming EVERY last sound effect individually…are you?! Just trying to be efficient here.

Hope someone can point me in the right direction!

-Mario
[import]uid: 11636 topic_id: 26590 reply_id: 326590[/import]

The call to audio.setVolume is wrong. I think it needs to be either:
audio.setVolume( 1.0, tempChannel )
or
audio.setVolume( 1.0, {channel=tempChannel} )
[import]uid: 7563 topic_id: 26590 reply_id: 107855[/import]

Thanks Mr. Wing! It works just as you said.

NO:

audio.setVolume( 1.0, tempChannel )  

YES:

audio.setVolume( 1.0, {channel=tempChannel} )  

So for the final chunk that loads sounds into a table and then a function to play 'em randomly:

randomChatterTable = {}  
  
local randomChatter = {"SFX/chatter1.wav","SFX/chatter2.wav","SFX/chatter3.wav","SFX/chatter4.wav","SFX/chatter5.wav" }  
  
for i=1,#randomChatter do  
 randomChatterTable[i] = audio.loadSound(randomChatter[i])  
end  
   
function playChatter()  
 local passedNumber = math.random(1,5)  
 print("Random sfx received....."..passedNumber)  
 local tempChannel = audio.play(randomChatterTable[passedNumber])  
 audio.setVolume( 1.0, {channel=tempChannel} )  
end  

Of course, you’ll have to manage your filenames etc. to suit your needs, but this is pretty handy I think.

Thanks again! [import]uid: 11636 topic_id: 26590 reply_id: 107895[/import]