Producing certain db using arduino due

Thanks for the code i will try for sure. Just one doubt to change the frequency of the wave do we need to change phase increment for frequency F. And what to do to change the amplitude of the wave

Yes.

Two ways:-

  1. You generate another look up table with a range of numbers.
  2. When you get the sample that you want to send to the D/A you multiply it by a number less than one, before sending it to the D/A.

fFrequency = ((pow(2.0,(unMidiNote-69.0)/12.0)) * 440.0);

can you explain the above relation please

This is converting a MIDI note number from 0 to 127 into a frequency, to fill a table of notes.
The relationship between MIDI note number and frequency is illustrated in the table.

So the frequency of the note A is a standard and is 440.00 HZ so any arbitrary MIDI Note number must first subtract 69 and then divide by 12 because there are 12 notes in an octave. Then it is multiplied by 440.00 to get the frequency. But it is not as simple as that because the ear is sensitive to the log of the frequency, and the inverse log is obtained by rasing the number to the power of 2.
For an explanation of pow see:-
Power function

sorry to trouble you but can you tell me what part of the code needs to be changed to get a desired frequency sine wave

You just need to change the phase increment for frequency. You do not need all the MIDI note number to frequency bit at all. So you can remove that

in my code will it fine if i just add an offset.

Sorry no idea what that means but it is simple enough to try, won't do any harm.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.