From: Toni Wilen Date: Sat, 29 Nov 2025 11:19:51 +0000 (+0200) Subject: Partial audio future plans, mostly disabled for now. X-Git-Tag: 6020~44 X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=29c42106ad6c439e74b0bf9911cb96956ba15fe9;p=francis%2Fwinuae.git Partial audio future plans, mostly disabled for now. --- diff --git a/audio.cpp b/audio.cpp index 0cd0e911..3d4c6ac4 100644 --- a/audio.cpp +++ b/audio.cpp @@ -825,9 +825,15 @@ static void check_sound_buffers(void) paula_sndbufpt = paula_sndbufpt_start; } #endif +#if SOUND_MODE_NG + if ((uae_u8*)paula_sndbufpt - (uae_u8*)paula_sndbuffer >= paula_sndbufsize * 2) { + paula_sndbufpt = paula_sndbuffer; + } +#else if ((uae_u8*)paula_sndbufpt - (uae_u8*)paula_sndbuffer >= paula_sndbufsize) { finish_sound_buffer(); } +#endif #if SOUNDSTUFF > 1 while (doublesample-- > 0) { memcpy(paula_sndbufpt, paula_sndbufpt_start, len * 2); diff --git a/custom.cpp b/custom.cpp index 4314f548..0b05f375 100644 --- a/custom.cpp +++ b/custom.cpp @@ -4903,6 +4903,9 @@ static bool framewait(void) while (rpt_vsync(clockadjust) < 0) { rtg_vsynccheck(); +#if 0 + audio_is_pull_event(); +#endif #if 0 if (audio_is_pull_event()) { maybe_process_pull_audio(); diff --git a/include/audio.h b/include/audio.h index c893652c..a0f58d57 100644 --- a/include/audio.h +++ b/include/audio.h @@ -47,6 +47,7 @@ int audio_pull_buffer(void); bool audio_finish_pull(void); bool audio_is_pull_event(void); bool audio_is_event_frame_possible(int); +void audio_got_pull_event(void); extern int sampleripper_enabled; diff --git a/od-win32/sounddep/sound.cpp b/od-win32/sounddep/sound.cpp index 4d08ec84..8ad6cb7d 100644 --- a/od-win32/sounddep/sound.cpp +++ b/od-win32/sounddep/sound.cpp @@ -110,6 +110,7 @@ struct sound_dp uae_u8 *pullbuffer; int pullbufferlen; int pullbuffermaxlen; + bool gotpullevent; #if USE_XAUDIO // xaudio2 @@ -148,7 +149,11 @@ static int statuscnt; #define SND_MAX_BUFFER2 524288 #define SND_MAX_BUFFER 65536 +#if SOUND_MODE_NG +uae_u16 paula_sndbuffer[SND_MAX_BUFFER * 2 + 8]; +#else uae_u16 paula_sndbuffer[SND_MAX_BUFFER]; +#endif uae_u16 *paula_sndbufpt; int paula_sndbufsize; int active_sound_stereo; @@ -2366,6 +2371,8 @@ static bool finish_sound_buffer_wasapi_pull_do(struct sound_data *sd) HRESULT hr; BYTE *pData; + s->gotpullevent = false; + if (s->pullbufferlen <= 0) return false; @@ -2634,6 +2641,7 @@ static bool send_sound_do(struct sound_data *sd) return finish_sound_buffer_wasapi_pull_do(sd); } else if (type == SOUND_DEVICE_PA) { struct sound_dp *s = sd->data; + s->gotpullevent = false; ResetEvent(s->pullevent); SetEvent(s->pullevent2); } @@ -2681,18 +2689,36 @@ HANDLE get_sound_event(void) return 0; } +static frame_time_t prevtime; + +void audio_got_pull_event(void) +{ + struct sound_dp *s = sdp->data; + if (s && !s->gotpullevent) { + frame_time_t cyc = read_processor_time(); + //write_log("%lld\n", cyc - prevtime); + prevtime = cyc; + s->gotpullevent = true; + } +} + bool audio_is_event_frame_possible(int ms) { int type = sdp->devicetype; - if (sdp->paused || sdp->deactive || sdp->reset) + if (sdp->paused || sdp->deactive || sdp->reset) { return false; + } if (type == SOUND_DEVICE_WASAPI || type == SOUND_DEVICE_WASAPI_EXCLUSIVE || type == SOUND_DEVICE_PA) { +#if 0 + return true; +#else struct sound_dp *s = sdp->data; int bufsize = (int)((uae_u8*)paula_sndbufpt - (uae_u8*)paula_sndbuffer); bufsize /= sdp->samplesize; int todo = s->bufferFrameCount - bufsize; int samplesperframe = (int)(sdp->obtainedfreq / vblank_hz); return samplesperframe >= todo - samplesperframe; +#endif } return false; } @@ -2738,7 +2764,14 @@ bool audio_is_pull_event(void) if (type == SOUND_DEVICE_WASAPI || type == SOUND_DEVICE_WASAPI_EXCLUSIVE || type == SOUND_DEVICE_PA) { struct sound_dp *s = sdp->data; if (s->pullmode) { - return WaitForSingleObject(s->pullevent, 0) == WAIT_OBJECT_0; + if (!s->gotpullevent) { + if (WaitForSingleObject(s->pullevent, 0) == WAIT_OBJECT_0) { + audio_got_pull_event(); + return true; + } + return false; + } + return true; } } return false; diff --git a/od-win32/sounddep/sound.h b/od-win32/sounddep/sound.h index b13c425f..5ed55ac1 100644 --- a/od-win32/sounddep/sound.h +++ b/od-win32/sounddep/sound.h @@ -7,6 +7,7 @@ */ #define SOUNDSTUFF 1 +#define SOUND_MODE_NG 0 extern uae_u16 paula_sndbuffer[]; extern uae_u16 *paula_sndbufpt; diff --git a/od-win32/win32.cpp b/od-win32/win32.cpp index d13b5c3b..c040b2e7 100644 --- a/od-win32/win32.cpp +++ b/od-win32/win32.cpp @@ -468,18 +468,20 @@ static int sleep_millis2 (int ms, bool main) HANDLE sound_event = get_sound_event(); bool wasneg = ms < 0; bool pullcheck = false; + int ret = 0; if (ms < 0) ms = -ms; if (main) { if (sound_event) { - bool pullcheck = audio_is_event_frame_possible(ms); + pullcheck = audio_is_event_frame_possible(ms); if (pullcheck) { if (WaitForSingleObject(sound_event, 0) == WAIT_OBJECT_0) { if (wasneg) { write_log(_T("efw %d imm abort\n"), ms); } + audio_got_pull_event(); return -1; } } @@ -521,10 +523,13 @@ static int sleep_millis2 (int ms, bool main) evt[c++] = sound_event; } DWORD status = WaitForMultipleObjects(c, evt, FALSE, ms); - if (sound_event_cnt >= 0 && status == WAIT_OBJECT_0 + sound_event_cnt) + if (sound_event_cnt >= 0 && status == WAIT_OBJECT_0 + sound_event_cnt) { ret = -1; - if (vblank_event_cnt >= 0 && status == WAIT_OBJECT_0 + vblank_event_cnt) + audio_got_pull_event(); + } + if (vblank_event_cnt >= 0 && status == WAIT_OBJECT_0 + vblank_event_cnt) { ret = -1; + } if (wasneg) { if (sound_event_cnt >= 0 && status == WAIT_OBJECT_0 + sound_event_cnt) { write_log(_T("efw %d delayed abort\n"), ms);