Exemple #1
0
int audriv_get_play_volume(void)
/* 演奏音量を 0 〜 255 内で得ます.0 は無音,255 は最大音量.
 * 失敗すると -1 を返し,そうでない場合は 0 〜 255 内の音量を返します.
 */
{
#ifndef SGI_OLDAL
    ALfixed lrgain[2];
    ALpv pv;
    double gain, l, r, min, max;
    int volume;
    int resource;

    min = alFixedToDouble(out_ginfo.min.ll);
    max = alFixedToDouble(out_ginfo.max.ll);
    pv.param = AL_GAIN;
    pv.value.ptr = lrgain;
    pv.sizeIn = 2;
    if(out == NULL)
	resource = AL_DEFAULT_OUTPUT;
    else
	resource = alGetResource(out);

    if(alGetParams(resource, &pv, 1) < 0)
    {
	audriv_err(ALERROR);
	return -1;
    }
    l = alFixedToDouble(lrgain[0]);
    r = alFixedToDouble(lrgain[1]);
    if(l < min) l = min; else if(l > max) l = max;
    if(r < min) r = min; else if(r > max) r = max;
    gain = (l + r) / 2;
    volume = (gain - min) * 256 / (max - min);
    if(volume < 0)
	volume = 0;
    else if(volume > 255)
	volume = 255;
    return volume;
#else
    long gain[4];
    int volume;

    gain[0] = AL_LEFT_SPEAKER_GAIN;
    gain[2] = AL_RIGHT_SPEAKER_GAIN;
    if(ALgetparams(AL_DEFAULT_DEVICE, gain, 4) < 0)
    {
	audriv_err(ALERROR);
	return -1;
    }

    volume = (gain[1] + gain[3]) / 2;
    if(volume < 0)
	volume = 0;
    else if(volume > 255)
	volume = 255;
    return volume;
#endif /* SGI_OLDAL */
}
Exemple #2
0
ad_rec_t *ad_open_sps (int32 samples_per_sec)
{
  // fprintf(stderr, "A/D library not implemented\n");
    ad_rec_t *handle;
    ALpv          pv; 
    int device  = AL_DEFAULT_INPUT;
    ALconfig portconfig = alNewConfig(); 
    ALport port; 
    int32 sampleRate;
    long long gainValue = alDoubleToFixed(8.5); 
    
    pv.param = AL_GAIN; 
    pv.sizeIn = 1; 
    pv.value.ptr = &gainValue; 
    
    if (alSetParams(device, &pv, 1)<0) {
      fprintf(stderr, "setparams failed: %s\n",alGetErrorString(oserror()));
      return NULL; 
    }
    

    pv.param = AL_RATE;
    pv.value.ll = alDoubleToFixed(samples_per_sec);
    
    if (alSetParams(device, &pv, 1)<0) {
      fprintf(stderr, "setparams failed: %s\n",alGetErrorString(oserror()));
      return NULL; 
    }
    
    if (pv.sizeOut < 0) {
      /*
       * Not all devices will allow setting of AL_RATE (for example, digital 
       * inputs run only at the frequency of the external device).  Check
       * to see if the rate was accepted.
       */
      fprintf(stderr, "AL_RATE was not accepted on the given resource\n");
      return NULL; 
    }
    
    if (alGetParams(device, &pv, 1)<0) {
        fprintf(stderr, "getparams failed: %s\n",alGetErrorString(oserror()));
     }
    
    sampleRate = (int32)alFixedToDouble(pv.value.ll);
#if 0
    printf("sample rate is set to %d\n", sampleRate);
#endif


    if (alSetChannels(portconfig, 1) < 0) {
      fprintf(stderr, "alSetChannels failed: %s\n",alGetErrorString(oserror()));
      return NULL; 
    }

    port = alOpenPort(" Sphinx-II input port", "r", portconfig); 

    if (!port) {
      fprintf(stderr, "alOpenPort failed: %s\n", alGetErrorString(oserror()));
      return NULL; 
    }
    if ((handle = (ad_rec_t *) calloc (1, sizeof(ad_rec_t))) == NULL) {
      fprintf(stderr, "calloc(%d) failed\n", sizeof(ad_rec_t));
      abort();
    }

    handle->audio = port; 
    handle->recording = 0;
    handle->sps = sampleRate;
    handle->bps = sizeof(int16);

    alFreeConfig(portconfig); 

    return handle;
}
// open & setup audio device
// return: 1=success 0=fail
static int init(int rate, int channels, int format, int flags) {

  int smpwidth, smpfmt;
  int rv = AL_DEFAULT_OUTPUT;

  smpfmt = fmt2sgial(&format, &smpwidth);

  mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_SGI_InitInfo, rate, (channels > 1) ? "Stereo" : "Mono", af_fmt2str_short(format));

  { /* from /usr/share/src/dmedia/audio/setrate.c */

    double frate, realrate;
    ALpv x[2];

    if(ao_subdevice) {
      rv = alGetResourceByName(AL_SYSTEM, ao_subdevice, AL_OUTPUT_DEVICE_TYPE);
      if (!rv) {
	mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_SGI_InvalidDevice);
	return 0;
      }
    }

    frate = rate;

    x[0].param = AL_RATE;
    x[0].value.ll = alDoubleToFixed(rate);
    x[1].param = AL_MASTER_CLOCK;
    x[1].value.i = AL_CRYSTAL_MCLK_TYPE;

    if (alSetParams(rv,x, 2)<0) {
      mp_msg(MSGT_AO, MSGL_WARN, MSGTR_AO_SGI_CantSetParms_Samplerate, alGetErrorString(oserror()));
    }

    if (x[0].sizeOut < 0) {
      mp_msg(MSGT_AO, MSGL_WARN, MSGTR_AO_SGI_CantSetAlRate);
    }

    if (alGetParams(rv,x, 1)<0) {
      mp_msg(MSGT_AO, MSGL_WARN, MSGTR_AO_SGI_CantGetParms, alGetErrorString(oserror()));
    }

    realrate = alFixedToDouble(x[0].value.ll);
    if (frate != realrate) {
      mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_SGI_SampleRateInfo, realrate, frate);
    }
    sample_rate = (int)realrate;
  }

  bytes_per_frame = channels * smpwidth;

  ao_data.samplerate = sample_rate;
  ao_data.channels = channels;
  ao_data.format = format;
  ao_data.bps = sample_rate * bytes_per_frame;
  ao_data.buffersize=131072;
  ao_data.outburst = ao_data.buffersize/16;

  ao_config = alNewConfig();

  if (!ao_config) {
    mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_SGI_InitConfigError, alGetErrorString(oserror()));
    return 0;
  }

  if(alSetChannels(ao_config, channels) < 0 ||
     alSetWidth(ao_config, smpwidth) < 0 ||
     alSetSampFmt(ao_config, smpfmt) < 0 ||
     alSetQueueSize(ao_config, sample_rate) < 0 ||
     alSetDevice(ao_config, rv) < 0) {
    mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_SGI_InitConfigError, alGetErrorString(oserror()));
    return 0;
  }

  ao_port = alOpenPort("mplayer", "w", ao_config);

  if (!ao_port) {
    mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_SGI_InitOpenAudioFailed, alGetErrorString(oserror()));
    return 0;
  }

  // printf("ao_sgi, init: port %d config %d\n", ao_port, ao_config);
  queue_size = alGetQueueSize(ao_config);
  return 1;

}
Exemple #4
0
// open & setup audio device
// return: 1=success 0=fail
static int init(int rate, int channels, int format, int flags) {

  int smpwidth, smpfmt;
  int rv = AL_DEFAULT_OUTPUT;

  smpfmt = fmt2sgial(&format, &smpwidth);

  mp_tmsg(MSGT_AO, MSGL_INFO, "[AO SGI] init: Samplerate: %iHz Channels: %s Format %s\n", rate, (channels > 1) ? "Stereo" : "Mono", af_fmt2str_short(format));

  { /* from /usr/share/src/dmedia/audio/setrate.c */

    double frate, realrate;
    ALpv x[2];

    if(ao_subdevice) {
      rv = alGetResourceByName(AL_SYSTEM, ao_subdevice, AL_OUTPUT_DEVICE_TYPE);
      if (!rv) {
	mp_tmsg(MSGT_AO, MSGL_ERR, "[AO SGI] play: invalid device.\n");
	return 0;
      }
    }

    frate = rate;

    x[0].param = AL_RATE;
    x[0].value.ll = alDoubleToFixed(rate);
    x[1].param = AL_MASTER_CLOCK;
    x[1].value.i = AL_CRYSTAL_MCLK_TYPE;

    if (alSetParams(rv,x, 2)<0) {
      mp_tmsg(MSGT_AO, MSGL_WARN, "[AO SGI] init: setparams failed: %s\nCould not set desired samplerate.\n", alGetErrorString(oserror()));
    }

    if (x[0].sizeOut < 0) {
      mp_tmsg(MSGT_AO, MSGL_WARN, "[AO SGI] init: AL_RATE was not accepted on the given resource.\n");
    }

    if (alGetParams(rv,x, 1)<0) {
      mp_tmsg(MSGT_AO, MSGL_WARN, "[AO SGI] init: getparams failed: %s\n", alGetErrorString(oserror()));
    }

    realrate = alFixedToDouble(x[0].value.ll);
    if (frate != realrate) {
      mp_tmsg(MSGT_AO, MSGL_INFO, "[AO SGI] init: samplerate is now %f (desired rate is %f)\n", realrate, frate);
    }
    sample_rate = (int)realrate;
  }

  bytes_per_frame = channels * smpwidth;

  ao_data.samplerate = sample_rate;
  ao_data.channels = channels;
  ao_data.format = format;
  ao_data.bps = sample_rate * bytes_per_frame;
  ao_data.buffersize=131072;
  ao_data.outburst = ao_data.buffersize/16;

  ao_config = alNewConfig();

  if (!ao_config) {
    mp_tmsg(MSGT_AO, MSGL_ERR, "[AO SGI] init: %s\n", alGetErrorString(oserror()));
    return 0;
  }

  if(alSetChannels(ao_config, channels) < 0 ||
     alSetWidth(ao_config, smpwidth) < 0 ||
     alSetSampFmt(ao_config, smpfmt) < 0 ||
     alSetQueueSize(ao_config, sample_rate) < 0 ||
     alSetDevice(ao_config, rv) < 0) {
    mp_tmsg(MSGT_AO, MSGL_ERR, "[AO SGI] init: %s\n", alGetErrorString(oserror()));
    return 0;
  }

  ao_port = alOpenPort("mplayer", "w", ao_config);

  if (!ao_port) {
    mp_tmsg(MSGT_AO, MSGL_ERR, "[AO SGI] init: Unable to open audio channel: %s\n", alGetErrorString(oserror()));
    return 0;
  }

  // printf("ao_sgi, init: port %d config %d\n", ao_port, ao_config);
  queue_size = alGetQueueSize(ao_config);
  return 1;

}
/*
 * public methods (static but exported through the sysdep_dsp or plugin struct)
 */
static void *
irix_dsp_create(const void *flags)
{
   ALpv pvs[4];
   long tempbits, tempchan;
   int oldrate;
   struct irix_dsp_priv_data *priv = NULL;
   struct sysdep_dsp_struct *dsp = NULL;
   const struct sysdep_dsp_create_params *params = flags;
   ALconfig devAudioConfig;	
   
   /* allocate the dsp struct */
   if (!(dsp = calloc(1, sizeof(struct sysdep_dsp_struct))))
   {
      fprintf(stderr, "Error: malloc failed for struct sysdep_dsp_struct\n"); 
      return NULL;
   }
   
   /* allocate private data */
   if(!(priv = calloc(1, sizeof(struct irix_dsp_priv_data))))
   {
      fprintf(stderr, "Error: malloc failed for struct irix_dsp_priv_data\n");
      free(dsp);
      return NULL;
   }
   
   /* fill in the functions and some data */
   priv->port_status = -1;
   dsp->_priv = priv;
   dsp->get_freespace = irix_dsp_get_freespace;
   dsp->write = irix_dsp_write;
   dsp->destroy = irix_dsp_destroy;
   dsp->hw_info.type = params->type;
   dsp->hw_info.samplerate = params->samplerate;

   tempchan = (dsp->hw_info.type & SYSDEP_DSP_STEREO) ? 2 : 1;
   tempbits = (dsp->hw_info.type & SYSDEP_DSP_16BIT) ? 2 : 1;

#ifdef IRIX_DEBUG
   fprintf(stderr, "Source Format is %dHz, %d bit, %s, with bufsize %f\n",
           dsp->hw_info.samplerate, 
           tempbits * 8, (tempchan == 2) ? "stereo" : "mono",
           params->bufsize);
#endif

   /*
    * Since AL wants signed data in either case, and 8-bit data from
    * core xmame is unsigned, let the core xmame convert everything
    * to 16-bit signed.
    */
   if (tempbits == 1)
   {
      dsp->hw_info.type |= SYSDEP_DSP_16BIT;
      tempbits = 2;
   }

   /*
    * Get the current hardware sampling rate
    */
   pvs[0].param = AL_RATE;
   if (alGetParams(AL_DEFAULT_OUTPUT, pvs, 1) < 0)
   {
      fprintf(stderr, "alGetParams failed: %s\n", alGetErrorString(oserror()));
      irix_dsp_destroy(dsp);
      return NULL;
   }

   oldrate = pvs[0].value.i;

   /*
    * If requested samplerate is different than current hardware rate,
    * set it.
    */
   if (oldrate != dsp->hw_info.samplerate)
   {
      int audioHardwareRate = oldrate;

      fprintf(stderr, "System sample rate was %dHz, forcing %dHz instead.\n",
              oldrate, dsp->hw_info.samplerate);

      /*
       * If the desired rate is unsupported, most devices (such as RAD) will
       * force the device rate to be as close as possible to the desired rate.
       * Since close isn't going to help us here, we avoid the call entirely,
       * and let core xmame audio convert to our rate.
       */
      if (RateSupported(AL_DEFAULT_OUTPUT, (float) dsp->hw_info.samplerate))
      {
         /* Set desired sample rate */
         pvs[0].param = AL_MASTER_CLOCK;
         pvs[0].value.i = AL_CRYSTAL_MCLK_TYPE;
         pvs[1].param = AL_RATE;
         pvs[1].value.i = dsp->hw_info.samplerate;
         alSetParams(AL_DEFAULT_OUTPUT, pvs, 2);

         /* Get the new sample rate */
         pvs[0].param = AL_RATE;
         if (alGetParams(AL_DEFAULT_OUTPUT, pvs, 1) < 0)
         {
            fprintf(stderr, "alGetParams failed: %s\n",
                    alGetErrorString(oserror()));
            irix_dsp_destroy(dsp);
            return NULL;
         }

         audioHardwareRate = pvs[0].value.i;
      }

      if (audioHardwareRate != dsp->hw_info.samplerate)
      {
         fprintf(stderr, "Requested rate of %dHz is not supported by "
                 "the audio hardware, so forcing\n"
                 "playback at %dHz.\n",
                 dsp->hw_info.samplerate, audioHardwareRate);
         dsp->hw_info.samplerate = audioHardwareRate;
      }
   }

   /* create a config descriptor */
   devAudioConfig = alNewConfig();
   if (devAudioConfig == NULL) {
      fprintf(stderr, "Cannot get a Descriptor. Exiting..\n");
      irix_dsp_destroy(dsp);
      return NULL;
   }

#ifdef FORCEMONO
   dsp->hw_info.type &= ~SYSDEP_DSP_STEREO;
   tempchan = 1;
#endif

   priv->buffer_samples = dsp->hw_info.samplerate * params->bufsize;

   priv->buffer_samples *= tempchan;

   priv->sampwidth = tempbits;
   priv->sampchan = tempchan;

   fprintf(stderr, "Setting sound to %dHz, %d bit, %s\n",
           dsp->hw_info.samplerate,
           tempbits * 8, (tempchan == 2) ? "stereo" : "mono");

   /* source specific audio parameters */
   alSetChannels(devAudioConfig, tempchan);
   alSetQueueSize(devAudioConfig, priv->buffer_samples);
   alSetWidth(devAudioConfig, tempbits);
   alSetSampFmt(devAudioConfig, AL_SAMPFMT_TWOSCOMP);

   /* Open the audio port with the parameters we setup */
   priv->devAudio = alOpenPort("audio_fd", "w", devAudioConfig);
   if (priv->devAudio == NULL)
   {
       fprintf(stderr, "Error: Cannot get an audio channel descriptor.\n");
       irix_dsp_destroy(dsp);
       return NULL;
   }

   alFreeConfig(devAudioConfig);

   /*
    * Since we don't use FD's with AL, we use this to inform us
    * of success
    */
   priv->port_status = 0;

   return dsp;
}
Exemple #6
0
static int open_sgi(audio_output_t *ao)
{
	int current_dev;
	ALport port = NULL;
	ALconfig config = alNewConfig();

	ao->userptr = NULL;

	/* Test for correct completion */
	if(config == 0)
	{
		error1("open_sgi: %s", alGetErrorString(oserror()));
		return -1;
	}

	/* Setup output device to specified device name. If there is no device name
	specified in ao structure, use the default for output */
	if((ao->device) != NULL)
	{
		current_dev = alGetResourceByName(AL_SYSTEM, ao->device, AL_OUTPUT_DEVICE_TYPE);

		debug2("Dev: %s %i", ao->device, current_dev);

		if(!current_dev)
		{
			int i, numOut;
			char devname[32];
			ALpv pv[1];
			ALvalue *alvalues;

			error2("Invalid audio resource: %s (%s)", ao->device, alGetErrorString(oserror()));

			if((numOut= alQueryValues(AL_SYSTEM,AL_DEFAULT_OUTPUT,0,0,0,0))>=0)
			fprintf(stderr, "There are %d output devices on this system.\n", numOut);
			else
			{
				fprintf(stderr, "Can't find output devices. alQueryValues failed: %s\n", alGetErrorString(oserror()));
				goto open_sgi_bad;
			}

			alvalues = malloc(sizeof(ALvalue) * numOut);
			i = alQueryValues(AL_SYSTEM, AL_DEFAULT_OUTPUT, alvalues, numOut, pv, 0);
			if(i == -1)
			error1("alQueryValues: %s", alGetErrorString(oserror()));
			else
			{
				for(i=0; i < numOut; i++)
				{
					pv[0].param = AL_NAME;
					pv[0].value.ptr = devname;
					pv[0].sizeIn = 32;
					alGetParams(alvalues[i].i, pv, 1);

					fprintf(stderr, "%i: %s\n", i, devname);
				}
			}
			free(alvalues);

			goto open_sgi_bad;
		}

		if(alSetDevice(config, current_dev) < 0)
		{
			error1("open: alSetDevice : %s",alGetErrorString(oserror()));
			goto open_sgi_bad;
		}
	} else
	current_dev = AL_DEFAULT_OUTPUT;

	/* Set the device */
	if(alSetDevice(config, current_dev) < 0)
	{
		error1("open_sgi: %s", alGetErrorString(oserror()));
		goto open_sgi_bad;
	}

	/* Set port parameters */

	if(alSetQueueSize(config, 131069) < 0)
	{
		error1("open_sgi: setting audio buffer failed: %s", alGetErrorString(oserror()));
		goto open_sgi_bad;
	}
	
	if(   set_format(ao, config) < 0
	   || set_rate(ao, config) < 0
	   || set_channels(ao, config) < 0 )
	goto open_sgi_bad;
	
	/* Open the audio port */
	port = alOpenPort("mpg123-VSC", "w", config);
	if(port == NULL)
	{
		error1("Unable to open audio channel: %s", alGetErrorString(oserror()));
		goto open_sgi_bad;
	}

	ao->userptr = (void*)port;

	alFreeConfig(config);
	return 1;

open_sgi_bad:
	/* clean up and return error */
	alFreeConfig(config);
	return -1;
}