#1
|
|||
|
|||
Fade in and fade out an audio file
Hi all,
I would like to create a spatial sound atmosphere. I made a script (very rudimentary) in which whenever the user turns the head 20 degrees, hears a different file (therefore I have 18 audio files in the scene, played simultaneously; one with volume =1, and the rest with volume = 0) Is there a way to made a fade out of the previous file and fade in of the new one in an overlapping sector of 10 degrees: 0-10 degrees: file 1 volume 1 (rest volume 0) 10-20: file 1 fade out, file 2 fade in (rest volume 0) 20-30: file 2 volume 1 (rest volume 0) 30-40: file 2 fade out, file 3 fade in (rest volume 0).... Maybe a way of changing the volume gradually in these junction circular sector regarding the position of the head? Thanks in advance |
#2
|
|||
|
|||
I forgot to say that the user will be in a fixed position within the scene, and will only have the possibility of turning 360 degrees in this fixed position without displacements.
|
#3
|
|||
|
|||
You could use the head tracker euler values to trigger custom events. There isn't built in sound fading so you would have to write a simple sound fader that reduces volume over a small period of time.
|
#4
|
|||
|
|||
In this case the sound shouldn't fade over time, but rather over a number of degrees. So you could write a fader that decreases the volume of file1 with 0.1 with every degree over 10 (until volume is 0), etc.
|
#5
|
|||
|
|||
Quote:
Any idea of how to write a fader that decreases the volume? Is there any tool with which it can be done? I am new in Vizard and I have no idea on how to make it in a simple way... |
#6
|
|||
|
|||
You could use vizact.onupdate to register a function that's called every frame. In that function, get the viewpoint orientation and based on that value play and fade audio files. Here's an example:
Code:
#0-10 degrees: play file 1 #10-20: fade out file 1, fade in file 2 #30-40: fade out file 2, fade in file 3 #50-60: fade out file 3, fade in file 4... import viz import vizact viz.go() viz.addChild('piazza.osgb') intervals = [0,10,30,50] audioFiles = ['bells.wav','fountain.wav','conversation.wav','birds.wav'] #create a list of audio objects, set to loop mode audioList = [] for file in audioFiles: audio = viz.addAudio(file) audio.loop() audioList.append(audio) def fadeAudio(): yaw = viz.MainView.getEuler()[0] print yaw for index,interval in enumerate(intervals): if interval < yaw <= interval + 10: # if first iteration only play first audio file if index == 0: if audioList[0].getState() in [viz.MEDIA_STOPPED,viz.MEDIA_PAUSED]: audioList[0].play() # for all others play next file and apply fades else: if audioList[index].getState() in [viz.MEDIA_STOPPED,viz.MEDIA_PAUSED]: audioList[index].play() audioList[index].volume(0) fadeInValue = (yaw-interval)/10 fadeOutValue = 1.0-fadeInValue audioList[index].volume(fadeInValue) audioList[index-1].volume(fadeOutValue) # pause audio if volume is close to 0 if fadeOutValue < 0.01 and audioList[index-1].getState() == viz.MEDIA_RUNNING: audioList[index-1].pause() vizact.onupdate(0,fadeAudio) #Spin the view to 60 degrees at 2 degrees/s. spinAction = vizact.spinto(0,1,0,60,2) viz.MainView.runAction(spinAction) Last edited by Jeff; 05-31-2016 at 06:27 AM. |
Thread Tools | |
Display Modes | Rate This Thread |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
cinematic fade to black? | billjarrold | Vizard | 4 | 12-23-2009 12:09 PM |