I am making an audio based sketch for a live performance. I would like to control the volume of my audio device in using python. so that I can fade it in based on some other events. However I can’t work out how to turn the volume down via python.
I have discovered there is no volume property for the audio device in.
I thought I could multiply it with a constant and alter the constant value with python - but I keep getting errors and from what I can see on the forum, it seems I can’t easily change the value of a chop channel.
Hopefully there is a really obvious easy way that I am missing.
Reply to myself already as I have realised I should be able to use the audio dynamics chop to set the level. I’ve just tried it and it works. I’m still curious about other ways to do this if there are suggestions or standard methods
To modify the values of the Audio Device In CHOP, use a Math CHOP and it’s Multiply parameter to lower or increase the volume of the sound. Make sure to toggle on the Interp Pars Per Sample parameter on the “OP” page.
Generally controlling these with python directly is discouraged and you would do so with other CHOP channel values or references to values.
How is your project setup?
For a general introduction to CHOPs, check out our curriculum at
which gives a good understanding of the underlying concepts of TouchDesigner.
There is a whole section on CHOPs which might be of particular interest to you.
I’m making a a performance where I am using media pipe so that if I am not smiling enough my volume mixes down and a heap of samples about smiling are triggered instead. The sample trigger keeps speeding up until a smile is detected again.
I’m calculating the smile percentage with a chop execute on the face track op from within media pipe so that I can calculate no smile at all, partial smile (where my performance sound starts to fade in) and full smile (all my sound). It’s within the partial smile range that I will be fading my volume out and as I’m detecting the percentage of smile with python (and as I have a programming background it seemed easier to just do it in python). I’m also setting general volumes - switching things off and on based on the smile variable in python.
Can you explain why it would be not advisable to use python for volume control?I feel like for this set up it is so much easier for me to just do it by typing. I’m using the audio dynamics (and yeah totally forgot about using a math multiply for this - too long staring at the screen ) - I guess it’s quite a bit heavier than just using a math, which would be a reason to use math instead.
setting parameters continously from within scripts hides the information flow and the processing. Besides CHOPs being optimized for processing such data and python being a bit slow, it also allows for easier further manipulation like filtering or as in your case simple control of parameters.
Are you using the mouthSmile channels from the face track component? A setup with CHOPs for me would be to calculate the average with a Math CHOP by selecing “Average” option from the Combine Channels parameter. Then pass it all through a Filter CHOP to remove some of the jitter and export it from here to the Math CHOP which controls the audios amplitude.
As these channels are all in the 0-1 range, they can be reranged to a 0-2 range for using them with a Fan CHOP to retrieve states (neutral, slight, and full for example) These new channels can again be used to control animations or with the help of Trigger CHOPs start playbacks etc.
In the end though - if things work the way that you have build them and it is perfomant enough, then it’s a proper solution
Hi
I had assumed python would be the faster option and I’m using it to have if statements. I didn’t know about using the fan chop in that way so I’ll check it out next time I want to work with conditionals.
thanks
Is there any way to be more specific about how the fan chop divides the incoming chop?
For example - I have another project I am working on where I am using the length of the audio track to set the scene length. Then I am using the fraction of the audio chop to set off timers to fade in specific elements.
I had been doing this in Python, assuming it was the most efficient way. I’m looking to switch it to using chops now as it’s a large project and I would like to optimise it wherever I can.
My script was like this - using a chop exec on the fraction channel from an info chop
def onValueChange(channel, sampleIndex, val, prev):
#the fraction of the music length, rounded to 2 decimal places
audioFraction = op('select2')['fraction']
roundednum = round(audioFraction, 2)
#timer one - switching the colour of the ice particles
# t1colswitch = op('timer1').par.start
# t1initialise = op('timer1').par.initialize
if roundednum == 0.00:
op('timer1').par.initialize.pulse()
op('timer2').par.initialize.pulse()
op('timer3').par.initialize.pulse()
if roundednum == 0.20:
op('timer1').par.start.pulse()
if roundednum == 0.33:
op('timer2').par.start.pulse()
if roundednum == 0.55:
op('timer3').par.start.pulse()
print(roundednum)
return
So, if possible I would like to keep this timing…
The only way I can think of to do this is to use the math to increase the amount of channels in the fan to 100 so I can use fine percentages - or something more reasonable eg - 10 channels. Is there a better method?
For now I am using multiple fans to only fan out the values I need. The first fan has 10 channels, then I am fanning the third channel into three so I can get 33% and the fifth channel fans into two so I can get 55%. Perhaps this is a good way to do it but I’m still curious if there are any better methods
for your particular task, there might be a better solution when using a Math CHOP. The idea behind this is that any value <=0 is interpreted as off while any value >0 is considered on. For you this would mean that subtracting the threshold values for each Timer CHOP start could be subtracted from the fraction channel and then passed to the individual Timer CHOP’s “start” input.
To initialize the Timer CHOPs you can make use of the Logic CHOP with it’s Channel Pre OP parameter’s “Falling Edge” option. The result of which will be a pulse when the fraction channel goes from a higher to a lower value.
Attached is a little example
cheers
Markus base_timer.tox (2.0 KB)