Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
first mic delay tests.
in the main menu: enter the sing menu and go back (i don't know why this
is necessary)
press W to play the wave file and measure the latency (shown on the top
right). try this multiple times to figure out what the actual latency
is.
press M to play the same tone via MIDI output and measure the latency.
on my system MIDI is 150ms slower than playing the wave file
  • Loading branch information
dgruss committed Sep 21, 2025
commit 348628505f1dd18e9fc91d68207e404048e15ea3
Binary file added game/sounds/ping.wav
Binary file not shown.
3 changes: 3 additions & 0 deletions src/base/UMusic.pas
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ TSoundLibrary = class
Change: TAudioPlaybackStream;
Option: TAudioPlaybackStream;
Click: TAudioPlaybackStream;
Ping: TAudioPlaybackStream;
Applause:TAudioPlaybackStream;
BGMusic: TAudioPlaybackStream;

Expand Down Expand Up @@ -990,6 +991,7 @@ procedure TSoundLibrary.LoadSounds();
Change := AudioPlayback.OpenSound(SoundPath.Append('select music change music 50.mp3'));
Option := AudioPlayback.OpenSound(SoundPath.Append('option change col.mp3'));
Click := AudioPlayback.OpenSound(SoundPath.Append('rimshot022b.wav'));
Ping := AudioPlayback.OpenSound(SoundPath.Append('ping.wav'));
Applause:= AudioPlayback.OpenSound(SoundPath.Append('Applause.mp3'));

BGMusic := AudioPlayback.OpenSound(SoundPath.Append('background track.mp3'));
Expand All @@ -1006,6 +1008,7 @@ procedure TSoundLibrary.UnloadSounds();
FreeAndNil(Change);
FreeAndNil(Option);
FreeAndNil(Click);
FreeAndNil(Ping);
FreeAndNil(Applause);
FreeAndNil(BGMusic);
end;
Expand Down
15 changes: 15 additions & 0 deletions src/menu/UDisplay.pas
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ TDisplay = class

procedure SaveScreenShot;

procedure DrawDelay(Delay: Integer);

function Draw: boolean;

// TODO rewrite ParseInput to include handling/suppressing input as return, use KeepGoing as by-reference
Expand Down Expand Up @@ -889,6 +891,19 @@ function TDisplay.ConsoleParseMouse(MouseButton: integer; BtnDown: boolean; X, Y
end;
end;

procedure TDisplay.DrawDelay(Delay: Integer);
begin
// set font specs using UDisplay methods
SetFontFamily(0);
SetFontStyle(ftRegular);
SetFontSize(21);
SetFontItalic(false);
glColor4f(0, 0, 0, 1);
SetFontPos(605, 0);
glPrint('Delay measured: ' + IntToStr(Delay) + ' ms');
glColor4f(1, 1, 1, 1);
end;

//------------
// DrawDebugInformation - procedure draw fps and some other informations on screen
//------------
Expand Down
46 changes: 46 additions & 0 deletions src/screens/UScreenMain.pas
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ interface
UFiles,
UMenu,
UMusic,
URecord,
UScreenSong,
USong,
UThemes,
MidiOut,
MidiCons,
Math,
MD5,
sdl2,
SysUtils;
Expand All @@ -52,6 +56,10 @@ TScreenMain = class(TMenu)
public
TextDescription: integer;
TextDescriptionLong: integer;
PingTime: integer;
PingResponse: integer;
CurrentSound: TCaptureBuffer;
MidiOut: TMidiOutput;

constructor Create; override;
function ParseInput(PressedKey: Cardinal; CharCode: UCS4Char;
Expand Down Expand Up @@ -111,6 +119,24 @@ function TScreenMain.ParseInput(PressedKey: Cardinal; CharCode: UCS4Char;
end;
end;

SDLK_W: begin
SoundLib.Ping.Volume := 1.0;
PingResponse := 0;
PingTime := SDL_GetTicks;
SoundLib.Ping.Play;
Exit;
end;

SDLK_M: begin
SoundLib.Ping.Volume := 1.0;
PingResponse := 0;
PingTime := SDL_GetTicks;
MidiOut.PutShort($B1, $7, 127);
MidiOut.PutShort($81, 24 + 60, 127);
MidiOut.PutShort($91, 24 + 60, 127);
Exit;
end;

SDLK_J: begin
FadeTo(@ScreenJukeboxPlaylist, SoundLib.Start);
Exit;
Expand Down Expand Up @@ -304,6 +330,12 @@ constructor TScreenMain.Create;
Interaction := 0;

WantSoftwareRenderingMsg := SoftwareRendering;

PingTime := 0;
PingResponse := 0;

MidiOut := TMidiOutput.Create(nil);
MidiOut.Open;
end;

procedure TScreenMain.OnShow;
Expand All @@ -322,6 +354,8 @@ procedure TScreenMain.OnShow;
* at the moment there is no better place for this
*}
Party.Clear;

AudioInput.CaptureStart;
end;

function TScreenMain.Draw: boolean;
Expand All @@ -336,6 +370,18 @@ function TScreenMain.Draw: boolean;
ScreenPopupError.ShowPopup(Language.Translate('ERROR_SOFTWARE_RENDERING'));
end;
end;

CurrentSound := AudioInputProcessor.Sound[0];
CurrentSound.AnalyzeBuffer;

if (CurrentSound.ToneAbs = 48) and (PingResponse = 0) then
begin
PingResponse := SDL_GetTicks - PingTime;
MidiOut.PutShort($B1, $7, 127);
MidiOut.PutShort($81, 24 + 60, 127);
MidiOut.PutShort(MIDI_STOP, 0, 0);
end;
Display.DrawDelay(PingResponse);
end;

procedure TScreenMain.SetInteraction(Num: integer);
Expand Down