loadtrain2

load samples from sdcard using into 2 table allocators (samples=16bit,starts=32bit) samples can be either .tab, .wav or .raw, all 16bit. You can load either a consecutive order of indexed samples when you've saved drumkits in consecutive order (eg. sample000.raw,sample001.raw,sample002.rar,etc) or set maximum and minimum index number to randomly load a set of samples between these index numbers (eg. sample053.raw,sample952.raw,sample002.raw,etc) For this, the rndLoad input has to be high. A randomisation can be skipped if the "new" input is low.
Author: Remco van der Most
License: BSD
Github: sss/sampler/loadtrain2.axo

Inlets

int32 offsets the sample loading index (sampleStart and SampleEnd)

int32 connects to the former loadtrain module to get the sample-loading offset. FIRST MODULE DOESN'T NEED AN OFFSET!

int32 connects to the former loadtrain module to get the sample-loading remaining size. FIRST MODULE DOESN'T NEED AN REMSIZE OFFSET!

bool32 when high and trigger goes high, uses the random-load-settings instead of sampleStart/sampleEnd settings

bool32 when low, keeps the old random selection, this way you can randomise only parts of the sampletrain if you're happy with some random loaded samples

bool32.rising send trigger for loading samples from sampleStart up to sampleEnd

Outlets

bool32 when the module is finished loading samples, outputs a pulse for the next sample-load module

int32 outputs the start-offset of the array, CONNECT THIS TO THE NEXT MODULE THAT'S LOADING SAMPLES!

int32 outputs the remaining size of the array, CONNECT THIS TO THE NEXT MODULE THAT'S LOADING SAMPLES!

int32 outputs the first sample index of the samples being loaded by the module

int32 outputs the amount of samples being loaded by this module

Parameters

int32 select first sample to be loaded

int32 selects last sample to be loaded (all samples in-between will be loaded)

int32 select maximum index selection for random load

int32 select minimum index selection for random load

int32 selects how many random samples will be loaded

Attributes

table enter (directory/..) sample prefix of samples to be loaded eg. /drumsamples/BD/bd

table enter sample file suffix eg. wav/raw

combo select "yes" if this is the first module in line of the sampletrain load, otherwise set it to "no"

objref refer to table allocator for samples (16bit SDRAM!)

objref refer to table allocator for start-times of samples (32bit SDram!)

Displays

int32.label shows bit starting offset (good for seeing whether your samples can actually fit in the array or that the array could be made smaller)

int32.label shows first index position of loaded samples

int32.label shows last index position of loaded samples (last module shows wrong value though!)

int32.label shows the samplesize of the samples being loaded (probably skips small samples as these load a bit to fast for the update rate)

Declaration
int ntrig;
int32_t rnd[64];
char c[64];
int ofs;
int pval;
int j;
int offset = 0;
int32_t s1;
int32_t s2;
bool rst;
int32_t LN;
int m;
int rem_sz;
Init
ntrig = 0;
strcpy(&c[0], "attr_prefix000attr_suffix");
ofs = strlen("attr_prefix");
pval = 0;
LN = 0;
Control Rate
/*
if((inlet_rst>0)&&!rst){
        rst=1;
        for(j=0;j<attr_samples.LENGTH;j++){
                attr_samples.array[j]=0;
        }
        for(j=0;j<attr_starts.LENGTH;j++){
                attr_starts.array[j]=0;
        }
        s2=0;
        s1=0;
}
else if(inlet_rst==0){rst=0;}
*/
outlet_load = 0;
int trig = inlet_load;
if ((trig > 0) && !ntrig) {
  if (attr_first > 0) {
    for (j = 0; j < attr_samples.LENGTH; j++) {
      attr_samples.array[j] = 0;
    }
    for (j = 0; j < attr_starts.LENGTH; j++) {
      attr_starts.array[j] = 0;
    }
  }
  bool R = inlet_rndLoad;
  ntrig = 1;
  int I = 1;
  int l = 0;
  while (attr_starts.array[I] > 0) {
    s1 = attr_starts.array[I];
    s2 = I;
    I += 1;
  }
  offset = inlet_offset;
  j = param_sampleStart;
  int k = s2;
  disp_first = k;
  if (inlet_new > 0) {
    for (j = 0; j < 64; j++) {
      rnd[j] = param_rndMin + ___SMMUL((int32_t)(GenerateRandomNumber() >> 1),
                                       param_rndMax - param_rndMin << 1);
    }
  }

  if (attr_first > 0) {
    rem_sz = sizeof(*attr_samples.array) * attr_samples.LENGTH;
  } else {
    rem_sz = inlet_remsize;
  }
  while ((R > 0 ? (l <= param_rndSamples)
                : ((j >= param_sampleStart) && (j <= param_sampleEnd))) &&
         (rem_sz > 0)) {
    // if(k>0){
    // attr_starts.array[k]+=attr_starts.array[k-1] ;
    // attr_starts.array[k]=offset>>4;
    //}
    FIL FileObject;
    FRESULT err;
    UINT bytes_read;
    codec_clearbuffer();
    int i = inlet_index + (R > 0 ? rnd[l] : j);
    int i0 = i / 10;
    c[ofs + 2] = '0' + i - 10 * i0;
    i = i0;
    i0 = i / 10;
    c[ofs + 1] = '0' + i - 10 * i0;
    i = i0;
    i0 = i / 10;
    c[ofs + 0] = '0' + i - 10 * i0;

    err = f_open(&FileObject, &c[0], FA_READ | FA_OPEN_EXISTING);
    if (err != FR_OK) {
      report_fatfs_error(err, &c[0]);
      return;
    }

    while (rem_sz > 0) {
      LN += 1;
      if (rem_sz > sizeof(fbuff)) {
        err = f_read(&FileObject, fbuff, sizeof(fbuff), &bytes_read);
        if (bytes_read == 0)
          break;
        memcpy((char *)(&attr_samples.array[0]) + offset, (char *)fbuff,
               bytes_read);
        rem_sz -= bytes_read;
        offset += bytes_read;

      } else {
        err = f_read(&FileObject, fbuff, rem_sz, &bytes_read);
        memcpy((char *)(&attr_samples.array[0]) + offset, (char *)fbuff,
               bytes_read);
        rem_sz = 0;
      }
    }
    if (err != FR_OK) {
      report_fatfs_error(err, &c[0]);
      return;
    };
    err = f_close(&FileObject);
    if (err != FR_OK) {
      report_fatfs_error(err, &c[0]);
      return;
    };

    // attr_starts.array[k]=f_size( &FileObject );
    // attr_starts.array[k]=attr_starts.array[k]>>2;
    // if(k>0){
    // attr_starts.array[k]+=attr_starts.array[k-1] ;
    // attr_starts.array[k]=offset;
    //}
    m = attr_samples.LENGTHMASK;
    while ((attr_samples.array[m] == 0) && (m > 0)) {
      m -= 1;
    }

    attr_starts.array[k] = m;
    disp_samplesize = m - (k > 0 ? attr_starts.array[k - 1] : 0);

    j += param_sampleStart < param_sampleEnd ? 1 : -1;
    // if(k<1){
    // 	int32_t TP=sizeof(fbuff);
    // 	disp_samplesize=offset/TP;
    // }
    k = k < attr_starts.LENGTHMASK ? k + 1 : attr_starts.LENGTHMASK;
    l += 1;
  }

  disp_last = k - (k < 63 ? 2 : 0);
  outlet_load = 1;
} else if (!(trig > 0))
  ntrig = 0;
disp_offset = s1;
outlet_offset = offset;
outlet_remsize = rem_sz;
outlet_first = disp_first;
outlet_samples = disp_last - disp_first + 1;

Privacy

© 2024 Zrna Research