Data Sonification. My guess.

9 views
Skip to first unread message

Gabriele Battaglia

unread,
Mar 18, 2024, 11:15:19 AM3/18/24
to pyo-d...@googlegroups.com

Hello all.

Days ago I asked about using pyo to sonify a numeric serie of data.


Just to exercise on pyo, I come out with this thing but it doesn't produce any sound... LOL

Yeah, I know I have a long way still ahead.


Could someone could tell me why it does not work?


The basic idea is to have a simplest python module to import and to pass a list with numbers to sonify.

It doesn't care to have notes played, for my porpous a sweeping sine could do the job.


Here is my code.


***

def sonify2(data=[], totalduration=10.0):
 # Sonify2 a serie of data, V3.0, march 18th, 2024
 # data= values list to sonify
 # float totalduration= duration of whole sonification in seconds
 # it plays sound and returns nothing
 totalduration=float(totalduration)
 datalength = len(data)
 if datalength < 2:
  print("Data serie too short.")
  return
 from pyo import Server, SigTo, Sine, Pan
 s=Server(verbosity=1).boot()
 s.start()
 singlesoundduration=totalduration/datalength
 soundlowerlimit=130.0 # C3
 soundupperlimit=4186.0 # C8
 soundrange=soundupperlimit - soundlowerlimit
 datarange = max(data) - min(data)
 startsound=soundlowerlimit + soundrange/2
 slide=SigTo(init=startsound, value=startsound, time=singlesoundduration)
 sound=Sine(freq=slide, mul=.35)
 stereo=SigTo(init=0.0, value=1.0, time=totalduration)
 p=Pan(sound, pan=stereo).out()
 for j in data:
  x = (j-min(data)) * 100/datarange
  y = x/100*soundrange
  slide.value=soundlowerlimit + y
 s.stop()
 s.shutdown()
 return

Alexandros Drymonitis

unread,
Mar 18, 2024, 12:08:07 PM3/18/24
to pyo-d...@googlegroups.com
With a quick glimpse, it looks like you're not keeping your function alive. In Pyo, in general you want all PyoObjects in the global scope, so they are not garbage collected once your function exits. 

--
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/125f68c5-2a9b-49c1-a0ae-40f8ee36d6f1%40libero.it.

Gabriele Battaglia

unread,
Mar 19, 2024, 4:32:52 AM3/19/24
to pyo-d...@googlegroups.com

Il 18/03/2024 17:07, Alexandros Drymonitis ha scritto:
> With a quick glimpse, it looks like you're not keeping your function
> alive. In Pyo, in general you want all PyoObjects in the global scope,
> so they are not garbage collected once your function exits.

Ok Alexandros, I'll try to pass it to a thread, so I can listen to the
sonification while function returns to main program.

I've never used threads so I must try to undestand how they works.

Thanks for your help.


Gabe.

Reply all
Reply to author
Forward
0 new messages