jmamma / MCL

MCL firmware for the MegaCommand MIDI Controller.
BSD 2-Clause "Simplified" License
53 stars 9 forks source link

SDDrive: sample pack #103

Closed yatli closed 1 year ago

yatli commented 4 years ago

ROM slots snapshots. We'll need to design the file format. .spk = concat a bunch of syx files?

Or, a list of file names. Could be .syx or .wav, more flexible.

yatli commented 4 years ago

https://github.com/jmamma/MIDICtrl20_MegaCommand/commit/cf75574c561dbff0bc463c103a99b860c82e3571#diff-3ac5ec1e588b83481f58ae3442cf4bb3R8

Add target slot param?

jmamma commented 4 years ago

cf75574#diff-3ac5ec1e588b83481f58ae3442cf4bb3R8

Add target slot param?

MIDISds classes have that functionality. https://github.com/jmamma/MIDICtrl20_MegaCommand/blob/master/avr/cores/megacommand/Midi/MidiSDS.hh

The MidiSysexFile class was created to send a raw dump from a file off the sdcard. It's untested.

yatli commented 4 years ago

MIDISds classes have that functionality

Ah, superb.

Btw figured out that 48Khz SDS sample will be downsampled 2x (never tried 48Khz myself though!) on the host side.

jmamma commented 4 years ago

Yeah. I've written support for sending/receiving SDS and also there is a fairly usable WAV library I created.

Btw figured out that 48Khz SDS sample will be downsampled 2x (never tried 48Khz myself though!) on the host side.

What evidence do you have for this. What about for other sample rates?

Usually downsampling is accompanied with filtering at the nyquist frequency. So you'd lose everything above 12khz.

yatli commented 4 years ago

Crude downsampling: 0x0020e806 Condition: 0x0020f60a

yatli commented 4 years ago

My brain isn't working now.

*piVar17 = ((iVar8 >> (uVar18 & 0x3f)) - iVar11 << (uVar13 & 0x3f)) >> (local_8 & 0x3f);

Does this look like it's also related to 12-bit resolution?

jmamma commented 4 years ago

ha, i was looking at my MIDISds code before shuddering at all the bit shifting.

Now i'm reliving it @ 0x0020f60a

yatli commented 4 years ago

This is what it really looks like:

      *piVar15 = ((iVar8 >> (uVar16 & 0x3f)) - bitcrush_mask << (bitcrush_up & 0x3f)) >>
                 (bitcrush_down & 0x3f);

Not really the 12-bit thing, because at format 0x10 (16-bit), both up and down are set to 0.

jmamma commented 4 years ago

the first shift might be removing padding from the sample. I'm not sure what the subtraction does. Convert from unsigned to signed? shrug.

jmamma commented 4 years ago

The SDS receive code from MIDICtrl.

      for (shift = 0; shift < midi_sds.midiBytes_per_word; shift++) {

        decode_val = decode_val << 7;
        decode_val |= (int32_t)(0x7F & sysex->getByte(n + 4 + shift));
      }
      // Remove 0 padding.
      decode_val = decode_val >> (8 - shift);
      // For bit depth greater than 8 we need to convert the sample
      // from unsigned to signed by subtracting offset

      if (midi_sds.bytes_per_word > 1) {
        signed_val = decode_val - midi_sds.sample_offset;
        // decode_val -= midi_sds.sample_offset;
      } else {
        signed_val = decode_val;
      }

where

 uint32_t sample_offset = (pow(2,midi_sds.sampleFormat) / 2);
yatli commented 4 years ago

sample_offset

This, exactly. bitcrush_mask = 1 << (sds_sample_format - 1U & 0x3f);

jmamma commented 4 years ago

maybe relabel that one :) .

also small typo here /* two samples in iVar8 and iVar7 now */ should be iVar6 and iVar7

yatli commented 4 years ago

ha, I shouldn't put the autovar names in comments -- they change when I label something

jmamma commented 4 years ago

now you know the joys of SDS.

I think my implementation doesn't look too bad in comparison.

Interesting find regarding the > 48khz downsample + averaging filter.

I wonder how many samples i've uploaded at 48khz in the past.

jmamma commented 4 years ago

Or, a list of file names. Could be .syx or .wav, more flexible.

I prefer strongly for converting sds to wav, and saving as wav format.

The MIDISds recv implementation already does this by saving as WAV.

See:

https://github.com/jmamma/MIDICtrl20_MegaCommand/blob/master/avr/cores/megacommand/Midi/MidiSDSSysex.cpp

yatli commented 4 years ago

Can we move SDDrive to the top-level?

Sound Manager, Wav Designer, Loudness, SD-Drive?

jmamma commented 4 years ago

Yeah we can move it up in Global Settings menu.

Leave quick select as it is for now.