Skip to content

Commit

Permalink
DualTone: Don't bother adding notes with zero frequency
Browse files Browse the repository at this point in the history
They're meant to be silent, so only increase the tick to effectively
"add" a silent note.
  • Loading branch information
AShiningRay committed Nov 19, 2024
1 parent e07c20b commit e9a012d
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/com/sprintpcs/media/DualTone.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,22 @@ public DualTone(int[] x_frequencies, int[] y_frequencies, int[] durations, int p
// x_frequencies and y-frequencies are expected to always be the same length, same for durations
for (int i = 0; i < x_frequencies.length; i++)
{
tmpNote = convertFreqToNote(x_frequencies[i]);

int durationInMillis = durations[i];
// Convert duration from milliseconds to ticks
long durationInTicks = Math.round(durationInMillis * TICKS_PER_MILLISECOND);

trackA.add(createMidiEvent(ShortMessage.NOTE_ON, tmpNote, 93, currentTick));
trackA.add(createMidiEvent(ShortMessage.NOTE_OFF, tmpNote, 0, currentTick + durationInTicks));

tmpNote = convertFreqToNote(y_frequencies[i]);

trackB.add(createMidiEvent(ShortMessage.NOTE_ON, tmpNote, 93, currentTick));
trackB.add(createMidiEvent(ShortMessage.NOTE_OFF, tmpNote, 0, currentTick + durationInTicks));

long durationInTicks = Math.round(durations[i] * TICKS_PER_MILLISECOND);

if(x_frequencies[i] != 0) // Don't add silent notes
{
tmpNote = convertFreqToNote(x_frequencies[i]);
trackA.add(createMidiEvent(ShortMessage.NOTE_ON, tmpNote, 93, currentTick));
trackA.add(createMidiEvent(ShortMessage.NOTE_OFF, tmpNote, 0, currentTick + durationInTicks));
}
if(y_frequencies[i] != 0)
{
tmpNote = convertFreqToNote(y_frequencies[i]);
trackB.add(createMidiEvent(ShortMessage.NOTE_ON, tmpNote, 93, currentTick));
trackB.add(createMidiEvent(ShortMessage.NOTE_OFF, tmpNote, 0, currentTick + durationInTicks));
}

currentTick += durationInTicks;
}

Expand Down

0 comments on commit e9a012d

Please sign in to comment.