Esempio n. 1
0
  void play(const char *s[]) {

    float duration = 0.5f * tempo / 4.0f;
    float len = strlen(s[0]);

    //fprintf(stderr, "%s\n", s[0]);

    // get the update for each string
    for(int l = 0; l < len; l++) {
      for(int i = 0; i < 6; i++) {
	if(s[i][l] != '-') {
	  if(s[i][l] == 'o') { // damp
	    
	  } else { // it's a note
	    int note = (s[i][l] - '0') + stringNote[i];
	    m_Strings[i].playNote(NoteToFreq(note));
	  }
	}	
      }

      // generate sound
      for(int d = 0; d < FREQ * duration; d++) {
	float output = 0.0f;
	for(int i = 0; i < 6; i++) {
	  // write sound
	  output += m_Strings[i].output(1.0f / FREQ);
	}
	
	fwrite(&output, sizeof(float), 1, stdout);
      }
      fflush(stdout);
    }
  }
Esempio n. 2
0
// piano note
void playNote(int note, float duration) {
  float freq = NoteToFreq(note);
  synth.playNote(freq);

  float dt = 1.0f / FREQ;
  float timer = 0.0f;
  while(timer < duration) {
    float out = synth.output(dt);
    fwrite(&out, sizeof(float), 1, stdout);
    timer += dt;
  }
}
Esempio n. 3
0
char loader(char song_id) {
	index = 0;
	waitFor = 0;
	if( song_id<'1' || song_id>'9' || song_id>DataModule[0] ) 
		return 1;
	int offset=2;
	song_id -= '0';
	if(song_id>1){										//moves variable offset past other songs
		for (char nulls = 0; nulls < song_id-1 ; ++offset){
			if(DataModule[offset]==0)
				nulls++;
		}
	}

	int i = 0;
	for(i=0; DataModule[offset+4*i] != 0 ; i++){
		freqs[i] = NoteToFreq( DataModule[offset + 4*i], DataModule[offset + 4*i+1] );
		durations[i] = CodeToMillisec( DataModule[offset + 4*i+2], DataModule[offset + 4*i+3] );
	}
	freqs[i] = 0;
	durations[i] = 0;
	return 0;
}