Пример #1
0
int sound_init()
{
  long pvbuf[2];
  pvbuf[0] = AL_OUTPUT_COUNT;
  pvbuf[2] = AL_MONITOR_CTL;
  if (ALgetparams(AL_DEFAULT_DEVICE, pvbuf, 4) < 0) 
  {    
    fprintf(stderr,"sound driver : No audio hardware\n");
    return 0;
  }
  pvbuf[0] = AL_OUTPUT_RATE;
  pvbuf[1] = 11025;
  if (ALsetparams(AL_DEFAULT_DEVICE,pvbuf,4) < 0)
  {    
    fprintf(stderr,"sound driver : Could not set sample rate\n");
    return 0;
  }

  ALseterrorhandler(0);
  audioconfig = ALnewconfig();
  if (!audioconfig)
  {
    fprintf(stderr,"failed to create audio config\n");
    return 0;
  }
  else if (ALsetchannels(audioconfig,AL_MONO))
  { fprintf(stderr,"sound driver : could not set audio channels\n");
    return 0;
  }
  else if (ALsetqueuesize(audioconfig,BUF_SIZE))
  { 
    fprintf(stderr,"sound driver : could not set audio que size\n");
    ALfreeconfig(audioconfig);
    return 0;
  } else if (ALsetwidth (audioconfig, AL_SAMPLE_8))
  {
    fprintf(stderr,"sound driver :could not set 8 bit samples\n");
    ALfreeconfig(audioconfig);
    return 0;
  }

  audioport=ALopenport("Abuse sound driver","w",audioconfig);
  if (!audioport)
  {
    fprintf(stderr,"sound driver : could not open audio port\n");
    ALfreeconfig(audioconfig);
    return 0;
  }

  int i=0,j;
  uchar *vd=volume_table;
  for (;i<32;i++) 
  {
    for (j=0;j<256;j++,vd++)
      *vd=(j-128)*i/31+128;
  }
  return 1;
}
Пример #2
0
/*
 * Open and initialize an audio port.
 */
static ALport sfxInitAudioPort(int init) {
	ALport ap;
	ALconfig audioPortConfig;
	long pvbuf[6];

	if (init) {
		pvbuf[0] = AL_LEFT_SPEAKER_GAIN;
		pvbuf[2] = AL_RIGHT_SPEAKER_GAIN;
		pvbuf[4] = AL_OUTPUT_RATE;
		ALgetparams(AL_DEFAULT_DEVICE, pvbuf, 6L);
		currLeftGain = origLeftGain = pvbuf[1];
		currRightGain = origRightGain = pvbuf[3];
		origOutputRate = pvbuf[5];
		sfxSetGainIndex((origLeftGain+origRightGain)/2);
	}

	/*
	 * Configure and open audio port.
	 */
	audioPortConfig = ALnewconfig();
	ALsetwidth(audioPortConfig, AL_SAMPLE_16);
	ALsetchannels(audioPortConfig, AL_STEREO);
	ALsetqueuesize(audioPortConfig, 16000);
	ap = ALopenport("spacetrek", "w", audioPortConfig);
	ALfreeconfig(audioPortConfig);

	return ap;
}
Пример #3
0
static int
open_audio_port (AudioContext return_ac, AudioContext desc)
{
  ALconfig config = ALnewconfig();
  long params[2];

  adjust_audio_volume (& desc->device);
  return_ac->ac_left_speaker_gain = desc->ac_left_speaker_gain;
  return_ac->ac_right_speaker_gain = desc->ac_right_speaker_gain;
  params[0] = AL_OUTPUT_RATE;
  params[1] = desc->ac_output_rate;
  ALsetparams (desc->ac_device, params, 2);
  return_ac->ac_output_rate = desc->ac_output_rate;
  if (set_channels (config, desc->ac_nchan)==-1)
    return -1;
  return_ac->ac_nchan = desc->ac_nchan;
  if (set_output_format (config, desc->ac_format)==-1)
    return -1;
  return_ac->ac_format = desc->ac_format;
  ALsetqueuesize (config, (long) CHUNKSIZE);
  return_ac->ac_port = ALopenport("XEmacs audio output", "w", config);
  ALfreeconfig (config);
  if (return_ac->ac_port==0)
    {
      report_file_error ("Opening audio output port", Qnil);
      return -1;
    }
  return 0;
}
Пример #4
0
void Audio_Irix::close ()
{
    if (_audio != NULL)
    {
        ALcloseport(_audio);
        ALfreeconfig(_config);
        _audio  = NULL;
        _config = NULL;
        outOfOrder ();
    }
}
Пример #5
0
static int sgi_init(const char *param, int *speed, int *fragsize, int *fragnr, int *channels)
{
    long chpars[] = { AL_OUTPUT_RATE, 0 };
    int st;

    /* No stereo capability. */
    *channels = 1;

    ALseterrorhandler(sgi_errorhandler);
    chpars[1] = *speed;
    st = ALsetparams(AL_DEFAULT_DEVICE, chpars, 2);
    if (st < 0) {
        return 1;
    }
    st = ALgetparams(AL_DEFAULT_DEVICE, chpars, 2);
    if (st < 0) {
        return 1;
    }
    *speed = chpars[1];

    sgi_audioconfig = ALnewconfig();
    if (!sgi_audioconfig) {
        return 1;
    }
    st = ALsetchannels(sgi_audioconfig, AL_MONO);
    if (st < 0) {
        goto fail;
    }
    st = ALsetwidth(sgi_audioconfig, AL_SAMPLE_16);
    if (st < 0) {
        goto fail;
    }
    st = ALsetqueuesize(sgi_audioconfig, *fragsize * *fragnr);
    if (st < 0) {
        goto fail;
    }
    sgi_audioport = ALopenport("outport", "w", sgi_audioconfig);
    if (!sgi_audioport) {
        goto fail;
    }
    return 0;
fail:
    ALfreeconfig(sgi_audioconfig);
    sgi_audioconfig = NULL;
    return 1;
}
Пример #6
0
static void sgi_close(void)
{
    /* XXX: code missing */
    ALfreeconfig(sgi_audioconfig);
    sgi_audioconfig = NULL;
}
Пример #7
0
void sound_uninit()
{
  ALfreeconfig(audioconfig);
  ALcloseport(audioport);
}
Пример #8
0
void *Audio_Irix::open (AudioConfig& cfg, const char *)
{
    // Copy input parameters. May later be replaced with driver defaults.
    _settings = cfg;
    
    _config = ALnewconfig();

    // Set sample format
    ALsetsampfmt(_config, AL_SAMPFMT_TWOSCOMP);

    // stereo or mono mode
    _settings.channels = cfg.channels >= 2 ? 2 : 1;
    if (_settings.channels == 2)
        ALsetchannels(_config, AL_STEREO);
    else
        ALsetchannels(_config, AL_MONO);

    // 16 or 8 bit sample
    _settings.precision = cfg.precision >= 16 ? 16 : 8;
    if (_settings.precision == 16)
        ALsetwidth(_config, AL_SAMPLE_16);
    else
        ALsetwidth(_config, AL_SAMPLE_8);

    // Frequency
    long chpars[] = {AL_OUTPUT_RATE, 0};
    if (cfg.frequency > 48000)
        chpars[1] = AL_RATE_48000;
    else if (cfg.frequency > 44100)
        chpars[1] = AL_RATE_44100;
    else if (cfg.frequency > 32000)
        chpars[1] = AL_RATE_32000;
    else if (cfg.frequency > 22050)
        chpars[1] = AL_RATE_22050;
    else if (cfg.frequency > 16000)
        chpars[1] = AL_RATE_16000;
    else
        chpars[1] = AL_RATE_11025;
    ALsetparams(AL_DEFAULT_DEVICE, chpars, 2);
    ALgetparams(AL_DEFAULT_DEVICE, chpars, 2);
    _settings.frequency = (uint_least32_t) chpars[1];

    // Allocate sound buffers and set audio queue
    ALsetqueuesize(_config, chpars[1]);

    // open audio device
    _audio = ALopenport("SIDPLAY2 sound", "w", _config);
    if (_audio == NULL)
    {
        perror("AUDIO:");
        _errorString = "ERROR: Could not open audio device.\n       See standard error output.";
        ALfreeconfig(_config);
        return 0;
    }

    // Setup internal Config
    _settings.encoding  = AUDIO_SIGNED_PCM;
    _settings.bufSize   = (uint_least32_t) chpars[1];

    // Update the users settings
    getConfig (cfg);

    // Allocate memory same size as buffer
#ifdef HAVE_EXCEPTIONS
    _sampleBuffer = new(std::nothrow) int_least8_t[chpars[1]];
#else
    _sampleBuffer = new int_least8_t[chpars[1]];
#endif

    _errorString = "OK";
    return (void *) _sampleBuffer;
}