Sinewaves sinewaves sinewaves

Status
Not open for further replies.

Admant

Member
Dear Teensy experts,
I have some questions about audio, I am not too technical, sorry.

I bought the CJMCU-5102 DAC to use with the Teensy4.1.
Is it ok to use a 24bit DAC with a 16 bit Teensy? I mean, does it make sense or is it useless, since the Teensy is 16bit depth?

I need to generate a sum of sinewaves (at audio rate) and I want them as more defined as possible (I am a bit maniac about sinewaves).
To use the AudioSynthWaveformSine is certainly a short way for doing this, but I wonder if doing it with a bigger LookUpTable and a 24 bit DAC can give better results. Without investing too much time, I mean. And in case, can someone patiently drive me into the subject?

About the mentioned DAC, should it work just out of the box or do I have to make some sort of conversion before sending it to I2S? Because I did not make it to work so far. Maybe I made mistakes with the connections. Could anyone tell me where to find a connection guide for Teensy4.1-to-CJMCU-5102? I haven't found it so far.

Thank you all for your time and your help

Antonio
 
Yes, the 5102 should work, without any changes.
Teensy Audio is meant for CD Quality. So more than 16 Bit are not needed here, and if you want more you have to modify the whole library. The lookup-table is good for 16 Bit.
May I ask for what purpose you want to use it?
I doubt that cheap boards can give you full 24 Bits. Do you use a battery to power it?

For the pin-connections, search this forum :)
 
Last edited:
Dear Teensy experts,
I have some questions about audio, I am not too technical, sorry.

I bought the CJMCU-5102 DAC to use with the Teensy4.1.
Is it ok to use a 24bit DAC with a 16 bit Teensy? I mean, does it make sense or is it useless, since the Teensy is 16bit depth?
It will work fine with only 16 bits, I2S is designed to be smart about this.
I need to generate a sum of sinewaves (at audio rate) and I want them as more defined as possible (I am a bit maniac about sinewaves).
To use the AudioSynthWaveformSine is certainly a short way for doing this, but I wonder if doing it with a bigger LookUpTable and a 24 bit DAC can give better results. Without investing too much time, I mean. And in case, can someone patiently drive me into the subject?
There are several ways to sythesize sine waves efficiently, table lookup is not the only way as there are several
schemes that are resonant digital filters. It's hard to find good articles on this, I did find this:
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.493.5555&rep=rep1&type=pdf
Such digital resonators are unstable over time unless you periodically ensure the amplitude is kept constant,
but will only need a couple of adds and multiplies per sample to generate precision sinusoids.
About the mentioned DAC, should it work just out of the box or do I have to make some sort of conversion before sending it to I2S? Because I did not make it to work so far. Maybe I made mistakes with the connections. Could anyone tell me where to find a connection guide for Teensy4.1-to-CJMCU-5102? I haven't found it so far.

From what I read of the datasheet you want to hardwire FLT, DMP, FMT as LOW, and XMT as HIGH (to unmute).
The MCLK/BCLK/LRCLK/DATA lines of the I2S bus connect as documented in the Audio lib design tool. Many
datasheets and breakout boards spuriously rename the I2S MCLK as SCLK or similar for no reason, note.
 
Hello Frank B,
thank you for reply. I will use the board to drive an exciter, connected to a metal plate where the sounding chord is notated. A sort of "sounding painting". No battery but I will connect the board to 12v power supply. You can find more details on my similar post in the arduino forum.
I understand that I would probably not be able to distinguish the difference between 16 and 24 bits, but, as I said, I just wanted to have a hi-end oscillator :)
Also I (wrongly?) thought that a bigger size wavetable (2048?) and SSD would correspond to a more defined sinewave.

I will dig deeper to find the wiring for the DAC.

Antonio
 
Hello MarkT,
thank you for your help. Very appreciated. As you see I moved here from the arduino forum...

Unfortunately the article you provided is far beyond my technical skills. I think the only way for me now is to go for the standard audio library and 16bit.
And for the hi-end stuff, well... maybe I should just commit the job to a professional. I really love the DIY philosophy, but sometime it's just too much.

Antonio
 
From what I read of the datasheet you want to hardwire FLT, DMP, FMT as LOW, and XMT as HIGH (to unmute).
The MCLK/BCLK/LRCLK/DATA lines of the I2S bus connect as documented in the Audio lib design tool. Many
datasheets and breakout boards spuriously rename the I2S MCLK as SCLK or similar for no reason, note.

Super
Now it works.
Thanksalot!


Antonio
 
I just skimmed the datasheet for the pinout and the application circuit - always worth doing.

right, I surfed online, but different versions / revisions / name / acronyms made me confusing. I found the datasheet of the chip but not the board one.
At least now, if someone has the same need, here is the solution. Thank you again.
 
I have some code using one of the techniques for generating sines (in fact this one generates quadrature,
ie cosine and sine simultaneously), in one of my experiment branches of the Audio library:
https://github.com/MarkTillotson/Audio/tree/synth_quadrature
The files synth_quadrature.h/cpp are the relevant ones. The comment in the .h file shows the maths used.

If you want speed, call the sincosf function. This function calculates both sin and cos at the same time.

The calling sequence is:
Code:
    void sincos (double x, double *sin, double *cos);
    vold sincosf (float x, float *sin, float *cos);
    void sincosl (long double x, long double *sin, long double *cos);

In addition, you might want to use the sinf and cosf functions. The sin and cos functions take double arguments, and do the calculations in double. The sinf and cosf functions take float arguments, and do the calculations in float. I suspect the double versions do more rounds of taylor series expansion because double has more mantissa bits of float. This matters more for the Teensy 3.5/3.6 since they have float hardware support, while the double type needs to be emulated.
 
I think we're at cross-purposes, I'm talking about methods of generating sampled sinusoids that are way faster than sincosf,
3 add/subs and 2 muls to generate both sin and cos per sample. Its the regular sampling that allows this - if your hardware
had fast CORDIC instructions then sincosf would be competitive, but as far as I know Arm M7 doesn't.

This is different from the Bressenham method for circle generation in graphics, but they both use coherence to reduce the
complexity of operations needed.
 
hou wow.. this is rocket science to me!
Pardon the silly question, but why should I generate cosine and sine simultaneously?
In the meantime I measured the AudioSynthWaveformSine and the result is in the pic attached
Schermata 2021-05-09 alle 22.55.34.jpg
 
Status
Not open for further replies.
Back
Top