Re: Using the Mozzi library to make a synth with 4 knobs and 8 arcade buttons

874 views
Skip to first unread message

Tim Barrass

unread,
Jan 16, 2017, 5:30:24 AM1/16/17
to mozzi...@googlegroups.com
Hi Dan,

it's achievable.

>however my ability to code is pretty poor
Could be a hurdle!  It might be worth going through some standard arduino examples/tutourials first if you're not very familiar with programming.

>Can i use digitalRead to read HIGH or LOW and play a note on button press(HIGH) with if statements?
you can use digitalRead for reading a button as normal, nothing special for it in Mozzi

>array with all of my different scales in it
you could have a seperate array for each scale, and have a pointer to the selected array (look up pointers in C if unfamiliar).  Or use switch-case, for a less efficient but also workable solution (better than if-else).  Or whatever you think of...

Tim







On 15 January 2017 at 21:58, dan Scott <danjo...@gmail.com> wrote:
sorry, I meant I haven't found any example using digitalRead() with a button IN MOZZI

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to mozzi...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/mozzi-users/46c08e6f-f483-4bdb-8e2f-1148fc54a0ec%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

dan Scott

unread,
Jan 26, 2017, 10:45:32 AM1/26/17
to Mozzi-users
Hey there Tim
 
, thanks for some advice.  I have been working through this (haven't gotten to using pointers yet) and decided to try using one analog pin for all of the buttons.  I'de like to start adding some cooler sounds than just the simple sin2048.  Through staring at the examples and reading a bunch and watching vids, I've tried to put together my code.  I've got the buttons working and 3 knobs as well.  the audio out is a bit noisy, but it works.  I've been trying to get my knobs to do different things and i usually end up with what sounds like just a pitch shift.  I'd like to have some cutoff or filter knob, some other nice knobs to play with, a way to shift the whole scale up and down chromatically (too much to ask?) and again a way to switch to a different sound.  Do you think working with the waveshaper or wavepackets might be a better idea for this?  I'm still not exactly sure what they are except some massive table that eventually makes a sound.  Anyways, here's my code, its quite messy because i've been trial and erring a lot.


//#include <ADC.h>  // Teensy 3.1 uncomment this line and install http://github.com/pedvide/ADC
#include <MozziGuts.h>
#include <Oscil.h> // oscillator template
//#include <AudioDelay.h>
#include <tables/sin2048_int8.h> // sine table for oscillator
//#include <tables/cos2048_int8.h> // wavetable for mod
#define CONTROL_RATE 64 // powers of 2 please
//#include <mozzi_midi.h> // for mtof (midi to freq)
//#include <mozzi_fixmath.h> //needed for vibrato
#include <AutoMap.h> // maps unpredictable inputs to a range
#include <RollingAverage.h>


// use: Oscil <table_size, update_rate> oscilName (wavetable), look in .h file of table #included above
Oscil <SIN2048_NUM_CELLS, AUDIO_RATE> aSin(SIN2048_DATA);
//Oscil<COS2048_NUM_CELLS, AUDIO_RATE> aCos(COS2048_DATA); //vibrato stuff
//Oscil<COS2048_NUM_CELLS, AUDIO_RATE> aVibrato(COS2048_DATA); //vibrato stuff

//Oscil<COS2048_NUM_CELLS, CONTROL_RATE> kFreq(COS2048_DATA); //delay stuff

//const byte intensity = 255; //vibrato stuff
const int buttons = 0;
const int knob1 = 1;
const int knob2 = 2;
//byte volume;  //vol knob to add later

int note[] =  {261, 277, 294, 311, 330, 349, 370, 392, 415, 440};  //indexed starting with 0
//            mid C  C#   D    D#   E    F    F#   G    G#   A

// min and max values of synth parameters to map AutoRanged analog inputs ALL FOR KNOBS
const int MIN_F = 5;
const int MAX_F = 1000;

const int MIN_BW = 1;
const int MAX_BW = 1000;

const int MIN_CF = 60;
const int MAX_CF = 2000;

// for smoothing the control signals
// use: RollingAverage <number_type, how_many_to_average> myThing ??
RollingAverage <int, 16> kAverageF;
RollingAverage <int, 16> kAverageBw;
RollingAverage <int, 16> kAverageCf;
AutoMap kMapF(0,1023,MIN_F,MAX_F);
AutoMap kMapBw(0,1023,MIN_BW,MAX_BW);
AutoMap kMapCf(0,1023,MIN_CF,MAX_CF);

//AudioDelay <256> aDel; //delay stuff
//int del_samps;  //delay stuff

void setup(){
  Serial.begin(115200);
  delay(200);
  startMozzi(CONTROL_RATE); // set a control rate of 64 (powers of 2 please)
}


void updateControl(){
  int button_value = mozziAnalogRead(buttons);
  //Serial.print("button value = ");
  //Serial.print(button_value); 
   
  int fundamental = mozziAnalogRead(knob1);  //fundamental freq
  Serial.print(fundamental);
  fundamental = kMapF(fundamental);
  Serial.print(fundamental);

  int bandwidth = mozziAnalogRead(knob2);   // bandwidth
  bandwidth = kMapBw(bandwidth);
  
  int centre_freq = mozziAnalogRead(knob3);   //centre freq
  centre_freq = kMapCf(centre_freq);

  //kFreq.setFreq(.63f);
  //del_samps = 128+kFreq.next(); //delay stuff
  //aVibrato.setFreq(8.f);
  
//button 1
  if (button_value >=400 && button_value <=450){
    //aSin.setFreq(mtof(60.f));
    aSin.setFreq(note[0]);     // + knob int's final output
  }
//button 2  
  else if (button_value >=500 && button_value <=550){
    aSin.setFreq(note[2]);
  }
//button 3
  else if (button_value >=650 && button_value <=710){
    aSin.setFreq(note[4]);
  }
//button 4  
  else if (button_value >=900 && button_value <=950){
    aSin.setFreq(note[5]);
  }
//button 5  
  else if (button_value >=980 && button_value <=1010){
    aSin.setFreq(note[7]);
  }
//button 6  
  else if (button_value >=1011 && button_value <=1040){
    aSin.setFreq(note[9]);
  }
//no buttons pressed  
  else{
    aSin.setFreq(0);
    //aVibrato.setFreq(0.0f); //vibrato stuff
  }
  
  Serial.println();
}


int updateAudio(){
  //Q15n16 vibrato = (Q15n16) intensity * aVibrato.next();     //vibrato stuff
  //return aSin.phMod(vibrato); // phase modulation to modulate frequency

  //char asig = aDel.next(aSin.next(), del_samps); //delay stuff
  //return (int) asig; //delay stuff
  return aSin.next()>>8; // return an int signal centred around 0
}


void loop(){
  audioHook(); // required here
}



Any help with a bit of direction would be awesome.


 

dan Scott

unread,
Jan 28, 2017, 5:13:52 AM1/28/17
to Mozzi-users
another question i have is whether or not i could just use the elechouse mp3 shield and the arduino joystick shield on top of that and just play samples from an sd card with little latency and effect the sample sounds with the buttons.  I haven't tried any shields other than the protoshield so im sure exactly how this works.  Can mozzi output through the mp3 shield? with the amp thats in the shield, wouldn't it sound much better?

cheers,
Dan

dan Scott

unread,
Jan 28, 2017, 5:19:48 AM1/28/17
to Mozzi-users
like this https://item.taobao.com/item.htm?spm=a230r.1.14.3.IHZ8iI&id=45375888022&ns=1&abbucket=16#detail  // for sd card and amplified output
and https://item.taobao.com/item.htm?spm=a230r.1.14.29.fn6dPV&id=524064452094&ns=1&abbucket=16#detail  // for controls that fit right onto the board and a good 'ol xy joystick for effects

Tim Barrass

unread,
Jan 28, 2017, 7:14:38 AM1/28/17
to mozzi...@googlegroups.com
Hi Dan,

- looks like you could use the joystick shield
- Mozzi won't play mp3's unless you work out a way to do it
- Mozzi might be able to read audio from an sd card, but again you'd have to work it out and then lots of people would be glad you did it


> a way to shift the whole scale up and down chromatically (too much to ask?)
do you mean like adding an offset to a midi note number?  eg. +2 so note 60 becomes 62?  and then mtof(62) to get the frequency?  Or is it something more complex?

tim


On 28 January 2017 at 21:19, dan Scott <danjo...@gmail.com> wrote:
like this https://item.taobao.com/item.htm?spm=a230r.1.14.3.IHZ8iI&id=45375888022&ns=1&abbucket=16#detail  // for sd card and amplified output
and https://item.taobao.com/item.htm?spm=a230r.1.14.29.fn6dPV&id=524064452094&ns=1&abbucket=16#detail  // for controls that fit right onto the board and a good 'ol xy joystick for effects

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to mozzi...@googlegroups.com.

dan Scott

unread,
Jan 28, 2017, 11:08:12 PM1/28/17
to Mozzi-users
cool beans on the joystick shield.  it'll look hilarious attached to my banjo.

mozzi won't play mp3s? dang.  i don't think i'm the person to figure out how then.  I'm sure lots of people would love if it could read sd cards. well that idea is out.  
would mozzi be able to use the amp on the mp3 shield?

to shift the whole scale up or down... lets say im in 'A' pentatonic and the next song is in 'C' pent, i could either turn a knob until i'm at the right key or press some button or something.  If you saw my code, i've been using the frequency values, would it be smarter to use mozzi_midi.h and mtof?

Tim Barrass

unread,
Jan 29, 2017, 7:02:28 AM1/29/17
to mozzi...@googlegroups.com
Hi Dan,


> lets say im in 'A' pentatonic and the next song is in 'C' pent
> use mozzi_midi.h and mtof
Yep using midi note numbers and mtof would make it easy... see https://sensorium.github.io/Mozzi/doc/html/group__midi.html
Some of the examples show fixed-point midi conversions, but if you can stand slight inaccuracies in pitch you can keep it simple by just using integers (not floats) with mtof().  A fixed-point example is 06.Synthesis/Detuned_Beats_Wash.


>would mozzi be able to use the amp on the mp3 shield?
I didn't see a pinout of the shield - you would need to connect pin 9 (on a uno) to the input of the amp, but it's hard to know if the levels etc. would be right.  I'm prototyping a Mozzi shield with an amp which could be available in about 20 years at this rate...

Tim


--
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+unsubscribe@googlegroups.com.
To post to this group, send email to mozzi...@googlegroups.com.

dan Scott

unread,
Jan 29, 2017, 10:03:44 PM1/29/17
to Mozzi-users
im actually starting to look at the wave shield and waverp/hc to make a sort of sampler/grain synth instead now.  After long thoughts I realized I already can make nice .wavs and use those or use the waverp lib to record realtime and playback and manipulate.  Thanks for listening to my ravings, Tim.

Glen van Alkemade

unread,
Jan 30, 2017, 5:27:33 PM1/30/17
to Mozzi-users
Use of mtof(midinote) looks pretty handy. I use a big array full of integer frequencies. My octave shift pot maps to values 0-3, which I use to pick the row out of the array. Thus,

unsigned int pitch_array[4][13]= {
  {65,   69,  73,  78,  82,  87,  92,  98, 104, 110, 117, 123, 131},
  {131, 139, 147, 156, 165, 175, 185, 196, 208, 220, 233, 247, 262},
  {262, 277, 294, 311, 330, 349, 370, 392, 415, 440, 466, 494, 523},
  {523, 554, 587, 622, 659, 698, 740, 784, 831, 880, 932, 988,1046}
  };
byte octave;
const IntMap  octIntMap(0,1024,0,5);   // returns 0-1-2-3 (really! On my synth, anyway.) Use for Array Row.

updateControl()
octave = octIntMap(mozziAnalogRead(31));           // Pin 31 is a pot labelled "Octave". returns 0-1-2-3.
//Now I poll each of 13 keys, i=0 to 12, to see which of them are triggered.
if(trigger[i] > 0) 
    {pitch = pitch_array[octave][i];}    // fetch the correct pitch from the pitch array, at row=octave, column=i.



On Monday, January 16, 2017 at 4:30:24 AM UTC-6, Mr Sensorium wrote:
Hi Dan,

it's achievable.

>however my ability to code is pretty poor
Could be a hurdle!  It might be worth going through some standard arduino examples/tutourials first if you're not very familiar with programming.

>Can i use digitalRead to read HIGH or LOW and play a note on button press(HIGH) with if statements?
you can use digitalRead for reading a button as normal, nothing special for it in Mozzi

>array with all of my different scales in it
you could have a seperate array for each scale, and have a pointer to the selected array (look up pointers in C if unfamiliar).  Or use switch-case, for a less efficient but also workable solution (better than if-else).  Or whatever you think of...

Tim






On 15 January 2017 at 21:58, dan Scott <danjo...@gmail.com> wrote:
sorry, I meant I haven't found any example using digitalRead() with a button IN MOZZI

--
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 post to this group, send email to mozzi...@googlegroups.com.

dan Scott

unread,
Jan 31, 2017, 11:25:27 PM1/31/17
to Mozzi-users
Hey Glen, that looks great! I'll try that now.
Reply all
Reply to author
Forward
0 new messages