Ejemplo n.º 1
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;
}
Ejemplo n.º 2
0
/** 
 * Device initialization: check device capability and open for recording.
 * 
 * @param sfreq [in] required sampling frequency.
 * @param dummy [in] a dummy data
 * 
 * @return TRUE on success, FALSE on failure.
 */
boolean
adin_mic_standby(int sfreq, void *dummy)
{
  long rate;
  long prec = AL_SAMPLE_16;
  long encd = AL_SAMPFMT_TWOSCOMP;
  long chan = AL_MONO;

  /* global setup */
  rate = sfreq;
  if (adin_o2_setup_global((double)rate) == FALSE) { /* failed */
    jlog("Error: adin_o2: cannot setup microphone device (global)\n");
    return(FALSE);
  }

  /* local parameter setup */
  if ((ac = ALnewconfig()) == 0) {
    jlog("Error: adin_o2: cannot config microphone device (local)\n");
    return(FALSE);
  }
  ALsetqueuesize(ac, rate * 2 * 1); /* 2 sec. of mono. */
  ALsetwidth(ac, prec);
  ALsetchannels(ac, chan);
  ALsetsampfmt(ac, encd);

  jlog("Stat: adin_o2: local microphone port successfully initialized\n");
  return(TRUE);
}
Ejemplo n.º 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;
}
Ejemplo n.º 4
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;
}
Ejemplo n.º 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;
}
Ejemplo n.º 6
0
FileDescriptor InitAudio(ALport *alpp) {
	/* initialize audio driver 
 	   for 16-bit 44100kHz monophonic sample source to DACs */
	ALconfig alc; 
 	alc = ALnewconfig();
	ALsetwidth (alc, AL_SAMPLE_16);
	ALsetqueuesize (alc, OUTPUTQUEUESIZE);
	ALsetchannels(alc, (long)1);
	*alpp = ALopenport("obuf", "w", alc);
	{
         	long pvbuf[2];
		long pvlen=2;
  	 	 
		pvbuf[0] = AL_OUTPUT_RATE;
		pvbuf[1] = AL_RATE_44100; 
		ALsetparams(AL_DEFAULT_DEVICE, pvbuf, pvlen);
		the_sample_rate = 44100.0f;
	}

	/* obtain a file descriptor associated with sound output port */
	return ALgetfd(*alpp);
}
Ejemplo n.º 7
0
int esd_audio_open()
{
    ALconfig audioconfig;
    audioconfig = ALnewconfig();
  
	rate_params[1] = esd_audio_rate;
	rate_params[3] = esd_audio_rate;

    if (!audioconfig) {
	printf( "Couldn't initialize new audio config\n" );
	esd_audio_fd = -1;
	return esd_audio_fd;
    } else {
	long pvbuf[] = { AL_OUTPUT_COUNT, 0, 
			 AL_MONITOR_CTL, 0, 
			 AL_OUTPUT_RATE, 0 };
    
	if (ALgetparams(AL_DEFAULT_DEVICE, pvbuf, 6) < 0)
	    if (oserror() == AL_BAD_DEVICE_ACCESS) {
		esd_audio_fd = -1;
		return esd_audio_fd;
	    }
    
	if (pvbuf[1] == 0 && pvbuf[3] == AL_MONITOR_OFF) {
	    ALsetparams(AL_DEFAULT_DEVICE, rate_params, 2);
	} else
	    if (pvbuf[5] != esd_audio_rate) {
		printf("audio device is already in use with wrong sample output rate\n");
		esd_audio_fd = -1;
		return esd_audio_fd;
	
	    }
    
	/* ALsetsampfmt(audioconfig, AL_SAMPFMT_TWOSCOMP); this is the default */
	/* ALsetwidth(audioconfig, AL_SAMPLE_16); this is the default */
    
	if ( (esd_audio_format & ESD_MASK_CHAN) == ESD_MONO)
	    ALsetchannels(audioconfig, AL_MONO);
	/* else ALsetchannels(audioconfig, AL_STEREO); this is the default */

	ALsetqueuesize(audioconfig, ESD_BUF_SIZE * 2);
    
	outaudioport = ALopenport("esd", "w", audioconfig);
	if (outaudioport == (ALport) 0) {
	    switch (oserror()) {
	    case AL_BAD_NO_PORTS:
		printf( "system is out of ports\n");
		esd_audio_fd = -1;
		return esd_audio_fd;
		break;
	
	    case AL_BAD_DEVICE_ACCESS:
		printf("couldn't access audio device\n");
		esd_audio_fd = -1;
		return esd_audio_fd;
		break;
	
	    case AL_BAD_OUT_OF_MEM:
		printf("out of memory\n");
		esd_audio_fd = -1;
		return esd_audio_fd;
		break;
	    }
	    /* don't know how we got here, but it must be bad */
	    esd_audio_fd = -1;
	    return esd_audio_fd;
	}
	ALsetfillpoint(outaudioport, ESD_BUF_SIZE);

	esd_audio_fd = ALgetfd(outaudioport);

	/*
	 * If we are recording, open a second port to read from
	 * and return that fd instead
	 */
	if ( (esd_audio_format & ESD_MASK_FUNC) == ESD_RECORD ) {
	    inaudioport = ALopenport("esd", "r", audioconfig);
	    if (inaudioport == (ALport) 0) {
		switch (oserror()) {
		case AL_BAD_NO_PORTS:
		    printf( "system is out of ports\n");
		    esd_audio_fd = -1;
		    return esd_audio_fd;
		    break;
	
		case AL_BAD_DEVICE_ACCESS:
		    printf("couldn't access audio device\n");
		    esd_audio_fd = -1;
		    return esd_audio_fd;
		    break;
	
		case AL_BAD_OUT_OF_MEM:
		    printf("out of memory\n");
		    esd_audio_fd = -1;
		    return esd_audio_fd;
		    break;
		default:
		    printf( "Unknown error opening port\n" );
		}
				/* don't know how we got here, but it must be bad */
		esd_audio_fd = -1;
		return esd_audio_fd;
	    }
	    ALsetfillpoint(inaudioport, ESD_BUF_SIZE);
	    ALsetparams(AL_DEFAULT_DEVICE, (rate_params + 2), 2);

	    esd_audio_fd = ALgetfd(inaudioport);
	}

    }
    return esd_audio_fd;
}
Ejemplo n.º 8
0
main() 
{
  LS_DATA ls_data;
  FILE *fp;
  double gains[MAX_CHANNELS];
  int azimuth=-10;
  int elevation=14;
  double *gainptr,  gain;
  short *inptr,*outptr;
  short out[BUFFER_LENGTH][MAX_CHANNELS];
  ALconfig c;
  AFfilehandle fh;
  ALport p;

  short *in;
  long frames;

  int i,j,k;
  int numchannels = 8; /* change this according your output device*/
  int ls_set_dim = 3;
  int ls_num = 8;
  int ls_dirs[MAX_FIELD_AM]={-30,0,  30,0, -45,45,  45,45,  -90,0, 
			     90,0,  180,0,  180,45};
  /* change these according to your loudspeaker positioning*/
  

  /* defining loudspeaker data */
  define_loudspeakers(&ls_data, ls_set_dim, ls_num, ls_dirs);
     /* ls_data is a struct containing matrices etc
     ls_set_dim  is 2 if loudspeakers are on a (horizontal) plane
     ls_set_dim  is 3 if also elevated or descended loudpeakers exist
     ls_num is the number of loudspeakers
     ls_dirs is an array containing the angular directions of loudsp*/

  
  /* gain factors for virtual source in direction
     (int azimuth, int elevation) */
  vbap(gains, &ls_data, azimuth, elevation);  
     /* panning monophonic stream  float *in 
     to multiple outputs           float *out[]
     with gain factors             float *gains  */
  

  /* input audio*/
  if((fh=afOpenFile("myaiff.aiff","r",0))==NULL){
    fprintf(stderr, "Could not open file myaiff.aiff\n");
    exit(-1);
  }
  frames=AFgetframecnt(fh,AF_DEFAULT_TRACK);
  if(afGetChannels(fh, AF_DEFAULT_TRACK) != 1){
    fprintf(stderr, "Supports only mono aiff-files\n");
    exit(-1);
  }
  in= malloc(frames*sizeof(short)*2);
  afReadFrames(fh,AF_DEFAULT_TRACK,in,frames);


  /*opening the audio port*/
  c = alNewConfig();
  if (!c) {
    printf("Couldn't create ALconfig:%s\n", alGetErrorString(oserror()));
    exit(-1);
  }
  alSetChannels(c,numchannels);
  ALsetqueuesize(c,BUFFER_LENGTH);
  p = alOpenPort("alVBAP example","w",c);
  if (!p) {
    printf("port open failed:%s\n", alGetErrorString(oserror()));
    exit(-1);
  }
  


  fprintf(stderr,"\nPanning audio");
  for(j=0;j<(frames/BUFFER_LENGTH);j++){
    inptr = &(in[j*BUFFER_LENGTH]); /* audio to be panned  */
    outptr= out[0];         

    for (i=0; i<BUFFER_LENGTH; i++){    /* panning */ 
      gainptr=gains;
      for (k=0; k<numchannels; k++){
	*outptr++ = (short) ((double) *inptr * *gainptr++); 
      }
      inptr++;
    }
    alWriteFrames(p, out, BUFFER_LENGTH); /* write frames */
    fprintf(stderr,".");
  }

  /*write rest samples out*/

  inptr = &(in[j*BUFFER_LENGTH]); /* partial buffer  */
  outptr= out[0];
  for (i=0; i<(frames-BUFFER_LENGTH*j); i++){    /* panning */ 
    gainptr=gains;
    for (k=0; k<numchannels; k++){
      *outptr++ = (short) ((double) *inptr * *gainptr++); 
    }
    inptr++;
  }
  for (;i<BUFFER_LENGTH; i++){    /* zeros  */ 
    for (k=0; k<numchannels; k++){
      *outptr++ = 0; 
    }
  }

  alWriteFrames(p, out, BUFFER_LENGTH); /* write frames */
  fprintf(stderr,".");

  printf("\n\nDone!\n\n");
}
Ejemplo n.º 9
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;
}
Ejemplo n.º 10
0
static int setaudio(struct xmp_options *o)
{
	int bsize = 32 * 1024;
	ALconfig config;
	long pvbuffer[2];
	char *token, **parm;
	int i;

	parm_init();
	chkparm1("buffer", bsize = strtoul(token, NULL, 0));
	parm_end();

	if ((config = ALnewconfig()) == 0)
		return XMP_ERR_DINIT;

	/*
	 * Set sampling rate
	 */

	pvbuffer[0] = AL_OUTPUT_RATE;

#if 0				/* DOESN'T WORK */
	for (i = 0; srate[i]; i++) {
		if (srate[i] <= o->freq)
			pvbuffer[1] = o->freq = srate[i];
	}
#endif				/* DOESN'T WORK */

	/*
	 * This was flawed as far as I can tell - it just progressively lowered
	 * the sample rate to the lowest possible!
	 * 
	 * o->freq = 44100
	 *
	 * i = 0 / if (48000 <= 44100)
	 * i = 1 / if (44100 <= 44100)
	 *     then pvbuffer[1] = o->freq = 44100
	 * i = 2 / if (32000 <= 44100)
	 *     then pvbuffer[1] = o->freq = 32000
	 * i = 3 / if (22050 <= 32000)
	 *     then pvbuffer[1] = o->freq = 22050
	 * etc...
	 *
	 * Below is my attempt to write a new one.  It picks the next highest
	 * rate available up to the maximum.  This seems a lot more reasonable.
	 *
	 * - 19990706 bdowning
	 */

	for (i = 0; srate[i]; i++) ;	/* find the end of the array */

	while (i-- > 0) {
		if (srate[i] >= o->freq) {
			pvbuffer[1] = o->freq = srate[i];
			break;
		}
	}

	if (i == 0)
		pvbuffer[1] = o->freq = srate[0];	/* 48 kHz. Wow! */

	if (ALsetparams(AL_DEFAULT_DEVICE, pvbuffer, 2) < 0)
		return XMP_ERR_DINIT;

	/*
	 * Set sample format to signed integer
	 */

	if (ALsetsampfmt(config, AL_SAMPFMT_TWOSCOMP) < 0)
		return XMP_ERR_DINIT;

	/*
	 * Set sample width; 24 bit samples are not currently supported by xmp
	 */

	if (o->resol > 8) {
		if (ALsetwidth(config, AL_SAMPLE_16) < 0) {
			if (ALsetwidth(config, AL_SAMPLE_8) < 0)
				return XMP_ERR_DINIT;
			o->resol = 8;
		} else
			al_sample_16 = 1;
	} else {
		if (ALsetwidth(config, AL_SAMPLE_8) < 0) {
			if (ALsetwidth(config, AL_SAMPLE_16) < 0)
				return XMP_ERR_DINIT;
			o->resol = 16;
		} else
			al_sample_16 = 0;
	}

	/*
	 * Set number of channels; 4 channel output is not currently supported
	 */

	if (o->outfmt & XMP_FMT_MONO) {
		if (ALsetchannels(config, AL_MONO) < 0) {
			if (ALsetchannels(config, AL_STEREO) < 0)
				return XMP_ERR_DINIT;
			o->outfmt &= ~XMP_FMT_MONO;
		}
	} else {
		if (ALsetchannels(config, AL_STEREO) < 0) {
			if (ALsetchannels(config, AL_MONO) < 0)
				return XMP_ERR_DINIT;
			o->outfmt |= XMP_FMT_MONO;
		}
	}

	/*
	 * Set buffer size
	 */

	if (ALsetqueuesize(config, bsize) < 0)
		return XMP_ERR_DINIT;

	/*
	 * Open the audio port
	 */

	if ((audio_port = ALopenport("xmp", "w", config)) == 0)
		return XMP_ERR_DINIT;

	return 0;
}
Ejemplo n.º 11
0
Error SoundCardPMO::Init(OutputInfo * info)
{
   ALconfig config = ALnewconfig();
   long pvbuffer[2];

   m_properlyInitialized = false;

   if (!info)
   {
      info = myInfo;
   }
   else
   {
      m_iDataSize = info->max_buffer_size;
   }

   pvbuffer[0] = AL_OUTPUT_RATE;
   pvbuffer[1] = info->samples_per_second;

   if (ALsetparams(AL_DEFAULT_DEVICE, pvbuffer, 2) < 0)
   {
      ReportError("Cannot set the soundcard's sampling speed.");
      return (Error) pmoError_IOCTL_SNDCTL_DSP_SPEED;
   }

   int ret = -1;
   if (info->bits_per_sample > 8)
       ret = ALsetwidth(config, AL_SAMPLE_16);
   else
       ret = ALsetwidth(config, AL_SAMPLE_8);

   if (ret < 0)
   {
      ReportError("The soundcard does not support 16 bit sample size.");
      return (Error) pmoError_IOCTL_SNDCTL_DSP_SAMPLESIZE;
   }

   ret = -1;
   if (info->number_of_channels == 2)
       ret = ALsetchannels(config, AL_STEREO);
   else
       ret = ALsetchannels(config, AL_MONO);
   if (ret < 0)
   {
      ReportError("Cannot set the soundcard to stereo.");
      return (Error) pmoError_IOCTL_SNDCTL_DSP_STEREO;
   }

   ALsetqueuesize(config, m_iDataSize);

   outaudioport = ALopenport("freeamp", "w", config);

   if (outaudioport == (ALport)0)
   {
       ReportError("Couldn't open port.");
       return (Error) pmoError_IOCTL_SNDCTL_DSP_STEREO;
   }

   audio_fd = ALgetfd(outaudioport);

   channels = info->number_of_channels;

   // configure the device:
   int       play_precision = info->bits_per_sample;
   int       play_stereo = channels - 1;
   int       play_sample_rate = info->samples_per_second;

   memcpy(myInfo, info, sizeof(OutputInfo));
   m_properlyInitialized = true;

   // PORTING: The GETOSPACE ioctl determines how much space the kernel's
   // output buffer has. Your OS may not have this.

   m_iTotalFragments = 2048; /* arbitrary blah */
   m_iOutputBufferSize = play_precision * m_iTotalFragments;
   m_iBytesPerSample = info->number_of_channels * (info->bits_per_sample / 8);

   return kError_NoErr;
}
Ejemplo n.º 12
0
static BOOL SGI_Init(void)
{
	long chpars[] = { AL_OUTPUT_RATE, AL_RATE_22050 };

	switch(md_mixfreq) {
		case 8000:
			chpars[1] = AL_RATE_8000;
			break;
		case 11025:
			chpars[1] = AL_RATE_11025;
			break;
		case 16000:
			chpars[1] = AL_RATE_16000;
			break;
		case 22050:
			chpars[1] = AL_RATE_22050;
			break;
		case 32000:
			chpars[1] = AL_RATE_32000;
			break;
		case 44100:
			chpars[1] = AL_RATE_44100;
			break;
		case 48000:
			chpars[1] = AL_RATE_48000;
			break;
		default:
			_mm_errno=MMERR_SGI_SPEED;
			return 1;
	}
	ALseterrorhandler(0);
	ALsetparams(AL_DEFAULT_DEVICE, chpars, 2);

	if (!(sgi_config=ALnewconfig())) {
		_mm_errno=MMERR_OPENING_AUDIO;
		return 1;
	}
	
	if (md_mode&DMODE_16BITS) {
		if (ALsetwidth(sgi_config,AL_SAMPLE_16)<0) {
			_mm_errno=MMERR_SGI_16BIT;
			return 1;
		}
		sample_factor = 1;
	} else {
		if (ALsetwidth(sgi_config,AL_SAMPLE_8)<0) {
			_mm_errno=MMERR_SGI_8BIT;
			return 1;
		}
		sample_factor = 0;
	}

	if (md_mode&DMODE_STEREO) {
		if (ALsetchannels(sgi_config,AL_STEREO)<0) {
			_mm_errno=MMERR_SGI_STEREO;
			return 1;
		}
	} else {
		if (ALsetchannels(sgi_config,AL_MONO)<0) {
			_mm_errno=MMERR_SGI_MONO;
			return 1;
		}
	}

	if ((getenv("MM_SGI_FRAGSIZE"))&&(sgi_fragsize!=DEFAULT_SGI_FRAGSIZE))
		sgi_fragsize=atol(getenv("MM_SGI_FRAGSIZE"));
	if (!sgi_fragsize) sgi_fragsize=DEFAULT_SGI_FRAGSIZE;
	if ((getenv("MM_SGI_BUFSIZE"))&&(sgi_bufsize!=DEFAULT_SGI_BUFSIZE))
		sgi_bufsize=atol(getenv("MM_SGI_BUFSIZE"));
	if (!sgi_bufsize) sgi_fragsize=DEFAULT_SGI_BUFSIZE;

	ALsetqueuesize(sgi_config, sgi_bufsize);
	if (!(sgi_port=ALopenport("libmikmod","w",sgi_config))) {
		_mm_errno=MMERR_OPENING_AUDIO;
		return 1;
	}

	if(!(audiobuffer=(SBYTE*)_mm_malloc(sgi_fragsize))) return 1;
	
	return VC_Init();
}
Ejemplo n.º 13
0
int
sgi_audio_open(audio_desc_t ad, audio_format* ifmt, audio_format *ofmt)
{
	ALconfig	c;
	long		cmd[8];

        if (audio_fd != -1) {
                sgi_audio_close(ad);
        }

        if (ifmt->encoding != DEV_S16) return FALSE;

	if ((c = ALnewconfig()) == NULL) {
		fprintf(stderr, "ALnewconfig error\n");
		exit(1);
	}

        switch(ifmt->channels) {
        case 1:
                ALsetchannels(c, AL_MONO); break;
        case 2:
                ALsetchannels(c, AL_STEREO); break;
        default:
                sgi_audio_close(ad);
        }

	ALsetwidth(c, AL_SAMPLE_16);
	ALsetqueuesize(c, QSIZE);
	ALsetsampfmt(c, AL_SAMPFMT_TWOSCOMP);

	if ((wp = ALopenport("RAT write", "w", c)) == NULL) {
		fprintf(stderr, "ALopenport (write) error\n");
                sgi_audio_close(ad);
                return FALSE;
        }

	if ((rp = ALopenport("RAT read", "r", c)) == NULL) {
		fprintf(stderr, "ALopenport (read) error\n");
                sgi_audio_close(ad);
                return FALSE;
        }

	cmd[0] = AL_OUTPUT_RATE;
	cmd[1] = ofmt->sample_rate;
	cmd[2] = AL_INPUT_RATE;
	cmd[3] = ifmt->sample_rate;
	cmd[4] = AL_MONITOR_CTL;
	cmd[5] = AL_MONITOR_OFF;
	/*cmd[6] = AL_INPUT_SOURCE;*/
	/*cmd[7] = AL_INPUT_MIC;*/

	if (ALsetparams(AL_DEFAULT_DEVICE, cmd, 6L/*was 8L*/) == -1) {
		fprintf(stderr, "audio_open/ALsetparams error\n");
                sgi_audio_close(ad);
        }

	/* Get the file descriptor to use in select */
	audio_fd = ALgetfd(rp);

	if (ALsetfillpoint(rp, ifmt->bytes_per_block) < 0) {
                debug_msg("ALsetfillpoint failed (%d samples)\n", ifmt->bytes_per_block);
        }
        bytes_per_block = ifmt->bytes_per_block;
        
	/* We probably should free the config here... */
        
	return TRUE;
}