custom tone generator help

Using Nyquist scripts in Audacity.
Post and download new plug-ins.

If you require help using Audacity, please post on the forum board relevant to your operating system:
Windows
Mac OS X
GNU/Linux and Unix-like

custom tone generator help

Permanent link to this post Posted by cristo1 » Fri Jan 26, 2018 11:32 pm

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 =)
cristo1
 
Posts: 6
Joined: Fri Jan 26, 2018 10:38 pm
Operating System: Windows 7

Re: custom tone generator help

Permanent link to this post Posted by Trebor » Sat Jan 27, 2018 1:59 am

changing the shape of one cycle of the waveform can have little effect on the sound heard, see ... viewtopic.php?p=336711#p336711

If there is a formula for your "custom waveform", try this "ExpressionGenerator.ny" plugin ...viewtopic.php?p=324316#p324316
Trebor
 
Posts: 4396
Joined: Sat Dec 27, 2008 5:22 pm
Operating System: Windows Vista

Re: custom tone generator help

Permanent link to this post Posted by cristo1 » Sat Jan 27, 2018 2:43 am

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: 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?
cristo1
 
Posts: 6
Joined: Fri Jan 26, 2018 10:38 pm
Operating System: Windows 7

Re: custom tone generator help

Permanent link to this post Posted by steve » Sat Jan 27, 2018 12:36 pm

cristo1 wrote:Should I have posted this in the nyquist thread?

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

cristo1 wrote: I was trying to follow this thread: viewtopic.php?f=46&t=92179&start=10

This is the relevant post in that thread: https://forum.audacityteam.org/viewtopi ... 27#p309227

cristo1 wrote: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 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"
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 46809
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: custom tone generator help

Permanent link to this post Posted by cristo1 » Sat Jan 27, 2018 8:39 pm

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/Wa ... 38594.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 =)
Attachments
modsquare.rar
(9.58 KiB) Downloaded 15 times
cristo1
 
Posts: 6
Joined: Fri Jan 26, 2018 10:38 pm
Operating System: Windows 7

Re: custom tone generator help

Permanent link to this post Posted by steve » Sun Jan 28, 2018 2:31 am

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".
Code: Select all
(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) Downloaded 16 times

arbitrarywaveform.ny
(2 KiB) Downloaded 15 times
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 46809
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: custom tone generator help

Permanent link to this post Posted by cristo1 » Sun Jan 28, 2018 6:49 am

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!!!
cristo1
 
Posts: 6
Joined: Fri Jan 26, 2018 10:38 pm
Operating System: Windows 7

Re: custom tone generator help

Permanent link to this post Posted by steve » Sun Jan 28, 2018 11:26 am

cristo1 wrote: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?

You want "Hz" rather than "Note" values?
To modify the ";control" line: http://wiki.audacityteam.org/wiki/Nyqui ... der_Widget
To convert Hz to Step: http://www.cs.cmu.edu/~rbd/doc/nyquist/ ... l#index315

cristo1 wrote:How would I change the duration from seconds to minutes (it's a small thing, I could do that math; just wondering)?

Modify the control line to say "minutes" rather than seconds,
then add a line to multiply the duration by 60
Code: Select all
(setf duration (* duration 60.0))


cristo1 wrote:Also, I think you hinted that my point table was too big

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

cristo1 wrote:my project is using elf waves anyway. Was just thinking that higher resolution is always better

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").
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 46809
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: custom tone generator help

Permanent link to this post Posted by cristo1 » Sun Jan 28, 2018 10:07 pm

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?
cristo1
 
Posts: 6
Joined: Fri Jan 26, 2018 10:38 pm
Operating System: Windows 7

Re: custom tone generator help

Permanent link to this post Posted by steve » Mon Jan 29, 2018 12:14 am

For "Hz", change this line:
Code: Select all
;control pitch "MIDI note number" float "" 60 0 127

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


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

This would make the waveform bandwidth limited?

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"
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 46809
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Next

Return to Nyquist



Who is online

Users browsing this forum: No registered users and 1 guest