custom tone generator help

Greetings all =)
I’m stuck on a problem and could use some help. Basically what I’m trying to do is “generate a constant frequency tone” of a specific duration ( 10 minutes ) same as the built-in tone generator does but with a custom waveform.

The outline of my process so far is: create a single cycle waveform in “arbexpress” and export to csv. Edit csv in excel to single column point values and save as txt file. Import to audacity using the “sample data import” dialogue. This is all working good. Should explain why I want to use audacity: The final output needs to be 16 bit pcm 44100 wav file which audacity does perfectly.

So this is where I’m stuck. I’ve done a little research on the nyquist commands and tried with no luck. From what little I’ve discovered I’m supposed to use the “maketable” command to convert my single cycle waveform to a wavetable? Don’t understand where this “wavetable” goes? Is a file created or does it go to memory?

Example:
(setf mytable (maketable mywav))
(hzosc 10 [mytable 0])

Judging by the debug output I’m missing a few steps. The code seems simple, but doesn’t work, Also don’t know what command would be used to designate the duration of the created waveform?

Any help from the big brains out there would be greatly appreciated by me and anyone else out there tyring to do the same thing =)

thanks

BTW - before you tell me to read and memorize the entire nyquist manual; please keep in mind that this is one part of a bigger project I’m working on and don’t have a couple months to learn a new language =)

changing the shape of one cycle of the waveform can have little effect on the sound heard, see … https://forum.audacityteam.org/t/is-there-any-way-to-remove-this-warning-from-the-draw-tool/47219/4

If there is a formula for your “custom waveform”, try this “ExpressionGenerator.ny” plugin …https://forum.audacityteam.org/t/expression-generator/45227/1

Thanks for the reply and for stating the obvious =) No, I do not know the equation of these custom waveforms. If I did I wouldn’t have asked the question.

Sorry if the first post wasn’t completely clear. I thought that nyquist would allow me to take a small single cycle wave sample and make a wavetable and create a constant tone wave at a specific frequency and duration. Can I not do this inside audacity? I was trying to follow this thread: http://forum.audacityteam.org/viewtopic.php?f=46&t=92179&start=10
but instead of a generated wave and midi osc, I thought I could use maketable and hzosc? It sure seems like it should be possible. Should I have posted this in the nyquist thread?

Probably the best place, so I’ve moved the topic.

This is the relevant post in that thread: waveform designer for music - #20 by steve

So you’ve got a single cycle of the waveform that you want in a mono audio track. Is that correct?

Please export the track as “32-bit float WAV” and post the file here (use the “Upload attachment” tab below the message composing box), then we’ll take it from there.

To export as “32-bit float WAV”:
“File menu > Export > Export Audio”
then select “Other uncompressed files”
then set “Header” to “WAV (Microsoft)”
and set “Encoding” to “32-bit float”

So you’ve got a single cycle of the waveform that you want in a mono audio track. Is that correct?

Yes; I don’t think I’m painting a very good picture of what I want to try to do. What I’m after is an audio based arbitrary waveform generator. Audacity has the tone generator that can output a wav file of sine, square, sawtooth, and square-no alias at a chosen frequency and duration. This is what I need, but with custom arbitrary waveforms. So from what I’ve read, this seems like nyquist should be able to “sample” my single cycle wav with the maketable function and make a wavetable from it? Then with the hzosc function, output a wav file of this wavetable at chosen frequency and duration? Just like the tone generator.

I was able to recreate the example in the above mentioned thread. Didn’t know I needed to use the nyquist generator prompt. Don’t even know what I don’t know - ha ha. My problem is I’m not very good at writing code and know absolutely nothing about nyquist. Don’t know the proper syntax and commands. I did find this: http://audacity.238276.n2.nabble.com/Wavetables-in-Audacity-td238594.html which seems to describe maketable and sampling, but I don’t understand it =( Should also mention that I’m not a math professor. So yes, I do not know the formulas for these waveforms. If I did, I could use any number of programs including audacity to make the wav files.

So am I to load my single cycle into a track then use the nyquist generate prompt to make a wavetable from it?

I have attached a rar file of the single cycle wav (2048 points) and the txt file it was made from. It wasn’t made perfect but will do for a test. This particular waveform could possibly be recreated with the pwl function, but others may not. That’s why I would like to try to do it this way

Thanks for any and all interest, help, and feedback =)
modsquare.rar (9.58 KB)

No need to RAR the files. Both TXT and WAV files may be uploaded to the forum.

I don’t think you’ve said what you are trying to do, but the final 10 values in your data look peculiar. All the other values show a slope of close to 0.000299 amplitude per sample, except for the final 10 samples, when there is a sudden jump from -0.901377197 to -0.9, followed by 9 values at -0.900000000. Is that intentional? If not, it is likely to have a significantly adverse effect on other measurements.

If the aim is to create a waveform that rises in linear fashion from 0.595183546 to 0.901077201 over a period of time, and then from -0.598393437 to 0.900000000 over an equal period of time, then a better (more accurate) way to achieve that is with a Nyquist “piecewise linear approximation”.

(pwlv 0.595183546 0.5 0.901077201 0.5 -0.598393437 1 -0.900000000)

Here’s a couple of plug-ins that you may find useful. Open them in a text editor and read the notes near the top of the file for information about what they do and how to use them.
If you have further questions, feel free to ask, but please be forthcoming about the “big picture” of what you are trying to do. The better we understand what you are trying to do, the better we can help.
cycletone.ny (958 Bytes)
arbitrarywaveform.ny (2 KB)

Yes, Thank you! The arbitrarywaveform.ny is what I was trying to describe (not well I guess =). Have a couple ?'s about it:
How would I mod the code to output any frequency I choose down to 2 or 3 decimal points (i.e. 7.84 or 7.845) instead of musical note value frequencies?
How would I change the duration from seconds to minutes (it’s a small thing, I could do that math; just wondering)?
Also, I think you hinted that my point table was too big. Would 512 sample points give a better result? I guess I don’t understand the interpolation algorithm because at higher frequencies the sample points are reduced quite a bit? Not too worried about that though; my project is using elf waves anyway. Was just thinking that higher resolution is always better

Thanks very much!!!

You want “Hz” rather than “Note” values?
To modify the “;control” line: Missing features - Audacity Support
To convert Hz to Step: Nyquist Functions

Modify the control line to say “minutes” rather than seconds,
then add a line to multiply the duration by 60

(setf duration (* duration 60.0))



No, I’m saying that the last 10 samples in your table may be wrong.

A waveform with a sudden jump has high frequency components even if the fundamental frequency is extremely low.

Is “aliasing” important?
If it’s not important, then piecewise linear approximation would be much simpler and more accurate than your current method of creating the waveform in other software, importing a list of sample values for wavetable synthesis.
On the other hand. if aliasing will mess up “the big picture”, then wavetable synthesis may be the better option, but you need to generate a bandwidth limited waveform (which “modsquare.wav” isn’t). I’m just guessing because you’ve not told us what you are really trying to accomplish (the “big picture”).

Thanks, I think I’m almost there =)

You want “Hz” rather than “Note” values?

Yes

It seems like the applicable part of the code are these two lines:

;control pitch “MIDI note number” float “” 60 0 127

and

(defun generate(bplist)
(let* ((lookuptable (maketable (make-cycle bplist))))
(osc pitch duration lookuptable)))

Could you please show me a quick example?

TIP: The defined waveform should normally start an end at zero.

This would make the waveform bandwidth limited?

For “Hz”, change this line:

;control pitch "MIDI note number" float "" 60 0 127

to:

;control freq "Frequency (Hz)" float "" 440 1 1000
(setf pitch (hz-to-step freq))



No, not necessarily.
Most waveforms don’t have discontinuities. It’s generally easier to define a waveform that doesn’t have discontinuities if you start and end at “zero crossing points”

That’s it !!! =) Thanks very much for your help and personal attention steve =)

I would consider this solved =)

I attached a copy of the modified arbitrarywaveform plugin if anyone is interested
arbitrarywaveform2.ny (2.03 KB)

Hi everyone,

First of all sorry for reviving an old topic, but I found quite interesting to be able to generate arbitrary waveforms.

So my question is, how can I know the points I should enter for a specific waveform? At the moment I just know how to generate triangle waveforms and sawtooth like. Could you give me a bit extra of information please? I’ve googled it and I didn’t find much about how this points system works.

Thanks a lot!

The points are the amplitude the successive of points, e.g. 1 0 1 -1 -1 1 draws an M-shaped waveform …


If you know the formula for the arbitrary-waveform try this other plugin … Expression Generator