static int NAS_Init(SDL_AudioDriverImpl * impl) { if (LoadNASLibrary() < 0) { return 0; } else { AuServer *aud = NAS_AuOpenServer("", 0, NULL, 0, NULL, NULL); if (aud == NULL) { SDL_SetError("NAS: AuOpenServer() failed (no audio server?)"); return 0; } NAS_AuCloseServer(aud); } /* Set the function pointers */ impl->OpenDevice = NAS_OpenDevice; impl->PlayDevice = NAS_PlayDevice; impl->WaitDevice = NAS_WaitDevice; impl->GetDeviceBuf = NAS_GetDeviceBuf; impl->CloseDevice = NAS_CloseDevice; impl->Deinitialize = NAS_Deinitialize; impl->OnlyHasDefaultOutputDevice = 1; /* !!! FIXME: is this true? */ return 1; /* this audio target is available. */ }
static void NAS_CloseDevice(_THIS) { if (this->hidden->aud) { NAS_AuCloseServer(this->hidden->aud); } SDL_free(this->hidden->mixbuf); SDL_free(this->hidden); }
static void NAS_CloseAudio(_THIS) { if ( this->hidden->mixbuf != NULL ) { SDL_FreeAudioMem(this->hidden->mixbuf); this->hidden->mixbuf = NULL; } if ( this->hidden->aud ) { NAS_AuCloseServer(this->hidden->aud); this->hidden->aud = 0; } }
static int Audio_Available(void) { if (LoadNASLibrary() == 0) { AuServer *aud = NAS_AuOpenServer("", 0, NULL, 0, NULL, NULL); if (!aud) { UnloadNASLibrary(); return 0; } NAS_AuCloseServer(aud); UnloadNASLibrary(); return 1; } return 0; }
static void NAS_CloseDevice(_THIS) { if (this->hidden != NULL) { SDL_FreeAudioMem(this->hidden->mixbuf); this->hidden->mixbuf = NULL; if (this->hidden->aud) { NAS_AuCloseServer(this->hidden->aud); this->hidden->aud = 0; } SDL_free(this->hidden); this2 = this->hidden = NULL; } }
static int NAS_OpenAudio(_THIS, SDL_AudioSpec *spec) { AuElement elms[3]; int buffer_size; Uint16 test_format, format; this->hidden->mixbuf = NULL; /* Try for a closest match on audio format */ format = 0; for ( test_format = SDL_FirstAudioFormat(spec->format); ! format && test_format; ) { format = sdlformat_to_auformat(test_format); if (format == AuNone) { test_format = SDL_NextAudioFormat(); } } if ( format == 0 ) { SDL_SetError("Couldn't find any hardware audio formats"); return(-1); } spec->format = test_format; this->hidden->aud = NAS_AuOpenServer("", 0, NULL, 0, NULL, NULL); if (this->hidden->aud == 0) { SDL_SetError("Couldn't open connection to NAS server"); return (-1); } this->hidden->dev = find_device(this, spec->channels); if ((this->hidden->dev == AuNone) || (!(this->hidden->flow = NAS_AuCreateFlow(this->hidden->aud, NULL)))) { NAS_AuCloseServer(this->hidden->aud); this->hidden->aud = 0; SDL_SetError("Couldn't find a fitting playback device on NAS server"); return (-1); } buffer_size = spec->freq; if (buffer_size < 4096) buffer_size = 4096; if (buffer_size > 32768) buffer_size = 32768; /* So that the buffer won't get unmanageably big. */ /* Calculate the final parameters for this audio specification */ SDL_CalculateAudioSpec(spec); this2 = this->hidden; /* These "Au" things without a NAS_ prefix are macros, not functions... */ AuMakeElementImportClient(elms, spec->freq, format, spec->channels, AuTrue, buffer_size, buffer_size / 4, 0, NULL); AuMakeElementExportDevice(elms+1, 0, this->hidden->dev, spec->freq, AuUnlimitedSamples, 0, NULL); NAS_AuSetElements(this->hidden->aud, this->hidden->flow, AuTrue, 2, elms, NULL); NAS_AuRegisterEventHandler(this->hidden->aud, AuEventHandlerIDMask, 0, this->hidden->flow, event_handler, (AuPointer) NULL); NAS_AuStartFlow(this->hidden->aud, this->hidden->flow, NULL); /* Allocate mixing buffer */ this->hidden->mixlen = spec->size; this->hidden->mixbuf = (Uint8 *)SDL_AllocAudioMem(this->hidden->mixlen); if ( this->hidden->mixbuf == NULL ) { return(-1); } SDL_memset(this->hidden->mixbuf, spec->silence, spec->size); /* Get the parent process id (we're the parent of the audio thread) */ this->hidden->parent = getpid(); /* We're ready to rock and roll. :-) */ return(0); }