Ambika firmware with avr-g++ 9.1

This makes me curious of how much work (if any) it would take to compile YAM with these gcc and avrlib versions. Even though all CPU cycles are exhausted it is always welcome with a little bit of space.
Cheers

@Bjarne I did it, but could not remember if it ever required any modification, maybe I forced the init phase of the submodule to grab the latest version of avrlib… I attach the resulting binary.

ambika_controller.bin.zip (32.9 KB)

cat ambika_controller.size | awk '{ print $1+$2 }' | tail -n1 | figlet | cowsay -n -f moose
     _______________________________ 
    /  ____ ____ _____ ___  _  _    \
    | | ___|___ \___  / _ \| || |   |
    | |___ \ __) | / / (_) | || |_  |
    |  ___) / __/ / / \__, |__   _| |
    | |____/_____/_/    /_/   |_|   |
    \                               /
     ------------------------------- 
      \
       \   \_\_    _/_/
        \      \__/
               (oo)\_______
               (__)\       )\/\
                   ||----w |
                   ||     ||

after a few tests, there are some things that do not work anymore:

  • my SVF sound card does not produce any sound when uploaded with an avr-g++ 9.1 compiled firmware
  • on the controller, while in the firmware update page, turning the encoder to browse through all cards/devices makes it hang: it’s because of the use of an int16_t version of clip instead of an int8_t. I may propose a patch to @pichenettes for this one

so there is still some hard corners on the controller, but they may be ironed out if properly diagnosed. For the soundcard it might be more tricky.

Thanks for the update
Cheers

actually no voice card works, regardless of their types. So far, I fixed two problems. I’m still investigating but here are the fixes for the record:

  1. I added a Clip8 version of Clip in avrlib/op.h:

static inline int8_t Clip8(int8_t value, int8_t min, int8_t max) {
return value < min ? min : (value > max ? max : value);
}

to be used by the controller os_info_page:

uint8_t OsInfoPage::OnIncrement(int8_t increment) {
active_control_ = Clip8(active_control_ + increment, 0, kNumVoices);
FindFirmwareFiles();
return 1;
}

  1. I changed the overlapping data-structure and bytes buffer in voicecard voice.cc

//uint8_t Voice::patch_data_[1];
Patch Voice::patch_;
uint8_t Voice::patch_data_ = reinterpret_cast<uint8_t> (&Voice::patch_)-1;
//uint8_t Voice::part_data_[1];
Part Voice::part_;
uint8_t Voice::part_data_ = reinterpret_cast<uint8_t> (&Voice::part_)-1;

There is still a problem though, when executing this line in Voice::Trigger:

modulation_sources_[MOD_SRC_VELOCITY] = velocity;

When compiled with avr-gcc 4.3, it works. When compiled with 9.1, the sound is muffled as if the velocity was 0… In fact, any of the following methods have problems when compiled with 9.1:

Voice::LoadSources()
Voice::ProcessModulationMatrix()
Voice::UpdateDestinations()
Voice::RenderOscillators()

Incidentally, they all use the modulation_sources_ static field of Voice… The thing is that it’s very difficult to debug, I painfully comment out line by line and try the firmware on the Ambika. I made a debug page on the controller to display various values, but it’s not accessible to voice cards…

One thing you should definitely check… make sure GCC warnings aren’t disabled in the makefile!

Check the GCC command in the makefiles, and if there is any -w flag used, you should delete it. Debugging was a great deal harder for me before I thought to check this. You might also like to add -pedantic and -std=c++14 flags, if you haven’t already.

If warnings aren’t disabled, what kinds of warnings are you getting, if any?

here is a excerpt of the compile commands:
/usr/local/CrossPack-AVR/bin/avr-g++ -c -mmcu=atmega328p -I. -g -Os -w -Wall -DF_CPU=20000000 -D__PROG_TYPES_COMPAT__ -fdata-sections -ffunction-sections -fshort-enums -fno-move-loop-invariants -DDISABLE_DEFAULT_UART_RX_ISR -DDISABLE_WAVETABLE_LFOS -DATMEGA328P -DSERIAL_RX_0 -mcall-prologues -fno-exceptions voicecard/leds.cc -o build/ambika_voicecard/leds.o

so you were right, I overlooked the -w option that inhibits all warnings :sigh: :man_facepalming:
ok, I’ll have another look when I have more time, maybe this week-end or next week…

Thank you for the advices!

so…

I tried with -Wall, fixed a few warnings, the most problematic ones being in oscillator.cc where the upper bound of a loop for formant was 4 instead of 3. No more warnings now.

still no luck with the final result though… The sound is “dirty”… The thing is, if I disable the mixing with the noise in voice.cc, the sound is ok. I still cannot find out why noise adds garbage, though my Ambika patch has a 0-level noise…
There is something funky somewhere… Maybe it comes from the operators in op.h. And maybe I should unit-test each operator… I tried to understand the assembler code, but could not find any obvious problem. Hopefully r0 and r1 are still tmp_reg and zero_reg

I provide patches to this message, to be applied with patch -p1 < patch.diff.

avrlib.patch.zip (3.3 KB) ambika.patch.zip (2.2 KB)

for the record:
tried with avr-g++ 9.2.0 from https://github.com/osx-cross/homebrew-avr => does not work
tried with avr-g++ 4.9.4 from https://github.com/osx-cross/homebrew-avr => does not work
tried with avr-g++ 4.3.3 from https://www.obdev.at/products/crosspack/index.html => WORKS
tried with avr-g++ 5.4.0 from https://www.microchip.com/mplab/avr-support/avr-and-arm-toolchains-c-compilers => WORKS

I’m stuck now. I do not know how to debug this, I’m giving up for a while.

A hint maybe: I still do not understand why I needed to implement an S8ClipS8 for the controller, when browsing through voicecards in the OS info page. This may be a hint that the compilers have a different way to handle conversions between types, which may result in this strange behaviour when those conversions happen in the dsp code.

got it working! :grinning:

turned out that the garbled sound was due to insufficient optimisation… -O2 is helping, at the expense of code size though. It seems that the latest versions of gcc change the optimisation trade off… That’s the reason why the controller firmware was so small with the latest gcc. But I guess the controller firmware does not need as much optimisation as the voicecard firmware…

In summary, we only need to:

  • add -O2 to voicecard CPPFLAGS
  • change the overlapping data-structure and bytes buffer in voicecard voice.cc
  • do nothing about the “clip” thing, it was entirely my fault

while we are it, maybe fix what -Wall raised up:

  • the interpolation of formant amplitude:

for (uint8_t i = 0; i < 4; ++i) {

should be:

for (uint8_t i = 0; i < 3; ++i) {

  • in sub_oscillator.h, replace

*buffer++ = U8Mix(*buffer, v, mix_gain, sub_gain);

with

*buffer = U8Mix(*buffer, v, mix_gain, sub_gain);
++buffer;

  • in transient_generator.h, replace

*buffer++ = U8Mix(*buffer, value, amplitude);

with

*buffer = U8Mix(*buffer, value, amplitude);
++buffer;

and that’s all. I will set up some github pull requests to Emilie.

Now on to the bootloader… Unfortunately, the resulting code size is 530 bytes, more than the original 506, I guess that’s the reason why avrdude complains.

Good work!

Note that when crackling due to insufficient optimization occurs, it does so depending on how computationally tough the patch is. Make sure you run tests with a “maxed out” patch. (For YAM this is probably using dual qpwm oscillator + sub oscillator + ring modulation.)

Cheers

You were right, some patches do not sound correctly… This is the case for 017 Flateric… :disappointed:

Don’t know what to do at this point, I guess this requires some disassembly abilities, which is a bit out of reach for me a this time without a substantial amount of effort…

Nice work. I intend to build an Ambika probably early next year once I am done with uni, so I will keep watching this thread for developments, and of course will definitely be getting my hands dirty with the firmware at that time :slight_smile:

Yes nice work! I’m going to chime in here aswell and see if anyone noticed the notes in the Ambika ‘Live’ release. When I was doing the mods I needed to find a way to squeeze more in and noticed that while 4.3.3 seemed to be the only thing that would compile the voice cards, 4.5.1 seemed to compile the controller fine and save a heap of bytes in the process, and I never noticed and bugs with it.

Notes on building the source:

	- For the voicecard build to succeed, avr-gcc 4.3.3 must be used. Any later versions will build, but result in a silent voice card.
	- For the controller, avr-gcc 4.3.3 build will break our file size limit (61440 bytes)
	- But 4.5.1 will successfully build the controller and save us about 2700 bytes!!!

Hey all, I’m currently back and working on getting the firmware to work with GCC 9. I’ve done quite a bit of refactoring etc, but still am experiencing the same problems with getting the voicecard to sound nice.

The sound is quite distorted - but less so when I compile with -O2 rather than -Os, and some notes don’t play at all. It’s really weird because changing the filter frequency by one step at a time ‘mutes’ and ‘unmutes’ the sound. I think it’s something like: when the MIDI note value and filter cutoff value are both even or odd, there is no sound, otherwise there is sound … so weird!

My current hypothesis is that the processing can’t keep up with real time, but that doesn’t really explain the specific behaviour above.

I would like to do some debugging with a working firmware binary, but I need an ELF file with debugging symbols. Could one of you @stefanovic @Bjarne @TijuanaKez (or @pichenettes, if you can be bothered) possibly upload an .elf binary of a tested working voicecard firmware and compiled with GCC 4.3 with debugging symbols (-g) enabled? Many thanks in advance :smile:

Hi machfour,

lockdown;-) ?

sure, hopefully joined to this message, compiled with:

/usr/local/CrossPack-AVR/bin/avr-g++ -v

Using built-in specs.

Target: avr

Configured with: …/configure --prefix=/usr/local/CrossPack-AVR-20100115 --disable-dependency-tracking --disable-nls --disable-werror --target=avr --enable-languages=c,c++ --disable-nls --disable-libssp --with-dwarf2

Thread model: single

gcc version 4.3.3 (GCC)

My last hypothesis was that ‘some’ optimization, which was included in gcc 4 with -Os, is not included anymore with latest gcc -Os.

I tried to review and compare the optimization list for each compiler (there is a switch that I do not find in my notes right now), to no avail, but I did not spend much time on that.

Good luck,

Stéphane

(Attachment ambika_voicecard.elf is missing)

1 Like

ambika_voicecard.elf.zip (81.3 KB) ambika_controller.elf.zip (353.5 KB)

1 Like

Thank you both!! I’ll report back with what i can find.

I found out the command I was mentioning:

gcc -Os -Q --help=optimizer

I tried to compare with:

diff -u <(/usr/local/CrossPack-AVR/bin/avr-gcc -Os -Q --help=optimizer ) <(/usr/local/bin/avr-gcc -Os -Q --help=optimizer)

but it’s difficult to read…

1 Like

Ooh, I didn’t know about --help=optimizer!! Thank you for that info :smiley:

And yes, the lockdown/restrictions can be quite good for productivity on these kinds of projects :wink:

By the way, is there any block of ‘extra’ processing code (i.e. adding extra effects) that I can simply comment out to determine whether saving a few cycles will actually improve processing? I tried a few things but it seemed to either not improve the sound or kill it altogether.