Page 1 of 1

Accurate Waveform-cycle Display

Posted: Thu Nov 26, 2015 6:42 pm
by tulamide
I know I'm asking for much, but I don't see any light at the end of the tunnel:

For Martin's awesome SWM-Sine Oscillator (from this thread) I would like to have a display of the waveform, so that any change to SWM is visible to the user. I don't need help regarding the displaying itself, but I have no clue how to get the correct data from the osc. Here are the requirements:

-Data should only be given out on a green trigger, to prevent contiguous cpu-load while active.
-The data should also be given out when no sound is playing.
-It needs to be the exact data needed to display exactly one cycle of the waveform, from beginning to end (not starting inbetween)

There's no size requirement; I can always map to 256 pixels, or 128 or whatever. The scope doesn't help me, because it just displays what is coming in.
My read is that it is somehow related to a frequency against the samplerate to get the right spot for the start of the data. But since there is no data if nothing is playing, I wouldn't know how to solve this.

Is someone able to help me finding a solution that meets the three points mentioned above?

Re: Accurate Waveform-cycle Display

Posted: Thu Nov 26, 2015 6:53 pm
by adamszabo
You mean like this? :)

Re: Accurate Waveform-cycle Display

Posted: Thu Nov 26, 2015 7:51 pm
by tulamide
Thank you so much for the quick answer! Unfortunately I have a lot of questions, and I can only hope you don't mind :oops:

It only works with an extra oscillator?
And how does it work exactly?
You seem to have calculated a frequency (how did you do it?) and I guess that a constant green float value forces the osc to stay active all time?
Would a selector switch activate and de-activate the oscillator, so that I can use it when needing to redraw, but keep it from cpu-usage when no redrawing is needed?

Re: Accurate Waveform-cycle Display

Posted: Thu Nov 26, 2015 11:05 pm
by martinvicanek
tulamide, the key is the analyzer prim. It will make the connected stream moduke run NS times and then stop. No wasted CPU. It is a very handy prim.

Re: Accurate Waveform-cycle Display

Posted: Thu Nov 26, 2015 11:53 pm
by tulamide
martinvicanek wrote:tulamide, the key is the analyzer prim. It will make the connected stream moduke run NS times and then stop. No wasted CPU. It is a very handy prim.

Thanks a lot, Martin! I didn't know that it works this way. Indeed very handy.

Now the only thing left is the calculation of the frequency. I don't mean the conversion from Hz to 0-1 or vice-versa, but how to calculate the actual value? Why is 0.008 something the correct value? It should be around 180 Hz which means 180 sample points per second. NS is at 256 sample points. I'm obviously missing something, just don't know what.

EDIT: Of course I meant 180 cycles, not sample points^^

EDIT 2: OH STUPID ME! Sample rate divided by the number of sample points = frequency to use :oops:

Re: Accurate Waveform-cycle Display

Posted: Fri Nov 27, 2015 3:57 am
by RJHollins
Thanks tulamide !

That made it clearer for me :mrgreen:

Re: Accurate Waveform-cycle Display

Posted: Fri Nov 27, 2015 11:25 am
by adamszabo
tulamide wrote:Now the only thing left is the calculation of the frequency.


Actually I just connected the float and changed the values until 1 cycle of waveform was displayed... nothing scientific lol. But what you wrote with the sample rate division should be the scientific answer.

Re: Accurate Waveform-cycle Display

Posted: Fri Nov 27, 2015 1:26 pm
by tulamide
adamszabo wrote:But what you wrote with the sample rate division should be the scientific answer.


I'm not sure if this is what people mean by "time domain", but at a sample rate of, for example, 44100, exactly 44100 sample points are used to play 1 second of sound.
So 256 sample points are just representing 0.0058s, which is the 1/172.265625th part of a second (you get this when dividing 44100 by 256).
So which frequency oscillates 172.265625 times per second? 172.265625 Hz, of course.