char2mozzy : how to prepare the waveforms

817 views
Skip to first unread message

Philippe DUVERGER

unread,
Dec 4, 2013, 3:55:19 AM12/4/13
to mozzi...@googlegroups.com
Hello

I have a little issue. It's not really a mozzy issue but more how  to prepare my sample/oscil. and to use it with char2mozzi.py.
I have a siren with a sound I really like, and I would like to copy this sound. (it is like a square oscil, but with some specificities giving a really special tone.)

So I configured the rate size (8192) of Audacity for one project. and also recorded my square waveforms (I have it with many samples (more than 8192) for one period but it's of course shorter than 1sec.)
How can I "extends" this recording to one second in order to have my whole period in 8192 ?
I really look in the audacity functionnality but could not find anything....

Hope I was clear enough and sorry if I am really wrong in the way to process that.

Thanks

Tim Barrass

unread,
Dec 4, 2013, 6:35:58 AM12/4/13
to mozzi...@googlegroups.com
Hi Philippe,
you might be able to do it better with a tool like sox, but anyway, with Audacity, how about this:

Set the project rate so that the duration of your wave will make it fit into 8192 samples of audio played back at that rate.
eg.

original_duration = 0.6 seconds
original_number_of_samples = 10000
original_sample_rate = 10000 * 1/0.6 = 16666.66 Hz

To get the sound to be 8192 samples long,
set the project rate to original_sample_rate * 8192/10000 = 13653 Hz
To check, 0.6 seconds * 13653 Hz = 8191.8

Then export your sample to raw 8 bit and it should be OK to convert with char2mozzi.py

You might have to manually adjust the file produced by char2mozzi.py, if it makes it a sample too short..

Does that make sense?  Will it work?

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...@googlegroups.com.
To post to this group, send an email to mozzi...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/mozzi-users/eacfdcfa-6895-4219-bbae-957a8fa1b815%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Tim Barrass

unread,
Dec 4, 2013, 6:37:28 AM12/4/13
to mozzi...@googlegroups.com
sorry, this line

set the project rate to original_sample_rate * 8192/10000 = 13653 Hz
should read
original_sample_rate * 8192/original_number_of_samples = 13653 Hz

Philippe DUVERGER

unread,
Dec 6, 2013, 3:52:52 AM12/6/13
to mozzi...@googlegroups.com
Hi
Thank for the reply. (and the wonderfull library ! )

Yes it makes sense and I could get the proper table with good rate.
I still not have something "clean" though.
Maybe I didn't cut the wave of the period properly, or maybe there is something else in the wave form.
I will inverstigate.
 
Sox seems a very very good tool.
Very easy as soon as you have the good parameters.
 
Fif

Philippe DUVERGER

unread,
Dec 15, 2013, 8:18:20 AM12/15/13
to mozzi...@googlegroups.com
Hello

Sorry I still don't manage to have something clean ..... I think I miss something

This is my original sound (few sec in wav) : 

From that,  I cut one period, and with your explanation I export one raw file (sample rate is 1024) in 8 bit unsigned.


Then I use char2mozzy and get this file : 

But when I import that in my sketch 
(basic sinewave example and change just this line 
Oscil <VIN_1024_NUM_CELLS, AUDIO_RATE> aSin(VIN_1024_DATA);

I get a crunchy sound. 
Is there something wrong in my raw file ?

Thank a lot for the help that you can bring.
Fif

Mr Sensorium

unread,
Dec 23, 2013, 6:22:17 AM12/23/13
to mozzi...@googlegroups.com
Hi Philippe,

sorry for the long delay, I've been away from the internet (very good)!

I think the problem is that I forgot to mention to export your raw data as signed 8 bit.  It looks like you've exported OnePeriod.raw unsigned.

Just a little quote from the docs for char2mozzi.py (http://sensorium.github.io/Mozzi/doc/html/char2mozzi_8py.html):
#    Save by exporting with the format set to "Other uncompressed formats",
#    options set to "RAW(headerless)" and "Encoding 8 bit signed PCM".

It's hard to find the documentation for this in the online API, due to me not being very expert with doxygen, the system which generates the docs from comments in the code.  I'll try (again, again) to make it clearer next time I have the chance to update the documentation.

Anyway, I hope this solves the problem, it looks like you've managed well so far!

Tim


Mr Sensorium

unread,
Jan 7, 2014, 11:22:53 PM1/7/14
to mozzi...@googlegroups.com
Hi Philippe,

I'm posting this back to you on the forum because it might help others.

>Did I miss again something or is it the best that I can get ?

You can improve the quality of the Mozzi wavetable, and the audio output quality of Mozzi is also about to improve, if it passes testing in the next week or so.

Long answer follows!

You can make sure your wavetable has the most detail possible.  For maximum dynamic range, using the "Normalise" effect on the original waveform in Audacity.  This will make your final wavetable range from -128 to 127 (or near), instead of the about +-50 or 60 in your previous test.  For more detail along the duration of the wave, best would be to sample the source played at a lower frequency or record it at a higher sample rate (if possible), or stretch your digitised recording.  I noticed that one cycle of your original waveform was not much more than 1024 samples long, which made 1024 a sensible choice for the final table length, but the higher frequencies of the original waveform were aliased during playback.  I experimented with stretching one cycle of the normalised original wave to 8 times its length, using of the good quality interpolation of the "Change Speed" effect at 50% a few times.  Then I used this to generate a full range, 8192 sample length Mozzi wavetable, with smooth, pre-calculated interpolation in the table itself when Mozzi plays it.

The higher-resolution wavetable did improve the sound, but not as much as I expected!  Then, changing the Mozzi AUDIO_RATE from 16384Hz to 32768Hz in mozzi_config.h made a big subjective improvement to the sound, because it was better able to reproduce the higher frequencies in your sample with less aliasing.  I used the development version of Mozzi which has much improved audio ouput, enabling 32768Hz pwm rate as well as optional 32768 AUDIO_RATE in STANDARD mode (and improved HIFI mode too).

I need to test the new Mozzi version properly yet, but if all goes well it should be available next week.

Some of the test files are attached.

All the best,
Tim
Original_One_Cycle.wav
Wavetable_test.zip
16k_audio_rate.wav
32k_audio_rate.wav
Reply all
Reply to author
Forward
0 new messages