Mozzi Library Audio Synthesizer

Hi everybody :)

Happy New Year and I hope you all had a great Christmas too. If you did not celebrate due to beliefs, I hope your celebrations / time off was a rested one.

I have a project due in to my education establishment in a couple of weeks and I would like some advice from experienced Arduino users. This seems to be THE place for discussing potential code and expansions for an Arduino board and I'm really hoping somebody can help.

This project is Audio based and I am required to synthesise or use the Mozzi Library to generate my audio signals.

I was involved in a car crash and I haven't had much time to get up to scratch with my coursework deliverable. As you can imagine, I'm getting very anxious about anything atm as I was diagnosed with PTSD as a result of it. To help you all understand the position I am in, I will jot down as much information about the expected Arduino build I am to design / configure / code.

I am to deliver the following:

  • Hardware build (Can be basic. As long as the it works, that is fine)

  • Schematics (For a breadboard with potentiometers for volume control and another for the frequency rate. I must also include a couple of push buttons which will be covered below)

  • Software (This will be the code drawn up in the Arduino application as I use OS X for Mac)

For the hardware side of things I have come to to require the following:

  • Need to use a breadboard and final Veroboard which has been soldered onto and not just loosely connected

  • 1 push Button / flick Switch (Controls the Note on/off)

  • 2 Pots (Volume control and Frequency control / rate)

  • 1 RCA Connector (Audio Out and perhaps I'll use a 3.5 mm (1/8″) minijack / 6.3 mm (1/4″)

For my Schematic design I have detailed what I believe I need here:

  • Block Diagram For my circuit

  • standard and expected Circuit diagram

  • Layout Diagram for Veroboard Flow Chart for Software

As for any software I have come to realise that I need the following:

  • Clear Explaining Comments as I go through the software

  • Properly Named Variables that are standard

  • Use Tabs to indicate sections of code to help with identiying particular section of code. I.E.

if (X=y) { Do Something here

}

I do also need to present this to a demonstrator who is marking my work and I would like to have this project finished by the end of the week. It's certainly doable as I've been told that this is a very basic project and there will be no need whatsoever to go anywhere near 100 lines of code. I need to present the following:

  • Pictures
  • Schematics
  • Show it working

I am using OS X Yosemite and have the Arduino Mega2560 with a USB connection.

Would anybody be able to share some insight into this project and help me get through this? The medications I have been prescribed make it extremely difficult for my mind to get a grasp on things and I've started to admit that I do currently need help with most things in my daily life.

I appreciate anybody reading this and I would certainly enjoy reading about your responses.

Help!

Have a great day :)

Deadcell: This project is Audio based and I am required to synthesise or use the Mozzi Library to generate my audio signals.

You seem to have an enormous amount of information in your Post about how you will present your results. But the above is the only sentence I can see that actually says anything about the project itself. You need to explain that in some detail.

Are you planning to write a program to make audio signals using that library? Have you figured out a clear English language description of what the program will do? Have you written any of the program? If so, post your code.

I have no idea what the "Mozzi" library is, or where it comes from. Can you post a link to it?

...R

Hi there Robin,

Thanks for your response and I appreciate the comments. I apologise for overseeing this. I had to rush off to the doctors.

I'll respond to your questions first, then move on to more information on what I am looking to do for my project.

In response to, "Are you planning to write a program to make audio signals using that library?"...

I do plan to write a program that could make audio signals from scratch, or by using this library. Signal generation seems far more interesting but at the same time I don't have much time and using an alternative library source may help as I do understand the real-world application of such a library. For your benefit I have also included the weblink to the Mozzi Library here: http://sensorium.github.io/Mozzi/

Responding to your quote, "Have you figured out a clear English language description of what the program will do?"...

At this stage I have not. However it has been put forward that this is to be done today so I will crack on with this once I can figure out what sort of behaviour I need. I have un uninterrupted day so can crack on with this for most of my day and night. I may need some assistance with this process but will post any progress I make.

You have questioned me stating, "Have you written any of the program? If so, post your code."

Unfortunately I have not yet written any code. I do have a few test codes which have been passed to me and I need to explore these today to get up to scratch. I've been told that my project does not have to be any more than 100 lines of code so I am confident that it shouldn't take much time once I have re-visted the basics.

In terms of providing you more information on what I am required to do I have detailed this in a paragraph for ease of reading. If you need more information, please let me know.

I'm tasked with designing and implementing an interactive audio system based around my Arduino Mega2560. It is anticipated that I utilise the Mozzi Sound Synthesis Library to output the generated output sounds. The finished system should implement the following;

  • 1 push button
  • 1 potentiometer
  • A second potentiometer (rotory or slider) OR a non-ohmic resistance device such as a thermistor.

The above points are critical for my project and I do need them to complete my project. However, with the above in mind, my system should exhibit the following behaviours;

– One button turns on/off a sine wave – One potentiometer (or non-ohmic device) controls the frequency rate of the sine wave. – The second potentiometer should be used as a master volume / gain control for the sine wave.

I am told that I should implement my own controller circuit to interface with the arduino, i.e. I shouldn't use any “off the shelf” controllers but should design and implement my own using electronic components.

Finally, I am to answer questions on any aspect of its design when I am demonstrating this.

Does this help you at all? I am baffled with this and will review the test code over the next couple of hours to see what sort of work I can complete.

Thanks for your time with this. I really do like the idea of designing and building audio electronics as it will help with my PTSD and I can see this becoming a very constructive hobby for the future. Sorry if there isn't any more for you to go off at this stage.

All the best.

Note Since sharing this post I have spoken to my demonstration marker and he has advised me that this page here is very close to the project that I am asked to complete: http://sensorium.github.io/Mozzi/learn/introductory-tutorial/

I shall dig a little bit more!

This project is Audio based and I am required to synthesise or use the Mozzi Library to generate my audio signals.

You need to rename your post title to "Mozzi Library Audio Synthesizer"

State your experience with electronics and software.

Would anybody be able to share some insight into this project and help me get through this? The medications I have been prescribed make it extremely difficult for my mind to get a grasp on things and I've started to admit that I do currently need help with most things in my daily life.

I don't quite know how to tell you this but we have been hearing "hard luck" stories from students with projects who waited till the last minute since the forum first began. We have heard them all. For example (Marijuana grow farm project pitch "My 80 year old sick grandmother needs something to tend her garden.....I would be so appreciative if you could give me schematics and code for this..."

I don't know if yours is on the level but I can tell you that no amount of hard luck stories is going to get you any special treatment (like drawing your schematics and writing your code). We normally don't do that. We frequently link tutorials that contain both but we expect you to do the bulk of the raw research. You asked a simple question: "How would you approach this project ?" Tell us what you have found from YOUR research and prove to us that you have done some and we'll go from there. I haven't seen any indication that you have done any research. We're not going to do your project for you but if you prove that you are making an effort we will do the same. It's that simple. A simple Google search yields plenty of useful hits, including a forum Playground page so what do you want from us ? We can't offer advice until we know what language you speak. Do you speak Electronics ? Do you speak code ? (haven't seen any from you yet) You gave a very detailed description of your overview , which may or may not be useful at this point. I really haven't seen any specific questions so what exactly do you want ?

Thanks for your time with this. I really do like the idea of designing and building audio electronics as it will help with my PTSD and I can see this becoming a very constructive hobby for the future. Sorry if there isn't any more for you to go off at this stage.

No need to be sorry. After all , it's your project, not ours.

I do also need to present this to a demonstrator who is marking my work and I would like to have this project finished by the end of the week. It's certainly doable as I've been told that this is a very basic project and there will be no need whatsoever to go anywhere near 100 lines of code. I need to present the following:

  • Pictures
  • Schematics
  • Show it working

So ? Why are you telling us all this ? Do we care ? (no)

The Topic title is "Project Guidance" not "Project Subcontracting" The way this works is you ask questions we answer them. We do not need to know your life story. We actually don't even need to know the project requirements to answer your questions.

We're here to answer questions. So far, I haven't seen any. If you want help, you have to ask specific questions. It's really that simple. We don't need to know your medical diagnosis or how much anxiety you are in to answer electronics and software questions, do we ?

I might add, don't hold your breath expecting the forum to spit out a finished project package for you. That's not going to happen. If you don't do it, it isn't going to get done. Period. Still waiting.... If you only have a week you better get the lead out.

Deadcell: For your benefit I have also included the weblink to the Mozzi Library here: http://sensorium.github.io/Mozzi/

That library looks interesting but I don't have any immediate use for it and I don't propose to learn it just to explain it to someone else.

I can't think of any practical advice to offer until you get to the point where you have a specific question about some aspect of your project. Preferably, at that stage, you will have tried out the Mozzi examples and will be familiar with the library.

...R

I think I would just jump right in and get the library to make some sound before trying to plan out my pseudo code. It looks really simple to do the Introductory Tutorial for Mozzi.

http://sensorium.github.io/Mozzi/learn/introductory-tutorial/

The first three steps should take no more than 30 minutes and you will then be generating audio. From there, the tutorial demonstrates how to attach sensors to later use for controlling the audio.

Run through that page and you are more than half way to completing your hardware setup. Then it's time to start coding. There are more tutorials that will help you with that too.

Hi guys,

Sorry for the delay and thanks for everyones input.

I’ve been messing around and I think that I have my code. However there seems to be some sort of compiling warning that I’m unsure of.

I’ve included my code here to show you what I have.

#include <MozziGuts.h> //
#include <Oscil.h> // include the oscillator template
#include <tables/sin2048_int8.h> // the sine table for oscillator
#define CONTROL_RATE 128
// Use: Oscil <table_size, update_rate> oscilName (wavetable).
// Needs to be a power of two, typically at least 256 cells and preferably longer for lower aliasing noise.
// Oscil will be operating as an audio generator, so the update rate will be AUDIO_RATE.
// The table_data is an array
Oscil <SIN2048_NUM_CELLS, AUDIO_RATE> Sine1(SIN2048_DATA); //
Oscil <SIN2048_NUM_CELLS, AUDIO_RATE> Sine2(SIN2048_DATA);//
const int INPUT_PIN_0 = 0; // set the input for the knob to analog pin 0
const int INPUT_PIN_1 = 1; // set the input for the knob to analog pin 1
const int INPUT_PIN_2 = 2; // set the input for the knob to analog pin 2
byte master_Gain;
// to convey the volume level from updateControl() to updateAudio()
unsigned int Gain_1;
unsigned int Gain_2;
void setup(){

  • Serial.begin(115200); // set up the Serial output so we can look at the input values*

  • Sine1.setFreq(440);*

  • Sine2.setFreq(880);*

  • startMozzi(CONTROL_RATE); // :))*

  • }*
    void updateControl(){

  • // read the variable resistor for volume*

  • int sensor_value1 = mozziAnalogRead(INPUT_PIN_0); // value is 0-1023*

  • int sensor_value2 = mozziAnalogRead(INPUT_PIN_1); // value is 0-1023*

  • int sensor_value_3 = mozziAnalogRead(INPUT_PIN_2); // value is 0-1023*

  • // map it to an 8 bit range for efficient calculations in updateAudio*

  • Gain_1 = map(sensor_value1, 0, 1023, 0, 127); *

  • Gain_2 = map(sensor_value2, 0, 1023, 0, 127); *

  • master_Gain = map(sensor_value_3, 0, 1023, 0, 255);*

  • // print the value to the Serial monitor for debugging *

  • Serial.print("Sine_Gain_1 = "); *

  • Serial.print("Sine_Gain_2 = "); *

  • Serial.print("Master_Gain = "); *

  • Serial.println((int)master_Gain); *

  • Serial.println((int)Gain_1); *

  • Serial.println((int)Gain_2);*

}
int updateAudio(){

  • long out;*
    out = (((int)Sine1.next()*Gain_1)+(int)Sine2.next()Gain_2)>>8;
    out = master_Gainout>>8;
  • return out;*
    }
    void loop(){

audioHook(); // required here
}

the program compiles and states: Sketch uses 7,202 bytes (22%) of program storage space. Maximum is 32,256 bytes.
Global variables use 889 bytes (43%) of dynamic memory, leaving 1,159 bytes for local variables. Maximum is 2,048 bytes.[/]
However, the issue I have is that at the end of the compiling I am left with a lot of red text. This is below.
In file included from /var/folders/t9/bf__3zrs4v59f5h5tfxbz42w0000gn/T/arduino_5b2ab2273d15ac4768dba8eb4f918a66/sketch_jan07b.ino:1:0:
/Users/deadcell/Documents/Arduino/libraries/Mozzi/MozziGuts.h:151:2: warning: #warning “AUDIO_MODE is set to STANDARD_PLUS in mozzi_config.h. If things sound wrong, check if STANDARD_PLUS is the correct AUDIO_MODE for your sketch.” [-Wcpp]
#warning “AUDIO_MODE is set to STANDARD_PLUS in mozzi_config.h. If things sound wrong, check if STANDARD_PLUS is the correct AUDIO_MODE for your sketch.”
* ^*
/var/folders/t9/bf__3zrs4v59f5h5tfxbz42w0000gn/T/arduino_5b2ab2273d15ac4768dba8eb4f918a66/sketch_jan07b.ino:4:0: warning: “CONTROL_RATE” redefined [enabled by default]
#define CONTROL_RATE 128
^
In file included from /var/folders/t9/bf__3zrs4v59f5h5tfxbz42w0000gn/T/arduino_5b2ab2273d15ac4768dba8eb4f918a66/sketch_jan07b.ino:1:0:
/Users/deadcell/Documents/Arduino/libraries/Mozzi/MozziGuts.h:36:0: note: this is the location of the previous definition
#define CONTROL_RATE 64
^
In file included from /Users/deadcell/Documents/Arduino/libraries/Mozzi/MozziGuts.cpp:19:0:
/Users/deadcell/Documents/Arduino/libraries/Mozzi/MozziGuts.h:151:2: warning: #warning “AUDIO_MODE is set to STANDARD_PLUS in mozzi_config.h. If things sound wrong, check if STANDARD_PLUS is the correct AUDIO_MODE for your sketch.” [-Wcpp]
#warning “AUDIO_MODE is set to STANDARD_PLUS in mozzi_config.h. If things sound wrong, check if STANDARD_PLUS is the correct AUDIO_MODE for your sketch.”
I know there may not be any Mozzi users here, but with my brain processing on my meds it can make it difficult to process too much information at once. Do I need to worry that the code still compiled but with errors?

Welcome to the Forum. You have posted code without using code tags. The code tags make the code look

like this

when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don’t do it, some of the character sequences in the code can be misinterpred by the forum code as italics or funny emoticons.
If you have already posted without using code tags, open your message and select “modify” from the pull down menu labelled, “More”, at the lower left corner of the message. Highlight your code by selecting it (it turns blue), and then click on the “</>” icon at the upper left hand corner. Click on the “Save” button. Code tags can also be inserted manually in the forum text using the code and /code metatags.

Please read these two posts:

How to use this forum - please read.
and
Read this before posting a programming question …

Many questions can be answered by reading the documentation which is provided with the IDE, available under the help tab, or online here.

There are many other things that programmers do to make their code understandable. Please do them, as a courtesy to the members who volunteer their time to help you here. One is to use a standard indentation to clearly show the code blocks. Never put more than one statement per line. Place any brackets by themselves on a separate line. Before posting the code, use Ctrl-T in the IDE to reformat the code in a standard format, which makes it easier for us to read. Another is to give things descriptive names. You can name numerical constants, pin numbers, variables and many other things in this way. For example, you can refer to a pin and an output level by number, like digitalWrite(3,0). But such a statement doesn’t reveal anything about the purpose. digitalWrite(hornRelayPin, LOW) does. You can do that by declaring const byte hornRelayPin = 3; before setup() in your program. Many such names are already defined for you by the compiler and the Arduino IDE. Here are some:

#define HIGH 0x1
#define LOW  0x0
#define PI 3.1415926535897932384626433832795

Use them. There are many more. Use compiler math to compute values so you can see where they came from (or at least document them). For example, if you see the number 73, you would be hard put to explain the significance of it. But if you see “daysPerYear/5”, it is obvious. One more thing. When you work on program continuously, you become familiar with it. So many things seem obvious even if they are not spelled out explicitly. But try looking at your own code six months later. It will be as if a stranger wrote it. So write for strangers, not yourself.

Thanks for the pointers. I’ll take these on board for future reference.

I were having issues generating sound from my code. This may have been something to do with my breadboard wiring and I wasn’t able to determine on how to rectify this. I did however, start writing some alternative code whereby the IDE did not give any errors. However I am yet to test this with physical wiring and still need to follow up a prototype.

I’ve detailed my newer code below:

#include <MozziGuts.h> // Uses Mozzi Library
#include <Oscil.h> // includes the oscillator template from library
#include <tables/sin2048_int8.h> // Using the sine wavetable from the library
#define CONTROL_RATE 128

// Use: Oscil <table_size, update_rate> oscilName (wavetable).
   // Oscil is the audio generator, as it updates the rate will be AUDIO_RATE.
      // The table_data is classed as an array 

Oscil <SIN2048_NUM_CELLS, AUDIO_RATE> Sound1(SIN2048_DATA); //
   Oscil <SIN2048_NUM_CELLS, AUDIO_RATE> Sound2(SIN2048_DATA);//
      const int INPUT_PIN_0 = 0; // sets input for the pot to analog pin 0 
         const int INPUT_PIN_1 = 1; // sets input for the pot to analog pin 1
            const int INPUT_PIN_2 = 2; // sets input for the pot to analog pin 2
               byte master_Volume;
  
// to transmit the volume level from updateControl() to updateAudio()

   unsigned int Volume_1;
      unsigned int Volume_2;


void setup(){
     Serial.begin(115200); // sets the Serial output to review the input values
        Sound1.setFreq(440);
           Sound2.setFreq(880);
              startMozzi(CONTROL_RATE); 
}



void updateControl(){
     // reads the resistor for gain
        int sensor_value1 = mozziAnalogRead(INPUT_PIN_0); // value is 0-1023
           int sensor_value2 = mozziAnalogRead(INPUT_PIN_1); // value is 0-1023
              int sensor_value_3 = mozziAnalogRead(INPUT_PIN_2); // value is 0-1023
  
                 // maps to an 8 bit range. Apparently this is efficient for calculating updateAudio
                    Volume_1 = map(sensor_value1, 0, 1023, 0, 127);  
                       Volume_2 = map(sensor_value2, 0, 1023, 0, 127);  
                          master_Volume = map(sensor_value_3, 0, 1023, 0, 255);
  
                             // print the value to the Serial monitor for debugging   
                                Serial.print("Sound_Volume_1 = ");  
                                   Serial.print("Sound_Volume_2 = ");  
                                      Serial.print("Master_Volume = ");  
                                         Serial.println((int)master_Volume);  
                                            Serial.println((int)Sound_1);  
                                               Serial.println((int)Sound_2);
    
}

int updateAudio(){
     long out;
        out = (((int)Sound1.next()*Volume_1)+(int)Sound2.next()*Volume_2)>>8;
           out = master_Volume*out>>8;
              return out;
}
void loop(){
  
 audioHook(); // required here
}

I hope this is easier to understand than my last code. I am still in need of drawing up a block diagram for this code. Can I assume that I jot down in logical order of events each step (by step) as it is expected to occur?

I feel as if I have started this project backwards but if this code looks fine, I will draw up a block diagram and start compiling a circuit diagram to prototype with.

Is there any way I can upload my schematic to this thread for everyone review? I’ve drawn it up and it looks fine. I’m to then conduct my wiring on to a breadboard to see if the schematic and code go hand in hand. I think I’m making progress …