What I am thinking of, is every time an audio signal completes a cycle, say zero to positive, positive pass zero to negative and back to zero, based on where the signal passes zero, then generates a sine wave that passes zero at the same spots. I don't care if it is a half cycle, or full cycle behind to achieve it, I think this is OK. The only thing I can think of is to count the samples every time it passes zero and generate a signal based on that, but I am not yet sure how to do this yet, but was wondering if there was an easier way, like maybe just sending a freq value to an OSC to change to the freq required.
So its not about reading the freq from the audio signal, its more just mimicking where it passes zero.
Replace any audio cycle with a sign wave object
How to do it depends on the kind of output you want and how advanced you want to go.
If you want to track well behaved repeating waveforms with only two zero crossings per period and possibly asymmetry in the half periods, you can count the half periods and generate sine half periods accordingly, although there will be some jitter in the output since only integer half periods are used. If the input waveform has multiple zero crossings per half period, this method doesn't work too well since the reconstructed waveform lags the input by one zero crossing. For an arbitrary source signal all bets are off.
The situation can be improved (again depending on what output you want) by pre filtering the source signal if you don't need to track more than two zero crossings per period. You can also simply take the sign of the source wave (as the matching square output) and low pass filter that to approximate a sine wave.
You could also measure the frequency of the fundamental, but then you will not be able to track asymmetry in the half periods or multiple zero crossing per half period, so again it depends on what kind of output you want.
I've attached an experimental patch with a simplistic embedded "sign_wave" object to play around with this based on the above techniques. It has some controls on the left hand side to let you play around with different source signals and enable pre filtering. The sign_wave object also has one control to control sine half period overshoot. The top row of oscilloscopes shows the various outputs, the bottom row shows the source signal. Regarding pre and post filtering; if the pitch control for the source signal is available you could use that to make the filters track the frequency of the source (can be done in the attached patch by connecting the pitch control to the filters pitch inputs).
Somebody else can probably give you a much more clever solution - this was just an experiment made because your posting made me curious.
test_sign_wave_embedded.axp (9.8 KB)
Thanks Dr J,
The way you describe it is certainly the original direction I thought the only solution was available, and I am very interested in testing it.
But I also had an odd epiphany about half hour ago, and I thought, can I just simply count the samples per crossing, divide that value by 48,000 and then that will give me the freq to send to an OSC to change to that freq. ? its morning here, so will have to wait till tonight to test it. I know it seams crude, but crude might be all I need.
Sure you can derive the approximate frequency from counting samples between zero crossings and just drive a sine oscillator with that. However, you'll then have that oscillator drifting in frequency relative to the input signal, there will be no fixed phase relationship and asymmetric half periods will not be part of it. If no direct relationship is needed you can count zero crossings for several periods and take an average to track frequency more precisely. From your OP I assumed that you wanted to track the source signal precisely, but I may have misunderstood.
There are also other more advanced methods you could use, such as an FFT for analysis of the source signal and reconstruction as a sine, although that'll use a lot of CPU power. You could also use the period counting method and use some clever curve fitting method to get a sine like output.
I think possibly my lack of experiences hinders the understanding I require to match my OP. First goal was to find a way to obtain a cleaner signal then the one coming from my bass guitar, this way I could possibly consider signal manipulation a little more relevant to a lot of the synth type analyzing that is often discussed on the forum. I know this might seem like I am just swapping one audio signal for a synth one, but there is a little more to it than that from what I am thinking, its more about having a signal that I can manipulate for possible potential triggers or re-shapes that may or may not interact with other audio sources etc, and so my thought was to have a signal in its most basic form to work with.
You are likely correct that I will require something more precise, but I am always open to crude methods as well as they provide some randomness, the ability to perceive a more natural outcome if possible.
I know it might seem long winded, and that could use things like freq detectors, or audio to midi converters and so on, but my goal is to not use these, come up with ideas a little different, and of course most importantly keep CPU usage on the Axo to a minimum.
Looking forward to trying out your patch..
Right, it helps to know the intended application. Browsing the object library I see that @SirSickSik has made a pitch tracking object using averaging of zero crossings, which you want to look at as well. I suppose both phase locked and free running solutions have their uses for experimenting with bass (or any input) analysis/processing/synthesis.
Thanks, I must have passed over it not realizing what it can do.
I am also starting to realize different ways of generating control variations just from counting samples at zero crossing..
More doors are opening today...
Don't forget to use a lowpass filter before trying to count the zero-crossings.
The cutoff frequency can be set pretty low, as you only need the zero crossings and even if you almost totally filter away the sound, it will always still move a bit around the zero. In some cases it's also useful to add a HP filter to remove possible DC-offset (also set at a fairly low cutoff frequency, 15-30 hz will be enough).
btw, another way to do this is by phase-lock-looping.
Use a comparator over the output of a sine oscillator and your original signal. Then put a lowpass filter over this comparator and use this to control the pitch of the sine oscillator (feedback path).
As long a the original signal is higher then the sine oscillator, it will increase it's frequency and vice versa. Thanks to the lowpass filter, the avaraged frequency/pitch outcome will end up being a integer division/multiplication of the original signal's frequency.
Thanks for tips @DrJustice & @SirSickSik, !!
I'm working on it.. The doorways a bit tight, but i'll get through it.. I hope..