static AuDeviceID choose_nas_device(AuServer *server, int samplesPerSec, int stereo, int recording) 
{
  int desiredDeviceKind=
    recording ?
       AuComponentKindPhysicalInput :
       AuComponentKindPhysicalOutput;
  int desired_channels= stereo ? 2 : 1;
  int i;
  
  /* look for a physical device of the proper kind, with the proper number of channels */
  for (i = 0; i < AuServerNumDevices(server); i++) {
    if((AuDeviceKind(AuServerDevice(server, i))
	==  desiredDeviceKind)
       && (AuDeviceNumTracks(AuServerDevice(server, i))
	   ==  desired_channels))
	 return AuDeviceIdentifier(AuServerDevice(server, i));
  }



  /* look for a physical device of the proper kind; ignore number of channels */
  for (i = 0; i < AuServerNumDevices(server); i++) {
    if(AuDeviceKind(AuServerDevice(server, i))
       ==  desiredDeviceKind)
	 return AuDeviceIdentifier(AuServerDevice(server, i));
  }



  return AuNone;
}
예제 #2
0
static
AuDeviceID getdevice(AuServer const *server, unsigned int *channels)
{
  AuDeviceID device = AuNone;
  int i;

  for (i = 0; i < AuServerNumDevices(server); ++i) {
    if (AuDeviceKind(AuServerDevice(server, i)) ==
	AuComponentKindPhysicalOutput &&
	AuDeviceNumTracks(AuServerDevice(server, i)) == *channels) {
      device = AuDeviceIdentifier(AuServerDevice(server, i));
      break;
    }
  }

  if (device == AuNone) {
    /* try a device with a different number of channels */

    for (i = 0; i < AuServerNumDevices(server); ++i) {
      if (AuDeviceKind(AuServerDevice(server, i)) ==
	  AuComponentKindPhysicalOutput &&
	  AuDeviceNumTracks(AuServerDevice(server, i)) >= 1 &&
	  AuDeviceNumTracks(AuServerDevice(server, i)) <= 2) {
	device    = AuDeviceIdentifier(AuServerDevice(server, i));
	*channels = AuDeviceNumTracks(AuServerDevice(server, i));
	break;
      }
    }
  }

  return device;
}
예제 #3
0
static AuDeviceID
find_device(_THIS)
{
    /* These "Au" things are all macros, not functions... */
    struct SDL_PrivateAudioData *h = this->hidden;
    const unsigned int devicekind = this->iscapture ? AuComponentKindPhysicalInput : AuComponentKindPhysicalOutput;
    const int numdevs = AuServerNumDevices(h->aud);
    const int nch = this->spec.channels;
    int i;

    /* Try to find exact match on channels first... */
    for (i = 0; i < numdevs; i++) {
        const AuDeviceAttributes *dev = AuServerDevice(h->aud, i);
        if ((AuDeviceKind(dev) == devicekind) && (AuDeviceNumTracks(dev) == nch)) {
            return AuDeviceIdentifier(dev);
        }
    }

    /* Take anything, then... */
    for (i = 0; i < numdevs; i++) {
        const AuDeviceAttributes *dev = AuServerDevice(h->aud, i);
        if (AuDeviceKind(dev) == devicekind) {
            this->spec.channels = AuDeviceNumTracks(dev);
            return AuDeviceIdentifier(dev);
        }
    }
    return AuNone;
}
예제 #4
0
파일: SDL_nasaudio.c 프로젝트: bohwaz/ozex
static AuDeviceID
find_device(_THIS, int nch)
{
	int i;
	for (i = 0; i < AuServerNumDevices(this->hidden->aud); i++) {
		if ((AuDeviceKind(AuServerDevice(this->hidden->aud, i)) ==
				AuComponentKindPhysicalOutput) &&
			AuDeviceNumTracks(AuServerDevice(this->hidden->aud, i)) == nch) {
			return AuDeviceIdentifier(AuServerDevice(this->hidden->aud, i));
		}
	}
	return AuNone;
}
예제 #5
0
static AuDeviceID
nas_find_device(AuServer *aud, int channels)
{
	int i;
	for (i = 0; i < AuServerNumDevices(aud); i++) {
		AuDeviceAttributes *dev = AuServerDevice(aud, i);
		if ((AuDeviceKind(dev) == AuComponentKindPhysicalOutput) &&
		     AuDeviceNumTracks(dev) == channels) {
			return AuDeviceIdentifier(dev);
		}
	}
	return AuNone;
}
예제 #6
0
static AuDeviceID
find_device(_THIS, int nch)
{
    /* These "Au" things are all macros, not functions... */
	int i;
	for (i = 0; i < AuServerNumDevices(this->hidden->aud); i++) {
		if ((AuDeviceKind(AuServerDevice(this->hidden->aud, i)) ==
				AuComponentKindPhysicalOutput) &&
			AuDeviceNumTracks(AuServerDevice(this->hidden->aud, i)) == nch) {
			return AuDeviceIdentifier(AuServerDevice(this->hidden->aud, i));
		}
	}
	return AuNone;
}
예제 #7
0
static int nas_finddev(WINE_WAVEOUT* wwo) {
   int i;

    for (i = 0; i < AuServerNumDevices(wwo->AuServ); i++) {
        if ((AuDeviceKind(AuServerDevice(wwo->AuServ, i)) ==
             AuComponentKindPhysicalOutput) &&
             AuDeviceNumTracks(AuServerDevice(wwo->AuServ, i)) == wwo->format.wf.nChannels)
        {
            wwo->AuDev = AuDeviceIdentifier(AuServerDevice(wwo->AuServ, i));
            break;
        }
    }

    if (wwo->AuDev == AuNone)
       return 0;
    return 1;
}
예제 #8
0
static AuDeviceID
NAS_getDevice (AuServer * aud, int numTracks)
{
    int i;

    for (i = 0; i < AuServerNumDevices (aud); i++) {
        if ((AuDeviceKind (AuServerDevice (aud, i))
                == AuComponentKindPhysicalOutput) &&
                (AuDeviceNumTracks (AuServerDevice (aud, i)) == numTracks)) {

            return AuDeviceIdentifier (AuServerDevice (aud, i));

        }
    }

    return AuNone;
}
예제 #9
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);
}
예제 #10
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;
}
예제 #11
0
파일: nas.c 프로젝트: dirker/mpg123
/* 0 on error */
static int nas_createFlow(out123_handle *ao)
{
    AuDeviceID      device = AuNone;
    AuElement       elements[2];
    unsigned char   format;
    AuUint32        buf_samples;
    int             i;
 

    switch(ao->format) {
    case MPG123_ENC_SIGNED_16:
    default:
		if (((char) *(short *)"x")=='x') /* ugly, but painless */
			format = AuFormatLinearSigned16LSB; /* little endian */
		else
		format = AuFormatLinearSigned16MSB; /* big endian */
        break;
    case MPG123_ENC_UNSIGNED_8:
        format = AuFormatLinearUnsigned8;
        break;
    case MPG123_ENC_SIGNED_8:
        format = AuFormatLinearSigned8;
        break;
    case MPG123_ENC_ULAW_8:
        format = AuFormatULAW8;
        break;
    }
    /* look for an output device */
    for (i = 0; i < AuServerNumDevices(info.aud); i++)
       if (((AuDeviceKind(AuServerDevice(info.aud, i)) ==
              AuComponentKindPhysicalOutput) &&
             AuDeviceNumTracks(AuServerDevice(info.aud, i))
             ==  ao->channels )) {
            device = AuDeviceIdentifier(AuServerDevice(info.aud, i));
            break;
       }
    if (device == AuNone) {
       error1("Couldn't find an output device providing %d channels.", ao->channels);
       return 0;
    }

    /* set gain */
    if(ao->gain >= 0) {
        info.da = AuGetDeviceAttributes(info.aud, device, NULL);
        if ((info.da)!=NULL) {
            AuDeviceGain(info.da) = AuFixedPointFromSum(ao->gain, 0);
            AuSetDeviceAttributes(info.aud, AuDeviceIdentifier(info.da),
                                  AuCompDeviceGainMask, info.da, NULL);
        }
        else
            error("audio/gain: setable Volume/PCM-Level not supported");
    }
    
    if (!(info.flow = AuCreateFlow(info.aud, NULL))) {
        error("Couldn't create flow");
        return 0;
    }

    buf_samples = ao->rate * NAS_SOUND_PORT_DURATION;

    AuMakeElementImportClient(&elements[0],        /* element */
                              (unsigned short) ao->rate,
                                                   /* rate */
                              format,              /* format */
                              ao->channels,        /* channels */
                              AuTrue,              /* ??? */
                              buf_samples,         /* max samples */
                              (AuUint32) (buf_samples / 100
                                  * NAS_SOUND_LOW_WATER_MARK),
                                                   /* low water mark */
                              0,                   /* num actions */
                              NULL);               /* actions */
    AuMakeElementExportDevice(&elements[1],        /* element */
                              0,                   /* input */
                              device,              /* device */
                              (unsigned short) ao->rate,
                                                   /* rate */
                              AuUnlimitedSamples,  /* num samples */
                              0,                   /* num actions */
                              NULL);               /* actions */
    AuSetElements(info.aud,                        /* Au server */
                  info.flow,                       /* flow ID */
                  AuTrue,                          /* clocked */
                  2,                               /* num elements */
                  elements,                        /* elements */
                  NULL);                           /* return status */

    AuRegisterEventHandler(info.aud,               /* Au server */
                           AuEventHandlerIDMask,   /* value mask */
                           0,                      /* type */
                           info.flow,              /* id */
                           nas_eventHandler,       /* callback */
                           (AuPointer) &info);     /* data */

    info.buf_size = buf_samples * ao->channels * AuSizeofFormat(format);
    info.buf = (char *) malloc(info.buf_size);
    if (info.buf == NULL) {
        error1("Unable to allocate input/output buffer of size %ld",
             (long)info.buf_size);
        return 0;
    }
    info.buf_cnt = 0;
    info.data_sent = AuFalse;
    info.finished = AuFalse;
    
    AuStartFlow(info.aud,                          /* Au server */
                info.flow,                         /* id */
                NULL);                             /* status */
    return 1; /* success */
}