:sound_in_stereo input not working

Hello there,

I am trying to use 2 microphones in sonic pi and there seems to be some kind of buffer or routing problem when I use:

synth :sound_in_stereo, input: 2

The problem is that I always get the audio from channel 1 but not always audio from channel 2.

Thats’s the case if I use>
live_loop :CH1 do
synth :sound_in_stereo, sustain: 120, input: 1, pan: -1
sleep(2)
end
live_loop :CH2 do
synth :sound_in_stereo, sustain: 120, input: 2, pan: 1
sleep(2)
end

If I comment input 1 like this :
live_loop :CH1 do
##| synth :sound_in_stereo, sustain: 120, input: 1, pan: -1
sleep(2)
end
##| end
live_loop :CH2 do
synth :sound_in_stereo, sustain: 120, input: 2, pan: 1
sleep(2)
end

I hear nothing. It is not a routing issue since I am sending this to my DAW and I can see clearly channels 1 and 2 receiving signal and more or less on the same levels.

I have also tried:

live_audio :ch1 do
synth :sound_in_stereo, sustain: 120, input: 1, pan: -1
end

live_audio :ch2 do
synth :sound_in_stereo, sustain: 120, input: 2, pan: 1
end

Same outcome. but also panner does not work anymore. channel 1 gets to both left and right and channel 2 is nowhere to be heard ( removing the sustain: 120 argument did not help either)

I think this second option would be the ideal setup as I want to use this in a 48 hour installation and use the mic input as control for other synths

Any tips on how to fix this or work within such a configuration is welcome.
Thanks in advance !
All the best !

Hi there,

I think you have a couple of issues with your code. First up, let’s look at the documentation for :sound_in_stereo:

"Treat sound card input as a synth. If your audio card has inputs, you may use this synth to feed the incoming audio into Sonic Pi. This synth will read in a stereo audio stream - for example from a stereo microphone or external stereo keyboard. See :sound_in for a similar synth capable of reading in a mono signal. The stereo input is expected to be on consecutive sound card channels.

Note that this means that you only need to use one synth for a stereo input.

Looking at the example:

live_loop :playback do
   synth :sound_in_stereo, sustain: 8
   sleep 8
end

Notice that the sustain: is 8 which matches the amount of sleep time. This is important as it means that the :sound_in_stereo synth will only last for 8 beats, and then a new one will be created immediately afterwards. In your code, you had a huge sustain: time which meant that each call to synth would last for 2 minutes and you were creating a new one every 2 seconds, so they would all start overlapping. You were also creating two different synths in two different live loops with different input: values to make things even more confusing.

With respect to your use of live_audio you’re calling it with a do/end block which doesn’t mean much. live_audio is a special kind of synth which needs a name and some options. It is intended to replace :sound_in_* in the case where you want a continuous input as this doesn’t need to be restarted within a live_loop and will continue to run and pipe any incoming audio to the surrounding context just like a standard synth.

Something like this would make sense for you:

live_audio :my_input, input: 1, stereo: true

Please do take a closer look at the built-in documentation for both live_audio and the sound_in_stereo synths. Hopefully the examples will get you going :slight_smile:

Hi Sam !

Thanks for the quick reply , unfortunately the documentation on multichannel input it’s useful for a different scenario I think.

As per your suggestion it is very helpful and appreciated, It does not do exactly what I need, which is discrete signals for channel 1 and 2 , so stereo: true will only give me a single stereo signal but not control over what’s going on with each signal. Following your suggestion I tried this and it seems to work:

live_audio :ch1, input: 1, pan: -1
live_audio :ch22, input: 2, pan: 1

Because I need to split those channels, as shown in the documentation example, I used the code like that originally, sorry my sonic pi skills are not great as I have not used it in a long time (I am also not too smart) but I am confident I can do what I need with this environment.

Next step for me is to route channels 1 and 2 separately to control other synths, so I am hoping I can use, for example, the amplitude of input one to modify some parameters on a different synth and input 2 to modify either other params of the same synth or a different synth all-together. I still need to test this, I think I remember doing something similar in the past, in any case I can now work out from the mono option you helped me sort out.

Again thanks so much for your feedback !
:heart: :heart: :heart:

Multi-channel input documantation example below:

" ## Multiple Inputs

You can select which audio input you want to play with the input: opt. You can also specify a stereo input (two consecutive inputs) using the :sound_in_stereo synth. For example, if you have a sound card with at least three inputs, you can treat the first two as a stereo stream and add distortion and the third as a mono stream and add reverb with the following code:

with_fx :distortion do
  synth :sound_in_stereo, sustain: 8, input: 1
end

with_fx :reverb do
  synth :sound_in, sustain: 8, input: 3
end
```"