First time here? Check out the FAQ!
x

How do I encapsulate an Oscillators Frequency parameter with arithmetic so it can still evaluate at sample rate?

0 votes
707 views

The updated Oscillators and AntialiasedOscillator can now take a Sound in the Frequency parameter which can vary the frequency at audio rate. Yay!

Imagine I've created a Sound that has two oscillators in it that are detuned. (Actually you don't need to imagine, that's what I did. To be honest I did it with 5 it being near Christmas and all). So one oscillator in its Frequency parameter has:

!Frequency

and the second one has

!Frequency * (1 + !Detune)

 

Now I want to encapsulate my detuned stereo oscillator. For the first oscillator I can replace its Frequency parameter with:

?Frequency

and in the Class builder specify that field as HotFrequencyOrSound, which means I'll be able to modulate the frequency at audio rates.

But the second oscillator's Frequency parameter has me scratching my head. What do I replace its Frequency parameter with so I can modulate it at audio rates? I could paste in a Product Sound, but what would the inputs to the Product be? A pair of CapyTalkToSounds with ?Frequency and ?Detune in their Value parameters would sample at control rate. Likewise with a Constant, I'm assuming.

 

asked Dec 21, 2018 in Using Kyma by alan-jackson (Virtuoso) (15,840 points)

2 Answers

+2 votes
 
Best answer

If you would like ?Frequency to behave similarly to the Oscillator's Frequency field, you could use a SelectableSound to choose either a Variable or a CapytalkToSound depending on the value of ?Frequency:

answered Dec 23, 2018 by ssc (Savant) (127,060 points)
selected Dec 13, 2019 by alan-jackson
woah, cool, yes that's what I was trying to do.

"?Frequency isSound", ah-hah!
I'm guessing you have to put a formula to convert the capytalk frequency in Hz to +/- 1  in the (?Frequency hz hzToSignal) constant, so that if capytalk is used in the encapsulated item field it can be in big numbers??
Hi Pete, the Capytalk message
hzToSignal
converts from [0, SR/2] to [0,1] so if you use ?Frequency hz hzToSignal, your ranges should be correct.
SelectableSound can change which input is selected at runtime.

Is there any advantage to using a Script instead with something like:

(inputs at: (?Frequency isSound ifTrue: [2] ifFalse: [1]))
    start: 0

Would that prevent the unchosen path being compiled and save some DSP? Or do the unchosen paths into the SelectableSound get optimised away because the expression in the Selection parameter is Smalltalk and not Capytalk?
Yes, SelectableSound optimizes away the extra path when your Selector is a constant.
0 votes
Assuming the Detune is not changing at audio rate, you could create a VariableSound called Frequency and feed it to a ScaleAndOffset with Scale = 1 and Offset = ?Detune hz hzToSignal
answered Dec 21, 2018 by ssc (Savant) (127,060 points)

If I make my Frequency as a VariableSound and set the parameter as a HotFrequencyOrSound when I encapsulate it I can only get it to work if I paste a Sound into that parameter. If I type anything into the parameter I can't seem to find anything that will make it give an audible frequency.

 

The pre-encapsulated Sound:

 

When I use the encapsulated Sound I can get it to work if I use a pasted Sound in the Frequency parameter:

 

 

But I can't get it to work if I use CapyTalk:

in fact in this example the !FreqVCS EventValue won't appear on the VCS.

Right, the idea was to paste the ScaleAndOffset set in the Frequency field (in other words, the VariableSound feeds into a ScaleAndOffset which is then pasted into the Frequency field).
Yes. I did that in the first example and that worked. But with a HotFrequencyOrSound parameter wouldn't I also be able to write a CapyTalk expression into that field too? I couldn't get the CapyTalk to work.
Hi Alan, when you have hot parameter fields that have the sample rate option, it is an either or field. that is if you use capytalk in the field (including pasted sounds with L or R written after them which also only work at capytalk rate) or you paste the sound into the field and remove the L or R which make that field act as if it were a sample rate sound input in which case you cannot have capytalk as well. In your example above with !Frequency you have made the field capytalk only and not sample rate, so what ever you do while encapsulating it will remain capytalk rate and needs to be set up that way. If you want sample rate control it needs a sample rate sound pasted in the field with no L or R and with no capytalk stuff in that field. You could Paste a sound like scale and offset but put capytalk into the scale and offsets hot parameter fields, but you would still need something that is at sample rate (another sound) feeding into the scale and offset. So if you put a variable sound (with the big question mark)  into the scale and offset and encapsulated with this as a sound field then in your final sound you could have a sample rate sound as the sample rate control and the parameters in the scale and offset and the capytalk adjustments to that sound. Don't forget that sample rate sounds are limited to +/- 1 where as capytalk isn't so you may need to scale up and down before encapsulating to make both the capytalk and the sample rate stuff work together. I hope this makes sense.
Further to the above. I think what you are asking for is to promote the two type field  (I call the field that can be both, a roasting parameter fields because they are hotter than hot parameter field), up to the encapsulated sound so that the field in the encapsulated sound can act as either one depending on what the user types into that sound. I don't think that is possible but may be worth adding to the SSC wish list.
Hi Pete, yes that's what I'm trying to do, have a two-type field on my encapsulated class. There is a field-type called HotFrequencyOrSound. If I use a Variable Sound as the input to the ScaleAndOffset like you suggest, then when I encapsulate it I can paste a Sound in the new (roasting) Frequency parameter of my encapsulated Sound, and it kind of works. It makes a noise.  But if I then try and type in some capytalk into the roasting parameter, instead of pasting a Sound, like I did in the example above with "!FreqVCS" I can't get it to do anything.

Do I need to do some kind of test in my pre-encapsulated Sound to detect whether a Sound or some CapyTalk are being passed in?
...