ΣSigmaStudio Ask AI Русский Log in

Real-time Tone Generation and Control with ADAU1761 and Microcontroller using SigmaDSP

SigmaDSP & SigmaStudio EA891 Aug 12, 2024 00:00 6 replies Original on forum ↗
Subscribe
EA891 Question
Aug 12, 2024 00:00

Hello, I'm new to SigmaDSP and I'm working on a project with the ADAU1761 audio processor. My goal is to control this chip in real-time using a microcontroller. Specifically, I want to generate and control multiple tones with precise timing and volume control. Here's what I'm trying to achieve:

When the program starts, a 300 Hz tone should automatically play.

I want to be able to add additional tones (e.g., 500 Hz, 1000 Hz, 2000 Hz) on top of the base 300 Hz tone.

These additional tones should be controllable in terms of when they start and stop, and their volume (in dB).

For example, I might want to add a 500 Hz tone at 80 dB for just 1 second.

My current approach is:

Set up a 300 Hz oscillator connected to the output.

Add additional oscillators at 500 Hz, 1000 Hz, and 2000 Hz, but initially have them turned off.

Is this the correct way to approach this project? If not, what would be the best way to structure this in SigmaDSP?

Also, how can I implement the real-time control of these tones from a microcontroller, including their timing and volume? An example sequence I'd like to control would be: 'add a 500 Hz tone at 80 dB for 1 second'.

Any advice on the overall project structure and how to achieve this precise control over frequency, volume, and timing would be greatly appreciated.

Thank you!

Audio Signal Processors

software

sigmastudio

SigmaDSP Audio Processors

adau1761

10acfa14-6b52-4f9c-96f9-aad341a7da7d.jpg
10acfa14-6b52-4f9c-96f9-aad341a7da7d.jpg
Harishgowtham Reply
Aug 12, 2024 00:00

Hello EA891,

EA891 said:
Is this the correct way to approach this project?

Yes, you are in the right path, and it can be done like the same way that you approached.

The gain, frequency are just parameters of the sine tone module. so, you can just control the parameters from an external MCU in real time.

You have to access/control the gain parameter for two things.

1) To turn ON and turn OFF the tone module, you have to access the gain parameter of the tone module. when you set this parameter to '0' then it will be muted (the sine samples will be multiplied by zero), so this is the turn OFF condition. When you set this to '1', then you have the 0dBFS signal.

2) To change the dB level, again you have to access the same gain parameter, I said the value '0' represents signal mute and value '1' represents full scale (0dB). If you set the parameters with different values, then you will be able to control the dB level of the signal. For example, setting '0.5' will give you -6dB and '0.7' will give you -3dB.

If you want a -80dB gain, then you have to find the respective decimal number.

dB to Decimal number:

V = 10^(dB/20) = 10^(-80/20) = 10^(-4)= 0.0001 , so if you set 0.0001 in the gain parameter then the tone output will be -80dB.

Decimal number to dB:

dB = 20log(0.0001) = -80dB

if you try my previous examples,

dB = 20log(0.5) = 6.02dB <==> V = 10^(-6/20) = 10^(-0.3) = 0.5011

I hope this will give you an idea about how to set the gain values in decimal to obtain the required dB level.

If you set the value to zero, the this is the turn off condition.

Please note that setting any value above '1' will clip the signal (inside the core you have a headroom but once it comes out it will clip at serial port).

So, to do turn off and turn on and setting different dB levels, you have to access the gain parameter, which I attached below.

3) You have to access the increment parameter to change the frequency. You can't directly enter the frequency you have to do a little operation. If your sample rate is 48KHz, then the Nyquist will be 24KHz. You can set the frequency up to 24kHz if your sample rate is 48KHz.

value = freq/Nyquist, example if you want 24KHz signal then value = 24000/24000 = 1

if you want 1KHz signal then, 1000/24000 = 0.04166666666

if you want 5KHz signal then, 5000/24000 = 0.2083333333

I can quickly show you this, please look below.

Now, you know what parameter to access to change the gain and frequency of the module.

Export the system files (icon next to link compile download) and look at the folder where it is extracted. You can see a file named PARAM.h. In that file you will find the address of every parameter. You can also see this in the capture window.

You can pass the address of the parameter and value from your controller with required logic implemented.

Below is a sample code, for simplicity I have only taken two signals. you can implement the code something like below.

We have a uC interfacing page, in that you can find the sample codes for interfacing uC with sigmaDSPs. we have used teensy controller which is Arduino based. Here is the link to the page.

You may need to safe load the values into the DSP from your uC since this is an older sigmaDSP. Otherwise, you may hear clicks and pops. Search the forum with the keyword 'safeload', you will have a lot of posts to refer and learn.

You can directly write the gain parameter from your uC for sigma3xx processors.

Kindly do reply if you have any questions.

Regards,

Harish

pastedimage1723456739885v1.png
pastedimage1723456739885v1.png
pastedimage1723457461547v2.png
pastedimage1723457461547v2.png
pastedimage1723457825192v3.png
pastedimage1723457825192v3.png
pastedimage1723458686814v4.png
pastedimage1723458686814v4.png
EA891 Reply
Aug 13, 2024 00:00

Thanks a lot, that was well explained. So, for each tone we're setting, we're writing three registers: one for the mask, one for the frequency increment, and the last one for the gain. Just out of curiosity, what exactly does the mask register do?

Best regards

EA891 Reply
Sep 13, 2024 00:00

I am currently controlling the DSP (ADAU1761) with the MCU, and so far, everything is working as expected. However, I am experiencing pops and clicks when adjusting the gain. To address this, I’m attempting to implement gain changes using safeload writes, which should reduce or eliminate these artifacts.

That said, I'm curious if there are any DSPs available that handle smooth gain transitions inherently, without the need for safeload writes. Additionally, retaining the digital microphone input functionality, as offered by the ADAU1761, is important for my project. Could you suggest any DSP alternatives that might better fit this requirement?

DaveThib Reply
Sep 13, 2024 00:00

Hello EA891,

The ADAU1452 and ADAU1467 families of parts have an extra feature in the core where if a peripheral is accessing the same memory address at the same exact system clock cycle, it stalls the core for one cycle then accesses the memory. This eliminates the need for Safeload writes for some objects but not all. No matter the DSP you will always need to do some sort of Safeload write for filter parameters to prevent the filter from becoming unstable. Volume controls will not need it in this part and usually a volume control that is used during run-time will be a slewed type. For a slewed type all you need to do is one write to the target value and let it do the ramping.

Which begs the question, are you using slewed volume controls now? Do not attempt to do the slew on your own with many writes.

These parts I suggested also have a PDM decimator so it can take in a PDM digital mic as well. Of course an I2S digital mic would be no problem.

Dave T

EA891 Reply
Sep 20, 2024 00:00

Thank you very much for your assistance! I’ve implemented safeload while writing to the register via my MCU, and so far everything is working smoothly. Regarding the slew approach, I need to write to both the Alg2target and Alg2step registers. Is it advisable to stick with the default step value, or is there a recommended step value that would optimize performance?

Best Regards

DaveThib Reply
Sep 20, 2024 00:00

Hello EA891,

You only need to write to the target parameter. The program will look at the difference between the current gain and the target gain and calculate the steps needed for each sample period. Writing to the step will be immediately overwritten by the program so you are doing no harm but it is a useless write.

The step size is chosen based on the slew setting for the slew time. Set the slew time that works for your application. There are some posts on the forum detailing the slew times. Search for "slew times" and I think it will come up.

Post Update:

I just searched and this post has a ton of details and also shows how to measure it.

(+) Clickless SW slew volume control Specification details - Q&A - SigmaDSP Processors & SigmaStudio Dev. Tool - EngineerZone (analog.com)

Dave T