From 528de868b92c79d98285719448b6c33fecc97d54 Mon Sep 17 00:00:00 2001 From: BeWorld <36823759+BeWorld2018@users.noreply.github.com> Date: Mon, 15 Jan 2024 20:34:26 +0100 Subject: [PATCH] MorphOS: adapt audio AHI --- src/audio/ahi/SDL_ahi_audio.c | 60 +++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 17 deletions(-) diff --git a/src/audio/ahi/SDL_ahi_audio.c b/src/audio/ahi/SDL_ahi_audio.c index 917e2015a47d3..63ce1a7bf1b7c 100644 --- a/src/audio/ahi/SDL_ahi_audio.c +++ b/src/audio/ahi/SDL_ahi_audio.c @@ -43,6 +43,25 @@ AHIAUD_Mute(ULONG mute) } static void +AHIAUD_DetectDevices(SDL_AudioDevice **default_output, SDL_AudioDevice **default_capture) +{ + + SDL_AudioSpec output, capture; + + output.freq = 44100; + output.format = SDL_AUDIO_S16BE; + output.channels = 2; + + capture.freq = 44100; + capture.format = SDL_AUDIO_S16BE; + capture.channels = 1; + + *default_output = SDL_AddAudioDevice(SDL_FALSE, "AHI default output device", &output, SDL_strdup("default")); + *default_capture = SDL_AddAudioDevice(SDL_TRUE, "AHI default capture device", &capture, SDL_strdup("default")); + +} + +static int AHIAUD_WaitDevice(SDL_AudioDevice *device) { MOSAudioData *hidden = device->hidden; @@ -55,9 +74,11 @@ AHIAUD_WaitDevice(SDL_AudioDevice *device) GetMsg(&hidden->ahiport); } + + return 0; } -static void +static int AHIAUD_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen) { MOSAudioData *hidden = device->hidden; @@ -81,6 +102,8 @@ AHIAUD_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen) hidden->playing = 1; SendIO((struct IORequest *)req); + + return 0; } static Uint8 * @@ -137,21 +160,18 @@ AHIAUD_OpenDevice(SDL_AudioDevice *device) int sample_format = -1; const SDL_AudioFormat *closefmts; switch (device->spec.format) { - case SDL_AUDIO_F32LSB: - case SDL_AUDIO_F32MSB: - case SDL_AUDIO_S32LSB: - device->spec.format = SDL_AUDIO_S32MSB; + case SDL_AUDIO_F32LE: + case SDL_AUDIO_F32BE: + case SDL_AUDIO_S32BE: + case SDL_AUDIO_S32LE: + device->spec.format = SDL_AUDIO_S32BE; break; - case SDL_AUDIO_S16LSB: + case SDL_AUDIO_S16LE: default: - device->spec.format = SDL_AUDIO_S16MSB; + device->spec.format = SDL_AUDIO_S16BE; break; } - //test_format = SDL_GetFirstAudioFormat(device->spec.format); - - //while (sample_format < 0 && test_format) { - closefmts = SDL_ClosestAudioFormats(device->spec.format); while ((test_format = *(closefmts++)) != 0) { switch (test_format) { @@ -160,12 +180,12 @@ AHIAUD_OpenDevice(SDL_AudioDevice *device) sample_format = device->spec.channels == 1 ? AHIST_M8S : AHIST_S8S; break; break; - case SDL_AUDIO_S16LSB: - case SDL_AUDIO_S16MSB: + case SDL_AUDIO_S16LE: + case SDL_AUDIO_S16BE: sample_format = device->spec.channels == 1 ? AHIST_M16S : AHIST_S16S; break; - case SDL_AUDIO_S32LSB: - case SDL_AUDIO_S32MSB: + case SDL_AUDIO_S32BE: + case SDL_AUDIO_S32LE: sample_format = device->spec.channels == 1 ? AHIST_M32S : AHIST_S32S; break; default: @@ -254,7 +274,7 @@ AHIAUD_CaptureFromDevice(SDL_AudioDevice *device, void *buffer, int buflen) current = hidden->current_buffer; request = &hidden->req[0]; - if ((now - hidden->lastCaptureTicks) > RESTART_CAPTURE_THRESHOLD) { + if (hidden->lastCaptureTicks == 0 || (now - hidden->lastCaptureTicks) > RESTART_CAPTURE_THRESHOLD) { if (hidden->requestSent) { WaitIO((struct IORequest *)request); @@ -277,7 +297,9 @@ AHIAUD_CaptureFromDevice(SDL_AudioDevice *device, void *buffer, int buflen) current = 1 - current; } else { - WaitIO((struct IORequest *)request); + if (hidden->requestSent) { + WaitIO((struct IORequest *)request); + } } AHIAUD_FillCaptureRequest( @@ -308,13 +330,17 @@ static SDL_bool AHIAUD_Init(SDL_AudioDriverImpl * impl) { + impl->DetectDevices = AHIAUD_DetectDevices; impl->OpenDevice = AHIAUD_OpenDevice; impl->ThreadInit = AHIAUD_ThreadInit; + impl->PlayDevice = AHIAUD_PlayDevice; impl->WaitDevice = AHIAUD_WaitDevice; impl->CaptureFromDevice = AHIAUD_CaptureFromDevice; impl->GetDeviceBuf = AHIAUD_GetDeviceBuf; impl->CloseDevice = AHIAUD_CloseDevice; + + impl->ProvidesOwnCallbackThread = SDL_FALSE; impl->HasCaptureSupport = SDL_TRUE; impl->OnlyHasDefaultOutputDevice = SDL_TRUE; impl->OnlyHasDefaultCaptureDevice = SDL_TRUE;