Applying multiple filters dynamically

5 views
Skip to first unread message

bo...@gmx.com

unread,
Apr 9, 2024, 6:20:37 AM4/9/24
to pyo-d...@googlegroups.com
Hi all, thanks for having me on this group. I am pretty new to pyo, and
to Python as well, so my question might have a very simple answer that I
cannot get on my own. In short, is it possible to dynamically apply
multiple filters to one playing sound file? A non-working example follows:
I would like to
load a source from an audio file,
apply the tone filter,
apply the pan filter,
start playing the file,
dynamically change parameters for both tone and pan, and hear them being
applyed to the audio file.
Qhat I guess is: every time I apply a filter I obtain a new object,
which has properties and methods according to its constructor. That's
why I can't modify both filters at the same time.

Here is my code:
from pyo import *

s = Server().boot()
s.start()

sound = SfPlayer("f:/sample.ogg", loop=True)

#Apply filters
sound = Tone(sound, freq=1000)
sound = Pan(sound, pan=0.1)

#start playing
sound.out()

#dynamically update filters function
def update_filters(tone_freq, pan_pos):
sound.setFreq(tone_freq) #this is the line where I get the
exception: 'Pan' object has no attribute 'setFreq'
sound.setPan(pan_pos)

#initialize filter parameters
initial_tone_freq = 1000
initial_pan_pos = 0.0


#Start updating cycle
while True:
initial_tone_freq += 100 #increase tone frequency
initial_pan_pos += 0.1 # modify pan position
if initial_pan_pos > 1.0:
initial_pan_pos = -1.0 # reset pan position

update_filters(initial_tone_freq, initial_pan_pos)

time.sleep(1)

Thanks for any help.
Luca

--
Questa email è stata esaminata alla ricerca di virus dal software antivirus Avast.
www.avast.com

Alexandros Drymonitis

unread,
Apr 9, 2024, 7:21:54 AM4/9/24
to pyo-d...@googlegroups.com
You shouldn't change the object that reads the sound file. You should
change the beginning of your code to:

```
sound = SfPlayer("f:/sample.ogg", loop=True)
tone = Tone(sound, freq=1000) # or give this object any name you want
pan = Pan(sound, pan=0.1).out()
```

The error message you get makes sense as you "sound" object is no longer
an object of the SfPlayer() or Tone() classes, but of Pan().

So, in your update_filters() function, call the setFreq() method for
tone instead of sound, and setPan() for pan instead of sound.

Olivier Bélanger

unread,
Apr 9, 2024, 8:11:33 PM4/9/24
to pyo-d...@googlegroups.com
Hi Luca,

You should never give the same name to more than one audio variable. These objects need to live for the whole duration of your process (unlike an integer that you compute, use, and discard), to generate the audio chunk that the sound driver will ask for continuously.

If you want to explore with some audio processor, I'd suggest starting with the GUI available for every audio object of pyo. Something like:

from pyo import *

s = Server().boot()

sf = SfPlayer(SNDS_PATH+"/transparent.aif", loop=True, mul=0.5)
lp = Tone(sf)
pan = SPan(lp, pan=0.1).out()

sf.ctrl()
lp.ctrl()
pan.ctrl()

s.gui(locals())

HTH,

Olivier

--
You received this message because you are subscribed to the Google Groups "pyo-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyo-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyo-discuss/7e3f7287-188f-4e48-ba8c-f6d164ce324a%40gmail.com.

bo...@gmx.com

unread,
Apr 10, 2024, 3:50:05 AM4/10/24
to pyo-d...@googlegroups.com
Hello, thank you for your reply. I have applied the hints you gave me,
however I could not manage to get both filters working and being updated
together.
In particular, the pan filter seems to prevail over the tone filter. If
I comment the pan line, then the tone filter gets applied.
How can I solve this?
Thanks,
Luca

bo...@gmx.com

unread,
Apr 10, 2024, 3:54:54 AM4/10/24
to pyo-d...@googlegroups.com
Hello, thank you. I had assumed that such filters as pan or tone were
just like methods to be applied to the same sound object, but that was
wrong.
Luca
> > www.avast.com <http://www.avast.com>
> >
>
> --
> You received this message because you are subscribed to the Google
> Groups "pyo-discuss" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to pyo-discuss...@googlegroups.com
> <mailto:pyo-discuss%2Bunsu...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pyo-discuss/7e3f7287-188f-4e48-ba8c-f6d164ce324a%40gmail.com <https://groups.google.com/d/msgid/pyo-discuss/7e3f7287-188f-4e48-ba8c-f6d164ce324a%40gmail.com>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "pyo-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to pyo-discuss...@googlegroups.com
> <mailto:pyo-discuss...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pyo-discuss/CAMXBGhTZCnRPF3PYm_7pzfGcgy7vOoUW940Tg3v5Vs6mxsV8HA%40mail.gmail.com <https://groups.google.com/d/msgid/pyo-discuss/CAMXBGhTZCnRPF3PYm_7pzfGcgy7vOoUW940Tg3v5Vs6mxsV8HA%40mail.gmail.com?utm_medium=email&utm_source=footer>.
Reply all
Reply to author
Forward
0 new messages