WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 05-20-2016, 01:02 PM
helena35 helena35 is offline
Member
 
Join Date: May 2016
Posts: 8
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
Reply With Quote
  #2  
Old 05-20-2016, 01:19 PM
helena35 helena35 is offline
Member
 
Join Date: May 2016
Posts: 8
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.
Reply With Quote
  #3  
Old 05-23-2016, 10:29 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
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.
Reply With Quote
  #4  
Old 05-24-2016, 03:09 AM
Erikvdb Erikvdb is offline
Member
 
Join Date: May 2013
Posts: 63
Quote:
Originally Posted by Jeff View Post
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.
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.
Reply With Quote
  #5  
Old 05-29-2016, 02:57 PM
helena35 helena35 is offline
Member
 
Join Date: May 2016
Posts: 8
Quote:
Originally Posted by Erikvdb View Post
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.
Thanks both for your answers...

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...
Reply With Quote
  #6  
Old 05-30-2016, 06:04 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
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 05:27 AM.
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
cinematic fade to black? billjarrold Vizard 4 12-23-2009 11:09 AM


All times are GMT -7. The time now is 03:30 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC