Skip to content

Commit

Permalink
Synths - update sound_in synth and add sound_in_stereo
Browse files Browse the repository at this point in the history
* Remove LPF from sound_in
* Create new synth sound_in_stereo which takes in
  two adjacent inputs
* Modify default env opts to have a sustain of 8
  and attack/release vals of 0
  • Loading branch information
samaaron committed Apr 10, 2016
1 parent c08472a commit ac3334b
Show file tree
Hide file tree
Showing 6 changed files with 362 additions and 134 deletions.
95 changes: 92 additions & 3 deletions app/server/sonicpi/lib/sonicpi/synths/synthinfo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2906,19 +2906,42 @@ def user_facing?
end
end

class SoundIn < StudioInfo
class SoundIn < SonicPiSynth
def name
"Sound In"
end

def introduced
Version.new(2,0,0)
Version.new(2,10,0)
end

def synth_name
"sound_in"
end

def doc
"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 single mono audio stream - for example from a standard microphone or guitar. See `:sound_in_stereo` for a similar synth capable of reading in a stereo signal.
As with all Sonic Pi synths, there is a default envelope which determines the duration of the lifetime of the synth. Therefore, to get a continuous stream of audio, you need to place consecutive calls to this synth in iteration or a `live_loop`. For example:
```
live_loop :playback do
```
```
synth :sound_in, sustain: 8
```
```
sleep 8
```
```
end
```
Note that if the microphone and speaker are close together (on a laptop or in a small room) you will potentially get a harsh feedback sound."
end

def arg_defaults
{
:amp => 1,
Expand All @@ -2929,12 +2952,77 @@ def arg_defaults
:pan_slide => 0,
:pan_slide_shape => 1,
:pan_slide_curve => 0,
:input => 0

:attack => 0,
:decay => 0,
:sustain => 1,
:release => 0,
:attack_level => 1,
:decay_level => :sustain_level,
:sustain_level => 1,
:env_curve => 0,

:input => 1
}
end

def specific_arg_info
{
:input =>
{
:doc => "Sound card input channel to obtain audio from. Indexing starts at 1 so input 1 represents the first channel, and channel 2 can be represented by `input: 2`",
:validations => [v_greater_than_oet(:input, 1)],
:modulatable => true,
}
}
end

end

class SoundInStereo < SoundIn
def name
"Sound In Stereo"
end

def synth_name
"sound_in_stereo"
end

def specific_arg_info
{
:input =>
{
:doc => "First of two consecutive sound card input channels to obtain audio from. Indexing starts at 1 so input 1 represents the first channel, and channel 2 can be represented by `input: 2`",
:validations => [v_greater_than_oet(:input, 1)],
:modulatable => true,
}
}
end

def doc
"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 stero 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 consectuive sound card channels.
As with all Sonic Pi synths, there is a default envelope which determines the duration of the lifetime of the synth. Therefore, to get a continuous stream of audio, you need to place consecutive calls to this synth in iteration or a `live_loop`. For example:
```
live_loop :playback do
```
```
synth :sound_in_stereo, sustain: 8
```
```
sleep 8
```
```
end
```
Note that if the microphone and speaker are close together (on a laptop or in a small room) you will potentially get a harsh feedback sound."
end
end


class BasicMonoPlayer < StudioInfo
Expand Down Expand Up @@ -6877,6 +6965,7 @@ class BaseInfo
:pluck => SynthPluck.new,

:sound_in => SoundIn.new,
:sound_in_stereo => SoundInStereo.new,
:noise => Noise.new,
:pnoise => PNoise.new,
:bnoise => BNoise.new,
Expand Down
Binary file modified etc/synthdefs/compiled/sonic-pi-sound_in.scsyndef
Binary file not shown.
Binary file not shown.
49 changes: 37 additions & 12 deletions etc/synthdefs/designs/sonic_pi/synths/studio.clj
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@
[out-buf 0 in_bus 0]
(disk-out out-buf (in in_bus 2)))


(defsynth sonic-pi-sound_in [amp 1
amp_slide 0
amp_slide_shape 1
Expand All @@ -132,34 +131,60 @@
pan_slide 0
pan_slide_shape 1
pan_slide_curve 0
attack 0.01
attack 0
decay 0
sustain 0
release 2
sustain 1
release 0
attack_level 1
decay_level -1
sustain_level 1
env_curve 1
cutoff 100
cutoff_slide 0
cutoff_slide_shape 1
cutoff_slide_curve 0

input 0
out_bus 0]
(let [decay_level (select:kr (= -1 decay_level) [decay_level sustain_level])
amp (varlag amp amp_slide amp_slide_curve amp_slide_shape)
pan (varlag pan pan_slide pan_slide_curve pan_slide_shape)
cutoff (varlag cutoff cutoff_slide cutoff_slide_curve cutoff_slide_shape)
cutoff-freq (midicps cutoff)
snd (sound-in input)
snd (lpf snd cutoff-freq)
env (env-gen:kr (core/shaped-adsr attack decay sustain release attack_level decay_level sustain_level env_curve) :action FREE)]
(out out_bus (pan2 (* env snd) pan amp)))))
(out out_bus (pan2 (* env snd) pan amp))))

(defsynth sonic-pi-sound_in_stereo [amp 1
amp_slide 0
amp_slide_shape 1
amp_slide_curve 0
pan 0
pan_slide 0
pan_slide_shape 1
pan_slide_curve 0
attack 0
decay 0
sustain 1
release 0
attack_level 1
decay_level -1
sustain_level 1
env_curve 1

input 0
out_bus 0]
(let [decay_level (select:kr (= -1 decay_level) [decay_level sustain_level])
amp (varlag amp amp_slide amp_slide_curve amp_slide_shape)
pan (varlag pan pan_slide pan_slide_curve pan_slide_shape)
snd-l (sound-in input)
snd-r (sound-in (+ input 1))
env (env-gen:kr (core/shaped-adsr attack decay sustain release attack_level decay_level sustain_level env_curve) :action FREE)
snd-l (* env snd-l)
snd-r (* env snd-r)
snd (balance2 snd-l snd-r pan amp)]

(out out_bus (pan2 (* env snd) pan amp))))
)


(comment
(core/save-synthdef sonic-pi-sound_in)
(core/save-synthdef sonic-pi-sound_in_stereo)
(core/save-synthdef sonic-pi-mixer)
(core/save-synthdef sonic-pi-basic_mixer)
(core/save-synthdef sonic-pi-recorder)))
Loading

0 comments on commit ac3334b

Please sign in to comment.