Skip to content

Commit

Permalink
MorphOS: adapt audio AHI
Browse files Browse the repository at this point in the history
  • Loading branch information
BeWorld2018 committed Jan 15, 2024
1 parent d1ef501 commit 528de86
Showing 1 changed file with 43 additions and 17 deletions.
60 changes: 43 additions & 17 deletions src/audio/ahi/SDL_ahi_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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 *
Expand Down Expand Up @@ -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) {
Expand All @@ -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:
Expand Down Expand Up @@ -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);
Expand All @@ -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(
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 528de86

Please sign in to comment.