External audio output function and new DAC supports

644 views
Skip to first unread message

tomco...@live.fr

unread,
Jan 18, 2021, 9:44:40 AM1/18/21
to Mozzi-users

Hi all,
Some of this is already a bit old but is getting a new kick now so I guess it is time to have a word about it!

Since PR#87, it is possible for most platforms (not ESP, yet, see after) to define an "external audio output function". This allows a great simplicity to output the sound using a non-standard (for Mozzi) way, for instance DACs, but also any way that you can think of (resistance ladder etc…).

Basically, if you configure mozzi correctly (there is an option in mozzi_config.h), you can declare a void audioOutput(int r, int l) function which will contains the sound sample(s) for you to take care of them. It will be called by Mozzi at the correct sample rate.

PR#90 and #103 provide examples of audioOutput functions for the following DACs:
  - MCP48/9XX, which are 8/10/12 bits mono/stereo DAC, connected via SPI, one example shows a way to output 24bits audio by combining two 12bits DAC. As standard AVR platforms have 16bits integers, this is not compatible. However users with more powerful platforms (like STM32) could be interested. From my personal tests, not all the 24bits get out of the noise, but it still gives a very nice 16/18 bits actual resolution on one channel).
  - PT8211 which is a stereo 16 bits DAC that is intended to be connected via I2S but can be made working using SPI interfaces.
They are available in the Examples of Mozzi.

This should ease by a lot the support of new output hardware, and if you happen to get it working on something else do not hesitate to pull request!


Additionally, a great work is being done now by tfry-git under PR#98 to simplify the internal way Mozzi is working. This is still work in progress and will be the subject of another post when it is ready but in short:
  - automatic scaling of the output will be provided, this means examples won't have to be modified for platform outputting a different number of bits that the default AVR,
  - external audio output will be supported for all platforms (including ESP32 which is missing now).

If you are not using the External audio output capability, these changes should not break any sketch, it will just allow to make them more portable across platforms.

Best and happy new year to all!
Message has been deleted

Joël Ucedo

unread,
Apr 5, 2021, 11:19:47 AM4/5/21
to Mozzi-users
Hi,

I want to use the PT8211 with a Teensy 3.6. Is it supported ? Can I use the external audio output function you mentioned ?

On the Teensy website The DIN pin from PT8211 shield is connected to analog pin 22 but in "AudioConfigTeensy3_12bit" pin 21 is used :

#elif defined(__MK64FX512__) || defined(__MK66FX1M0__)
#define AUDIO_CHANNEL_1_PIN A21

Can I change it to A22 ?

One more question. I don't know if I have to use 2048, 4096 or 8192 wavetables. With 16bits 44.1KHz DAC, what is the best option and why ? Does it affects sound quality ?





Le lundi 18 janvier 2021 à 15:48:35 UTC+1, tomco...@live.fr a écrit :
PS: practical examples of synthesizers (with schematics, PCB and codes) using an external output function can be found in my git: https://github.com/tomcombriat/TES_10-knobs-synth

tomco...@live.fr

unread,
Apr 6, 2021, 9:32:35 AM4/6/21
to Mozzi-users
Hi!
I haven't tested with the Teensy 3.6 but as long as you get mozzi compiling for it it should work!
The "AudioConfigTeensy3_12bit" file is only use for outputting the sound using the "standard" way: the DAC pin on the teensy, so you should not touch it as using an external dac is not standard.
If you want to use the DAC the way to go is to configure mozzi to use an external audio output function (this has to be enable in mozzi_config.h) and then define this function in your code.
The example in Mozzi about the PT8211 is using the SPI port to emulate the I2S protocol expected by the DAC. With the right configuration and the right wiring (in the example) this should work straigh outside of the box.
If you are using a shield which is using different pins to communicate with the DAC, then you'll have to modify the function given in the example accordingly, probably by looking in the Teensy audio library how they are doing it. The external audio output function is just a way to get the samples out from mozzi, then you can do whatever you want with it, like sending them to a DAC. This "sending" part (the external audio output function) is highly dependent on how you want to output the sound so needs to be adapted to every hardware config. This shouldn't be too hard though.

About the WT: note that the default sample frequency of Mozzi is not 44.1kHz, but 32.768kHz for Teensy by default. This should not be a problem though is the DAC is adressed in a synchroneous fashion like it is done in the example. For the sizes, usually the bigger the smoother the sound but it also takes more memory of the chip. If you have no problem on that side you can safely go for the bigger wavetables.

Hope that helps, let us know!
Thomas

Andrew Brown

unread,
Apr 6, 2021, 4:48:43 PM4/6/21
to Mozzi-users
Thomas, thanks for your responses here and all your work on Mozzi.

I'm curious about the comment regarding wavetables that "For the sizes, usually the bigger the smoother". If wavetables resolution is limited to 8 bit (perhaps it's not?) then are not longer versions of the same waveform simply elongating time between the same quantised amplitude steps? If so there would be no reason to have longer versions of the wavetables so I must be missing something.

Andrew

Tim Barrass

unread,
Apr 6, 2021, 9:40:20 PM4/6/21
to 'Ian C.' via Mozzi-users
>elongating time between the same quantised amplitude steps?
yes, but with more precisely timed changes from one step to the next... same x resolution but more y resolution... though I might also be missing something!
There's an example with observations comparing the sound of different wavetable sizes: 01_Basics>Table_Resolution

-- 
You received this message because you are subscribed to the Google Groups "Mozzi-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mozzi-users...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/mozzi-users/4b124f83-74c3-4d64-a36c-0ebbd4a9f584n%40googlegroups.com.

tomco...@live.fr

unread,
Apr 7, 2021, 3:18:26 AM4/7/21
to Mozzi-users
To add on Mr Sensorium:
That's a good point and it actually depends on the wave you want to reproduce: if it is not varying very quickly (no more than one unit between two timesteps) increasing the WT length will not provide any gain as it will just add duplicates of the same values (actually, it might even be worth as Mozzi won't interpolate any more between two successive values, I do not know the resolution of this interpolation).

For instance for a symetrical triangle wave: a wavetable of 512 is enough to describe it with all the resolution given by the 8 bits : first half increasing of +1 but sample (from -127 to 128, 256 steps) and second half from 128 to -127 the other way around. Increasing the size of this WT will just add duplicates values that won't add information, so for instance going to 1024 will change the WT this way:
[512] :  0    1    2    3 …
[1024]: 0 0 1 1 2 2 3 …

But, if you have a sharper wave, varying more quickly, for instance a non-symmetric triangle (or, in Mozzi, the non-alias version of the square wave for instance), then sometimes a shorter WT won't reproduce all the details: two successive values won't be separated by one unit, but more than that, then there will be a gain in increasing the WT,  for instance:
[512]:  0    4    8
[1024]:0 2 4 6 8

Here, adding more values decribes better the wave, the result will be more accurate.

Actually, you can open the WT of Mozzi with a standard text editor, if you spot big gaps between the values (not for the pure square wave obviously, for which these gaps are inherent) then you'll actually gain in precision by increasing the WT size. For fun, you can look at the values of the different WT sizes of the same wave, it might be more clear than my explanation…

Hope it helps!

Andrew Brown

unread,
Apr 8, 2021, 7:44:56 AM4/8/21
to Mozzi-users
Thanks for those responses. I've been doing dynamic wavetable synthesis with a 512 array, but after some tests based on these responses, I'm now using 1024. This ensures no steps are skipped for any standard wave shapes, but there may be some skips during morph transformations. However, I heard little discernible improvement with larger arrays. What did change, interestingly, was filter response. In particular resonance settings for the state variable filter needed adjusting based on wavetable size.

Joël Ucedo

unread,
Apr 14, 2021, 1:55:12 PM4/14/21
to Mozzi-users
Hi,


I tried with Arduino IDE and PlateformIO+VSCODE and same errors.

src\main.cpp:17:24: error: 'AudioOutput' does not name a type
 void audioOutput(const AudioOutput f) // f is a structure containing both channels
                        ^
src\main.cpp: In function 'void audioOutput(int)':
src\main.cpp:20:20: error: request for member 'r' in 'f', which is of non-class type 'const int'
   SPI.transfer16(f.r());
                    ^
src\main.cpp:23:20: error: request for member 'l' in 'f', which is of non-class type 'const int'
   SPI.transfer16(f.l());
                    ^
src\main.cpp: At global scope:
src\main.cpp:50:1: error: 'AudioOutput_t' does not name a type
 AudioOutput_t updateAudio()
 ^
*** [.pio\build\teensy36\src\main.cpp.o] Error 1

Do you have an idea ?

tomcombriat

unread,
Apr 14, 2021, 2:08:33 PM4/14/21
to j.uc...@gmail.com, mozzi...@googlegroups.com
Hi,
Very quickly : did you configure mozzi_config for both using an external audio output and stereo hack?
Also: are you using the latest version of Mozzi?



tomcombriat@live.fr
Envoyé depuis mon téléphone realme
You received this message because you are subscribed to a topic in the Google Groups "Mozzi-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mozzi-users/6_QgJAkEmuU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mozzi-users...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/mozzi-users/0bc3e327-162f-43f9-819e-693d10250679n%40googlegroups.com.

Joël Ucedo

unread,
Apr 14, 2021, 2:33:41 PM4/14/21
to Mozzi-users
I found something.

I copied and pasted the latest version from github in the Arduino library folder and  the code compiles now with Arduino IDE. But when I download the repo directly from PlatformIO it is not the latest version, the mozzi_config file is different. Problem is that when I do it manually (copy/past), platformIO automatically download the older version and overwrite what I just pasted. Don't know why.

tomcombriat

unread,
Apr 14, 2021, 3:22:06 PM4/14/21
to j.uc...@gmail.com, mozzi...@googlegroups.com
Probably that platformio is not taking the latest version, what is weird then is that it had the latest examples, or maybe you found the examples on the git?
The examples you get with the version you download should be adapted to this version. To be on the safe side, especially with these new features, you probably have to use the last git version...
Hope it helps!
Tom



tomcombriat@live.fr
Envoyé depuis mon téléphone realme
Reply all
Reply to author
Forward
0 new messages