I recently generated a sine wave with audacity - 1kHz @ 96k sample rate. I then tested it with RMAA to determine the worthiness of Audacity as a sine wave generator. On the far right of the FFT there are some peaks which are probably results of sampling and digital errors. Does anyone else use Audacity to generate sine waves?
- keantoken
- keantoken
Attachments
Keantoken, is this an fft plot of a wave file ? If yes, the quality is more than bad. How big was the wave file ? 1 second ?
The artefacts are likely to be jitter or resampling.
Attched is fft plot of 1khz/1sec/48khz-fs/16bit, kaiser window beta of 15. fft-window size reduced to 8192. (Created with goldwave)
Mike
The artefacts are likely to be jitter or resampling.
Attched is fft plot of 1khz/1sec/48khz-fs/16bit, kaiser window beta of 15. fft-window size reduced to 8192. (Created with goldwave)
Mike
Attachments
I did not resample (to my knowledge).
I could think of two different types of equations for dithering:
1: Analyze the curves before and after the place needing dithering and pick the optimal place to insert a sample using an algorithm.
2: Insert a sample between two samples.
I would think that the optimal type of sound format would take samples depending on the skew rate (if this is the correct term) of the piece of a wave, so that all samples would be equal distance away from each other if viewed by Audacity. This would produce the same number of samples for each frequency, and even out the quality of the sound. It could be hard to code and play, though. Have you heard of FLAC? It's Free Lossless Audio Codec. It's like the sound version of PNG image format. Do you think that this would work for quality sine waves?
My sine waves were 30 seconds long.
-keantoken
I could think of two different types of equations for dithering:
1: Analyze the curves before and after the place needing dithering and pick the optimal place to insert a sample using an algorithm.
2: Insert a sample between two samples.
I would think that the optimal type of sound format would take samples depending on the skew rate (if this is the correct term) of the piece of a wave, so that all samples would be equal distance away from each other if viewed by Audacity. This would produce the same number of samples for each frequency, and even out the quality of the sound. It could be hard to code and play, though. Have you heard of FLAC? It's Free Lossless Audio Codec. It's like the sound version of PNG image format. Do you think that this would work for quality sine waves?
My sine waves were 30 seconds long.
-keantoken
With a 30sec sinewave you shouldn't have any problems... See attached file for fft of 30sec file.
About the dithering, you are thinking way too complex. Simply add white noise (output from a random number generator) to the signal (Scaled down to the scale of a single bit) before quantizing to 16bit.
And, don't rely on proper rounding from the FPU, it doesn't. You need to round yourself with (int)floorf(Val+0.5). Otherwise you get crossover distortion, as the FPU always rounds to the number closest to zero.
Another trap when generating a sinewave is jitter, caused by unaccuray of the float format when calculating the phase for the sinewave absolute instead of relative.
Mike
About the dithering, you are thinking way too complex. Simply add white noise (output from a random number generator) to the signal (Scaled down to the scale of a single bit) before quantizing to 16bit.
And, don't rely on proper rounding from the FPU, it doesn't. You need to round yourself with (int)floorf(Val+0.5). Otherwise you get crossover distortion, as the FPU always rounds to the number closest to zero.
Another trap when generating a sinewave is jitter, caused by unaccuray of the float format when calculating the phase for the sinewave absolute instead of relative.
Mike
Attachments
Okay, looks like Audacity isn't my generator of choice any more. Unless I have some way of applying this rounding equation and know the decibel value of 1 bit. Any free software that you can suggest? I would try to make my own, but I don't know the equation that represents sine. And its probably way over my head anyways.
keantoken said:I would try to make my own, but I don't know the equation that represents sine. And its probably way over my head anyways.
I don't think so... (If you really want to know the equation to generate sine, google for taylor series)
Mike
Attachments
I believe that I might be able to manage if I pulled out my calculus book and concentrated extremely hard on learning about the f^👎 (a) thing (This is how I learned about rate of change t(delta), but it still didn't tell me how to calculate the speed of a falling object vs. time relative to air pressure, which was my motive at the time
). I know more about mathematics than others may see, even though I make a lot of errors sometimes.

-agent_keantoken_signing_out


-agent_keantoken_signing_out
I’ve used Audacity to play/record .wav test files, but LtSpice to create and analyze them (also SciLab free MatLab work-alike but the 24 bit .wav i/o needs a modified xwavread function which is stackspace expensive, keep test files short) http://www.scilab.org/
This LtSpice file should get you started
The problem is getting it started;
LtSpice reads in a .wav file and then outputs a .wav file so this example needs an initial .wav to startup, otherwise it just reports a file error
After installing the free LtSpice simulator you can rename the attached file by just trimming off the .txt and you can open it in LtSpice SwCAD III
http://linear.com/company/software.jsp
Rt clik on the text line “wavefile=.\output.wav chan=0” (the “Value” of V2 Voltage Source)
Type 0
Run (rt clik on blank space to get Sim menu )
Undo (<F9> or Edit>undo) to get wavefile line back for V2
Run
(now for any further changes you have to run the file twice to have the V(in) values reflect any changes in the V(out), 1st Run writes the new .wav but reads the preexisting .wav, 2nd pass reads the modified .wav)
This is an attempt to show dither and show how LtSpice can create .wav source for testing and analysis
The Dither source is supposed to be a triangular probability distribution function by adding 2 white noise sequences (adding 1e6 to 2nd white function arg to get a decorrelated series from the underlying random number generator)
I’m not certain the dither spectrum and level is optimal; with the noise created at the sample output rate it is sinc filtered with a zero at fs/2
This LtSpice file should get you started

The problem is getting it started;
LtSpice reads in a .wav file and then outputs a .wav file so this example needs an initial .wav to startup, otherwise it just reports a file error
After installing the free LtSpice simulator you can rename the attached file by just trimming off the .txt and you can open it in LtSpice SwCAD III
http://linear.com/company/software.jsp
Rt clik on the text line “wavefile=.\output.wav chan=0” (the “Value” of V2 Voltage Source)
Type 0
Run (rt clik on blank space to get Sim menu )
Undo (<F9> or Edit>undo) to get wavefile line back for V2
Run
(now for any further changes you have to run the file twice to have the V(in) values reflect any changes in the V(out), 1st Run writes the new .wav but reads the preexisting .wav, 2nd pass reads the modified .wav)
This is an attempt to show dither and show how LtSpice can create .wav source for testing and analysis
The Dither source is supposed to be a triangular probability distribution function by adding 2 white noise sequences (adding 1e6 to 2nd white function arg to get a decorrelated series from the underlying random number generator)
I’m not certain the dither spectrum and level is optimal; with the noise created at the sample output rate it is sinc filtered with a zero at fs/2
Attachments
Thanks, JCX!
That should work well for my purposes.
I hadn't thought of using LTSpice to generate sine waves.
Does 32768 have some connection with pi? That's the only thing that I don't understand.
Skew rate... I funny! 🙄
Actually, it's slew rate - am I right?
hehe... Anyways what do you guys think of that idea? I might try it (unless, of course, it's already been done).

-keantoken
That should work well for my purposes.
I hadn't thought of using LTSpice to generate sine waves.
Does 32768 have some connection with pi? That's the only thing that I don't understand.
Originally posted by me
I would think that the optimal type of sound format would take samples depending on the skew rate (if this is the correct term) of the piece of a wave, so that all samples would be equal distance away from each other if viewed by Audacity. This would produce the same number of samples for each frequency, and even out the quality of the sound. It could be hard to code and play, though.
Skew rate... I funny! 🙄
Actually, it's slew rate - am I right?
hehe... Anyways what do you guys think of that idea? I might try it (unless, of course, it's already been done).

-keantoken
32768 = 2^15
16 bit PCM lsb size in LtSpice is 1/32768 V since +/-1 V is the full scale range in Volts
for 24 bit PCM 1 lsb = 1/8388608 = ( 1/2^23 )
I'm pretty sure my dither needs to be 2 lsb instead of 1, maybe I'll look at a IMD plot
If you can verify Adacity tone generator problems plese complain, post bug reports on http://www.nabble.com/Audacity-f463.html
16 bit PCM lsb size in LtSpice is 1/32768 V since +/-1 V is the full scale range in Volts
for 24 bit PCM 1 lsb = 1/8388608 = ( 1/2^23 )
I'm pretty sure my dither needs to be 2 lsb instead of 1, maybe I'll look at a IMD plot
If you can verify Adacity tone generator problems plese complain, post bug reports on http://www.nabble.com/Audacity-f463.html
- Status
- Not open for further replies.
- Home
- Design & Build
- Equipment & Tools
- Audacity sine - Is this good enough?