Changeset - r22910:67b1add3dd42
[Not reviewed]
master
0 2 0
Niels Martin Hansen - 6 years ago 2018-06-06 16:20:22
nielsm@indvikleren.dk
Change: Compensate for MIDI transmission time when skipping start of song
2 files changed with 10 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/music/dmusic.cpp
Show inline comments
 
@@ -690,12 +690,15 @@ static void MidiThreadProc(void *)
 
					if (block.ticktime >= current_segment.start) {
 
						if (current_segment.loop) {
 
							DEBUG(driver, 2, "DMusic: timer: loop from block %d (ticktime %d, realtime %.3f, bytes %d)", (int)bl, (int)block.ticktime, ((int)block.realtime) / 1000.0, (int)preload_bytes);
 
							current_segment.start_block = bl;
 
							break;
 
						} else {
 
							/* Skip the transmission delay compensation performed in the Win32 MIDI driver.
 
							 * The DMusic driver will most likely be used with the MS softsynth, which is not subject to transmission delays.
 
							 */
 
							DEBUG(driver, 2, "DMusic: timer: start from block %d (ticktime %d, realtime %.3f, bytes %d)", (int)bl, (int)block.ticktime, ((int)block.realtime) / 1000.0, (int)preload_bytes);
 
							playback_start_time -= block.realtime * MIDITIME_TO_REFTIME;
 
							break;
 
						}
 
					}
 
				}
src/music/win32_m.cpp
Show inline comments
 
@@ -181,24 +181,29 @@ void CALLBACK TimerCallback(UINT uTimerI
 

	
 
	/* skip beginning of file? */
 
	if (_midi.current_segment.start > 0 && _midi.current_block == 0 && _midi.current_segment.start_block == 0) {
 
		/* find first block after start time and pretend playback started earlier
 
		* this is to allow all blocks prior to the actual start to still affect playback,
 
		* as they may contain important controller and program changes */
 
		size_t preload_bytes = 0;
 
		uint preload_bytes = 0;
 
		for (size_t bl = 0; bl < _midi.current_file.blocks.size(); bl++) {
 
			MidiFile::DataBlock &block = _midi.current_file.blocks[bl];
 
			preload_bytes += block.data.Length();
 
			if (block.ticktime >= _midi.current_segment.start) {
 
				if (_midi.current_segment.loop) {
 
					DEBUG(driver, 2, "Win32-MIDI: timer: loop from block %d (ticktime %d, realtime %.3f, bytes %d)", (int)bl, (int)block.ticktime, ((int)block.realtime)/1000.0, (int)preload_bytes);
 
					_midi.current_segment.start_block = bl;
 
					break;
 
				} else {
 
					/* Calculate offset start time for playback.
 
					 * The preload_bytes are used to compensate for delay in transmission over traditional serial MIDI interfaces,
 
					 * which have a bitrate of 31,250 bits/sec, and transmit 1+8+1 start/data/stop bits per byte.
 
					 * The delay compensation is needed to avoid time-compression of following messages.
 
					 */
 
					DEBUG(driver, 2, "Win32-MIDI: timer: start from block %d (ticktime %d, realtime %.3f, bytes %d)", (int)bl, (int)block.ticktime, ((int)block.realtime) / 1000.0, (int)preload_bytes);
 
					_midi.playback_start_time -= block.realtime / 1000;
 
					_midi.playback_start_time -= block.realtime / 1000 - preload_bytes * 1000 / 3125;
 
					break;
 
				}
 
			}
 
		}
 
	}
 

	
0 comments (0 inline, 0 general)