/****************************************************************** 
 *	Sample the piezo port for NSAMPLES. Convert to 0 centered 
 *	voltage and sent over UART. Send the string "END" after
 *	all samples are sent.
 *	
 ******************************************************************/ 
void stringTestControls::sampleFreq(int strng)
{
	int sensorValue[NSAMPLES];
	double sensorValVolts;
	pluck(strng);
  	
	//Fill a buffer with sample data
	for(int i =0; i <NSAMPLES; i++)
	{
		sensorValue[i] = analogRead(PIEZOPORT);//100 microseconds
		//                              Sampling Rate	
		//delay(2);			//472.8Hz
		//delay(1);			//888 Hz
		//delayMicroseconds(750);	//1142.8 Hz
		delayMicroseconds(700);		//1215 Hz 
		//delayMicroseconds(500);	//1606 Hz

	}

	for(int i =0; i <NSAMPLES; i++)
	{
		//Convert the sensorValue to volts and center it at 0
		sensorValVolts = (((sensorValue[i]/1023.0)*5.0)-2.5);
		printDouble(sensorValVolts,1);
	}
	Serial.println("END");
}
示例#2
0
//timer based auto plucking
void autoPluck() {
	if (super_pluck && globalMode==advanceMode && is_plucking){
		if (millis() >= last_pluck) {
			last_pluck = millis() + Pluck_rate;
			pluck();
		}
	}
}
示例#3
0
文件: mu_13.cpp 项目: rdpoor/mu
 // truncate the previous note, start the new note 'd' seconds after its
 // start, where 'd' is the time elapsed between previous note and this.
 void hammer(mu::MuStream *source, mu::MuTick start, mu::MuFloat gain = 1.0) {
   if (prev_note_ == NULL) {
     pluck(source, start, gain);
   } else {
     mu::MuTick elapsed = start - prev_start_;
     mu::CropStream *c = new mu::CropStream();
     c->set_source(source);
     c->set_source_start(elapsed);
     flush_prev(elapsed);
     prev_note_ = c;
     // prev_start_ = prev_start_;
     prev_gain_ = gain;
   }
 }
示例#4
0
void _handler_MIDI_Note_On(byte channel, byte note, byte velocity) {
	blink();
	if (globalMode == basicMode) {
		if (note != 72) KillAllTangents();
		note = note - 72;
		triggerSolenoid(constrain(note, G4, G4 + 16));
		if (basic_auto_pluck) pluck();
		else if (note == 0) pluck();
	} else {
		//individual plucking
		if (note == 72) {
			if (super_pluck) {
				last_pluck = millis() + Pluck_rate;
				is_plucking = true;
			}
			pluck();
		} else {
			//individual solenoid control
			note = note - 72;
			note = constrain(note, G4, G4 + 16);
			triggerSolenoid(note);
		}
	}
}
示例#5
0
void _handler_MIDI_Control_Change(byte channel, byte number, byte value) {
	blink();
	if (number == 39) {
		if (value >= 64) {
			globalMode = advanceMode;
		} else {
			globalMode = basicMode;
			if (is_plucking){
				is_plucking = false;
				pluck();
			}
		}
	}

	if (number == 36) {
		if (value >= 64) {
			dampOn();
		} else {
			dampOff();
		}
	}

	if (number == 37) {
		if (value >= 64) {
			basic_auto_pluck = true;
		} else {
			basic_auto_pluck = false;
		}
	}

	if (number == 1) { //mod weel advanced mode plucking
		if (value > 0 && globalMode == advanceMode ) super_pluck = true;
		else super_pluck = false;
		Pluck_rate = ((127-value)*4) + MAX_PLUCK_SPEED;
	}
}
示例#6
0
/*  
  main opens the input and temporary files, generates the audio data
  as a stream of numbers in ASCII format, then calls convert_to_wave()
  to convert the temporary file into the output file in .wav format.
*/    
int main(int argc, char **argv)
{
  static double notes[NUM_NOTES][BASE_SIZE] = {0};
  static int position[NUM_NOTES] = {0};
  double temp;
  int i,j;
  FILE *input;
  FILE *output = stdout;
  int current_time = 0;
  int current_sample = 0;
  double next_volume;
  double tempo = 1.0;
  char *endptr;
  int num_samples;
  static uint16_t data[2048];
  int16_t sample;
  double MAX = 1.0;
  struct filedat next_note;
  
  if(argc < 2)
    scream_and_die(argv[0]);
  
  if(argc == 3)
    {
      // try to interpret argv[2] as a float
      tempo = strtof(argv[2],&endptr);
      if(endptr==argv[2] || tempo<0.25 || tempo > 4.0)
	{
	  fprintf(stderr,"Illegal tempo value.\n");
	  scream_and_die(argv[0]);
	}
      tempo = 1.0/tempo;
    }

  if((input = fopen(argv[1],"r"))==NULL)
    {
      perror("Unable to open input file");
      scream_and_die(argv[0]);
    }

  /* find time of for end of song */
  while((fread(&next_note,sizeof(next_note),1,input)==1)&&
	(next_note.note != 1));
  fseek(input,0,SEEK_SET);
  
  num_samples = tempo * next_note.time * SAMPLE_RATE / 100;

  write_wave_header(STDOUT_FILENO,num_samples);

  srand(time(NULL));
  
  do{
    // read the next note
    if(fread(&next_note,sizeof(next_note),1,input)==1)
      {
	next_note.time = (int)(next_note.time * tempo);
	// generate sound, one ms at a time, until we need to start
	// the next note
	while(current_time < next_note.time)
	  {
	    // generate another millsecond of sound 
	    for(i=current_sample; i < current_sample + SMPLS_PER_MS; i++)
	      {
		temp = 0.0;
		// update each active string and add its output to the sum
		for(j = 0; j< NUM_NOTES; j++)
		  temp += update(notes[j],array_size(j),&position[j]);
		// write a sample to the wave file 
		sample = (int16_t)((temp/MAX) * (INT16_T_MAX-1));
		fwrite(&sample,sizeof(int16_t),1,output);
	      }
	    current_sample += SMPLS_PER_MS;
	    current_time++;
	  }
	if(next_note.note >= 0) // pluck the next note
	  pluck(notes[next_note.note],array_size(next_note.note),
		next_note.vol/32767.0);
      }
  }while(!feof(input) && (next_note.note > 0));  
  fclose(input);
  fclose(output);
  return 0;
}
示例#7
0
void	rot_down(t_list **stack)
{
	if (!stack || !*stack)
		return ;
	push(stack, pluck(stack));
}
示例#8
0
int main(void) {

	char line[MAX_LINE];
	entry *entryHead;       //head of entry list
	snapshot *snapHead;		//head of snapshot list
	entryHead = NULL;  
	snapHead = NULL;
	
	while (true) {
		printf("> ");

		if (fgets(line, MAX_LINE, stdin) == NULL) {
			printf("\n");
			command_bye(entryHead, snapHead);
			return 0;
		}
		
		//get command from the input line as well as a second parameter if it exists
		char *ptr = strtok(line, " ");
		char firstToken[MAX_COMMAND];    //stores a command
		strcpy(firstToken, ptr);
		ptr = strtok(NULL, " ");
		char secondToken[MAX_KEY];  	 //stores either a key or a second part of the command
		secondToken[0] = '\0';
		
		//get rid of a new line character if it exists in the last valid token entered
		char *newLine;
		if (ptr != NULL) {		
			strcpy(secondToken, ptr);
			newLine = strchr(secondToken, '\n');
		}
		else {
			newLine = strchr(firstToken, '\n');
		}
		if (newLine) {
			*newLine = 0;	
		}
		
		//identify the command and call the right function to execute the command entered
		if (strcasecmp(firstToken, "BYE") == 0) {
			command_bye(entryHead, snapHead);
			return 0;
		}
		else if (strcasecmp(firstToken, "HELP") == 0) {
			command_help();
		}
		else if (strcasecmp(firstToken, "LIST") == 0) {
			if (strcasecmp(secondToken, "ENTRIES") == 0) {
				list_entries(entryHead);	
			}
			else if (strcasecmp(secondToken, "KEYS") == 0) {
				list_keys(entryHead);
			}
			else if(strcasecmp(secondToken, "SNAPSHOTS") == 0) {
				list_snapshots(snapHead);
			}
			else {
				printf("unknown\n");	
			}
		}
		else if (strcasecmp(firstToken, "GET") == 0) {
			get(secondToken, entryHead);
		}
		else if (strcasecmp(firstToken, "DEL") == 0) {
			entryHead = del(entryHead, secondToken);
		}
		else if (strcasecmp(firstToken, "PURGE") == 0) {
			entryHead = purge(secondToken, entryHead, snapHead);
		}
		else if (strcasecmp(firstToken, "SET") == 0) {
			if (ptr != NULL && secondToken[0] != '\0') {
				entryHead = set(ptr, secondToken, entryHead);
			}
			else {
				printf("invalid input\n");	
			}
		}
		else if (strcasecmp(firstToken, "PUSH") == 0 || strcasecmp(firstToken, "APPEND") == 0) {
			push_append(ptr, secondToken, entryHead, firstToken);
		}
		else if (strcasecmp(firstToken, "PICK") == 0) {
			ptr = strtok(NULL, " ");
			int index = atoi(ptr);
			pick(index, secondToken, entryHead);
		}
		else if (strcasecmp(firstToken, "PLUCK") == 0) {
			ptr = strtok(NULL, " ");
			int index = atoi(ptr);
			pluck(index, secondToken, entryHead);
		}
		else if (strcasecmp(firstToken, "POP") == 0) {
			pluck(1, secondToken, entryHead);
		}
		else if (strcasecmp(firstToken, "DROP") == 0) {
			snapHead = drop(snapHead, atoi(secondToken));
		}
		else if (strcasecmp(firstToken, "ROLLBACK") == 0) {
			entryHead = checkout(atoi(secondToken), entryHead, snapHead);
			snapHead = remove_snapshots(atoi(secondToken), snapHead);
		}
		else if (strcasecmp(firstToken, "CHECKOUT") == 0) {
			entryHead = checkout(atoi(secondToken), entryHead, snapHead);
		}
		else if (strcasecmp(firstToken, "SNAPSHOT") == 0) {
			snapHead = take_snapshot(entryHead, snapHead);
		}
		else if (strcasecmp(firstToken, "MIN") == 0) {
			min(secondToken, entryHead);
		}
		else if (strcasecmp(firstToken, "MAX") == 0) {
			max(secondToken, entryHead);
		}
		else if (strcasecmp(firstToken, "SUM") == 0) {
			sum(secondToken, entryHead);
		}
		else if (strcasecmp(firstToken, "LEN") == 0) {
			len(secondToken, entryHead);
		}
		else if (strcasecmp(firstToken, "REV") == 0) {
			reverse(secondToken, entryHead);
		}
		else if (strcasecmp(firstToken, "UNIQ") == 0) {
			unique(secondToken, entryHead);
		}
		else if (strcasecmp(firstToken, "SORT") == 0) {
			sort(secondToken, entryHead);
		}
		else if (strcasecmp(firstToken, "DIFF") == 0) {
			diff(ptr, secondToken, entryHead);
		}
		else if (strcasecmp(firstToken, "INTER") == 0) {
			inter(ptr, secondToken, entryHead);
		}
		else if (strcasecmp(firstToken, "UNION") == 0) {
			union_oper(ptr, secondToken, entryHead);
		}
		else {
			printf("unknown\n");	
		}
		
		printf("\n");
  	}

	return 0;
}