Giter Site home page Giter Site logo

sensorium / mozzi Goto Github PK

View Code? Open in Web Editor NEW
1.0K 66.0 184.0 363.46 MB

sound synthesis library for Arduino

Home Page: https://sensorium.github.io/Mozzi/

License: GNU Lesser General Public License v2.1

C++ 3.54% C 37.09% Python 0.19% HTML 56.54% JavaScript 1.95% CSS 0.45% Shell 0.09% TeX 0.16%

mozzi's Introduction

Mozzi

sound synthesis library for Arduino

Currently your Arduino can only beep like a microwave oven. Mozzi brings your Arduino to life by allowing it to produce much more complex and interesting growls, sweeps and chorusing atmospherics. These sounds can be quickly and easily constructed from familiar synthesis units like oscillators, delays, filters and envelopes.

You can use Mozzi to generate algorithmic music for an installation or performance, or make interactive sonifications of sensors, on a small, modular and super cheap Arduino, without the need for additional shields, message passing or external synths.


Features

  • Available for a wide and growing range of MCUs, with and without inbuilt DACs: Arduino Uno R3 and R4, STM32, Teensy, ESP8266, ESP32, Raspberry Pi Pico, and more.
  • Configurable sample rate, usually in powers of two (16384 Hz, or 32768 Hz).
  • Variable control rate from 64 Hz upwards.
  • Various inbuilt output modes, including 16 bit output to an external DAC.
  • Allows interfacing to custom output routines, with examples for playing audio on external DAC modules, and even bluetooth.
  • Useful basic audio toolkit: oscillators, samples, lines, envelopes, scheduling, filtering.
  • Fast ADC and other cpu-efficient code utilities to help keep audio running smoothly.
  • Example sketches for easy modification.
  • Readymade wavetables and a script to convert your own soundfiles for Mozzi.
  • Mozzi is designed to be easy to use, open source and extendable.

Installation

The easiest installation option nowadays is to install Mozzi via the Library Manager in your Arduino application: Arduino➞Sketch➞Include Library➞Library Manager type "Mozzi" into the search field, then click "install".

For other installation methods (e.g. the development version), see the Download page.

Quick Start

To hear Mozzi, wire a 3.5mm audio jack with the centre to the audio out pin for your Arduino as shown in the table below, and the shield to GND on the Arduino. Plug into your computer and listen with a sound program like Audacity. (Or connect any other high-impedance input, like an active speaker) Try some examples from the File > Examples > Mozzi menu.

For more about audio output, including high quality output modes Mozzi Output tutorial.

A note for users coming from Mozzi 1.x

Mozzi 2.0 brings a lot of changes under the hood, and is not 100% source compatible with earlier versions of Mozzi. Most sketches should continue to compile, but with a lot of warnings. A few others will no longer work. See Porting to Mozzi 2.0 for what to change. If desparate, there is still a "Mozzi_1" branch in the git repository, but this will not get any new development.

Supported boards, output modes and default pins

Table is not necessarily complete. Abbreviations explained below the table. The default output mode is in bold for each row. If stereo is supported, in a mode, the cell PWM-1 has two numbers with the second pin number is given in parentheses (+X). Check the hardware section of the API-documentation for platform specific notes and (pin) configuration options.

Board or family / Output mode PWM-1 PWM-2 PDM inbuilt DAC I2S DAC (native)
ATmega328/168: Uno (R3), Nano, Pro Mini, Duemilanove, Leonardo, etc. 9 (+10) 9, 10
ATmega32U4: Teensy, Teensy2, 2++ B5/B6 correspond to pins 14/15 in Arduino B5 (+B6) B5, B6
ATmega2560: Arduino Mega, Freetronics EtherMega, etc. 11 (+12) 11, 12
ATmega1284: Sanguino 13 (+12) 13, 12
Teensy3.x - note: DAC Pin number depends on model: A14, A12, or A21 DAC
Teensy4.x A8 (+A9)
LGT8F328P: "Register clone" of the ATmega328, uses the same code in Mozzi 9 (+10) 9, 10
SAMD: Arduino Nano 33 Iot, Adafruit Playground Express, Gemma M0 etc. A0/Speaker
Renesas Arduino Core: Arduino Uno R4 A0
Arduino MBED Core: Arduino Giga (only model tested so far in this family) SERIAL2TX A13 (+A12)
STM32 maple core: Various STM32F1 and STM32F4 boards, "Blue/Black Pill" PB8 (+PB9) PB8, PB9
STM32duino (STM official) core: Huge range of STM32Fx boards PA8 (+PA9) PA8, PA9
ESP8266: ESP-01, Wemos D1 mini, etc. note: Beware of erratic pin labels GPIO2 yes
ESP32: note: Beware of vastly different pin labels across board variants yes GPIO25 (+GPIO26) yes
RP2040: Raspberry Pi Pico and friends 0 (+1) 0, 1 yes
  • PWM-1: 1-pin PWM mode (MOZZI_OUTPUT_PWM)
  • PWM-2: 2-pin PWM mode (MOZZI_OUTPUT_2PIN_PWM)
  • PDM: Pulse density modulation, may be either MOZZI_OUTPUT_PDM_VIA_SERIAL or MOZZI_OUTPUT_PDM_VIA_I2S
  • inbuilt DAC: MOZZI_OUTPUT_INTERNAL_DAC
  • I2S DAC (native): native support for externally connected I2S DACs (MOZZI_OUTPUT_I2S_DAC). Since this requires several, often configurable pins, and is never the default option, no pin numbers are shown in this table.
  • All platforms also support "external" output modes (MOZZI_OUTPUT_EXTERNAL_TIMED or MOZZI_OUTPUT_EXTERNAL_CUSTOM), which allow for connecting DACs or other external circuitry.

Using Mozzi

Here's a template for an empty Mozzi sketch:

#include <Mozzi.h>   // at the top of your sketch

void setup() {
	startMozzi();
}

void updateControl(){
	// your control code
}

AudioOutput_t updateAudio(){
	MonoOutput::from16Bit( [my_cool_sample] );
}

void loop() {
	audioHook();
}

There's a detailed example explaining the different parts here.

Documentation

For getting started, browse the practical help on the learn page on the Mozzi site.
API reference documentation is available in the doc folder in the Mozzi download and online.
Start or look up a topic on the users forum.
Also, feel free to submit any issues on the GitHub Mozzi site.
Look for code and usage changes here.
For hardware specific details, including supported features, caveats, and hardware-dependent configuration options, refer to the Hardware Section of the API-Documentation.

Compatibiliy issues

  • In most setups, Mozzi claims one or two hardware timers. This may result in incompatibilities with certain libraries, and / or the ability to use timer-based functions such as analogWrite(). As the details on this differ a lot between the supported boards, read up on the details - and available workarounds - in the ardware Section of the API-Documentation.

  • There is also an example on emulating analogWrite() on any digitial pin in Mozzi>examples>11.Communication>Sinewave_PWM_pins_HIFI.

  • The timers can be made available with stopMozzi(), which stops audio interrupts, until you call startMozzi().

  • Note that it is of utmost importance to write non-blocking code, such that the audio buffer never runs low. Hints on how to do this, including why, and how you should avoid using delay(), analogRead(), and how to make your code run faster, can be found at on the learn pages.

Extending Mozzi

Using external chips to produce the sound

External chips (DAC) can also be used on any platform which does not support natively the I2S protocol using an user defined audioOutput function. This can allow a greater audio quality over the native ways to output the sound (PWM for AVR Arduinos and STM32 and 12 bit DAC for Teensy 3.*). Examples are provided for the MCP492X DAC (12 bit on SPI) and for the (PT8211) 16 bit stereo DAC using SPI port to emulate the I2S protocol. The latter should be compatible with any DAC using I2S.

Extendig the library itself

If you enjoy using Mozzi for a project, or have extended it, we would be pleased to hear about it and provide support wherever possible. Contribute suggestions, improvements and bug fixes to the Mozzi wiki on Github, or Fork it to contribute directly to future developments.

Mozzi is a development of research into Mobile Sonification in the SweatSonics project.


Contributions / Included Dependencies

Modified versions of the following libraries are included in the Mozzi download:

TimerOne library
FrequencyTimer2 library - now a fork with support for ATmega32u4 processors

Mozzi has also drawn on and been influenced by (among many others):

xorshift random number generator, George Marsaglia, (2003)
ead~.c puredata external (creb library) Copyright (c) 2000-2003 by Tom Schouten (GPL2)
AF_precision_synthesis by Adrian Freed, 2009
Resonant filter posted to musicdsp.org by Paul Kellett, and fixed point version of the filter on dave's blog of art and programming
State Variable filter pseudocode at musicdsp.org and here
Various examples from Pure Data by Miller Puckette
Practical synthesis tutorials by Andy Farnell


Use and Remix

Mozzi is licensed under a the LGPL version 2.1 or (at your option) any later version of the license.

Disclaimer: This is a human-readable summary of (and not a substitute for) the license.

  • You may copy, distribute and modify the Mozzi library itself provided that you state modifications and license them under LGPL-2.1.

  • You may distribute your own source code which merely uses the Mozzi-API under any licence that you wish.

  • Regarding distribution of binaries (also inside a hardware project) that include Mozzi, the Arduino FAQ sums up the situation as follows: "Using the Arduino core and libraries for the firmware of a commercial product does not require you to release the source code for the firmware. The LGPL does, however, require you to make available object files that allow for the relinking of the firmware against updated versions of the Arduino core and libraries. Any modifications to the core and libraries must be released under the LGPL."

  • Note that using third-party libraries/code - including as shown in some of the Mozzi examples - may introduce additional restrictions.

mozzi's People

Contributors

adrianfreed avatar andor-pierdelacabeza avatar apiel avatar del avatar dependabot[bot] avatar dietervandoren avatar dudozermaks avatar j-enns avatar joefiorini avatar jypma avatar lfsaw avatar majikthys avatar per1234 avatar pschatzmann avatar sensorium avatar storrdev avatar sweatsonics avatar tfry-git avatar tinwelint78 avatar tomcombriat avatar wingunder avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mozzi's Issues

Teensy 2 Problem

Hello,
I tried to Upload some Mozzi examples to my teensy 2 but i can't compil them and i get this message:

C:\Documents and Settings\Me\Mes documents\electronique\teensy\arduino-1.0.1\libraries\Mozzi\utils.cpp: In function 'void startAnalogRead(unsigned char)':
C:\Documents and Settings\Me\Mes documents\electronique\teensy\arduino-1.0.1\libraries\Mozzi\utils.cpp:314: error: 'analogPinToChannel' was not declared in this scope

Sorry my english is bad.

reading some wavetables from SD card

Hello guys

I'm developing an oscillator that have many wavetables that dont fit into board memory.
I can load then from SD card because this operation is made in "stand by" mode , so I can stop all oscillators and change my wavetables .
But , I cant figure out how to read a new wavetable that wasnt loaded at compile time.
Any clue ?

Thank you!!

Issue Importing library to Arduino

Hello, I am on mac with mavericks with IDE 1.0.6

This is the Error message I got when choosing the Mozzi.zip file for library import.

java.util.zip.ZipException: error in opening zip file
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.(ZipFile.java:128)
at java.util.zip.ZipFile.(ZipFile.java:145)
at processing.app.tools.ZipDeflater.(ZipDeflater.java:25)
at processing.app.Base.handleAddLibrary(Base.java:2397)
at processing.app.Base$4.actionPerformed(Base.java:959)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.AbstractButton.doClick(AbstractButton.java:389)
at com.apple.laf.ScreenMenuItem.actionPerformed(ScreenMenuItem.java:95)
at java.awt.MenuItem.processActionEvent(MenuItem.java:650)
at java.awt.MenuItem.processEvent(MenuItem.java:609)
at java.awt.MenuComponent.dispatchEventImpl(MenuComponent.java:343)
at java.awt.MenuComponent.dispatchEvent(MenuComponent.java:331)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:720)
at java.awt.EventQueue.access$400(EventQueue.java:82)
at java.awt.EventQueue$2.run(EventQueue.java:676)
at java.awt.EventQueue$2.run(EventQueue.java:674)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:690)
at java.awt.EventQueue$3.run(EventQueue.java:688)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:687)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

Can you help me make sense of this, Thank you.

Mozzi supports atmega16u2 processor?

Sei, não é exatamente um issue. Acho que outros podem pesquisar sobre isso.
Porque eu tenho visto algumas placas baseadas em Arduino UNO com este processador "atmega16u2" e não com tradicional "atmega328p-pu".

Question: Teensy 3.6 Analog Pins 39-33

First off: the Mozzi Library is amazing and I am very grateful to everyone involved in the creation and the port to the Teensy 3.6, which I am using.
My problem in short:
when using the Mozzi Library, I am unable to read the analog input values of pins 39-33.

Project: I am trying to create a monophonic 4 oscilator (+1 Sub) synthesizer with variable volume and detune per oscilator, an LFO for modulating the pitch and filter cutoff, LowPassFilter, ADSR-Envelope, Midi-Capabilities and some analog audio effects.

Problem: The oscilator section and Midi work fine, so does the LFO. However, while implementing the filter, I ran into the issue. I tried to modulate the filter cutoff frequency with a potentiometer connected to pin 39 (also sometimes called A20). But it didn't work.
I tested the potentiometer before coding, and tested it again in a clean sketch. It seemed to be connected, but testing it in a sketch, which implements the Mozzi Library, it suddenly didn't work. (Testing by Serial.pintln(mozziAnalogRead(pin))). The other analog pins I used so far (pin14-13, A0-A9) work fine and were tested in the same manner.

Question: Is anyone else having the same issue? What could I do?

AMsynth examples do not compile under Linux due to wrong header names

Problem

The examples
/examples/06.Synthesis/AMsynth
and
/examples/06.Synthesis//AMsynth_HIFI

contain basically the same bug. In line 48 respectively 23, the include
#include <tables/COS2048_int8.h>
is written in capital letters. The actual file name however is cos2048_int8.h. This leads to a file not found error while compiling under linux and probably also OSX since both systems are case-sensitive in contrast to Windows.

My system

Ubuntu 12.4, 64-Bit.
Arduino 1.0.5

HIFI examples overflow audio range on avr

HIFI examples which used to output audio without major distortion now overflow. The examples work when the audio in the sketches is right shifted >> 1. Not sure if the old behaviour was incorrect and the examples should be adjusted, or if the newer code has introduced an error.

#if (AUDIO_MODE == HIFI)

Mozzi 0.01.1x HIFI issue

Hi,

First of all thanks for this great library!
I have an error to report: when switching to hifi mode, arduino gives an error about variable num_out not being defined in MuzziGuts.cpp line 201

the variable's name is probably deprecated, i managed to fix it by looking at the code for standard audio

still wanted to point this out to you.

cheers
Thomas

teensy 4.0 support?

Well Teensy 4.0 is a thing and on the website for Mozzi it only lists Teensy 2.0 and 3.0. I'm a little confused if it will ever get support. Also i cant just try to use the 3.0 stuff because for some reason it only has A0 to A13.

Mozzi Pins
Teensy2, 2++ | B5 (25)
Teensy3.x | A14 (analog out)
link to pin out
https://www.pjrc.com/store/teensy40.html

Question: Emulating legendary Roland TB-303 Bass Line

What was the closest you managed get to 303 sound? :-) I know this is not exactly easy task.
But do you have some example sketches or tricks and tips on how to mimmick that sharp chirping bass of Roland using Mozzi?

Mozzi ignores selected reference voltage set by analogReference()/overwrites REFS0 in ADMUX when using mozziAnalogRead()

mozziAnalogRead() is currently limited to "AV CC with external capacitor at AREF pin" (REFS[1:0] = 00) as the ADC reference voltage. Setting a reference via Arduino's analogReference() is ignored. Setting REFS[1:0] in ADMUX manually is also overwritten in adcSetChannel()

ADMUX = (1 << REFS0) | (channel & 0x07);
.

There should be at least a warning about this unexpected behavior, since sources connected to AREF could get damaged by getting their output connected to AVCC inside the MCU when calling mozziAnalogRead().

Adafruit Feather M0 degraded audio issue

Hello,

I've successfully ran most Mozzi examples on an Uno. I am however having a problem running the same examples on an Adafruit Feather M0 (which uses an ATSAMD21G18 ARM Cortex M0 processor).

The audio does come out but it seems distorted. It was pretty clear when running the Sinewave example, but it became really obvious when running the Samples Tables Arrays examples (I'm running all examples as is).

Please see below (all recordings done on the same computer using the same USB interface):

Is there an obvious fix, or at least a direction that I could try looking into? Is this related to the onboard DAC (one of its settings)..?

Thank you very much!

swapping out different wave-table arrays in struct

I am trying to build a multi-channel synth (4 voices with choice of whatever wave-table you want.) To make it simple, I am using all 512-sized wave-tables. I want to define each channel as a struct, like this:

#include <tables/sin512_int8.h>
#include <tables/saw_analogue512_int8.h>
#include <tables/triangle_analogue512_int8.h>
#include <tables/square_analogue512_int8.h>

#define SIN 0
#define SAW 1
#define TRI 2
#define SQR 3

#define VOICE_COUNT 4

struct  {
    byte gain;
    int freq;
    byte wavenum;
} channel[VOICE_COUNT] = {0, 440, SIN};

I imagine that things like this would be happening in updateControl():

void updateControl(){
    channel[1].gain = 1;
    channel[1].wavenum = TRI;
    channel[1].freq = mtof(64);
}

I am having trouble understanding how to init Oscil() into an array structure (in example: wave_tables,) so in my updateAudio() I can just do this:

int updateAudio(){
  output=0;

  for(i=0;i<VOICE_COUNT;i++){
    if (channel[i].gain != 0){
        wave_tables[ channel[i].wavenum ].setFreq(channel[i].freq);
        output += wave_tables[ channel[i].wavenum ].next() * channel[i].gain;
    }
  }

  return output;
}

I don't understand how to make wave_tables array. Am I thinking about this the wrong way? Do I need to do something with pointers or manually mess with phase?

ESP8266 support

Hi!!! Thanks for this awesome library, it rocks!!! :)

Would it be possible to add support for make it work in a ESP8266 board? ESP8266 is much more powerful than Arduino ande it has WiFi and MIDI over WiFi compatibility. I think it will be a superb combination :)

What should I do for making Mozzi compatible with ESP8266??

Thanks

404s in documentation

I've been seeing a few 404s in the documentation. Example: click the hyperlink to MozziGuts.h (at the bottom of the CONTROL_RATE section). It links to this url which is 404.

Weirdly, the file does exist in the repo.

My feeling is that the underscore at the beginning of the file is creating an issue. Actually, that's most probably it -- see here!

Probably that adding a .nojekyll file to the root path (as instructed in the page linked above) would be the simplest thing to do..?

ESP32 support

Thanks for the ESP8266 Support but the ESP32 is better in every manner.

teensy2 compile error / analog_pin_to_channel_PGM

I am trying to get Mozzi running with a teensy2 but i get this error message.

Mozzi/mozzi_analog.cpp.o: In function adcStartConversion(unsigned char)': .../Documents/Arduino/libraries/Mozzi/mozzi_analog.cpp:115: undefined reference toanalog_pin_to_channel_PGM'

A fix found in a issue opened by Nanoblender does not seem to work.

Mozzi suddenly stopped compiling - something about a missing file: #include <compat/twi.h>

Using a Teensy 3.5, I started going through the Mozzi tutorials and examples, everything was fine. Went back 2 days later and suddenly nothing will compile. I've tried fully uninstalling Arduino, Teensyduino and Mozzi and reinstalling different versions. Always the same result. Basic Arduino sketches are uploading so I'm guessing it's not a board/port issue.

Arduino: 1.6.12 (Mac OS X), TD: 1.31, Board: "Teensy 3.5, Serial, 120 MHz, US English"

WARNING: Category 'Sound' in library Mozzi is not valid. Setting to 'Uncategorized'
In file included from /Users/joaoorecchia/Documents/Arduino/libraries/Mozzi/twi_nonblock.cpp:12:0:
/Users/joaoorecchia/Documents/Arduino/libraries/Mozzi/twi_nonblock.h:17:24: fatal error: compat/twi.h: No such file or directory
#include <compat/twi.h>
^
compilation terminated.
Error compiling for board Teensy 3.5.

Possible to use high-speed PWM pin 11?

I have eurorack module using pin 11 for output ( phase-correct ). Current code looks like:

#define PWM_PIN       11
#define PWM_VALUE     OCR2A

void audioOn() {
  // Set up PWM to 31.25kHz, phase accurate
  TCCR2A = _BV(COM2A1) | _BV(WGM20);
  TCCR2B = _BV(CS20);
  TIMSK2 = _BV(TOIE2);
}

void setup() {
  pinMode(PWM_PIN,OUTPUT);
  audioOn();
}

SIGNAL(PWM_INTERRUPT) {
  // get output value logic..
  PWM_VALUE = output;
}

Having hard times figuring out how to run Mozzi on it. Is it possible? Sorry if noob question or unrelated.

Mozzi and wire.h

I want to control mozzi reading raw data, but when I include wire.h library I got thia error while compiling:
libraries\Wire\utility\twi.c.o: In function `__vector_24':

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src\utility/twi.c:384: multiple definition of `__vector_24'

libraries\Mozzi-master\twi_nonblock.cpp.o:C:\Program Files (x86)\Arduino\libraries\Mozzi-master/twi_nonblock.cpp:456: first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino/Genuino Uno.

Since i think there’s a conflict between the libraries, Is there any way to read raw directly using mozzi libraries or read raw data without wire.h?

Problem w/ Sketch Upload

After creating a .h file with a wave table, in python, my sketch compiles with no errors in the arduino environment, but when I upload to the arduino board I get an error:

Binary sketch size: 19,340 bytes (of a 258,048 byte maximum)
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: verification error, first mismatch at byte 0x4135
0x01 != 0xff
avrdude: verification error; content mismatch

Have you seen this before, or know what could be going on?
Thanks,

r

Size of samples on Teensy LC

Hello,

First off, thanks to all developers for a wonderful library!

I've been trying to use it with Teensy LC. After scaling the audio data to 12-bit range, I can get a sound from a simple sample playback and an oscillator.

However, if I try to load a sample larger than 8kB, Teensy seems to freeze once I initialize Sample with that data. My understanding is that samples are read directly from flash, is that not the case? Teensy LC has 8kB RAM and 62kB flash, according to the specs.

I'm experiencing this e.g. with the Sample sketch that uses burroughs1_18649_int8 table. I'd appreciate any pointers as to what might be the issue here.

I am using the latest version downloaded from github.

fatal error: Mozziguts.h: No such file or directory

Running Arduino on Ubuntu 12.04, received:

~/arduino/libraries/Mozzi/MozziGuts.cpp:24:23: fatal error: Mozziguts.h: No such file or directory

Changing line 24 of MozziGuts.cpp to

include "MozziGuts.h"

resolves the problem. Easy fix.

Wrong pitch for ESP8266 and external I2S DAC output (pt8211)

\Mozzi\MozziGuts.cpp:378:51: error: 'i2s_lr' was not declared in this scope
i2s_lr((uint16_t) (updateAudio() + AUDIO_BIAS), 0);

I've changed to
i2s_write_lr((uint16_t) (updateAudio() + AUDIO_BIAS), 0);

and now compliing is done but sound is a bit distorted.
MCP49xx dac feature is awesome. In fact, examples like fmsynth on atmega328 + MCP49xx sounds much better than ESP8266 + PT8211 so there must be something wrong on code, but I can't find it.

Configure AUDIO_MODE in sketch

I've found a way to configure AUDIO_MODE in sketches instead of editing mozzi_config.h. AUDIO_MODE will be STANDARD_PLUS by default. Including a file called hifi.h in the first line of the sketch will set it to HIFI.

Old HIFI sketches would need to be updated, but it's a simple fix which a compiler warning could also advise.

Would it be better to require the config file also for STANDARD_PLUS, so AUDIO_MODE is always explicit in the sketch? It would break more sketches but is more consistent.

Any suggestions are welcome.

If there are no objections I'll go ahead as I think it's a good improvement in usability.

problem using hifi mode with serial communication

Hi,
First of all my compliments for this brilliant library.

I am using mozzi to create an electronic hurdy gurdy, where I am generating the sound of two strings with mozzi, based on the speed of an encoder. I use 1 Arduino for running mozzi (Duemilanove with ATmega168), and a second Arduino to read the encoder (Arduino Pro Mini 328), because I didn't want to mess up Mozzi with the interrupts that I need for the encoder.

On the second Arduino I calculate the speed of the encoder, and I send it over a serial link to the first arduino, to change the sound based on the speed.

I set everything up in 'standard' mode, and it was working fine (except for my wife complaining about the high-pitched squeal). Then I switched to hifi mode, including the proposed filtering. I checked this on a single Arduino, and it works fine.

BUT: for some reason my serial communication has stopped working. I have double checked, and it seems that switching to hifi mode kills my serial communication. Is this a known fact with an existing work around? Advice is much appreciated.

Jaap

teensy 2++ support

I have a teensy 2++, and I can't seem to load Mozzi on it and get sound output. The built-in USB support (act as a USB MIDI device) and low cost make this an awesome platform for Mozzi. I also have atmega8, 168, & 328s for testing compatibility, if more hardware testing needs to be done.

initializeCPUCycles and FAST error

Wonderful project, thank you so much! I get an error trying to compile my sketch, which I believe is from the Mozzi library:

Users/JeffThompson/Documents/Arduino/libraries/Mozzi/MozziGuts.cpp: In function 'void startAudioStandard()':
/Users/JeffThompson/Documents/Arduino/libraries/Mozzi/MozziGuts.cpp:285:9: error: 'class TimerOne' has no member named 'initializeCPUCycles'
  Timer1.initializeCPUCycles(16000000UL/PWM_RATE, FAST); // fast mode enables higher PWM rate
         ^
/Users/JeffThompson/Documents/Arduino/libraries/Mozzi/MozziGuts.cpp:285:50: error: 'FAST' was not declared in this scope
  Timer1.initializeCPUCycles(16000000UL/PWM_RATE, FAST); // fast mode enables higher PWM rate
                                                  ^
exit status 1
Error compiling.

Is this an issue with the library?

Issues uploading to Arduino DUE

Hello,

I'm trying to use Mozzi on arduino DUE, the code compiles Ok, but when I try to upload it I get this error, any ideas on how to deal with this?

Arduino: 1.6.1 (Mac OS X), Board: "Arduino Due (Native USB Port)"

WARNING: library Mozzi claims to run on [avr] architecture(s) and may be incompatible with your current board which runs on [sam] architecture(s).

In file included from mozzi_basic.ino:2:0:
/Users/cavadagonzalo/Documents/Arduino/libraries/Mozzi-master/Oscil.h:24:25: fatal error: util/atomic.h: No such file or directory
#include <util/atomic.h>
^
compilation terminated.
Error compiling.

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.

Thanks in advance for any help with this!

Problem with AudioDelayFeedback Example Sketch

Hi all,

I've tried to use the AudioDelayFeedback example on GitHub for implement my code with a delay.
So i want to learn the basic form of delay.

Using the AudioDelayFeedback example i would like to create a sketch that only reproduce the signal delayed after release the button.
When i press the button, i want only signal in my ear.

If i try to use the delay only option in the output part of the code, i recive an error.

The error is:

testdelay:57:47: error: call of overloaded 'next(int8_t, byte&)' is ambiguous

   return aDel.next(aTriangle.next(), del_samps); // instead of the previous 2 lines for only the delayed signal

                                               ^

In file included from C:\Users\User\Documents\Arduino\testdelay\testdelay.ino:18:0:

C:\Users\User\Documents\Arduino\libraries\Mozzi-master/AudioDelayFeedback.h:92:10: note: candidate: int16_t AudioDelayFeedback<NUM_BUFFER_SAMPLES, INTERP_TYPE>::next(int8_t, uint16_t) [with unsigned int NUM_BUFFER_SAMPLES = 128u; signed char INTERP_TYPE = 0; int16_t = int; int8_t = signed char; uint16_t = unsigned int]

  int16_t next(int8_t input, uint16_t delaytime_cells)

          ^

C:\Users\User\Documents\Arduino\libraries\Mozzi-master/AudioDelayFeedback.h:117:10: note: candidate: int16_t AudioDelayFeedback<NUM_BUFFER_SAMPLES, INTERP_TYPE>::next(int8_t, Q16n16) [with unsigned int NUM_BUFFER_SAMPLES = 128u; signed char INTERP_TYPE = 0; int16_t = int; int8_t = signed char; Q16n16 = long unsigned int]

  int16_t next(int8_t input, Q16n16 delaytime_cells)

          ^

exit status 1
call of overloaded 'next(int8_t, byte&)' is ambiguous

My code is:

/*  Example of flanging,
    using Mozzi sonification library.
    Demonstrates AudioDelayFeedback.
    Circuit: Audio output on digital pin 9 on a Uno or similar, or
    DAC/A14 on Teensy 3.1, or
    check the README or http://sensorium.github.com/Mozzi/
		Mozzi documentation/API
		https://sensorium.github.io/Mozzi/doc/html/index.html
		Mozzi help/discussion/announcements:
    https://groups.google.com/forum/#!forum/mozzi-users
    Tim Barrass 2012-13, CC by-nc-sa.
*/

#include <MozziGuts.h>
#include <Oscil.h>
#include <tables/triangle_analogue512_int8.h> // wavetable
#include <tables/triangle512_int8.h> // wavetable
#include <AudioDelayFeedback.h>
#include <mozzi_midi.h> // for mtof

#define CONTROL_RATE 128 // Hz, powers of 2 are most reliable

Oscil<TRIANGLE_ANALOGUE512_NUM_CELLS, AUDIO_RATE> aTriangle(TRIANGLE_ANALOGUE512_DATA); // audio oscillator
Oscil<TRIANGLE512_NUM_CELLS, CONTROL_RATE> kDelSamps(TRIANGLE512_DATA); // for modulating delay time, measured in audio samples

AudioDelayFeedback <128> aDel;

// the delay time, measured in samples, updated in updateControl, and used in updateAudio
byte del_samps;

void setup(){
  startMozzi(CONTROL_RATE);
  aTriangle.setFreq(mtof(48.f));
  kDelSamps.setFreq(.163f); // set the delay time modulation frequency (ie. the sweep frequency)
  aDel.setFeedbackLevel(-111); // can be -128 to 127
}


Q16n16 deltime;


void updateControl(){
  // delay time range from 0 to 127 samples, @ 16384 samps per sec = 0 to 7 milliseconds
  del_samps = 64+kDelSamps.next();

  // delay time range from 1 to 33 samples, @ 16384 samps per sec = 0 to 2 milliseconds
  //del_samps = 17+kDelSamps.next()/8;

  //deltime = Q8n0_to_Q16n16(17) + ((long)kDelSamps.next()<<12);

}


int updateAudio(){
  char asig = aTriangle.next(); // get this so it can be used twice without calling next() again
  //return asig/8 + aDel.next(asig, del_samps); // mix some straight signal with the delayed signal
  return aDel.next(aTriangle.next(), del_samps); // instead of the previous 2 lines for only the delayed signal
  //return asig/8 + aDel.next(asig, deltime); // mix some straight signal with the delayed signal
}


void loop(){
  audioHook();
}

How i can fix it?

Setting USE_AUDIO_INPUT to true causes NS1 Nanosynth to hang after 10s

Steps to reproduce:

Expected result:

  • Sawtooth wave is played out of PIN 9 whilst the nanosynth has power

Actual result:

  • Sawtooth wave stops playing after around 10 seconds, and the device becomes unresponsive to MIDI input (no LED flashes when notes are sent)

Note: After problem has occurred to reflash the nanosynth you need to hold down the reset button, and release it only when the new sketch is shown as "uploading" in the Arduino IDE.

3.5 mm jack and sound from Mozzi Arduino examples

Hi I connected a jack back into my powermac - it had two cables the black to ground and the other to pin 9 on an Arduino demimilanove - i was getting a readout from my input level meter in the sound input window in Powerbooks system prefs. But no sound !!

you mention running it through audacity? is this for playback or have i missed something fundamental

thanks
Frank

MOZZI Library with Teensy LC

Hi to all,
I have read in the documentation that the test on the Teensy LC has been carried out with positive result, but it does not result anywhere how to configure it.
If I try to follow the documentation regarding the changes needed to use a Teensy, I have a lot of compiling problems.

The wording on the https://sensorium.github.io/Mozzi/ page also speaks of Teensy LC. Is this an error or can I not find the specific documentation?

"released version" from downloads page seems really old?

I downloaded the "most recent version" from https://sensorium.github.io/Mozzi/download/

I am getting this message in Arduino:

Invalid version 'version 2013-07-07-17:51' for library in: /Users/skybrian/Documents/Arduino/libraries/Mozzi

I looks like this was fixed many years ago and the zip file there might not actually be the most recent release? libraries.properties on GitHub says 1.0.3 and looking at the GitHub releases tab, 1.0.2 seems to be the most recent stable release.

Does not compile when set to HIFI mode

Arduino 1.8.1
Mozzi 1.0.3rc4
Windows 10

Examples work fine in the default STANDARD_PLUS mode, but when attempting to compile any example in HIFI mode (by setting it in the mozzi_config.h file), it produces the following error:

`In file included from C:...\Arduino\libraries\Mozzi-1.0.3rc4\MozziGuts.cpp:13:0:

C:...\Arduino\libraries\Mozzi-1.0.3rc4\MozziGuts.cpp: In function 'void setupTimer2()':

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:104:37: error: expected unqualified-id before '(' token

#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )

                                 ^

C:...\Arduino\libraries\Mozzi-1.0.3rc4\MozziGuts.cpp:443:29: note: in expansion of macro 'clockCyclesPerMicrosecond'

period *= FrequencyTimer2::clockCyclesPerMicrosecond();

                         ^

C:...\Arduino\libraries\Mozzi-1.0.3rc4\MozziGuts.cpp:444:2: error: 'setPeriod' is not a member of 'FrequencyTimer2'

FrequencyTimer2::setPeriod(period);

^

exit status 1
Error compiling for board Arduino/Genuino Uno.`

Strange frequency shift on STM32

I have identified a strange problem running mozzi on STM32. Playing a Sample or an Oscil is slightly faster than it should be (exactly 1.5% faster). For example, if I make a sketch that plays a sinewave at 440 Hz, on the AVR I obtain a correct 440 Hz sinewave, the same sketch running on a STM32 produces a 447Hz sound.
I verified this is independent from audio mode (HIFI or STANDARD_PLUS), and independent from the actual wavetable used.

Problem running example _01_Sinewave with sin256_int8 sample

Changing the wavetable from sin2048_int8 to sin256_int8 in the _01_Sinewave example, you can hear a very detuned A4 sound (a G4, actually).

Can it be some kind of bug or is there some explanation for this behaviour?

Hint: at higher frequencies (tested 880+) the detuning shortens to a half tone.

Gemma M0 support

Hi,
it seems that Mozzi has trouble to support Gemma M0 boards. Compilation aborts because the file <util/atomic.h> is missing. As it has been tested and verified as working, I tried with others release, without any improvement.
Nice tool btw !

A strange clicking when StateVariable filter is used in a couple with phMod method

I'm new in Mozzi. I've experimented with code and tried to pass FM-modulated signal across StateVariable filter. Then I discovered strange clicking sound on output. Moreover it is present only if I call next() for another Oscill else (when I comment this //char s2 = sig2.next(); ) it is ok. The same behavior is in Proteus when I simulate ATMega2560. Please help me to solve that problem. Code:

include <MozziGuts.h>

include <Oscil.h>

include <StateVariable.h>

include <tables/sin512_int8.h>

define CONTROL_RATE 64

Oscil <512, AUDIO_RATE> sig1(SIN512_DATA);
Oscil <512, AUDIO_RATE> sig2(SIN512_DATA);
Oscil <512, AUDIO_RATE> fmVib(SIN512_DATA);
StateVariable svFilter;

void setup(){
startMozzi();

fmVib.setFreq(10);
sig1.setFreq(880);
sig2.setFreq(440);
svFilter.setResonance(100);
svFilter.setCentreFreq(1500);
}

void updateControl(){
}

int updateAudio(){
long vibrato = 300 * fmVib.next();
char s2 = sig2.next();
int unfiltered = (int) sig1.phMod(vibrato);
int filtered = svFilter.next(unfiltered);
return filtered >> 2;
}

void loop(){
audioHook();
}

RFC: Scaling output samples when switching audio configuration or CPU

I don't know how many people are playing / will be playing with Mozzi on different CPUs, but one of the annoying aspects while cross-testing is that different ports expect a different audio resolution to be returned from updateAudio(). The same problem applies when switching between available audio configurations on the same CPU.

An example written for StandardPlus (8.5bits or so) will be somewhat quiet on the STM32 (10 bits), very quiet on the Teensy (12 bits), definitely too quiet in HIFI mode (14 bits), and barely audible on the upcoming ESP8266 port (16 bits). That's rather sad, as everything else in a typical Mozzi sketch can be expected to work, unchanged. You would not believe how many times I went hunting for "what did I break now" while cross-testing, when the whole problem was that I forgot to adjust updateAudio() to my current configuration. I wonder how many users will experience similar woes when trying something new. Another symptom of this problem is "duplicate" examples for standard and HIFI modes.

So: Wouldn't it be cool, if Mozzi could do the necessary scaling all automatically? (Yeah!) But how?

  1. A first, naive approach would be to make all ports assume the value returned by updateAudio() are 8 (or 9) bit resolution, these could then be scaled up to the output bits inside audioHook(), for those ports/configs that support more bits. But this approach has severe problems:
  • Breaks existing sketches using higher resolution in updateAudio()
  • Adjusts the volume, but limits the effective audio resolution to 8 bits, where some ports could offer much better quality.
  1. A second approach would be to make all ports assume samples scaled to - say - 16 bits returned by updateAudio(), and scale down from this, automatically, as appropriate. As the intermediate resolution is high, each port can support maximum quality. However, this time, the problems are:
  • Breaks the vast majority of existing sketches returning 8-9 bits in updateAudio()
  • Places an additional (small) processing requirement on the lower end CPUs, where processing power is already most scarce.
  1. A third approach will be to use an opt-in "best practice" solution to automatic scaling. This would specify the number of audio bits generated, and auto-magically scale those to the appropriate output resolution. To elaborate, this would rest on macros like this (where AUDIO_BITS is the desired output resolution):
// Assume that "value" is scaled to "bits" resolution, and scale it to the output resolution appropriate for the current configuration
// As long as bits is a compile time constant, the compiler should be smart enough to optimize this to a static shift operation (or nothing)
#define SCALE_AUDIO(bits, value) ((bits < AUDIO_BITS) ? (value << (AUDIO_BITS-bits)) : ((bits > AUDIO_BITS) ? (value >> (bits-AUDIO_BITS)) : value))
#define SCALE_AUDIO8(value) SCALE_AUDIO(8, value)
#define SCALE_AUDIO16(value) SCALE_AUDIO(16, value)

Then to "opt-in" to auto-scaling, users would be encouraged to wrap the return value in updateAudio() like this:

int updateAudio() {
   int ret = [terribly complicated maths resulting in 13 used bits];
   return SCALE_AUDIO(13, ret);
}

The third approach is much better, IMO:

  • Being an opt-in solution, it cannot break any existing sketches, by definition.
  • No need to limit the returned resolution, arbitrarily, but still any required up-or-down shifting will only need to be done once.

Now, that's all fine and dandy, but then there's the (important!) special case of "StandardPlus", where the supported audio output resolution is "almost, but not quite 9 bits". There, we cannot assume that we can safely shift samples to 9 bit resolution, but shifting everything to 8 bits would be wasteful. What to do?

Looking at the existing examples for StandardPlus, these seem to fall into two categories: a) One simply returns exactly 8 bits, assuming the full range will be used - e.g. direct output from an Oscil. b) The other category returns values that will not usually, but might reach 9 bits. E.g. "08.Samples/Samples_Tables_Arrays". Here, the return value is constrain()ed to the actual -243..244 range before returning.

My current idea is to for dealing with this is (I hope I'm explaining it well):

  • No special handling for case a). This will simply use SCALE_AUDIO(8,...) or SCALE_AUDIO8(...), which will be set to not do any scaling for StandardPlus, or more precisely, this will shift to a target level of 8 bits in StandardPlus (if necessary). On other ports/configurations, the input will be scaled as shown above.
  • For case b) add a second set of macros SCALE_CLIP_AUDIO(9,...) or SCALE_CLIP_AUDIO9(...). This will signify that the supplied values will have around 9 bits, possibly even more, but usually less. It will (not) shift to a target level of 9 bits in StandardPlus, but also add add a constrain(). On other ports/configurations, the input will be scaled as if it was 9 bits (and also constrained).

Your thoughts?

Next release - any concerns?

I'd like to make a new release soon, as I've had reports that v1.0.3rc6 is not working in some situations and Mozzi has developed with Thomas' work particularly in the last 2 years.

Are there any concerns or suggestions towards getting the release together with the current development code?

High pitched squeal

On an Arduino Diecimila (ATmega168), when running the Example sketches, I hear a high pitched squeal somewhere in the vicinity of dog-whistle frequency space.

Is the library specific to certain Arduino boards (e.g. for timing purposes) ?

library properties version line 8 crashes Arduino IDE

I'm getting started using mozzi but as soon as I add the library manually or via zip it crashes everything.
By elimination it led me to line 8 (version info) of the library properties. Not sure what's wrong with it but after deleting it it loads Arduino IDE.

I'm using windows 10

this is the line I deleted "version=version 2013-07-07-17:51 "

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.