Puzzling question about sqrt ~
Now I'v got it ..( I hope )
The line~ into sqrt does phase distortion
I compared it with ( cyclone ) kink~ (phasor into kink~) which adds a variabe breakpoint to the linear ramp of the phasor
First screenshot shows phasor into sqrt~(upper ) and lower phasor into kink~ .
Second screenshot shows both outputs (left sqrt,right kink ) multiplied and into separate cosines .
The cosine when driven by kink ~ is obviously played a higher pitches before the breakpoint ( steeper rise ) and a steady lower pitch .after that . ( when using mul*)
The sqrt ~ becasue of the conitinous rise has a fallen pitchbend
Always worked with phase disrtion to distort ramps into lookuptables , kind of asurprise its capable of pitchbend
looper overdubbing not lining up.....
Hey @whale-av and anyone else interested in this issue.
I'm still trying to wrap my head around this.
So this looper works if you loop one pass and play it. It works with overdubbing at speed = 1 or -1.. The problem is if you overdub at any speed other than 1 or -1.
I am going to explain the issue as I see it, although I may be mistaken. It is set up so the buffer length will not change after the first recording, so when overdubbing the buffer size doesn't change. If you doing playback at a speed other than 1 or -1 the speed of the phasor~ reading the array with the loop will change to that new speed. When you are done overdubbing, it would seem that the phasor~ should be at the same speed it was during the overdub, but if this is the case things get out of whack. At least that was my observation in the "simple3.pd" patch a few posts up.
I added an [expr] object to try and accomodate for what I was hearing. But now what is happening is it seems that the loop is getting shorter if it is less than 1 and it's too long if it's greater than 1.
I must be missing something obvious here.
I haven't tried this yet, but maybe I should add another phasor~ that is lined up to start with the first phasor~ playing the array, but when I alter playback speed this 2nd phasor will change as well and i can use that to start and stop the overdub process. What I am hearing is the overdub, when playing at speed = 2, will double in speed , then double in speed again during a recording. and the opposite is true for half speed. I think maybe a 2nd phasor can modulate to the new speed when an overdub is activated then take over reading the array when an overdub is finished. It's just an idea I had.
Anyway, any suggestions into this would be much appreciated.
Here is what I have now. simple6.pd
Thank you.
get phase of [osc~]
[phasor~]
|
[cos~]
should be the same as
[osc~]
but this time I need to measure the phase of [osc~]
and do the same as
with [osc~] instead of [phasor~].
I have a running patch, but sometimes it flips the phase by 180 degrees.
Do you know why or how to avoid that?
Here is the patch:
phase_of_normalized_cosine~.pd
The patch calculates the phase of a normalized cosine y(x) by
asin(y(x)) / (pi/2)
this is a triangle wave, following cosine's shape linearized.
Then a tri-to-saw waveshper:
invert the falling part of the triangle
and divide it's frequency by 2.
late EDIT: also read this: https://forum.pdpatchrepo.info/topic/15128/snapshotting-and-restoring-the-state-of-a-phasor-exactly
Signal logic - Clocks, Division and sequences
clock division and clock multiplication for a phaseaccumulator?
division is easy.
[*~ 4.]
[%~ 1.]
but multiplication is more or less impossible, as it would require something to count the current subcycle.
there are a workarounds though. if you want to use a phasor~ and a phasor~ which is 4 times slower, you could
a ) use multiple phasors~ from the beginning on and then select one of them
or, if you need them to be in sync with a "master phasor",
b ) use a phasor which is 8 times slower than the rated rate and derive the base speed phasor from it already using multiplication.
How to reset detuned pitch of a midifile?
I have some midifiles that send control change values that detune the pitch. The problem is if I load a new midifile the pitch is still detuned (until I restart the midi device). What I want to do, is to reset every cc setting when loading a new file (or at least - the detune setting).
https://www.recordingblogs.com/wiki/midi-controller-message
I already do reset cc 120,121 and 123 and it has some effect, but not for the pitch. I also tried without pitchbend information, but its still detuned.
Also tried the midi reset message: https://www.recordingblogs.com/wiki/midi-reset-message
But it only seems to work if send from a midi file (I play them from a [text] object).
Any idea which cc (or something else) setting to reset for a correct pitch?
Audio click occur when change start point and end point using |phasor~| and |tabread4~|
Hi Junzhe
I often like to think through something like this with a concrete example.
Let's start with 10 seconds of audio: phasor = 0 --> time 0, phasor = 1 --> time 10000 (ms).
Then, at 5000 ms, you change the end time to 7000 ms.
So, now, phasor = 0.5, time = 5000. And you need phasor = 1 now to map onto 7000 ms.
So two things need to happen:
- The phasor, running at its current speed, would reach its end 5000 ms later -- but you actually need it to reach the end in 2000 ms. So the phasor's speed has to increase by a factor of 5/2 = current_time_to_end / new_time_to_end.
- The linear mapping currently locates phasor = 1 at time = 10000, but now you need phasor = 1 --> time 7000. So the slope of the linear mapping will have to adjust by a factor of 2/5 = new_time_to_end / current_time_to_end (and the linear function's intercept would have to change too).
The changes in phasor frequency and linear slope should cancel out.
Then, at the start of the next cycle (which can be detected by [samphold~]), you would have to recalculate the slope for the entire start <--> end segment.
I might be overthinking it, but e.g. jameslo admits that in a simpler solution "the pitch is not steady as you adjust the start and end" so I think there aren't many shortcuts to be taken.
BTW there is another way to integrate a rate: rpole~. With an integrator, you don't have to worry about rejiggering slopes -- it just continues on its way, and reaches the end value in its own time. But, you would be responsible for triggering the reset at that point. This version uses control messages for triggering, so it would be quantized to block boundaries. To do it sample-accurately involves feedback and I never worked that out.
And a quick test patch (array "a" is 44100 samples, vertical range -10 to +50):
hjh
PS Hm, now I guess the [route float bang] isn't needed after all.
Best way to avoid clicks (tabread4~)
Amplitude modulation of any sort, including envelopes, always distorts the spectrum to some extent.
Normally we don't notice because typical sounds have a complex spectrum, which masks the distortion.
But here, you are applying it to an artificially simple spectrum, containing only DC offset. DC offset is silent, and the spectral distortion is not, so there is nothing to cover it.
I generated an audio file with a 30 ms ramp up and 50 ms ramp down. For comparison, I applied this envelope to a sine wave in the right channel. Then I opened this file in Audacity and looked at the spectrogram.
I think it's pretty easy to see here why the envelope might be audible in the case of DC * envelope, but not perceptible in the case of the audible signal * envelope.
Bottom line is, just because you hear spectral distortion in an artificial scenario which you would never encounter with audible signals, doesn't mean that it will be noticeable in real world scenarios.
(Carrying it further: If there is no envelope, there's a risk of an instantaneous transition from non-zero to zero or vice versa. Instantaneous transitions require a lot of high-frequency content, which we hear as a click. A linear transition effectively lowpass-filters the instantaneous transition -- there are still artifacts, but they are relatively low amplitude, and in a frequency range normally occupied by musical tones at a much higher amplitude. A ramp-enveloped sound will never be perfect, but it's better than a rectangular envelope.)
"replaced by something better" -- A sinusoidal envelope shows a smoother spectrogram. You might try that: cos * 0.5 + 0.5 -- from pi to 2pi is your ramp up, 0 to pi is the ramp down.
Edit: You can eliminate the +0.5 by squaring the cos and halving theta, because cos^2 x = cos(2x) * 0.5 + 0.5. Actually cos~, IIRC, scales radians down to 0 .. 1, so you could do line~ --> cos~ --> [*~] (cos~ to both inlets) and drive it by "0.25, 0.5 30" for the ramp up, and "0, 0.25 50" for the ramp down. Haven't verified this at the computer but I think it's right.
hjh
Resetting phase of Phasor~
@nuromantix Because the bang and float are at control rate, they are both processed between audio blocks. Therefore, [snapshot~] can only return the last sample of [phasor~] from the previous block, and the phase of [phasor~] is reset for first sample of the next block. So what you're getting in the snapshot is the last value of the phasor before it's reset to 0. (Try setting the phasor frequency to 44100/64, 44100/128, 44100/192... and see how things change)
s~/r~ throw~/catch~ latency and object creation order
For a topic on matrix mixers by @lacuna I created a patch with audio paths that included a s~/r~ hop as well as a throw~/catch~ hop, fully expecting each hop to contribute a 1 block delay. To my surprise, there was no delay. It reminded me of another topic where @seb-harmonik.ar had investigated how object creation order affects the tilde object sort order, which in turn determines whether there is a 1 block delay or not. Object creation order even appears to affect the minimum delay you can get with a delay line. So I decided to do a deep dive into a small example to try to understand it.
Here's my test patch: s~r~NoLatency.pd
The s~/r~ hop produces either a 64 sample delay, or none at all, depending on the order that the objects are created. Here's an example that combines both: s~r~DifferingLatencies.pd
That's pretty kooky! On the one hand, it's probably good practice to avoid invisible properties like object creation order to get a particular delay, just as one should avoid using control connection creation order to get a particular execution order and use triggers instead. On the other hand, if you're not considering object creation order, you can't know what delay you will get without measuring it because there's no explicit sort order control. Well...technically there is one and it's described in G05.execution.order, but it defeats the purpose of having a non-local signal connection because it requires a local signal connection. Freeze dried water: just add water.
To reduce the number of cases I had to test, I grouped the objects into 4 subsets and permuted their creation orders:
The order labeled in the diagram has no latency and is one that I just stumbled on, but I wanted to know what part of it is significant, so I tested all 24 permuations. (Methodology note: you can see the object creation order if you open the .pd file in a text editor. The lines that begin with "#X obj" list the objects in the order they were created.)
It appears that any time the phasor group is created before the r~, there is latency. Nothing else matters. Why would that be? To test if it's the whole audio chain feeding s~ that has to be created before, or only certain objects in that group, I took the first permutation with latency and cut/pasted [phasor~ 1] and [*~ 44100] in turn to push the object's creation order to the end. Only pushing [phasor~ 1] creation to the end made the delay go away, so maybe it's because that object is the head of the audio chain?
I also tested a few of these permutations using throw~/catch~ and got the same results. And I looked to see if connection creation order mattered but I couldn't find one that did and gave up after a while because there were too many cases to test.
So here's what I think is going on. Both [r~ next] and [phasor~ 1] are the heads of their respective locally connected audio chains which join at [-~]. Pd has to decide which chain to process first, and I assume that it has to choose the [phasor~ 1] chain in order for the data buffered by [s~ next] to be immediately available to [r~ next]. But why it should choose the [phasor~ 1] chain to go first if it's head is created later seems arbitrary to me. Can anyone confirm these observations and conjectures? Is this behavior documented anywhere? Can I count on this behavior moving forward? If so, what does good coding practice look like, when we want the delay and also when we don't?
looking for velvet noise generator
@porres oh yeah I always forget about [expr~]
for some reason.. maybe bc of the license it used to have.
There's no real reason to have the phase reset inlet, just more control.
From what I can tell, velvet noise is outputting a 1-sample impulse of value that's either 1 or -1, chosen randomly, at a random point in a regular period.
So I have a [phasor~]
to keep track of the period, and the [samphold~]
samples a random value from 0-1 when the [phasor~]
resets. This will be the point in the phase of that period that the impulse will occur. When the [phasor~]
gets to above or equal to this value, the [<~ ]
will go from 1 to 0. That goes into [rzero~ 1]
, which will put out a -1 on the sample that occurs. That goes into the [==~ -1]
, which acts (together with [*~ ]
) as a gate for the noise value that has been manipulated to either be 1 or -1, depending on if the output of [noise~]
is positive or not.
The issue with this original implementation was that when the [phasor~]
wraps around to start a new phase, it can wrap to a value greater than the new [samphold~]
value from the noise. That means that if the noise value is very small, there will be no impulse for that period since the [phasor~]
value will never be less than the sampled noise value for that period (and therefore the [<~ ]
won't go from 1 to 0, which means the [rzero~ 1]
below it won't output a -1, and so on). So, the [rzero~]
and [<~ 0]
put out a 1-sample value of 1 when the [phasor~]
wraps around, which is combined with the other signal in [min~ 1]
to take care of this. That way the [rzero~ 1]
below the [min~ 1]
will get a 1 even if the wrapped-around [phasor~]
value is less than the new sampled noise value, and there will be an impulse for that period.
(that is what "make sure there is at least 1 1 on wraparound" means)
edit: after writing all of this it occurred to me that the sampled noise value could also be greater than the value that the [phasor~]
will get to before it wraps around.. perhaps the solution is to constrain the sampled noise value depending on the frequency and phase of the [phasor~]
...