[LAD] SysEx data-conversion woes: nibbles and complements (Microwave 2)
fons at linuxaudio.org
Thu May 13 11:48:54 CEST 2021
On Thu, May 13, 2021 at 11:18:49AM +0200, Jeanette C. wrote:
> > How does it sound ?
> Many, many thanks, Fons! I can't exactly say how it sounds, because I
> don't have a listing of waveforms within wavetables. But there is a list
> of all spectra, as images, I think this is it:
It's exactly the first one. The sine wave is #32.
> char sysex_string;
> signed char samples;
> ... // fill string
> for (int item = 0;item<64;item++)
> sample[item] = (sysex_string[item /2])^0x80 + (sysex_string[(item / 2) +1]
Mmmmm... I'll let you discover the errors (more than one)...
for (int i = 0; i < 64; i++)
sample [i] = (16 * sysex_string [2*i] + sysex_string [2*i+1]) ^ 0x80;
Now if you want float samples (e.g. to do an FFT) you need
v = (16 * sysex_string [2*i] + sysex_string [2*i+1]) ^ 0x80;
if (v & 0x80) v -= 256; // Sign extension
float_sample [i] = v;
More information about the Linux-audio-dev