[LAD] SysEx data-conversion woes: nibbles and complements (Microwave 2)

Fons Adriaensen 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:
> http://www.carbon111.com/300waves.pdf

It's exactly the first one. The sine wave is #32.
 

> char sysex_string[128];
> signed char samples[64];
> ... // fill string
>
> for (int item = 0;item<64;item++)
> {
>   sample[item] = (sysex_string[item /2])^0x80 + (sysex_string[(item / 2) +1]
>     <<4);
> }

Mmmmm... I'll let you discover the errors (more than one)...

Try this:

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

for (...)
{
   int v;

   v = (16 * sysex_string [2*i] + sysex_string [2*i+1]) ^ 0x80;
   if (v & 0x80) v -= 256;  // Sign extension 
   float_sample [i] = v;
}


Ciao,

-- 
FA



More information about the Linux-audio-dev mailing list