예제 #1
0
static int nas_init(void) {
    TRACE("NAS INIT\n");
    if (!(AuServ = AuOpenServer(NULL, 0, NULL, 0, NULL, NULL)))
       return 0;

    return 1;
}
예제 #2
0
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;
}
예제 #3
0
파일: naplay.c 프로젝트: EQ4/rsynth
int
audio_init(int argc,char *argv[])
{
 int rate_set = samp_rate;
 int vol = 0;

 argc = getargs("Nas",argc, argv,
                "r", "%d", &rate_set, "Sample rate Hz",
                "V", "%d", &vol,      "Volume 0 .. 1.0",
                "a", "", &audioserver,"Name of server",
                NULL);
 if (help_only)
  return argc;

 if ((aud = AuOpenServer(audioserver, 0, NULL, 0, NULL, NULL)) == (AuServer *) 0)
  perror(audioserver);

 if (rate_set && rate_set != samp_rate)
  samp_rate = rate_set;

 if (vol)
  volume = vol;

 return argc;
}
예제 #4
0
파일: SDL_nasaudio.c 프로젝트: bohwaz/ozex
static int Audio_Available(void)
{
	AuServer *aud = AuOpenServer("", 0, NULL, 0, NULL, NULL);
	if (!aud) return 0;

	AuCloseServer(aud);
	return 1;
}
예제 #5
0
파일: audio.c 프로젝트: jgoerzen/netmaze
int init_audio(void)
{
#ifdef USE_SOUND
  int type;

  if(!sm->usesound)
    return -1;

 #if defined(HP_LINEAR)
  if(read_data(AUDIOPATH,AUDIO_8UL) )
    audio = open("/dev/audioBL",O_WRONLY|BLOCKDEVICE); /* test */
  if(audio == -1)
    sm->usesound = 0;
 #elif defined(SIMPLE_AUDIO)
  if(read_data(AUDIOPATH,AUDIO_8ULAW) )
    audio = open("/dev/audio",O_WRONLY|BLOCKDEVICE);
  if(audio == -1)
    sm->usesound = 0;
 #elif defined(SS10_AUDIO)
  if(read_data(AUDIOPATH,AUDIO_16SL) )
  {
    audio = open("/dev/audio",O_WRONLY|BLOCKDEVICE);
    if(ioctl(audio, AUDIO_GETDEV, &type))
      audio = -1;
    if(type == AUDIO_DEV_UNKNOWN || type == AUDIO_DEV_AMD)
      audio = -1;
    AUDIO_INITINFO(&ainfo);
    ainfo.play.encoding = AUDIO_ENCODING_LINEAR;
    ainfo.play.channels = 1;
/* 8000, 9600, 11025, 16000, 18900, 22050, 32000, 37800, 44100, 48000 */
    ainfo.play.sample_rate = 22050; /* 44100 */
    ainfo.play.precision = 16;
    if(ioctl(audio, AUDIO_SETINFO, &ainfo))
      audio = -1;
    ioctl(audio, AUDIO_GETINFO, &ainfo);

    printf("rate: %d\n",ainfo.play.sample_rate);
    printf("channels: %d\n",ainfo.play.channels);
    printf("precision: %d\n",ainfo.play.precision);
    printf("encoding: %d\n",ainfo.play.encoding);
  }
  if(audio == -1)
    sm->usesound = 0;
 #elif defined(NCD_AUDIO)
  audio = -1;
  aud = AuOpenServer(auservername, 0, NULL, 0, NULL, NULL);
  if (!aud)
  {
    fprintf(stderr, "Can't connect to audio server\n");
    sm->usesound = 0;
  }
 #endif

  fprintf(stderr,"audioopen: %d\n",audio);
#endif
  return audio;
}
예제 #6
0
파일: ao_nas.c 프로젝트: has207/libao
int ao_plugin_test()
{
    AuServer* aud = 0;

    aud = AuOpenServer(0, 0, 0, 0, 0, 0);
    if (!aud)
        return 0;
    else {
        AuCloseServer(aud);
        return 1;
    }
}
예제 #7
0
파일: nas.c 프로젝트: dirker/mpg123
/* returning -1 on error, 0 on success... */
static int open_nas(out123_handle *ao)
{
	if(!ao) return -1;

    if (!(info.aud = AuOpenServer(ao->device, 0, NULL, 0, NULL, NULL))) {
		if (ao->device==NULL) {
            error("could not open default NAS server");
		} else {
			error1("could not open NAS server %s\n", ao->device);
		}
        return -1;
    }
    info.buf_size = 0;
        
    return 0;
}
예제 #8
0
static AuServer *
nas_try_connection(char *server)
{
	AuServer *result = NULL;
	char *err_message = NULL;

	/* open server */
	NAS_DEBUG_C("trying to contact NAS server: %s\n", server);
	message(GETTEXT("trying to contact NAS server at %s..."),
		server);
	result = AuOpenServer(server, 0, NULL, 0, NULL, &err_message);

	if (!result) {
		NAS_DEBUG_C("cannot contact NAS server: %s\n",
			     (err_message ? err_message : ":("));
	}

	return result;
}
예제 #9
0
static gboolean
gst_nas_sink_open (GstAudioSink * asink)
{
    GstNasSink *sink = GST_NAS_SINK (asink);

    GST_DEBUG_OBJECT (sink, "opening, host = '%s'", GST_STR_NULL (sink->host));

    /* Open Server */
    sink->audio = AuOpenServer (sink->host, 0, NULL, 0, NULL, NULL);
    if (sink->audio == NULL) {
        GST_DEBUG_OBJECT (sink, "opening failed");
        return FALSE;
    }
    sink->flow = AuNone;
    sink->need_data = 0;

    /* Start a flow */
    GST_DEBUG_OBJECT (asink, "opened audio device");
    return TRUE;
}
예제 #10
0
파일: SDL_nasaudio.c 프로젝트: bohwaz/ozex
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);
}
예제 #11
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);
}
/* 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 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;
}
예제 #14
0
파일: ao_nas.c 프로젝트: has207/libao
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;
}