Using char2mozzi.py to convert a file from Audacity

590 views
Skip to first unread message

Richard Gallon

unread,
Aug 9, 2018, 6:38:21 AM8/9/18
to Mozzi-users
Hello

A basic question, which may be answered elsewhere, but am a Mozzi (and Python) newbie. Any step-by-step advice on how to use char2mozzi.py to convert a soundfile from Audacity using the script? Specifically running the script on a Mac (getting the file out of Audacity seems straightforward enough) to convert it.

Thanks in advance. Richard

Tim Barrass

unread,
Aug 9, 2018, 10:08:32 AM8/9/18
to 'Ian C.' via Mozzi-users
--
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.
To view this discussion on the web, visit https://groups.google.com/d/msgid/mozzi-users/1bc8786b-3d4b-47ee-b737-2b1325f231b2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted
Message has been deleted

Richard Gallon

unread,
Aug 9, 2018, 1:17:55 PM8/9/18
to Mozzi-users
Thanks for the reply, I saw that, but don't understand how to use the char2mozzi.py script? Do I need a program to run it? Do I download it? I am on a Mac.
As I said, a basic question. Hope you can help.

Tim Barrass

unread,
Aug 9, 2018, 10:22:43 PM8/9/18
to 'Ian C.' via Mozzi-users
In a terminal, type:
  python (path to your Mozzi/extras/python folder)/char2mozzi.py

and it should return this:
Usage: char2mozzi.py <infile outfile tablename samplerate>

so then you can type something like:
    python char2mozzi.py ~/Desktop/mysound.raw ~/Desktop/mysoundtable.h MYTABLENAME 16384

and if you have your prepared raw sound file  ~/Desktop/mysound.raw, hopefully mysoundtable.h will appear on your desktop, and you can drag it into your sketch.


Richard Gallon

unread,
Aug 10, 2018, 3:37:07 PM8/10/18
to Mozzi-users
Exactly what I was looking for. Thank you.

Richard Gallon

unread,
Aug 19, 2018, 4:18:33 PM8/19/18
to Mozzi-users
Hello Tim

I converted a couple of samples from Audactiy using the method you decsribed. However, when I try to add them to the example 'sample' sketch, I get lots of errors.

This is the code I tried to upload. I simply changed the names for your Burroughs sample to the info from the table I created, but it won't run:
[code]
/*  Example of playing a sampled sound,
    using Mozzi sonification library.
 
    Demonstrates one-shot samples scheduled
    with EventDelay.
 
    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 help/discussion/announcements:
    https://groups.google.com/forum/#!forum/mozzi-users
 
    Tim Barrass 2012, CC by-nc-sa.
*/

#include <MozziGuts.h>
#include <Sample.h> // Sample template
#include <samples/dancerclip2.h>
#include <EventDelay.h>

#define CONTROL_RATE 64

// use: Sample <table_size, update_rate> SampleName (wavetable)
Sample <dancerclip2_NUM_CELLS, AUDIO_RATE> aSample(dancerclip2_DATA);

// for scheduling sample start
EventDelay kTriggerDelay;

void setup(){
  startMozzi(CONTROL_RATE);
  aSample.setFreq((float) dancerclip2_SAMPLERATE / (float) dancerclip2_NUM_CELLS); // play at the speed it was recorded
  kTriggerDelay.set(1500); // 1500 msec countdown, within resolution of CONTROL_RATE
}


void updateControl(){
  if(kTriggerDelay.ready()){
    aSample.start();
    kTriggerDelay.start();
  }
}


int updateAudio(){
  return (int) aSample.next();
}


void loop(){
  audioHook();
}



[/code]

Any suggestions as to why it is not working? I get the repeated error
/Users/richardgallon/Documents/Arduino/libraries/Mozzi-master/samples/dancerclip2.h:4994:21: sorry, unimplemented: non-trivial designated initializers not supported

And also
/var/folders/g6/__n6jb317nscwd98_dy03vp00000gn/T/arduino_modified_sketch_565403/Sample.ino:25:42: warning: large integer implicitly truncated to unsigned type [-Woverflow]
 Sample <dancerclip2_NUM_CELLS, AUDIO_RATE> aSample(dancerclip2_DATA);
                                                                                   ^
exit status 1


Any help appreciated. Thanks in advance.


On Friday, 10 August 2018 03:22:43 UTC+1, Mr Sensorium wrote:

Tim Barrass

unread,
Aug 20, 2018, 12:27:29 AM8/20/18
to mozzi...@googlegroups.com
Hi Richard,

just a quick question, how big is your sample?  Maybe it's not fitting in memory?

Tim

Richard Gallon

unread,
Aug 20, 2018, 2:47:45 AM8/20/18
to Mozzi-users
It was quite long initially so I tried a shorter version, as I was getting an error saying as much. Will try an even shorter one and see if that works. Is there an optimum length?

Richard Gallon

unread,
Aug 20, 2018, 5:04:41 AM8/20/18
to Mozzi-users
Hi Tim

Thanks again. That was the issue. I managed to squeeze about 0.5 seconds on there in the end.

Richard

Tim Barrass

unread,
Aug 20, 2018, 5:36:52 AM8/20/18
to 'Ian C.' via Mozzi-users
If you don't need to do much processing, you can fit about 3 times more time (one and a half seconds!) by using the compressed sample format.  See examples>08.Samples>SampleHuffman_Umpah...

Richard Gallon

unread,
Aug 20, 2018, 7:10:14 AM8/20/18
to Mozzi-users
I'll give that a go. It would be good to have longer samples if possible.

Richard Gallon

unread,
Aug 20, 2018, 8:29:35 AM8/20/18
to mozzi...@googlegroups.com
Hi Tim

I tried running the audio2huff.py script but am getting an error - 'Error: Scikits.audiolab not found'. I tried to find Scikits.audiolab to download it, but am going round in circles a bit. Any ideas? Thanks. 

Richard

Tim Barrass

unread,
Aug 21, 2018, 12:04:03 AM8/21/18
to 'Ian C.' via Mozzi-users
Aha... does this help? https://pypi.org/project/scikits.audiolab/
Thanks for the alert, I'll add it to the documentation (if it works for you).


On 20 Aug 2018, at 10:29 pm, 'Richard Gallon' via Mozzi-users <mozzi...@googlegroups.com> wrote:

Scikits.audiola

Tim Barrass

unread,
Aug 21, 2018, 12:21:31 AM8/21/18
to 'Ian C.' via Mozzi-users
Mmm, I just tried it here and scikits.audiolab didn't install straight away.
You might have more luck from here: https://github.com/cournape/audiolab
And the README leads down some more rabbit holes requiring other dependencies...
It must have seemed worth the effort at the time of writing the Huffman converter, but looks like it might take a while to set up...

tim

Richard Gallon

unread,
Aug 21, 2018, 8:34:52 AM8/21/18
to mozzi...@googlegroups.com
I got as far as trying to install it (thanks for the link), but now it tells me sndfile (http://www.mega-nerd.com/libsndfile/) library not found and I am a bit stuck now as to how to install that bit. Was there much beyond that to do? If not, I will persevere, as will be great to have longer samples.

--
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.

Richard Gallon

unread,
Aug 23, 2018, 7:23:59 AM8/23/18
to mozzi...@googlegroups.com
I realise this may be outside of the scope of Mozzi assistance, but any pointers on how I can get the audio2huff.py script working? I would love to use some longer samples in your framework?

Tim Barrass

unread,
Aug 23, 2018, 8:22:49 AM8/23/18
to 'Ian C.' via Mozzi-users
Hi Richard, here's what didn't work for me today (a couple of other pathways failed yesterday):

install homebrew on osx if you haven't already

then, in the terminal,

brew install libsndfile
pip install scikits.audiolab 

fails

brew install python (to upgrade to python 3 to use updated numpy)
pip3 install numpy
pip3 install scikits.audiolab 

fails

google shows lots of people struggling to install scikits.audiolab on all platforms

It's probably worth noting on the Github Mozzi issue tracker in case someone has time to find a solution in the future...

tim

Tim Barrass

unread,
Aug 23, 2018, 8:42:20 AM8/23/18
to 'Ian C.' via Mozzi-users
another option is to use non-copressed samples with one of the platforms with more memory such as the Teensy3's or (with the current github development code) STM32F103C8T6 blue pill board...

christopher galicia

unread,
Jun 18, 2019, 8:14:42 PM6/18/19
to Mozzi-users
Hello

i´m trying to run the python script char2mozzi.py but is not clear how enter the data, so i tried with this, but it has mistakes. Thanks in advance:

char2mozzi.py <"C:\Users\Circus\Desktop\Snare01.raw" "C:\Users\Circus\Desktop\Snare01_int8.h" SNARE01 4096>
SyntaxError: invalid syntax
To unsubscribe from this group and stop receiving emails from it, send an email to mozzi...@googlegroups.com.

Tim Barrass

unread,
Jun 19, 2019, 6:38:16 AM6/19/19
to 'Ian C.' via Mozzi-users
Hi,

try it like this (without <...>):

char2mozzi.py "C:\Users\Circus\Desktop\Snare01.raw" "C:\Users\Circus\Desktop\Snare01_int8.h" SNARE01 4096

christopher galicia

unread,
Jun 19, 2019, 5:51:00 PM6/19/19
to Mozzi-users
Thanks for the answer, but it not work. Also i tried all these options without success

char2mozzi.py "~/Desktop/Snare01.raw" "~/Desktop/Snare01_int8.h" SNARE01 4096
char2mozzi.py ~/Desktop/Snare01.raw ~/Desktop/Snare01_int8.h SNARE01 4096
char2mozzi.py <~/Desktop/Snare01.raw ~/Desktop/Snare01_int8.h SNARE01 4096>
char2mozzi.py <"~/Desktop/Snare01.raw" "~/Desktop/Snare01_int8.h" SNARE01 4096>
char2mozzi.py "~/Desktop/Snare01.raw", "~/Desktop/Snare01_int8.h", SNARE01, 4096
char2mozzi.py "C:/Users/Circus/Desktop/Snare01.raw" "C:/Users/Circus/Desktop/Snare01_int8.h" SNARE01 4096

Any suggestion?

Tim Barrass

unread,
Jun 20, 2019, 7:38:10 AM6/20/19
to 'Ian C.' via Mozzi-users
Sorry, I forgot you need to prefix it with python (and you need python installed).

python char2mozzi.py "C:\Users\Circus\Desktop\Snare01.raw" "C:\Users\Circus\Desktop\Snare01_int8.h" SNARE01 4096



Alexander Henriksson

unread,
Sep 5, 2024, 6:24:06 AM9/5/24
to Mozzi-users
Hi everyone. im new to mozzi. Im trying to upload my code: 

#include <Mozzi.h>
#include <Sample.h> // Sample template
#include "A1_16384_int8.h" // Include your custom sample header
#include <EventDelay.h>

// Adjust the template parameters to match your sample's properties
Sample <A1_16384_NUM_CELLS, MOZZI_AUDIO_RATE> aSample(A1_16384_DATA);

// for scheduling sample start
EventDelay kTriggerDelay;

void setup(){
startMozzi();
aSample.setFreq((float) A1_16384_SAMPLERATE / (float) A1_16384_NUM_CELLS); // play at the speed it was recorded
kTriggerDelay.set(1500); // 1500 msec countdown, within resolution of MOZZI_CONTROL_RATE
}

void updateControl(){
if(kTriggerDelay.ready()){
aSample.start();
kTriggerDelay.start();
}
}

AudioOutput updateAudio(){
return MonoOutput::from8Bit((int) aSample.next());
}

void loop(){
audioHook();
}


Aand i get the following error in IDE:



/Users/alexanderhenriksson/Documents/Arduino/OwnSample/OwnSample.ino:7:9: error: 'A1_16384_NUM_CELLS' was not declared in this scope
 Sample <A1_16384_NUM_CELLS, MOZZI_AUDIO_RATE> aSample(A1_16384_DATA);
         ^~~~~~~~~~~~~~~~~~
/Users/alexanderhenriksson/Documents/Arduino/OwnSample/OwnSample.ino:7:9: note: suggested alternative: 'kk_NUM_CELLS'
 Sample <A1_16384_NUM_CELLS, MOZZI_AUDIO_RATE> aSample(A1_16384_DATA);
         ^~~~~~~~~~~~~~~~~~
         kk_NUM_CELLS
/Users/alexanderhenriksson/Documents/Arduino/OwnSample/OwnSample.ino:7:45: error: template argument 1 is invalid
 Sample <A1_16384_NUM_CELLS, MOZZI_AUDIO_RATE> aSample(A1_16384_DATA);
                                             ^
/Users/alexanderhenriksson/Documents/Arduino/OwnSample/OwnSample.ino:7:55: error: 'A1_16384_DATA' was not declared in this scope
 Sample <A1_16384_NUM_CELLS, MOZZI_AUDIO_RATE> aSample(A1_16384_DATA);
                                                       ^~~~~~~~~~~~~
/Users/alexanderhenriksson/Documents/Arduino/OwnSample/OwnSample.ino: In function 'void setup()':
/Users/alexanderhenriksson/Documents/Arduino/OwnSample/OwnSample.ino:14:11: error: request for member 'setFreq' in 'aSample', which is of non-class type 'int'
   aSample.setFreq((float) A1_16384_SAMPLERATE / (float) A1_16384_NUM_CELLS); // play at the speed it was recorded
           ^~~~~~~
/Users/alexanderhenriksson/Documents/Arduino/OwnSample/OwnSample.ino:14:27: error: 'A1_16384_SAMPLERATE' was not declared in this scope
   aSample.setFreq((float) A1_16384_SAMPLERATE / (float) A1_16384_NUM_CELLS); // play at the speed it was recorded
                           ^~~~~~~~~~~~~~~~~~~
/Users/alexanderhenriksson/Documents/Arduino/OwnSample/OwnSample.ino:14:27: note: suggested alternative: 'kk_SAMPLERATE'
   aSample.setFreq((float) A1_16384_SAMPLERATE / (float) A1_16384_NUM_CELLS); // play at the speed it was recorded
                           ^~~~~~~~~~~~~~~~~~~
                           kk_SAMPLERATE
/Users/alexanderhenriksson/Documents/Arduino/OwnSample/OwnSample.ino:14:57: error: 'A1_16384_NUM_CELLS' was not declared in this scope
   aSample.setFreq((float) A1_16384_SAMPLERATE / (float) A1_16384_NUM_CELLS); // play at the speed it was recorded
                                                         ^~~~~~~~~~~~~~~~~~
/Users/alexanderhenriksson/Documents/Arduino/OwnSample/OwnSample.ino:14:57: note: suggested alternative: 'kk_NUM_CELLS'
   aSample.setFreq((float) A1_16384_SAMPLERATE / (float) A1_16384_NUM_CELLS); // play at the speed it was recorded
                                                         ^~~~~~~~~~~~~~~~~~
                                                         kk_NUM_CELLS
/Users/alexanderhenriksson/Documents/Arduino/OwnSample/OwnSample.ino: In function 'void updateControl()':
/Users/alexanderhenriksson/Documents/Arduino/OwnSample/OwnSample.ino:20:13: error: request for member 'start' in 'aSample', which is of non-class type 'int'
     aSample.start();
             ^~~~~
/Users/alexanderhenriksson/Documents/Arduino/OwnSample/OwnSample.ino: In function 'AudioOutput updateAudio()':
/Users/alexanderhenriksson/Documents/Arduino/OwnSample/OwnSample.ino:26:45: error: request for member 'next' in 'aSample', which is of non-class type 'int'
   return MonoOutput::from8Bit((int) aSample.next());
                                             ^~~~

exit status 1

Compilation error: 'A1_16384_NUM_CELLS' was not declared in this scope

Mozzi-users

unread,
Sep 5, 2024, 8:36:57 AM9/5/24
to Mozzi-users
Hi,
just some basic questions first....
How does your sample file look? 
Does it have A1_16384_NUM_CELLS at the top? 
Is it in the folder with your sketch?


Reply all
Reply to author
Forward
0 new messages