示例#1
0
文件: drumbox.c 项目: kspi/drumbox
int process(jack_nframes_t nframes, void *arg) {
  sample_t *in = jack_port_get_buffer(input_port, nframes);

  void *midi_out = jack_port_get_buffer(output_port, nframes);
  jack_midi_clear_buffer(midi_out);

  for (unsigned int i = 0; i < nframes; i++) {
    sample_t cur = in[i];

    last_idx = wrap(last_idx + 1, LAST_WIDTH);
    last[last_idx] = fabs(cur);

    for (unsigned int j = 0; j < LAST_WIDTH; j++) {
      fft_in[j] = last[wrap(last_idx + j, LAST_WIDTH)];
    }

    fftwf_execute(fft_plan);

    power = 0;
    for (unsigned int j = 0; j < FFT_SIZE; j++) {
      power += fabs(fft_out[j]);
    }
    power /= FFT_SIZE;
    
    if (!hit && (power > 2)) {
      hit = true;
      DEBUG("HIT   power = %.3f \n", power);
      send_note(midi_out, i, 0.5);
    } else if (hit && (power < 0.9)) {
      hit = false;
      DEBUG("UNHIT power = %.3f \n", power);
    }
    
    static float minp;
    static float maxp;
    if (delay == 0) {
      DEBUG("power ∈ [%+2.3f, %+2.3f] \r", minp, maxp);
      /* unsigned int star = power; */
      /* for (unsigned int j = 0; j < star; j++) DEBUG(" "); */
      /* DEBUG("*\r"); */
      delay = 30000;
      minp = 1e9;
      maxp = -1e9;
    } else {
      if (power < minp) minp = power;
      if (power > maxp) maxp = power;
      
      --delay;
    }
  }
    
  return 0;      
}
示例#2
0
static long new_midi_ioctl(struct file *f, unsigned int cmd, unsigned long arg) {
    dbg("`cmidid_ioctl' called with f=%p, cmd=%d, arg=%lu\n", f, cmd, arg);

    switch (cmd) {
    case NEWMIDI_BLA:
        dbg("bla\n");
        break;
    case NEWMIDI_BLUPP:
        dbg("blupp\n");
        send_note(0x3b, 127);
        break;
    default:
        dbg("didnt work\n");
    }

    return 0;
}