Can sonic-pi generate ultra or infra sound?

i just wonder if sonic-pi can generate ultra or infra sound with play

Hey @leonllrmc :slight_smile:
Take a look at the hz_to_midi function.
Note that by default, Sonic Pi doesn’t like playing MIDI notes that round down to 0 or less - so if you want to play frequencies less than ~ 9Hz, you will need to switch off the automatic safety checking system that normally prevents ‘unusual’ values for synth opts.
(Which in recent versions of Sonic Pi is in the main menu bar, (Audio > Safe Audio Mode) or the Preferences panel, (Audio > Synths and FX > Safe Mode).

thanks you but one more question I don’t use sonic-pi with a MIDI device but just a normal pc, it’s normal that hz_to_midi seam to not generate sound even with frequences in hearable range ?

hz_to_midi is just a method to convert Hz to the corresponding note number that represents that pitch in terms of MIDI notes (which are like numbering the keys on a piano) - it does not actually play the frequency - you call play or synth with the value that you get from hz_to_midi.
The following commands all play the same note:

play hz_to_midi(440)
sleep 1
play 69
sleep 1
play :a4

When using Sonic Pi, if you are able to hear other synths and samples through it, when using the hz_to_midi command in combination with play or synth and asking for frequencies within your particular hearing range, then you should hear them :slight_smile:

1 Like

Hi there @leonllrmc

Thanks for the interesting question! I’m pretty sure it can’t for at least three reasons:

Firstly, I’m pretty sure no standard sound system (sound card and speakers) are designed to produce audio at that frequency range. They will likely be limited to working within the human range of hearing.

Secondly, the internal audio rate of SuperCollider (which is linked to the sound card rate) will determine the highest frequencies that can be mathematically represented. This is usually 44.1k o 48k.

Finally, Sonic Pi itself constrains the frequencies with filters to not let anything out that’s above/below human hearing range. This is part of the safety system to ensure the audio is not too loud or can damage any equipment by being somehow out of range.

I hope that this helps.



Sorry for the red herring then @leonllrmc/everyone. I’ll double-check my understanding next time :joy:

1 Like