Skip to content

Commit

Permalink
MelodyComposer: Try to match BPM to nokia's OTA/OTT tones.
Browse files Browse the repository at this point in the history
AH-1 SeaBomber has versions for both tone implementations, with
Nokia's newest implementation being assumed to be more correct,
as it is backed by some documentation. So tailor the sequence
BPM calculation and speed in siemens' MelodyComposer to be closer
to Nokia's on this game, hopefully improving other MelodyComposer
jars as well. Notes still sound very different, but there's not
much that can be done since Siemens is only supposed to go from
C0(12) to A4(69) directly, at least if Siemens' note definitions
and MIDI's note values are to match.
  • Loading branch information
AShiningRay committed Dec 2, 2024
1 parent 0440d49 commit dc076c7
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/com/siemens/mp/game/MelodyComposer.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.IOException;

import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.MetaMessage;
import javax.sound.midi.MidiEvent;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.Sequence;
Expand Down Expand Up @@ -393,9 +394,19 @@ public void setBPM(int bpm)
try
{
curMelody.bpm = bpm;
tmpSequence = new Sequence(Sequence.PPQ, 60000 / bpm);
tmpSequence = new Sequence(Sequence.PPQ, (int) (BPM*1.5)); // This PPQ value is just to approximate Siemens's Melody playback speed to Nokia's OTA/OTT (assumed to be correct). Tested in AH-1 SeaBomber which is available for both
tmpTrack = tmpSequence.createTrack();
tmpTrack.add(new MidiEvent(new ShortMessage(ShortMessage.PROGRAM_CHANGE, 0, 80, 0), 0)); // 80 is the Square Wave / Lead 1 instrument, which we'll use to get closer to what this should sound like

int microsecondsPerBeat = 60000000 / bpm;
MetaMessage metaMessage = new MetaMessage();
metaMessage.setMessage(0x51, new byte[]
{
(byte) (microsecondsPerBeat >> 16),
(byte) (microsecondsPerBeat >> 8),
(byte) (microsecondsPerBeat)
}, 3);
track.add(new MidiEvent(metaMessage, curTick)); // Add BPM change event at the current tick pos
}
catch (Exception e) { Mobile.log(Mobile.LOG_ERROR, MelodyComposer.class.getPackage().getName() + "." + MelodyComposer.class.getSimpleName() + ": " + " couldn't create new Melody with BPM:" + e.getMessage()); }
}
Expand Down

0 comments on commit dc076c7

Please sign in to comment.