static int audio_set_format(struct audio_info_struct *ai, ALconfig config) { if (alSetSampFmt(config,AL_SAMPFMT_TWOSCOMP) < 0) fprintf(stderr,"audio_set_format : %s\n",alGetErrorString(oserror())); if (alSetWidth(config,AL_SAMPLE_16) < 0) fprintf(stderr,"audio_set_format : %s\n",alGetErrorString(oserror())); return 0; }
static int set_format(audio_output_t *ao, ALconfig config) { if (alSetSampFmt(config,AL_SAMPFMT_TWOSCOMP) < 0) error1("set_format : %s",alGetErrorString(oserror())); if (alSetWidth(config,AL_SAMPLE_16) < 0) error1("set_format : %s",alGetErrorString(oserror())); return 0; }
RD_BOOL sgi_open(void) { ALparamInfo pinfo; static int warned = 0; #if (defined(IRIX_DEBUG)) fprintf(stderr, "sgi_open: begin\n"); #endif if (!warned && sgi_output_device) { warning("device-options not supported for libao-driver\n"); warned = 1; } if (alGetParamInfo(AL_DEFAULT_OUTPUT, AL_GAIN, &pinfo) < 0) { fprintf(stderr, "sgi_open: alGetParamInfo failed: %s\n", alGetErrorString(oserror())); } min_volume = alFixedToDouble(pinfo.min.ll); max_volume = alFixedToDouble(pinfo.max.ll); volume_range = (max_volume - min_volume); #if (defined(IRIX_DEBUG)) fprintf(stderr, "sgi_open: minvol = %lf, maxvol= %lf, range = %lf.\n", min_volume, max_volume, volume_range); #endif audioconfig = alNewConfig(); if (audioconfig == (ALconfig) 0) { fprintf(stderr, "sgi_open: alNewConfig failed: %s\n", alGetErrorString(oserror())); return False; } output_port = alOpenPort("rdpsnd", "w", 0); if (output_port == (ALport) 0) { fprintf(stderr, "sgi_open: alOpenPort failed: %s\n", alGetErrorString(oserror())); return False; } #if (defined(IRIX_DEBUG)) fprintf(stderr, "sgi_open: returning\n"); #endif return True; }
void wave_out_volume(uint16 left, uint16 right) { double gainleft, gainright; ALpv pv[1]; ALfixed gain[8]; #if (defined(IRIX_DEBUG)) fprintf(stderr, "wave_out_volume: begin\n"); fprintf(stderr, "left='%d', right='%d'\n", left, right); #endif gainleft = (double) left / IRIX_MAX_VOL; gainright = (double) right / IRIX_MAX_VOL; gain[0] = alDoubleToFixed(min_volume + gainleft * volume_range); gain[1] = alDoubleToFixed(min_volume + gainright * volume_range); pv[0].param = AL_GAIN; pv[0].value.ptr = gain; pv[0].sizeIn = 8; if (alSetParams(AL_DEFAULT_OUTPUT, pv, 1) < 0) { fprintf(stderr, "wave_out_volume: alSetParams failed: %s\n", alGetErrorString(oserror())); return; } #if (defined(IRIX_DEBUG)) fprintf(stderr, "wave_out_volume: returning\n"); #endif }
BOOL wave_out_open(void) { ALparamInfo pinfo; #if (defined(IRIX_DEBUG)) fprintf(stderr, "wave_out_open: begin\n"); #endif if (alGetParamInfo(AL_DEFAULT_OUTPUT, AL_GAIN, &pinfo) < 0) { fprintf(stderr, "wave_out_open: alGetParamInfo failed: %s\n", alGetErrorString(oserror())); } min_volume = alFixedToDouble(pinfo.min.ll); max_volume = alFixedToDouble(pinfo.max.ll); volume_range = (max_volume - min_volume); #if (defined(IRIX_DEBUG)) fprintf(stderr, "wave_out_open: minvol = %lf, maxvol= %lf, range = %lf.\n", min_volume, max_volume, volume_range); #endif queue_lo = queue_hi = 0; audioconfig = alNewConfig(); if (audioconfig == (ALconfig) 0) { fprintf(stderr, "wave_out_open: alNewConfig failed: %s\n", alGetErrorString(oserror())); return False; } output_port = alOpenPort("rdpsnd", "w", 0); if (output_port == (ALport) 0) { fprintf(stderr, "wave_out_open: alOpenPort failed: %s\n", alGetErrorString(oserror())); return False; } #if (defined(IRIX_DEBUG)) fprintf(stderr, "wave_out_open: returning\n"); #endif return True; }
static int set_rate(audio_output_t *ao, ALconfig config) { int dev = alGetDevice(config); ALpv params[1]; /* Make sure the device is OK */ if (dev < 0) { error1("set_rate: %s",alGetErrorString(oserror())); return 1; } params[0].param = AL_OUTPUT_RATE; params[0].value.ll = alDoubleToFixed(ao->rate); if (alSetParams(dev, params,1) < 0) error1("set_rate: %s",alGetErrorString(oserror())); return 0; }
static int audio_set_rate(struct audio_info_struct *ai, ALconfig config) { int dev = alGetDevice(config); ALpv params[1]; /* Make sure the device is OK */ if (dev < 0) { fprintf(stderr,"audio_set_rate : %s\n",alGetErrorString(oserror())); return 1; } params[0].param = AL_OUTPUT_RATE; params[0].value.ll = alDoubleToFixed(ai->rate); if (alSetParams(dev, params,1) < 0) fprintf(stderr,"audio_set_rate : %s\n",alGetErrorString(oserror())); return 0; }
static int set_channels(audio_output_t *ao, ALconfig config) { int ret; if(ao->channels == 2) ret = alSetChannels(config, AL_STEREO); else ret = alSetChannels(config, AL_MONO); if (ret < 0) error1("set_channels : %s",alGetErrorString(oserror())); return 0; }
static int audio_set_channels(struct audio_info_struct *ai, ALconfig config) { int ret; if(ai->channels == 2) ret = alSetChannels(config, AL_STEREO); else ret = alSetChannels(config, AL_MONO); if (ret < 0) fprintf(stderr,"audio_set_channels : %s\n",alGetErrorString(oserror())); return 0; }
static int set_format(audio_output_t *ao, ALconfig config) { if(ao->format == MPG123_ENC_FLOAT_32) { if(alSetSampFmt(config, AL_SAMPFMT_FLOAT) < 0) { error1("SetSampFmt: %s", alGetErrorString(oserror())); return -1; } } else { if(alSetSampFmt(config, AL_SAMPFMT_TWOSCOMP) < 0) { error1("SetSampFmt: %s", alGetErrorString(oserror())); return -1; } if(alSetWidth(config, AL_SAMPLE_16) < 0) { error1("SetWidth: %s", alGetErrorString(oserror())); return -1; } } return 0; }
/* Set the sample rate of an audio port. */ void setrate (ALport port, double rate) { int rv; ALpv params; rv = alGetResource(port); params.param = AL_RATE; params.value.ll = alDoubleToFixed(rate); if (alSetParams(rv, ¶ms, 1) < 0) { printf("alSetParams failed: %s\n", alGetErrorString(oserror())); } }
void *OpenPlay(struct FFTSound *fftsound){ struct Sgiplay *sgiplay; sgiplay=malloc(sizeof(struct Sgiplay)); sgiplay->out_c = alNewConfig(); alSetQueueSize(sgiplay->out_c, _I); alSetSampFmt(sgiplay->out_c,AL_SAMPFMT_DOUBLE); alSetChannels(sgiplay->out_c, fftsound->samps_per_frame); sgiplay->out_port = alOpenPort("Ceres Play", "w", sgiplay->out_c); if(!sgiplay->out_port){ printf("Couldn't open output port: %s\n",alGetErrorString(oserror())); free(sgiplay); return NULL; } return sgiplay; }
BOOL wave_out_set_format(WAVEFORMATEX * pwfx) { int channels; int frameSize, channelCount; ALpv params; #if (defined(IRIX_DEBUG)) fprintf(stderr, "wave_out_set_format: init...\n"); #endif g_swapaudio = False; if (pwfx->wBitsPerSample == 8) width = AL_SAMPLE_8; else if (pwfx->wBitsPerSample == 16) { width = AL_SAMPLE_16; /* Do we need to swap the 16bit values? (Are we BigEndian) */ #if (defined(B_ENDIAN)) g_swapaudio = 1; #else g_swapaudio = 0; #endif } /* Limited support to configure an opened audio port in IRIX. The number of channels is a static setting and can not be changed after a port is opened. So if the number of channels remains the same, we can configure other settings; otherwise we have to reopen the audio port, using same config. */ channels = pwfx->nChannels; g_snd_rate = pwfx->nSamplesPerSec; alSetSampFmt(audioconfig, AL_SAMPFMT_TWOSCOMP); alSetWidth(audioconfig, width); if (channels != alGetChannels(audioconfig)) { alClosePort(output_port); alSetChannels(audioconfig, channels); output_port = alOpenPort("rdpsnd", "w", audioconfig); if (output_port == (ALport) 0) { fprintf(stderr, "wave_out_set_format: alOpenPort failed: %s\n", alGetErrorString(oserror())); return False; } } resource = alGetResource(output_port); maxFillable = alGetFillable(output_port); channelCount = alGetChannels(audioconfig); frameSize = alGetWidth(audioconfig); if (frameSize == 0 || channelCount == 0) { fprintf(stderr, "wave_out_set_format: bad frameSize or channelCount\n"); return False; } combinedFrameSize = frameSize * channelCount; params.param = AL_RATE; params.value.ll = (long long) g_snd_rate << 32; if (alSetParams(resource, ¶ms, 1) < 0) { fprintf(stderr, "wave_set_format: alSetParams failed: %s\n", alGetErrorString(oserror())); return False; } if (params.sizeOut < 0) { fprintf(stderr, "wave_set_format: invalid rate %d\n", g_snd_rate); return False; } #if (defined(IRIX_DEBUG)) fprintf(stderr, "wave_out_set_format: returning...\n"); #endif return True; }
// 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; }
// 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; }
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"); }
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; }
/* * 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; }
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; }
static int open_sgi(audio_output_t *ao) { int dev = AL_DEFAULT_OUTPUT; ALconfig config = alNewConfig(); ALport port = NULL; /* Test for correct completion */ if (config == 0) { error1("open_sgi: %s",alGetErrorString(oserror())); return -1; } /* Set port parameters */ if(ao->channels == 2) alSetChannels(config, AL_STEREO); else alSetChannels(config, AL_MONO); alSetWidth(config, AL_SAMPLE_16); alSetSampFmt(config,AL_SAMPFMT_TWOSCOMP); alSetQueueSize(config, 131069); /* Setup output device to specified module. If there is no module specified in ao structure, use the default four output */ if ((ao->device) != NULL) { char *dev_name; dev_name=malloc((strlen(ao->device) + strlen(analog_output_res_name) + 1) * sizeof(char)); strcpy(dev_name,ao->device); strcat(dev_name,analog_output_res_name); /* Find the asked device resource */ dev=alGetResourceByName(AL_SYSTEM,dev_name,AL_DEVICE_TYPE); /* Free allocated space */ free(dev_name); if (!dev) { error2("Invalid audio resource: %s (%s)",dev_name, alGetErrorString(oserror())); return -1; } } /* Set the device */ if (alSetDevice(config,dev) < 0) { error1("open_sgi: %s",alGetErrorString(oserror())); return -1; } /* Open the audio port */ port = alOpenPort("mpg123-VSC", "w", config); if(port == NULL) { error1("Unable to open audio channel: %s", alGetErrorString(oserror())); return -1; } ao->userptr = (void*)port; set_format(ao, config); set_channels(ao, config); set_rate(ao, config); alFreeConfig(config); return 1; }