Skip to content

Commit

Permalink
Updates for music repeat functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
mesheets committed Jul 27, 2024
1 parent 03daecc commit 6609cc6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
7 changes: 7 additions & 0 deletions demo/c/music.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ static const note_t amazing_grace[] = {
{ PITCH_A4, QUARTER },
{ PITCH_G4, HALF_DOTTED },

// Slowly repeat the last phrase
{ PITCH_TEMPO, TEMPO_FROM_BPM(QUARTER, 80) },
{ PITCH_REPEAT, 1 }, // Number of times to repeat
{ 0, 8 }, // Number of array elements to repeat,
// expressed as two unsigned byte values that will
// be read as a single, unsigned two-byte value

{ PITCH_END, 0 }
};

Expand Down
9 changes: 7 additions & 2 deletions include/dmusic.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,12 @@ extern "C" {
//! maximum pitch value
#define PITCH_MAX 98

//! repeat last {note->length} notes forever
//! repeat last {note->length} notes
//! PITCH_REPEAT is a two-element sequence:
//! The length value of the first element is the number of times to repeat
//! The second element is the number of array elements to repeat, expressed as
//! two unsigned byte values that will be read as a single, unsigned two-byte value
//! NOTE: Repeats cannot be nested
#define PITCH_REPEAT 252

//! mark the end of a list of note_t entries
Expand All @@ -271,7 +276,7 @@ extern "C" {
//! set duration of internote spacing
#define PITCH_INTERNOTE 253

//! calculate duration based on beats per minute (bpm)
//! calculate duration for PITCH_TEMPO based on beats per minute (bpm)
#define TEMPO_FROM_BPM(note_type,beats_per_minute) (60000 / (note_type * beats_per_minute))


Expand Down
4 changes: 2 additions & 2 deletions kernel/dsound.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ static void dsound_handler(void *data) {
repcnt = 0;
dsound_next_note += 2;
} else {
dsound_next_note -= (dsound_next_note[1].pitch << 8)
| dsound_next_note[1].length;
dsound_next_note -= (((unsigned short)dsound_next_note[1].pitch) << 8)
| ((unsigned short)dsound_next_note[1].length);
}
} else { /* PITCH_END or broken sound */
play_pause();
Expand Down

0 comments on commit 6609cc6

Please sign in to comment.