Waveform synthesis on the R4

Further to my thread Hairy output on R4 DAC the discussion has moved on from the initial problem to a wider discussion so I requested this new thread to be created.

Just been adding a timer to my wave form generator, with the help of
Under the Hood: Arduino UNO R4 - Timers - Phil Schatzmann. Although he says you can't get CD speed sampling (44.1KHz) with the audio tool kit There was no problem with the timer. I suspect it was without @susan-parker magic direct access methods. The big problem, as I see it, with the analogWave library is that if you change the scaling of the samples (volume) it just reduces the peak value. What needs to happen is that the DC bias at the mid range point needs to be maintained, if you are going to avoid the thump you get when a new note starts.

So I have been playing about with frequency and volume controls variables in the loop function as the wave plays. You can do that almost instantly unlike the analogWave library, which needed a minimum of about 50mS delay fefore any changes will take place.

At the moment I have just been seeing what they do. Here is a video of some 'effects' you can get with my odd ball wave function.

4 Likes

Nice video.
I am currently running in loop() code for a sine and a cosine by direct calculation (NOT lookup tables) which is clocking in at 226kHz.
This includes floating-point amplitude adjustment (not just shifts).
Would be slightly faster without the pin set/clear calls at 83nS each.
Of course there isn't anything else happening... :slight_smile:
Next to put it in a timer-interrupt - maybe 96kHz to start with.

As the post thing prompts, maybe we should change the thread?

Yes so does my code.

Yes I agree, I will ask a moderator to do this.

I have split the posts to a dedicated topic as requested.

Regards,
pert

3 Likes

Thanks again @susan-parker for all the code. I have it up and running on my minima and I am starting to get my head around the direct register access.

I noticed that in your DAC setup code, you have the following

//  *DAC12_DAVREFCR = 0x06;        // D/A VREF Control Register - Select External Vref; set VREFH&L pins used for LED

A few, hopefully simple, questions.

  1. Can you use the voltage on the minima AREF pin as the external reference voltage for the DAC Or is the external voltage reference in the code comments from somewhere else?

  2. If it is from somewhere else do you know of a way to supply a reference voltage to the DAC?

Hi,
The DAC uses different reference source setup and pins to the ADC.
On the Minima the DAC references are on the RxLED and TxLED pins. If you unsolder the two LED resistors R14 and R15 you can provide external reference into the DAC.
Yes, they are teeny!
Hope this helps

2 Likes

Thanks for splitting off the topic.

Update:

My loop is now running at 328kHz :slight_smile:

Cool, thanks for the update. Don't think I'll bother unsoldering anything. It's not crucial for my application but would be nice...

1 Like

Looking at the RA4M1 datasheet I note that sadly the Serial Sound Interface Enhanced (SSIE) is only available on the 100-pin package, see pin-lists section 1.7 :frowning:
However the SSIBCLK is available on P112 i.e. D10, so that might be useful if one wants to generate an audio-specific clock for something... maybe?

It could be, if you could hang an ISR off it. It would save using one of the timers to generate this.

Unfortunately, I have discovered that it needs the GPT321 for an internal clock source, so not really worth doing until I get a 100-pin version of the RA4M1.

2 Likes

Have just got the SSIE generating I2S running on the EK-RA4M1 dev board and a Pico Audio Pack with a PCM5100A DAC.

Pic show pure sine-wave in purple, and waveform constructed from 1st to 9th harmonics. This is all calculated "on-the-fly" in c. 14uS.

#define AUDIO_AMP_1      (float)0.70
#define AUDIO_AMP_2      (float)0.35
#define AUDIO_AMP_3      (float)0.20
#define AUDIO_AMP_4      (float)-0.05
#define AUDIO_AMP_5      (float)0.05
#define AUDIO_AMP_6      (float)-0.05
#define AUDIO_AMP_7		 (float)0.01
#define AUDIO_AMP_8      (float)-0.05
#define AUDIO_AMP_9		 (float)0.01

1 Like

Have added the frequency changes cause by inharmonicity for strings, e.g. piano, etc. where the 3rd and higher harmonics are actually slightly higher than expected because of the effect of string-stiffness affects the node-points.

This is nominally the same tone as per the previous post's image, which has locked harmonics such as with a flute.

I got the info from here:
https://physics.stackexchange.com/questions/268568/why-are-the-harmonics-of-a-piano-tone-not-multiples-of-the-base-frequency

I will put up the code for this when I have it tidied up.

I think that answer ignored the fact that a piano has multiple strings and so can not be expected to have all the harmonics fixed to one fundamental, as there is more than one. This is because all the strings can't be tuned without instruments beyond that a piano tuner uses. And even if they were they would not stay that way for long.

This is also for single (metal) strings per note e.g. guitar as well - not because there are multiple strings for the same note, which is another complication.

What I am testing is how far I can push the RA4M1 processor, which is of course quite slow compared to many other 32bit offerings, with doing some sort of real-world waveform-synthesis application at CD speed samples at 44.1kHz

Also I am currently generating 10 sines at 25bit accuracy per loop through direct calculation - not using any form of lookup table - including scaling their respective amplitudes - before adding them all together.

I can also generate a bit-clock close enough to get a 44.1kHz frame rate with the standard 12.0 MHz clock to get a reliable PLL lock in the Audio DAC :slight_smile: