Re: [OT] DIY Trigger - Piezo to MIDI to PC

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ray Rashif wrote:
Sorry for the very random subject, but I figured I'd need all the help I can get.

I've read about this for a _little_ while (time constraints..arghhh) on the WWW, and I've posted on www.edrum.info <http://www.edrum.info> too. In case anyone here has better/fast/helpful suggestions/advice/shizznit, I'm sort of cross-posting:

I just want one trigger, which I'll use for the kick drum. As such, I'm interested to know if there are premade boards for the MIDI conversion. Basically all I need is something which can take the vibrations and convert them to electrical signals (piezo), and then fed to something else that will convert that electrical signal to a MIDI-ON message, after which I can plug it into the MIDI input of an audio interface or use a MIDI-USB adapter to plug in to a USB port.

And regarding MIDI, if I want to take into consideration dynamics, and let the piezo trigger MIDI messages with varying attack information, how would it be done? So depending on the voltage generated, it'd be a MIDI-ON but the final message to the computer (audio interface) would be a "MIDI-ON && ATTACK == 75" sort of logic. Sorry for the noobish description, have just started to dabble into (audio/midi) electronics.

I understand the concept and design roughly and I can move on by reading the construction manual (refering to edrum's DIY guide), but at the moment I'm looking for a quick way to build a trigger as I need it asap (and no $$ for a real trigger kit/module).

Are you thinking of attaching the piezo to a real bass drum with kicker (don't know if that's the right name), or forgetting about the drum and having the kicker strike the piezo directly (which is what I'd do)?

There was a project in one of the linux magazines recently (Linux format I think) to make a simple set of drum pads using an arduino board ( www.arduino.cc ), some piezos and a loudspeaker. I managed to adapt this to send the trigger data back to the computer through the arduino's usb cable and to a laptop. Then I wrote a short C program to translate the incoming data into midi signals.

The way I worked out the attack was to work out the time it took in samples between crossing a low threshold and the first maximum at the start of the strike, divided by the height of the maximum. Piezos are a bit tricky because they 'ring' after a hit, so you get an oscillating signal for a while after the initial pulse, but the method I just said seemed to work reasonably well.

The code that ran on the board is pasted below; I've also attached my C code and an example config file for it if you want to look at that.

I haven't done much with this project since I got it to work, as the piezo pads are a bit small to really play easily- more a toy than an instrument. But the same approach might work quite nicely in the case you're talking about.

andy

#define TRIGGER 50
#define RELEASE 20
#define PEAKTHRESH 700
#define MAXPADS 4
#define RELEASEDEL 100
#define SAMPLEDEL 10
int samples=0;
int piezoIn[]={0,1,2,3}; // analogue pin numbers for each pad.
int piezoState[]={0,0,0,0};
int piezoStartVal[]={0,0,0,0};
long piezoStartTime[]={0,0,0,0};
int piezoMax[]={170,170,170,170}; // maximum velocity values to use for each pad. 170 is good for fingers - maybe higher for sticks.
int pattern=0;

void setup()
{
 for (int i=0; i<MAXPADS; i++) {
   pinMode(piezoIn[i],INPUT);
  }
 Serial.begin(19200);
}

void loop()
{
 int val;
 long time;
 int midiVel;
 int aveVel;
 for (int i=0; i<MAXPADS; i++) {
   val=analogRead(piezoIn[i]);
   time=millis();
   if ((val>=TRIGGER) && (piezoState[i]==0)) {
     piezoState[i]=1;
     piezoStartVal[i]=val;
     piezoStartTime[i]=time;
     samples=0;
   } else if ( ( val >= PEAKTHRESH ) && (piezoState[i]==1) ) {
       aveVel=(val-piezoStartVal[i])/(samples);
       if ( (aveVel>piezoMax[i]) || (piezoStartVal[i]>PEAKTHRESH))
         midiVel=127;
       else
         midiVel=(127*aveVel)/piezoMax[i];
        Serial.print(i);
        Serial.print(", ");
       Serial.print(midiVel);
       Serial.print(", ");
       Serial.print(aveVel);
      Serial.print(", ");
      Serial.print(samples);
      Serial.print(", ");
      Serial.print(val);
      Serial.print(", ");
      Serial.print(piezoStartVal[i]);
       Serial.print("\n");
       piezoState[i]=2;
     }
else if ((piezoState[i] > 0) && (val < RELEASE) && (time-piezoStartTime[i]>RELEASEDEL) ) {
     piezoState[i]=0;
   }
  samples++;
 }
delayMicroseconds(SAMPLEDEL); // not really needed but can adjust this if necessary for some reason.
}

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
//#include <errno.h>
#include <alsa/asoundlib.h>

int main()
{
	char buffer[1];
	unsigned char insts[]=
		//{57,60,62,64}; // A minor pentatonic.
		{64,63,62,75}; // congas and clave.
		//{35,38,44,42}; // drum kit ( bass snare and hi hat)
		//{41,47,48,50}; // tom-toms
	int nread;
	unsigned char inst=0;
	int midi_err;
	unsigned char ch;
	snd_rawmidi_t *handle_out=0;
	int pad,vel,rawvel,samples,val,startval;
	int ret;
	FILE * usbf;
	printf("opening usb device.\n");
	usbf=fopen("/dev/ttyUSB0","r");
	if (usbf == NULL)
		exit(0);
	printf("Opening midi port\n");
	midi_err=snd_rawmidi_open(NULL, &handle_out, "virtual",0);
	if (midi_err)
		{
		printf("error: %d\n", midi_err);
		exit(1);
		}
	printf("waiting for first hit\n");
	while (-1) {
		ret=fscanf(usbf,"%d, %d, %d, %d, %d, %d",&pad,&vel,&rawvel,&samples,&val,&startval);
		if (ret == EOF) break;
		printf("pad: %d, vel: %d, rawvel: %d, samples: %d, value: %d, start value: %d\n",pad,vel,rawvel,samples,val,startval);
		inst=insts[pad];
		printf("playing note %d at velocity %d\n",inst,vel);
		ch=0x99; snd_rawmidi_write(handle_out,&ch,1);
		ch=insts[pad]; snd_rawmidi_write(handle_out,&ch,1);
		ch=vel; snd_rawmidi_write(handle_out,&ch,1);
		snd_rawmidi_drain(handle_out);
		}
	printf("Closing midi port\n");
	snd_rawmidi_drain(handle_out); 
        snd_rawmidi_close(handle_out);  
		
	exit (0);
}
// config file for usbmidi

device="/dev/ttyUSB0";

kits:(
	GM:(
		(35,"Acoustic Bass Drum"), (59,"Ride Cymbal 2"),
		(36,"Bass Drum 1"), (60,"Hi Bongo"),
		(37,"Side Stick"), (61,"Low Bongo"),
		(38,"Acoustic Snare"), (62,"Mute Hi Conga"),
		(39,"Hand Clap"), (63,"Open Hi Conga"),
		(40,"Electric Snare"), (64,"Low Conga"),
		(41,"Low Floor Tom"), (65,"High Timbale"),
		(42,"Closed Hi-Hat"), (66,"Low Timbale"),
		(43,"High Floor Tom"), (67,"High Agogo"),
		(44,"Pedal Hi-Hat"), (68,"Low Agogo"),
		(45,"Low Tom"), (69,"Cabasa"),
		(46,"Open Hi-Hat"), (70,"Maracas"),
		(47,"Low-Mid Tom"), (71,"Short Whistle"),
		(48,"Hi-Mid Tom"), (72,"Long Whistle"),
		(49,"Crash Cymbal 1"), (73,"Short Guiro"),
		(50,"High Tom"), (74,"Long Guiro"),
		(51,"Ride Cymbal 1"), (75,"Claves"),
		(52,"Chinese Cymbal"), (76,"Hi Wood Block"),
		(53,"Ride Bell"), (77,"Low Wood Block"),
		(54,"Tambourine"), (78,"Mute Cuica"),
		(55,"Splash Cymbal"), (79,"Open Cuica"),
		(56,"Cowbell"), (80,"Mute Triangle"),
		(57,"Crash Cymbal 2"), (81,"Open Triangle"),
		(58,"Vibraslap")
	)
);

_______________________________________________
Linux-audio-user mailing list
Linux-audio-user@xxxxxxxxxxxxxxxxxxxx
http://lists.linuxaudio.org/mailman/listinfo/linux-audio-user

[Index of Archives]     [Linux Sound]     [ALSA Users]     [Pulse Audio]     [ALSA Devel]     [Sox Users]     [Linux Media]     [Kernel]     [Photo Sharing]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux