Synth Keyboard questions

180 views
Skip to first unread message

Pierre Banwarth

unread,
Aug 8, 2022, 6:02:11 PM8/8/22
to mozzi...@googlegroups.com
Hi, 

I'm trying to make a kind of Melodica (MIDI and Synth Concertina Keyboard) 

putting both concertina Hand on a face plate (cherry mx switches with a custom PCB and 3D printing)  
278510975_10222100827969495_4949327471096888762_n (1).jpg
I have an extra Switch to control air in/out (maybe later with a pressure sensor)

This version is using mozzi but i'm working hard to figure out what is not working.

I have both functions for midi and mozzi working pretty well.

I use 2 envelopes (one for drones and one for main theme)

I can setup with the screen two oscillators by envelopes in order to tune output sound.

int updateAudio(){
long note = (long)envelope.next() * (oscil1.next()+oscil2.next());
long noteBourdon = (long)envelopeBourdon.next() * (bourdon1.next()+bourdon2.next());
return (note + noteBourdon) >>9;
}

I don't really understand this byte shift with >> 9 ? 
I put 9 because that work but.

All this part is working (excepted some noise when i use the encoder and the screen) 

I'm know looking for a way to make that thing polyphonic

Is it 8 + (Number of Note you play) ?

If i want to play as many note i want, do i need to put 
 
>> 8 + NumberOfKey ?

I want to know if i can work like that or if i need a fifo with maybe four or five notes at the same time

I work on Arduino Mega.
I saw other libraries who work with polyphonic keyboards with teensy.
I want to make more keyboards like that for other musicians and for myself but i want to add the teensy or mega on a pcb plate so i need to figure out wich one is better at doing mooggy things.

I have made the output circuitry and that's working very well with the basic two voices.

my git project (not well documented it's a work alone in progress but i try to do my best on it)

Here's a MIDI only version of a concertina i made before.
https://www.youtube.com/watch?v=G6iePFmdnJg
  
It's a real pleasure to use MOZZI and thanks a lot for the work on it. 
Sorry for my english and i hope this question is clear enough and respect the community standards

Pierre Banwarth

staffa...@oscillator.se

unread,
Aug 9, 2022, 2:54:57 AM8/9/22
to mozzi...@googlegroups.com
That is a beautiful build!

Sorry, don't have the time to comment on the specifics of your code.

BUT. I think that you sooner or later will feel the need to more
powerful hardware. So here are two ideas that I have worked with:

1. ESP32.I built a groovebox, polyphonic/multitimbral, using Mozzi, on
this more powerful hardware.
Code and demo: https://www.oscillator.se/opensource/#m5stack

2. Daisy Seed. A really powerful MCU. It has its own DSP library which
is pretty similar to Mozzi. I have used it to build fx boxes, synths, a
sampler.
Code and demo: https://www.oscillator.se/opensource/#daisy

Good luck!

Staffan

PS You can check out my Arduino/Mozzi projects here:
https://www.oscillator.se/arduino/


2022-08-09 00:01 skrev Pierre Banwarth:
> Hi,
>
> I'm trying to make a kind of Melodica (MIDI and Synth Concertina
> Keyboard)
>
> putting both concertina Hand on a face plate (cherry mx switches with
> a custom PCB and 3D printing)
>
> --
> 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/CAOjQJ04Ae25oUE%2Bj6n_%3DNuiJfywabfbseZs7CY%3DAiwtzUfcXug%40mail.gmail.com
> [1].
>
>
> Links:
> ------
> [1]
> https://groups.google.com/d/msgid/mozzi-users/CAOjQJ04Ae25oUE%2Bj6n_%3DNuiJfywabfbseZs7CY%3DAiwtzUfcXug%40mail.gmail.com?utm_medium=email&utm_source=footer

tomco...@live.fr

unread,
Aug 15, 2022, 4:07:22 AM8/15/22
to Mozzi-users
Hi Pierre,
Sorry for the late reply!

Without the full code I'll have to make a few assumptions but here are a few answers to your questions:
  - I don't really understand this byte shift with >> 9 ?
This is because you have too many bits for the capacity of the board to output, let's count them: (multiplying two things add their bits, adding things of same width add 1)

long note = (long)envelope.next() * (oscil1.next()+oscil2.next());   // is 7 + (8+1) = 16 if you have a envelope going to 128
long noteBourdon = (long)envelopeBourdon.next() * (bourdon1.next()+bourdon2.next());  // is 7 + (8+1) = 16
So return (note + noteBourdon) // is 16+1  = 17bits

But if you are using an arduino, the output is 8bits wide, so you need to shovel out 9 in order for it to not overflow, hence the byte shift.
In order to make things independant of the platform you can use the MonoOutput::fromNBit(17,note + noteBourdon); which will automatically scale the output to the good width, even if you change to a platform with more output bits, like the Teensy.

For polyphony, you'll need to do an array of oscillators of the size of the polyphony and to code how things are going to work out when you run out of voices (can be fifo or any other algorithm for note stealing). It is a bit messy, but here is an example of polyphonic sketch (triggered with MIDI) using mozzi: https://github.com/tomcombriat/TES_8-knobs-synth/tree/master/XORAND_poly
Hope this helps!

Pierre Banwarth

unread,
Aug 18, 2022, 7:31:20 AM8/18/22
to mozzi...@googlegroups.com
Following the given link i got something like this. I'm near the good solution but again i'm loss with the byte shifting

  long note = 0;
  long newNote = 0;
  for (byte i = 0; i < POLYPHONY; i++){
    //        1     +       7 + 8 + 1
    newNote = (long)envelope[i].next() * (oscil1[i].next()+oscil2[i].next())>>8;
    note = (note + newNote)>>1;
  }
  long noteBourdon =  (long)envelopeBourdon.next() * (bourdon1.next()+bourdon2.next()) >>8;
  return (note + noteBourdon)>>1;



tomco...@live.fr

unread,
Aug 19, 2022, 7:36:04 AM8/19/22
to Mozzi-users
Hi!
Alright I think this is getting close!
One thing that I think is wrong straight away is: note = (note + newNote)>>1; By doing that, note is actually divided by 2 for every loop. Hence, if you have a polyphony of 8, the first note (loop index 0) will end up being divided by
256 and will be way less volume than the last one which will be divided by 2 only.

One other thing to keep in mind is to make the shifts as late as possible as they are removing some informations. As you are using long type (this can lead to performance issue on 8bits platforms but completely fine on 32bits platforms as teensy), I think there is no need for shifting before the return of the function:

long note = 0;

  for (byte i = 0; i < POLYPHONY; i++){
  long newNote = 0; // a bit cleaner here
//                                             7                *               8              +            8   
//                                            7                 *                                9             = 16 plenty of room for 32 bits!!
    newNote = (long)envelope[i].next() * (oscil1[i].next()+oscil2[i].next()); 
    note += newNote;     // gets one more bit every loop, if polyphony is 8, will end up with 16+8=24
  }
note = note>>POLYPHONY;   // scale back to 16bits

  long noteBourdon =  (long)envelopeBourdon.next() * (bourdon1.next()+bourdon2.next());    // similarly this is 16 bits
note += noteBourdon; // 17 bits
MonoOutput::fromNBit(17,note);


Again, if you are on Arduino you might want to use int type instead of long for which performances are greater (see the bottom of this post: https://groups.google.com/g/mozzi-users/c/sOF3QgWQxB0/m/dtp9RQ6FAAAJ). In that case you need to shift down newNote before adding it to note so that the latter does not overflow.

Hope it helps!

Pierre Banwarth

unread,
Aug 19, 2022, 8:19:30 AM8/19/22
to mozzi...@googlegroups.com
Ok, 

So i think POLYPHONY = 36; was greedy

I was trying to use 36 enveloppes. Very hard to know if bad result is from byteshift or too long computation in the loop...

I will use int and try to solve with a fifo and 4 or 5 enveloppes.

Anyway i'm in HIFI mode. Not really convinced by the >> 6 final return.

I'll let you know about my progress soon

Thanks a lot for your help

tomco...@live.fr

unread,
Aug 19, 2022, 8:25:24 AM8/19/22
to Mozzi-users
Hi again,

36 is probably very greedy, especially on an Arduino. The way I usually proceed is to start with two and when everything works increase the polyphony until it breaks. Normally the code should be scalable by only changing the #define POLYPHONY.
The good thing with
MonoOutput::fromNBit(17,note);
is that it will automatically scale down to the correct number of bits, both for HiFi and Standard mode, as long as you are correct on the number of bits of your sample.

Pierre Banwarth

unread,
Aug 20, 2022, 8:48:28 AM8/20/22
to mozzi...@googlegroups.com
int updateAudio(){
  int8_t note = 0;
  int8_t noteBourdon = 0;

  for (byte i = 0; i < POLYPHONY; i++){
    note += (int8_t) envelope[i].next() * (oscil1[i].next()+oscil2[i].next())>>8;
  }
  note >>= POLYPHONY;
  noteBourdon = (int8_t) envelopeBourdon.next() * (bourdon1.next()+bourdon2.next())>>8;
  note += noteBourdon;
  return (int8_t)note>>1;
}

Ok now i need to speed up this loop because this work when i overclock the arduino mega but i got a detune effect.
Also i try to work with MonoOutput::fromNBit(17,note); but compiler is not friendly with this one.
(Arduino Mega is lagging with polyphony = 2)


Reply all
Reply to author
Forward
0 new messages