Scriptnode - halve frequency
-
Is there a way to halve the frequency of a realtime input or is this some DSP wizardry we'd have to do in SNEX @Christoph-Hart ?
-
I think you could use the math.mul and turn the knob to 0.5.
Or you could do this in snexvoid prepare(double sampleRate, int blockSize, int numChannels)
{}
void processFrame(block frame)
{
frame[0] = frame[0]*0.5;
frame[1] = frame[1]*0.5;
} -
that's the amplitude :)
-
@Christoph-Hart :) oops, durp he said "half the freq" lol
dont know what i was thinking.
well, if anyone wants to know how to turn down the volume... -
@giftlift yep, that's the amplitude :)
What I basically need is a Clock/Frequency Divider to output f/2.
Shouldn't be that much of a hustle, I already found some gen~ code to do that.History previousInput; History output; if (in1 > 0 && previousInput <= 0) { if (output) output = 0; else output = 1; } out1 = output; previousInput = in1;
-
@clumsybear Are you trying to cut your freq in half like 400Hz to 200Hz or do you want to slice the waveform like this?
this ↓ seems to double the freq but you have to put a hp filter after it or the freq will be offset like above
if i try frame[0]/frame[0] though, it crashes the oscillator and no sound will come out even if i change the code back, the oscillator has to be deleted and reloaded..
¯\__(ツ)_/¯ -
@giftlift said in Scriptnode - halve frequency:
Are you trying to cut your freq in half like 400Hz to 200Hz or do you want to slice the waveform like this?
Nice! :)
yes, that's one step of an octave down effect. It's basically full wave rectification, you can achieve this with the
math.abs
module in scriptnode as well. now to halve the frequency every 4th or 2nd halve of the rectified signal has to be phase inverted, that's what the clock divider function should do. It counts the zero crossings divides the value by two and flips the phase of every other halve wave. At least that's how I understood it -
@clumsybear I was playing around and made this script, you might be able to mod something from its output?
int count = 0.0; int aSig = 0.0; void countPeaks(int sIg) { //counting +peaks only if (sIg == 1)//you can change this to 0 { //but u got to put frame[0] = aSig + frame[0]; count += 1; } else{} if (count == 3)//divide peaks by # { count = 0.0; aSig = sIg; } else{aSig = 0.0;} } void processFrame(block frame) { countPeaks((int)frame[0]); frame[0] = aSig; }
-
Interesting, I’ll give it a try later. Thanks :) @giftlift
-
@giftlift the script causes HISE to crash while compiling the JIT module.
@Christoph-Hart any ideas why? I'm on the scriptnode branch from 7th Oct -
Yeah, there's something going on. It works on the one I built from oct 3rd. But it crashes the one from oct 23rd?
-
@giftlift said in Scriptnode - halve frequency:
But it crashes the one from oct 23rd?
Does it? I don't know, I'm on one of the branches from mid October.
I'll give it a try on an older branch though, can't wait to see if this works in SNEX.
The infrastructure for the octave down effect is pretty much set, it's just about the frequency divider to modulate the polarity of every other halve wave... -
Thanks guys, it was indeed a typo that I introduced while I was cleaning up code and remove warnings (I was wondering because I didn't touch the SNEX codebase for a few weeks except for that minor refactoring).
There was also something off with the Math constants so
Math.PI
will now work again. -
Great it's fixed, thanks @Christoph-Hart