The Mozzi library was very useful when making music gadgets with Arduino.
However, it became difficult to handle because it changed to CC-BY-NC-SA due to license change.
Let's make a sound library to replace Mozzi.
This is the beginning.
The first thing I did was that Arduino alone could output 8bit stereo at 11 KHz.
I used high speed PWM for this.
Because I am using high-speed PWM, I encountered the problem that I can not produce sound with my desired waveform.
There was also a problem of noise.
For a while...
I thought that adding a parallel 8bit DAC would solve the problem.
If you use SPI's DAC, you can probably output audio at 22 KHz with Arduino.
Serial is not good for outputting at 44 KHz, there is a need for parallel.
Speaking of a simple parallel DAC, it is an R-2R ladder.
However, it is not easy to obtain few varieties at present.
(I feel I saw it with digi-key etc)
However, since it is easy to make the R-2R by yourself, I decided to adopt it.
Because it is 8 bit output, use 8 output pins.
Considering the number of Arduino's I / Os, it is not Easy, but I think this is the best.
When outputting 8 bits, we recommend arranging I / O side by side when referring to registers.
that's it.
PB 4, PB 5, PB 6, PB 7
PF 4, PF 5, PF 6, PF 7
(In the case of Leonardo)
Also, please do not use I / O planned to use in other places.
For example, Digital 2 and Digital 3 are assigned to I2C of Leonardo.
I began making libraries for Leonardo for the first time, but I also need to pay attention to library setting of UNO and pin settings as well.
Values that can be expressed with 8 bit DAC are in the range of -128 to 127.
How many channels to output,
When making WaveTable, it is better to first divide -128 to 127 by the number of channels.
After DAC output, LPF, coupling capacitor, etc. are necessary.
This is the same except when making instruments with Arduino.
Prepare the amplifier as necessary.
I got a sound like this.
pinMode.
A total of eight pins are set.
Set them all at once. Because it is troublesome.
like this.
DDRB |= 0xf0;
DDRF |= 0xf0;
PighiXXX is a reference to the board pinout. Convenient.
For output,
char data; // -128 to 127
data += 127 // offset
PORTB = (PINB & 0x0f) | ( data & 0xf0 );
PORTF = (PINF & 0x0f) | (( data & 0xf) << 4);
Why did Mozzi change its license?
I think like this.
Mozzi was available free,
Many gadget devices using Mozzi were announced and sold.
They used a cheap Arduino (ATMega 328) chip using the free Mozzi library ... but they were very expensive.
Of course, none of those selling has been fed back to Tim Barrass, creator of Mozzi (?). maybe.
If so, I will be bored.
Do not you think so?
Everyone can make their own music gadget.
Graduated the sound of a boring buzzer that used the Tone library!
Arduino can do such a wonderful thing.
That's Mozzi.
As a result Mozzi became CC-BY-NC-SA.
I do not want to repeat the same thing.
So, I am not planning to publish a library that I am currently producing in its complete form.
If you are made with some tips and some knowledge, and skills, that is a fine original.
I hope you will make an original.