Пример #1
0
//begin main
int main (void) {

	short waveform [TOTAL_SAMPLES] ;
	FILE *f ;
	f = wavfile_open("music.wav") ;
	if(!f) {
		printf("couldn't open music.wav for writing: %s",strerror(errno)) ;
		return 1 ;
	}

	char input ;
	float octavefactor = 1 ;
	float notelength = .5 * WAVFILE_SAMPLES_PER_SECOND ;		//quarter note is default note length
	double frequency ;
	printf("Please enter valid instructions for octaves, notes, rests, and their lengths.  Enter X for end of song.\n") ; 

	do {
		scanf(" %c", &input) ;
		if (input == 'X') break ;

		int change = determine_change_type(input) ;
		int volume = 30000 ;
		switch (change) {
			case 0:
				printf("Error. Invalid character entered. File was written ignoring this invalid data.\n") ;
				break ;

			case 1:	
				frequency = letters_to_frequency(input) * octavefactor ;
				update_waveform(waveform, volume, frequency, notelength, f) ;	//only updated when a note is read
				break ;		

			case 2: 
				octavefactor *= change_octave(input) ;
				break ;
	
			case 3:
				notelength = new_notelength(input)*WAVFILE_SAMPLES_PER_SECOND ;
				break ;

			case 4:
				insert_rest(waveform, notelength, f) ;
		}
		
	} while (input != 'X' ) ;

	wavfile_close(f) ;

	return 0 ;
}
Пример #2
0
void
main ()
{
  UBYTE keys;
  UBYTE pos, old_pos = 0;
  UBYTE note, old_note = 0;
  UBYTE relative_octave = 0;
  UBYTE absolute_octave;
  UBYTE waveform = pulse_50;
  UBYTE mode = 0;
  UBYTE root = C;
  SCALE scale[8];

  font_t big_font, small_font;
  font_init ();
  big_font = font_load (font_ibm);
  small_font = font_load (font_spect);
  font_set (big_font);
 
  printf (";; Boueux v%s\n", BOUEUX_VERSION);
 
  INIT_SOUND;
  MASTER_VOLUME = OFF;
  update_waveform (waveform);
  MASTER_VOLUME = HIGH;
  
  build_scale_mode (scale, root, mode);
  
  for (;;)
   {
    keys = joypad ();
    pos = scale_position (keys);
    
    if (pos)
     {
      note = scale[pos - 1] + relative_octave*OCTAVE_LEN;
    
      /* Raise by perfect 4th */
      if (PRESSED (B)) note += 5; /* a perfect fourth = 5 semitones */
      /* Lower by semitone */
      if (PRESSED (A)) note -= 1;
     }
    
    /* Change octave */
    if (PRESSED (START))
     {
      relative_octave = !relative_octave;
      printf ("\n;; rel octave +%d\n", relative_octave);
      WAIT_KEY_UP (START);
     }

    if (PRESSED (SELECT))
     {
       /* Change mode */
       if (PRESSED (RIGHT))
        {
         mode = (mode + 1) % NUM_MODES;
         WAIT_KEY_UP (RIGHT);
         build_scale_mode (scale, root, mode);
        }
       /* Change waveform */
       if (PRESSED (LEFT))
        {
         WAIT_KEY_UP (LEFT);
         waveform = (waveform + 1) % NUM_WAVEFORMS;
         update_waveform (waveform);
       }
       /* Increment root note */
       if (PRESSED (UP))
        {
         WAIT_KEY_UP (UP);
         root = (root + 1) % OCTAVE_LEN;
         build_scale_mode (scale, root, mode);
        }
       /* Decrement root note */
       if (PRESSED (DOWN))
        {
         WAIT_KEY_UP (DOWN);
         if (root == 0)
           root = OCTAVE_LEN - 1;
         else
           root = (root - 1) % OCTAVE_LEN;
         build_scale_mode (scale, root, mode);
        }
        
       continue;
     }

     if ((note != old_note) || (pos != old_pos))
     {
      if (pos) /* Note will be played */
       {
        CH1_VOL = HIGH;
        CH2_VOL = HIGH;
        
        play_note (note, waveform);
        
        font_set (small_font);
        printf (note_names[note % OCTAVE_LEN]);
        
        absolute_octave = note/OCTAVE_LEN + 3;
        printf ("%d", absolute_octave);
        
        printf (" ");
        font_set (big_font);
       }
      else /* Stop note */
       {
        CH1_VOL = OFF;
        CH2_VOL = OFF;
        printf (". ");
       }
     }
    
    if (waveform == wawa) wawa_update();
    
    old_note = note;
    old_pos = pos;
   }
}