mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-29 08:03:33 +08:00
lib tunes: clean up
This commit is contained in:
committed by
Daniel Agar
parent
dcfd2f1579
commit
e9ea7ab698
@@ -254,7 +254,7 @@ unsigned Tunes::next_dots()
|
|||||||
|
|
||||||
int Tunes::next_note(unsigned &frequency, unsigned &duration, unsigned &silence)
|
int Tunes::next_note(unsigned &frequency, unsigned &duration, unsigned &silence)
|
||||||
{
|
{
|
||||||
// make sure we still have a tune - may be removed by the write / ioctl handler
|
// make sure we still have a tune
|
||||||
if ((_next == nullptr) || (_tune == nullptr)) {
|
if ((_next == nullptr) || (_tune == nullptr)) {
|
||||||
return TUNE_ERROR;
|
return TUNE_ERROR;
|
||||||
}
|
}
|
||||||
@@ -263,7 +263,6 @@ int Tunes::next_note(unsigned &frequency, unsigned &duration, unsigned &silence)
|
|||||||
unsigned note = 0;
|
unsigned note = 0;
|
||||||
unsigned note_length = _note_length;
|
unsigned note_length = _note_length;
|
||||||
|
|
||||||
// NOTE: is this while loop necessary?
|
|
||||||
while (note == 0) {
|
while (note == 0) {
|
||||||
// we always need at least one character from the string
|
// we always need at least one character from the string
|
||||||
int c = next_char();
|
int c = next_char();
|
||||||
@@ -441,7 +440,6 @@ tune_end:
|
|||||||
return TUNE_CONTINUE;
|
return TUNE_CONTINUE;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
_default_tune_number = 0;
|
|
||||||
return TUNE_STOP;
|
return TUNE_STOP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+48
-27
@@ -53,45 +53,66 @@ public:
|
|||||||
Tunes();
|
Tunes();
|
||||||
Tunes(unsigned tempo, unsigned octave, unsigned note_length, NoteMode mode);
|
Tunes(unsigned tempo, unsigned octave, unsigned note_length, NoteMode mode);
|
||||||
~Tunes() = default;
|
~Tunes() = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* parse a tune_control_s in frequency(Hz), duration(us) and silence(us).
|
||||||
|
*
|
||||||
|
* @param tune_control struct containig the uORB message
|
||||||
|
* @param frequency return frequency value (Hz)
|
||||||
|
* @param duration return duration of the tone (us)
|
||||||
|
* @param silence return silance duration (us)
|
||||||
|
* @return -1 for error, 0 for play one tone and 1 for continue a sequence
|
||||||
|
*/
|
||||||
int parse_cmd(tune_control_s &tune_control, unsigned &frequency, unsigned &duration, unsigned &silence);
|
int parse_cmd(tune_control_s &tune_control, unsigned &frequency, unsigned &duration, unsigned &silence);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* parse a tune string, formatted with the syntax of the Microsoft GWBasic/QBasic, in frequency(Hz),
|
||||||
|
* duration(us) and silence(us).
|
||||||
|
*
|
||||||
|
* @param string tune input string
|
||||||
|
* @param frequency return frequency value (Hz)
|
||||||
|
* @param duration return duration of the tone (us)
|
||||||
|
* @param silence return silance duration (us)
|
||||||
|
* @return -1 for error, 0 for play one tone and 1 for continue a sequence
|
||||||
|
*/
|
||||||
int parse_string(const char *string, unsigned &frequency, unsigned &duration, unsigned &silence);
|
int parse_string(const char *string, unsigned &frequency, unsigned &duration, unsigned &silence);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const unsigned _tune_max = 1024 * 8; // be reasonable about user tunes
|
static const char *_default_tunes[TONE_NUMBER_OF_TUNES];
|
||||||
static const char *_default_tunes[TONE_NUMBER_OF_TUNES];
|
static const uint8_t _note_tab[];
|
||||||
static const char *_tune_names[TONE_NUMBER_OF_TUNES];
|
bool _repeat; // if true, tune restarts at end
|
||||||
static const uint8_t _note_tab[];
|
|
||||||
|
|
||||||
unsigned _default_tune_number; // number of currently playing default tune (0 for none)
|
const char *_tune = nullptr; // current tune string
|
||||||
|
const char *_next = nullptr; // next note in the string
|
||||||
|
|
||||||
const char *_user_tune;
|
unsigned _tempo;
|
||||||
|
unsigned _note_length;
|
||||||
|
NoteMode _note_mode;
|
||||||
|
unsigned _octave;
|
||||||
|
|
||||||
const char *_tune = nullptr; // current tune string
|
unsigned _default_tempo = 120;
|
||||||
const char *_next = nullptr; // next note in the string
|
unsigned _default_note_length = 4;
|
||||||
|
NoteMode _default_mode = NoteMode::MODE_NORMAL;
|
||||||
unsigned _tempo;
|
unsigned _default_octave = 4;
|
||||||
unsigned _note_length;
|
|
||||||
NoteMode _note_mode;
|
|
||||||
unsigned _octave;
|
|
||||||
unsigned _default_tempo = 120;
|
|
||||||
unsigned _default_note_length = 4;
|
|
||||||
NoteMode _default_mode = NoteMode::MODE_NORMAL;
|
|
||||||
unsigned _default_octave = 4;
|
|
||||||
// unsigned _silence_length; // if nonzero, silence before next note
|
|
||||||
bool _repeat; // if true, tune restarts at end
|
|
||||||
int _cbrk; //if true, no audio output
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert note to frequency
|
* Convert note to frequency
|
||||||
* @param note
|
*
|
||||||
* @return frequency
|
* @param note unsigned value of the semitone from C
|
||||||
|
* @return frequency (Hz)
|
||||||
*/
|
*/
|
||||||
uint32_t note_to_frequency(unsigned note);
|
uint32_t note_to_frequency(unsigned note);
|
||||||
|
|
||||||
// Calculate the duration in microseconds of play and silence for a
|
/**
|
||||||
// note given the current tempo, length and mode and the number of
|
* Calculate the duration in microseconds of play and silence for a
|
||||||
// dots following in the play string.
|
* note given the current tempo, length and mode and the number of
|
||||||
//
|
* dots following in the play string.
|
||||||
|
*
|
||||||
|
* @param silence return silence duration (us)
|
||||||
|
* @param note_length note length
|
||||||
|
* @param dots extention of the note length
|
||||||
|
* @return duration of the note (us)
|
||||||
|
*/
|
||||||
unsigned note_duration(unsigned &silence, unsigned note_length, unsigned dots);
|
unsigned note_duration(unsigned &silence, unsigned note_length, unsigned dots);
|
||||||
|
|
||||||
// Calculate the duration in microseconds of a rest corresponding to
|
// Calculate the duration in microseconds of a rest corresponding to
|
||||||
@@ -99,7 +120,7 @@ private:
|
|||||||
//
|
//
|
||||||
unsigned rest_duration(unsigned rest_length, unsigned dots);
|
unsigned rest_duration(unsigned rest_length, unsigned dots);
|
||||||
|
|
||||||
// Parse the next note out of the string and play it
|
// Parse the next note out of the string
|
||||||
//
|
//
|
||||||
int next_note(unsigned &frequency, unsigned &duration, unsigned &silence);
|
int next_note(unsigned &frequency, unsigned &duration, unsigned &silence);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user