Пример #1
0
int main() {
  char song[] = "HauntedHouse: d=4,o=5,b=120: 2a4, 2e, 2d#, 2b4, 2a4, 2c, 2d, 2a#4, 2e., e, 1f4, 1a4, 1d#, 2e., d, 2c., b4, 1a4, 1p, 2a4, 2e, 2d#, 2b4, 2a4, 2c, 2d, 2a#4, 2e., e, 1f4, 1a4, 1d#, 2e., d, 2c., b4, 1a4";

  char *defaultsstring, *tune;
  struct defaults defs;

  defaultsstring = malloc(strlen(song) + 1);		// allocate memory for the defaults section of the string
  if (defaultsstring == NULL){error("Out of memory.");}

  tune = break_up_string(song, defaultsstring);		// break up song into its 3 parts.

  parse_defaults(defaultsstring,&defs);			// parse default string into default struct

  int count = count_notes(tune, ',');
  struct note notes[count];			// count notes and allocate array

  int i = 0;
  char *currentNote = tune;				// while there are notes in the note section, parse them into the array
  while(!isEmpty(currentNote)){
    if (i >= count) {error("Bad Note Section.");}
    currentNote = parse_note_string(currentNote, &defs, &notes[i]);
    i++;
  }

  play_tune(notes,defs.bpm, i);				// play the song

  free(defaultsstring);					// free memory
  return 0;
}
Пример #2
0
// update - updates led according to timed_updated.  Should be called at 50Hz
void ToneAlarm_Linux::update()
{
    // exit immediately if we haven't initialised successfully
    if (!_initialized) {
        return;
    }

    // exit if buzzer is not enabled
    if (pNotify->buzzer_enabled() == false) {
        return;
    }

    // check for arming failure
    if (AP_Notify::events.arming_failed) {
        play_tune(TONE_ARMING_FAILURE_TUNE);
    }

    // check if arming status has changed
    if (flags.armed != AP_Notify::flags.armed) {
        flags.armed = AP_Notify::flags.armed;
        if (flags.armed) {
            // arming tune
            play_tune(TONE_ARMING_WARNING_TUNE);
        }else{
            // disarming tune
            play_tune(TONE_NOTIFY_NEUTRAL_TUNE);
        }
    }

    // check if battery status has changed
    if (flags.failsafe_battery != AP_Notify::flags.failsafe_battery) {
        flags.failsafe_battery = AP_Notify::flags.failsafe_battery;
        if (flags.failsafe_battery) {
            // low battery warning tune
            play_tune(TONE_BATTERY_WARNING_FAST_TUNE);
        }
    }

    // check parachute release
    if (flags.parachute_release != AP_Notify::flags.parachute_release) {
        flags.parachute_release = AP_Notify::flags.parachute_release;
        if (flags.parachute_release) {
            // parachute release warning tune
            play_tune(TONE_PARACHUTE_RELEASE_TUNE);
        }
    }
}
Пример #3
0
// update - updates led according to timed_updated.  Should be called at 50Hz
void ToneAlarm_PX4::update()
{
    // exit immediately if we haven't initialised successfully
    if (_tonealarm_fd == -1) {
        return;
    }

    // check if arming status has changed
    if (flags.armed != AP_Notify::flags.armed) {
        flags.armed = AP_Notify::flags.armed;
        if (flags.armed) {
            // arming tune
            play_tune(TONE_ARMING_WARNING_TUNE);
        }else{
            // disarming tune
            play_tune(TONE_NOTIFY_NEUTRAL_TUNE);
        }
    }

    // check if battery status has changed
    if (flags.failsafe_battery != AP_Notify::flags.failsafe_battery) {
        flags.failsafe_battery = AP_Notify::flags.failsafe_battery;
        if (flags.failsafe_battery) {
            // low battery warning tune
            play_tune(TONE_BATTERY_WARNING_FAST_TUNE);
        }
    }

    // check gps glitch
    if (flags.gps_glitching != AP_Notify::flags.gps_glitching) {
        flags.gps_glitching = AP_Notify::flags.gps_glitching;
        if (flags.gps_glitching) {
            // gps glitch warning tune
            play_tune(TONE_GPS_WARNING_TUNE);
        }
    }

    // check gps failsafe
    if (flags.failsafe_gps != AP_Notify::flags.failsafe_gps) {
        flags.failsafe_gps = AP_Notify::flags.failsafe_gps;
        if (flags.failsafe_gps) {
            // gps glitch warning tune
            play_tune(TONE_GPS_WARNING_TUNE);
        }
    }
}
Пример #4
0
void game_over(){
	int i,j,offset;
	if (score[LEFT_PLAYER]==21){
		winner=LEFT_PLAYER;
		offset=0;
	}else{
		winner=RIGHT_PLAYER;
		offset=4;
	}
	for (i=0;i<32;i++){
		for (j=0;j<4;j++){
			video_buffer[(i+TOP_BORDER+1)*ROW_SIZE+j+offset]|=WINNER[i][j];
		}
	}
	play_tune(gonna_fly_now,60);
	running=0;
}//f()
Пример #5
0
int
tone_alarm_main(int argc, char *argv[])
{
	unsigned tune = 0;

	/* start the driver lazily */
	if (g_dev == nullptr) {
		g_dev = new ToneAlarm;

		if (g_dev == nullptr) {
			errx(1, "couldn't allocate the ToneAlarm driver");
		}

		if (g_dev->init() != OK) {
			delete g_dev;
			errx(1, "ToneAlarm init failed");
		}
	}

	if (argc > 1) {
		const char *argv1 = argv[1];

		if (!strcmp(argv1, "start")) {
			play_tune(TONE_STOP_TUNE);
		}

		if (!strcmp(argv1, "stop")) {
			play_tune(TONE_STOP_TUNE);
		}

		if ((tune = strtol(argv1, nullptr, 10)) != 0) {
			play_tune(tune);
		}

		/* It might be a tune name */
		for (tune = 1; tune < TONE_NUMBER_OF_TUNES; tune++)
			if (!strcmp(g_dev->name(tune), argv1)) {
				play_tune(tune);
			}

		/* If it is a file name then load and play it as a string */
		if (*argv1 == '/') {
			FILE *fd = fopen(argv1, "r");
			int sz;
			char *buffer;

			if (fd == nullptr) {
				errx(1, "couldn't open '%s'", argv1);
			}

			fseek(fd, 0, SEEK_END);
			sz = ftell(fd);
			fseek(fd, 0, SEEK_SET);
			buffer = (char *)malloc(sz + 1);

			if (buffer == nullptr) {
				errx(1, "not enough memory memory");
			}

			fread(buffer, sz, 1, fd);
			/* terminate the string */
			buffer[sz] = 0;
			play_string(buffer, true);
		}

		/* if it looks like a PLAY string... */
		if (strlen(argv1) > 2) {
			if (*argv1 == 'M') {
				play_string(argv1, false);
			}
		}

	}

	errx(1, "unrecognized command, try 'start', 'stop', an alarm number or name, or a file name starting with a '/'");
}
Пример #6
0
// update - updates led according to timed_updated.  Should be called at 50Hz
void ToneAlarm_PX4::update()
{
    // exit immediately if we haven't initialised successfully
    if (_tonealarm_fd == -1) {
        return;
    }

    // check for arming failure
    if(flags.arming_failed != AP_Notify::flags.arming_failed) {
        flags.arming_failed = AP_Notify::flags.arming_failed;
        if(flags.arming_failed) {
            play_tune(TONE_ARMING_FAILURE_TUNE);
        }
    }

    // check if arming status has changed
    if (flags.armed != AP_Notify::flags.armed) {
        flags.armed = AP_Notify::flags.armed;
        if (flags.armed) {
            // arming tune
            play_tune(TONE_ARMING_WARNING_TUNE);
        }else{
            // disarming tune
            play_tune(TONE_NOTIFY_NEUTRAL_TUNE);
        }
    }

    // check if battery status has changed
    if (flags.failsafe_battery != AP_Notify::flags.failsafe_battery) {
        flags.failsafe_battery = AP_Notify::flags.failsafe_battery;
        if (flags.failsafe_battery) {
            // low battery warning tune
            play_tune(TONE_BATTERY_WARNING_FAST_TUNE);
        }
    }

    // check gps glitch
    if (flags.gps_glitching != AP_Notify::flags.gps_glitching) {
        flags.gps_glitching = AP_Notify::flags.gps_glitching;
        if (flags.gps_glitching) {
            // gps glitch warning tune
            play_tune(TONE_GPS_WARNING_TUNE);
        }
    }

    // check gps failsafe
    if (flags.failsafe_gps != AP_Notify::flags.failsafe_gps) {
        flags.failsafe_gps = AP_Notify::flags.failsafe_gps;
        if (flags.failsafe_gps) {
            // gps glitch warning tune
            play_tune(TONE_GPS_WARNING_TUNE);
        }
    }

    // check baro glitch
    if (flags.baro_glitching != AP_Notify::flags.baro_glitching) {
        flags.baro_glitching = AP_Notify::flags.baro_glitching;
        if (flags.baro_glitching) {
            // gps glitch warning tune
            play_tune(TONE_BARO_WARNING_TUNE);
        }
    }

    // check parachute release
    if (flags.parachute_release != AP_Notify::flags.parachute_release) {
        flags.parachute_release = AP_Notify::flags.parachute_release;
        if (flags.parachute_release) {
            // parachute release warning tune
            play_tune(TONE_PARACHUTE_RELEASE_TUNE);
        }
    }

    // check ekf has gone bad
    if (flags.ekf_bad != AP_Notify::flags.ekf_bad) {
        flags.ekf_bad = AP_Notify::flags.ekf_bad;
        if (flags.ekf_bad) {
            // ekf warning tune
            play_tune(TONE_EKF_WARNING_TUNE);
        }
    }
}
Пример #7
0
void tick(unsigned long tick_usec) {
    if (g_play_tune) {
        play_tune(g_play_tune);
        g_play_tune = 0;
    }
}