static int init(struct audio_init *init) { char const *servername; char *message; servername = init->path; if (servername && *servername == 0) servername = 0; server = AuOpenServer(servername, 0, 0, 0, 0, &message); if (server == 0) { audio_error = message ? message : _("AuOpenServer() failed"); /* N.B. AuFree(message) never called */ return -1; } flow = AuCreateFlow(server, 0); if (flow == 0) { AuCloseServer(server); audio_error = _("could not create flow"); return -1; } return 0; }
static int finish(struct audio_finish *finish) { AuCloseServer(server); return 0; }
static int Audio_Available(void) { AuServer *aud = AuOpenServer("", 0, NULL, 0, NULL, NULL); if (!aud) return 0; AuCloseServer(aud); return 1; }
void audio_term(void) { if (aud) { AuFlush(aud); AuCloseServer(aud); } }
static int nas_end(void) { if (AuServ) { AuCloseServer(AuServ); AuServ = 0; } return 1; }
int ao_plugin_close(ao_device *device) { ao_nas_internal *internal = (ao_nas_internal *) device->internal; if(internal->aud) { AuStopFlow(internal->aud, internal->flow, 0); AuCloseServer(internal->aud); } return 1; }
static void NAS_CloseAudio(_THIS) { if ( this->hidden->mixbuf != NULL ) { SDL_FreeAudioMem(this->hidden->mixbuf); this->hidden->mixbuf = NULL; } if ( this->hidden->aud ) { AuCloseServer(this->hidden->aud); this->hidden->aud = 0; } }
static int sound_Stop(void) { if(server != NULL) { aioDisable(AuServerConnectionNumber(server)); AuCloseServer(server); server = NULL; } return 0; }
static int close_nas(out123_handle *ao) { if (info.aud == NULL) { return 0; } if (info.buf_size == 0) { /* Au server opened, but not yet initialized */ AuCloseServer(info.aud); return 0; } while (!info.finished) { flush_nas(ao); } AuCloseServer(info.aud); free(info.buf); return 0; }
static void myshutdown(struct xmp_context *ctx) { while (!info.finished) { nas_flush(); } xmp_smix_off(ctx); AuDestroyFlow(info.aud, info.flow, NULL); AuCloseServer(info.aud); free(info.buf); }
int ao_plugin_test() { AuServer* aud = 0; aud = AuOpenServer(0, 0, 0, 0, 0, 0); if (!aud) return 0; else { AuCloseServer(aud); return 1; } }
static gboolean gst_nas_sink_close (GstAudioSink * asink) { GstNasSink *sink = GST_NAS_SINK (asink); if (sink->audio) { AuCloseServer (sink->audio); sink->audio = NULL; } GST_DEBUG_OBJECT (sink, "closed audio device"); return TRUE; }
static void sound_nas_finish(ad_device_data *data) { sound_nas_data_t *snd = data; NAS_DEBUG("finishing NAS\n"); if (snd->aud) { NAS_DEBUG("closing 0x%x\n", (unsigned int)snd->aud); AuCloseServer(snd->aud); } snd->aud = NULL; NAS_DEBUG("audio-device finished.\n"); return; }
static GstCaps * gst_nas_sink_getcaps (GstBaseSink * bsink) { GstNasSink *nassink = GST_NAS_SINK (bsink); const GstCaps *templatecaps; AuServer *server; GstCaps *fixated, *caps; int i; server = nassink->audio; templatecaps = gst_static_pad_template_get_caps (&sink_factory); if (server == NULL) return gst_caps_copy (templatecaps); fixated = gst_caps_copy (templatecaps); for (i = 0; i < gst_caps_get_size (fixated); i++) { GstStructure *structure; gint min, max; min = AuServerMinSampleRate (server); max = AuServerMaxSampleRate (server); structure = gst_caps_get_structure (fixated, i); if (min == max) gst_structure_set (structure, "rate", G_TYPE_INT, max, NULL); else gst_structure_set (structure, "rate", GST_TYPE_INT_RANGE, min, max, NULL); } caps = gst_caps_intersect (fixated, templatecaps); gst_caps_unref (fixated); if (nassink->audio == NULL) AuCloseServer (server); return caps; }
static gboolean gst_nas_sink_close (GstAudioSink * asink) { GstNasSink *sink = GST_NAS_SINK (asink); if (sink->audio == NULL) return TRUE; if (sink->flow != AuNone) { NAS_flush (sink); AuStopFlow (sink->audio, sink->flow, NULL); AuReleaseScratchFlow (sink->audio, sink->flow, NULL); sink->flow = AuNone; } sink->need_data = 0; AuCloseServer (sink->audio); sink->audio = NULL; GST_DEBUG_OBJECT (sink, "closed audio device"); return TRUE; }
static int sound_Start(int frameCount, int samplesPerSec, int stereo0, int semaIndex0) { AuElement elements[2]; /* first is a client element, second is a device output element */ AuDeviceID device; /* ID of the device to play to */ /* open the server */ DPRINTF("opening server\n"); server = AuOpenServer(NULL, 0, NULL, 0, NULL, NULL); if(server == NULL) { DPRINTF("failed to open audio server\n"); return false; } /* XXX should check the protocol version! */ /* record requested info */ semaIndex = semaIndex0; stereo = stereo0; sampleRate= samplesPerSec; /* pick a device to play to */ device = choose_nas_device(server, samplesPerSec, stereo, 0); if(device == AuNone) { DPRINTF("no available device on the server!\n"); AuCloseServer(server); server = NULL; return false; } /* set up output parameters */ fmtBytes=2; fmtSigned=1; fmtStereo=stereo; fmtIsBigendian=0; recording=0; /* create a flow to write on */ DPRINTF("creating flow\n"); flow = AuCreateFlow(server, NULL); /* create client and device elements to play with */ DPRINTF("creating elements(%d,%d)\n", frameCount, frameCount / 4); AuMakeElementImportClient(&elements[0], samplesPerSec, AuFormatLinearSigned16LSB, /* XXX this should be chosen based on the platform */ stereo ? 2 : 1, AuTrue, 2*frameCount, /* max: 2 buffers */ frameCount, /* low */ 0, NULL); AuMakeElementExportDevice(&elements[1], 0, device, samplesPerSec, AuUnlimitedSamples, 0, NULL); /* set up the flow with these elements */ AuSetElements(server, flow, AuTrue, 2, elements, NULL); /* start her up */ DPRINTF("starting flow\n"); AuStartFlow(server, flow, NULL); AuFlush(server); /* initialize the space indication */ bytesAvail = 0; /* arrange to be informed when events come in from the server */ aioEnable(AuServerConnectionNumber(server), 0, AIO_EXT); aioHandle(AuServerConnectionNumber(server), handleAudioEvents, AIO_R); return true; }
int ao_plugin_open(ao_device *device, ao_sample_format *format) { ao_nas_internal *internal = (ao_nas_internal *) device->internal; unsigned char nas_format; AuElement elms[2]; /* get format */ switch (format->bits) { case 8 : nas_format = AuFormatLinearUnsigned8; break; case 16 : if (device->machine_byte_format == AO_FMT_BIG) nas_format = AuFormatLinearSigned16MSB; else nas_format = AuFormatLinearSigned16LSB; break; default : return 0; } /* open server */ internal->aud = AuOpenServer(internal->host, 0, 0, 0, 0, 0); if (!internal->aud) return 0; /* Could not contact NAS server */ /* find physical output device */ { int i; for (i = 0; i < AuServerNumDevices(internal->aud); i++) if ((AuDeviceKind(AuServerDevice(internal->aud, i)) == AuComponentKindPhysicalOutput) && (AuDeviceNumTracks(AuServerDevice(internal->aud, i)) == device->output_channels)) break; if ((i == AuServerNumDevices(internal->aud)) || (!(internal->flow = AuCreateFlow(internal->aud, 0)))) { /* No physical output device found or flow creation failed. */ AuCloseServer(internal->aud); return 0; } internal->dev = AuDeviceIdentifier(AuServerDevice(internal->aud, i)); } /* set up flow */ AuMakeElementImportClient(&elms[0], format->rate, nas_format, device->output_channels, AuTrue, internal->buf_size, internal->buf_size / 2, 0, 0); AuMakeElementExportDevice(&elms[1], 0, internal->dev, format->rate, AuUnlimitedSamples, 0, 0); AuSetElements(internal->aud, internal->flow, AuTrue, 2, elms, 0); AuStartFlow(internal->aud, internal->flow, 0); device->driver_byte_format = AO_FMT_NATIVE; if(!device->inter_matrix) { /* set up out matrix such that users are warned about > stereo playback */ if(device->output_channels<=2) device->inter_matrix=strdup("L,R"); //else no matrix, which results in a warning } return 1; }
/* StartRecording: open the device for recording. XXX this routine is almost identical to snd_Start(). The two should be factored into a single function! */ static int sound_StartRecording(int desiredSamplesPerSec, int stereo0, int semaIndex0) { AuElement elements[2]; /* elements for the NAS flow to assemble: element 0 = physical input element 1 = client export */ AuDeviceID device; /* physical device ID to use */ DPRINTF("StartRecording\n"); sound_Stop(); DPRINTF("opening server\n"); server = AuOpenServer(NULL, 0, NULL, 0, NULL, NULL); if(server == NULL) { DPRINTF("failed to open audio server\n"); return false; } /* XXX check protocol version of the server */ semaIndex= semaIndex0; stereo= stereo0; sampleRate= desiredSamplesPerSec; device= choose_nas_device(server, desiredSamplesPerSec, stereo, 1); if(device == AuNone) { DPRINTF("no available device on the server!\n"); AuCloseServer(server); server = NULL; return false; } /* record format info */ fmtBytes=2; fmtSigned=1; fmtStereo=stereo; fmtIsBigendian=0; recording=1; /* create a flow to read from */ DPRINTF("creating flow\n"); flow = AuCreateFlow(server, NULL); /* create client and device elements to record with */ DPRINTF("creating elements\n"); AuMakeElementImportDevice(&elements[0], desiredSamplesPerSec, /* XXX should use the actual sampling rate of device */ device, AuUnlimitedSamples, 0, NULL); AuMakeElementExportClient(&elements[1], 0, desiredSamplesPerSec, AuFormatLinearSigned16LSB, /* XXX this should be chosen based on the platform */ stereo ? 2 : 1, AuTrue, 1000000, /* was AuUnlimitedSamples */ 1000, /* water mark: go ahead and send frequently! */ 0, NULL); /* set up the flow with these elements */ AuSetElements(server, flow, AuTrue, 2, elements, NULL); /* start her up */ DPRINTF("starting flow\n"); AuStartFlow(server, flow, NULL); AuFlush(server); /* initialize the space indication */ bytesAvail = 0; /* arrange to be informed when events come in from the server */ aioEnable(AuServerConnectionNumber(server), NULL, AIO_EXT); aioHandle(AuServerConnectionNumber(server), handleAudioEvents, AIO_W); return true; }
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 = 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 = AuCreateFlow(this->hidden->aud, NULL)))) { 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; 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); AuSetElements(this->hidden->aud, this->hidden->flow, AuTrue, 2, elms, NULL); AuRegisterEventHandler(this->hidden->aud, AuEventHandlerIDMask, 0, this->hidden->flow, event_handler, (AuPointer) NULL); 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); } 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); }
static int init(struct xmp_context *ctx) { struct xmp_options *o = &ctx->o; int channels, rate, format, buf_samples; int duration, gain, watermark; char *server; AuDeviceID device = AuNone; AuElement element[2]; char *token, **parm; int i; duration = 2; gain = 100; server = NULL; watermark = 10; channels = 2; rate = o->freq; parm_init(); chkparm1("duration", duration = atoi(token)); chkparm1("gain", gain = atoi(token)); chkparm1("server", server = token); chkparm1("watermark", watermark = atoi(token)); parm_end(); if (o->resol == 8) { format = o->outfmt & XMP_FMT_UNS ? AuFormatLinearUnsigned8 : AuFormatLinearSigned8; } else { if (o->big_endian) { format = o->outfmt & XMP_FMT_UNS ? AuFormatLinearUnsigned16MSB : AuFormatLinearSigned16MSB; } else { format = o-> outfmt & XMP_FMT_UNS ? AuFormatLinearUnsigned16LSB : AuFormatLinearSigned16LSB; } } if (o->outfmt & XMP_FMT_MONO) channels = 1; info.aud = AuOpenServer(server, 0, NULL, 0, NULL, NULL); if (!info.aud) { fprintf(stderr, "xmp: drv_nas: can't connect to server %s\n", server ? server : ""); return XMP_ERR_DINIT; } for (i = 0; i < AuServerNumDevices(info.aud); i++) { if (((AuDeviceKind(AuServerDevice(info.aud, i)) == AuComponentKindPhysicalOutput) && AuDeviceNumTracks(AuServerDevice(info.aud, i)) == channels)) { device = AuDeviceIdentifier(AuServerDevice(info.aud, i)); break; } } info.da = AuGetDeviceAttributes(info.aud, device, NULL); if (!info.da) { fprintf(stderr, "xmp: drv_nas: can't get device attributes\n"); AuCloseServer(info.aud); return XMP_ERR_DINIT; } AuDeviceGain(info.da) = AuFixedPointFromSum(gain, 0); AuSetDeviceAttributes(info.aud, AuDeviceIdentifier(info.da), AuCompDeviceGainMask, info.da, NULL); info.flow = AuCreateFlow(info.aud, NULL); if (!info.flow) { fprintf(stderr, "xmp: drv_nas: can't create flow\n"); AuCloseServer(info.aud); return XMP_ERR_DINIT; } buf_samples = rate * duration; AuMakeElementImportClient(&element[0], rate, format, channels, AuTrue, buf_samples, (AuUint32) (buf_samples * watermark / 100), 0, NULL); AuMakeElementExportDevice(&element[1], 0, device, rate, AuUnlimitedSamples, 0, NULL); AuSetElements(info.aud, info.flow, AuTrue, 2, element, NULL); AuRegisterEventHandler(info.aud, AuEventHandlerIDMask, 0, info.flow, nas_event, (AuPointer) & info); info.buf_size = buf_samples * channels * AuSizeofFormat(format); info.buf = (char *)malloc(info.buf_size); info.buf_cnt = 0; info.data_sent = AuFalse; info.finished = AuFalse; AuStartFlow(info.aud, info.flow, NULL); return xmp_smix_on(ctx); }