How to Make Wavetables

Status
Not open for further replies.

tensian

Member
Hi I'm working with WAVEFORM_ARBITRARY, I have used the milow wavetables (Thank )
https://github.com/mihow/audio-patches/tree/master/Teensy/CustomWavetable

Now I want my own wavetables, but I do not know how to get this kind of data from a WAV, like it has? What program can I use? I do not even understand these figures that appear in the .h

const int16_t AKWF_cello_0001[257] = {
-35, 782, 2274, 3066, 4472, 6150, 7266, 7481, 7257,
6923, 6415, 5629, 4613, 3706, 3071, 3357, 4845, 7561, 10867,
13533, 15696, 17734, 18669, 18854, 18760, 19617, 21384, 23526, 26659,
29816, 32208, 32688, 31570, 29928, 28656, 27624, 26016, 24008, 22328,
21262, 20200, 18822, 17165, 15455, 13811, 12414, 10693, 8444, 5873,
3071, 280, -2792, -5623, -7743, -8928, -9539,-10819,-12907,-15836,
-18949,-22558,-25862,-28072,-29296,-29242,-28109,-26819,-26329,-25850,
-25006,-24355,-24821,-25712,-26449,-26796,-26439,-24847,-22220,-19948,
-17827,-16254,-16953,-18441,-19776,-20998,-21247,-20823,-19570,-17947,
-16753,-15783,-14617,-13490,-12596,-11502,-10320, -8987, -7376, -6152,
-4044, -933, 1629, 2949, 3746, 5104, 6584, 7244, 7912, 8737,
8883, 8201, 7256, 6692, 5959, 5009, 4549, 4382, 3595, 1956,
-324, -2383, -3985, -4994, -5574, -5313, -4436, -3778, -4273, -4781,
-5061, -5427, -5626, -5563, -4619, -2676, -471, 1838, 4501, 5782,
7078, 6814, 6244, 5924, 5807, 7270, 7392, 8134, 8273, 8760,
10731, 10974, 11927, 11655, 11740, 12454, 12650, 12791, 13521, 15953,
17704, 18675, 18065, 19877, 20233, 20099, 20499, 18905, 18099, 16009,
15291, 13709, 10469, 10044, 9393, 7583, 4070, -252, -2875, -5240,
-6049, -5359, -3033, -393, 1491, 2121, 2059, 1238, -554, -524,
-138, 1871, 4813, 7148, 10391, 12053, 11377, 8392, 3827, -340,
-4231, -7194, -9300,-10242,-11004,-13035,-15760,-18899,-21577,-24165,
-25513,-25279,-23477,-21512,-19672,-16851,-14505,-12956,-12179,-11460,
-10221, -9112, -7789, -6138, -4209, -1803, -484, 342, -351, -1657,
-2348, -2493, -2049, -1083, 1373, 4258, 5907, 5789, 4393, 2931,
1951, 704, -463, -894, -570, -555, -862, -1605, -2315, -3361,
-4063, -3853, -3392, -2603, -1718, -891, -227, -35
};

It is clear that they have to do with the position of the wave, and I suppose with tone, time and amplitude, but I am somewhat lost, some idea
 
These numbers are just the result of an analog to digital conversion of the waveform. It's a simple array of 257 numbers - no magic.

To create new waveforms, you might either write these samples by hand, number for number, if you have a Fourier synthesis mind and imagination. You might also generate the array with mathematics, as long as you are able to define a function which describes exactly the waveform. Or you might record a waveform digitally, cut off exactly one period and then export the result.
 
Thanks for the quick reply


, you might either write these samples by hand, number for number, if you have a Fourier synthesis mind and imagination.
Very hard for me

You might also generate the array with mathematics, as long as you are able to define a function which describes exactly the waveform.
Know some example that can guide me

Or you might record a waveform digitally, cut off exactly one period and then export the result.
That would be easy, what happens in the export gives me a wav and I do not know how to read it to que me of values like these
 
The wav file format is well documented on the web. You'd have to write some simple code, which could be done in the language you are most used to (for example Python, or even php) to read the file byte per byte, identify and analyse the header data block, check it for byte order, sampling rate and depth first, and then read and re-assemble the audio data until you get exactly one period of the waveform. Then, you'll most probably have to do some upsampling/downsampling/interpolation to squeeze it into exactly 257 samples, write these out as an array and you are done. Nothing complicated.
 
If your goal is to play sample-based instrument sounds (difficult to understand your desires from the limited text you wrote), perhaps look at this newer, much more complete wavetable synthesis project.

https://github.com/TeensyAudio/Wavetable-Synthesis

If your goal really is just creating specific waveforms, you've got some work to do. The arb waveform feature is very spartan. It's not a complete solution, only 1 piece of a larger puzzle. For higher frequency output, it requires you to pre-filter your data to avoid Nyquist aliasing, as well as the ability to deal with getting data converted to the array it requires. If you're not familiar with how to do these sorts of things, I'm afraid the usability of this particular feature probably just isn't easy enough in its current state.
 
I really like this project, that's the idea I was looking for, thanks Paul
A question, the wavetable event does not exist in the sound tool?
Many thanks to you too Theremingenieur
 
tensian wrote........ Now I want my own wavetables, but I do not know how to get this kind of data from a WAV,

If it is just the wave table you want.....the easiest way is play the WAV file in Audacity, if stereo tracks, merge it it mono track in audacity, Zoom in to expand the waveform until you can see the waveform shape and pick what looks like 1 cycle that repeats itself. Set the display measurement to samples and note or count the number of samples for 1 cycle. Example if playing WAV of note A=440 Hz or you have generated a tone of 440 Hz in Audacity, zoom in and select 1 cycle, press Z to get the Zero crossings and you should have 100 samples if your samplerate is 44100, edit copy the selection, close the track and set samplerate to 257/100=2.57 times 44100 = 113337, open a new mono track and paste your cilpboard to the start of the track. Zoom to fill screen width and you should see one cycle of the waveform but now 257 samples. You can play it in Audacity using shift cilck play to hear it. Using Audacity Sample Data Export this out as text Linear, give it a name and you should have a text file of the amplitude of each sample in the cycle. It will be a big long single column list but that is OK for teensy. Now using Excel or any spreadsheet paste this into a single column, multiply each cell to give a max value of 30000. Insert a line graph of this column of data and you should see your waveform. Check that there are 257 items in the list and make the first and last the same value. Append a comma to the end of each cell and copy and past this as text into a text file called anyname.h. You need to add these bits as well to make it and array.....const int16_t AKWF_cello_0001[257] = { } etc It does not need to be in 10 columns wide and save it in the same folder as your sketch and put a #include anyname.h in the top of the sketch. and it should all work....but it is only a few miliseconds of a sound that will be repeated over and over as teensy plays it.........so its OK for constant tones and can be played at various frequencies. ...any more than that you need to use envelope and filters etc to create realistic sounds
 
Status
Not open for further replies.
Back
Top