void ClosePlay(void *port){ struct Sgiplay *sgiplay=(struct Sgiplay *)port; type j; j = alClosePort(sgiplay->out_port); j = alFreeConfig(sgiplay->out_c); free(sgiplay); }
void audriv_free_audio(void) /* audio の後処理を行います. */ { if(!out_config) return; if(out != NULL) { alClosePort(out); out = NULL; } alFreeConfig(out_config); out_config = NULL; if(out_config != NULL) alFreeConfig(out_config); out_config = NULL; }
Bool audriv_setup_audio(void) /* オーディオの初期化を行います. * 成功した場合は True を,失敗した場合は False を返します. */ { if(out_config) return True; if((out_config = alNewConfig()) == NULL) { audriv_err(ALERROR); return False; } out = NULL; #ifndef SGI_OLDAL if(alGetParamInfo(AL_DEFAULT_OUTPUT, AL_GAIN, &out_ginfo) < 0) { audriv_err(ALERROR); alFreeConfig(out_config); out_config = NULL; return False; } #endif /* SGI_OLDAL */ if(alSetSampFmt(out_config, AL_SAMPFMT_TWOSCOMP) < 0) { audriv_err(ALERROR); return False; } #if 0 if(alSetQueueSize(out_config, OUT_AUDIO_QUEUE_SIZE) != 0) { fprintf(stderr, "Warning: Can't set queue size: %d\n", OUT_AUDIO_QUEUE_SIZE); } #else alSetQueueSize(out_config, OUT_AUDIO_QUEUE_SIZE); #endif return True; }
// close audio device static void uninit(int immed) { /* TODO: samplerate should be set back to the value before mplayer was started! */ mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_SGI_Uninit); if (ao_config) { alFreeConfig(ao_config); ao_config = NULL; } if (ao_port) { if (!immed) while(alGetFilled(ao_port) > 0) sginap(1); alClosePort(ao_port); ao_port = NULL; } }
void sgi_close(void) { /* Ack all remaining packets */ #if (defined(IRIX_DEBUG)) fprintf(stderr, "sgi_close: begin\n"); #endif while (!rdpsnd_queue_empty()) rdpsnd_queue_next(0); alDiscardFrames(output_port, 0); alClosePort(output_port); output_port = (ALport) 0; alFreeConfig(audioconfig); #if (defined(IRIX_DEBUG)) fprintf(stderr, "sgi_close: returning\n"); #endif }
void wave_out_close(void) { /* Ack all remaining packets */ #if (defined(IRIX_DEBUG)) fprintf(stderr, "wave_out_close: begin\n"); #endif while (queue_lo != queue_hi) { rdpsnd_send_completion(packet_queue[queue_lo].tick, packet_queue[queue_lo].index); free(packet_queue[queue_lo].s.data); queue_lo = (queue_lo + 1) % MAX_QUEUE; } alDiscardFrames(output_port, 0); alClosePort(output_port); alFreeConfig(audioconfig); #if (defined(IRIX_DEBUG)) fprintf(stderr, "wave_out_close: returning\n"); #endif }
static int AL_OpenAudio(_THIS, SDL_AudioSpec *spec) { ALconfig audio_config; #ifdef OLD_IRIX_AUDIO long audio_param[2]; #else ALpv audio_param; #endif int width; /* Determine the audio parameters from the AudioSpec */ switch ( spec->format & 0xFF ) { case 8: { /* Signed 8 bit audio data */ spec->format = AUDIO_S8; width = AL_SAMPLE_8; } break; case 16: { /* Signed 16 bit audio data */ spec->format = AUDIO_S16MSB; width = AL_SAMPLE_16; } break; default: { SDL_SetError("Unsupported audio format"); return(-1); } } /* Update the fragment size as size in bytes */ SDL_CalculateAudioSpec(spec); /* Set output frequency */ #ifdef OLD_IRIX_AUDIO audio_param[0] = AL_OUTPUT_RATE; audio_param[1] = spec->freq; if( ALsetparams(AL_DEFAULT_DEVICE, audio_param, 2) < 0 ) { #else audio_param.param = AL_RATE; audio_param.value.i = spec->freq; if( alSetParams(AL_DEFAULT_OUTPUT, &audio_param, 1) < 0 ) { #endif SDL_SetError("alSetParams failed"); return(-1); } /* Open the audio port with the requested frequency */ audio_port = NULL; audio_config = alNewConfig(); if ( audio_config && (alSetSampFmt(audio_config, AL_SAMPFMT_TWOSCOMP) >= 0) && (alSetWidth(audio_config, width) >= 0) && (alSetQueueSize(audio_config, spec->samples*2) >= 0) && (alSetChannels(audio_config, spec->channels) >= 0) ) { audio_port = alOpenPort("SDL audio", "w", audio_config); } alFreeConfig(audio_config); if( audio_port == NULL ) { SDL_SetError("Unable to open audio port"); return(-1); } /* Allocate mixing buffer */ mixbuf = (Uint8 *)SDL_AllocAudioMem(spec->size); if ( mixbuf == NULL ) { SDL_OutOfMemory(); return(-1); } memset(mixbuf, spec->silence, spec->size); /* We're ready to rock and roll. :-) */ return(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; }
main (int argc, char **argv) { AFfilehandle file; AFframecount count, frameCount; int channelCount, sampleFormat, sampleWidth; float frameSize; void *buffer; double sampleRate; ALport outport; ALconfig outportconfig; if (argc < 2) usage(); file = afOpenFile(argv[1], "r", NULL); if (file == AF_NULL_FILEHANDLE) { fprintf(stderr, "Could not open file %s.\n", argv[1]); exit(EXIT_FAILURE); } frameCount = afGetFrameCount(file, AF_DEFAULT_TRACK); frameSize = afGetVirtualFrameSize(file, AF_DEFAULT_TRACK, 1); channelCount = afGetVirtualChannels(file, AF_DEFAULT_TRACK); sampleRate = afGetRate(file, AF_DEFAULT_TRACK); afGetVirtualSampleFormat(file, AF_DEFAULT_TRACK, &sampleFormat, &sampleWidth); if (sampleFormat == AF_SAMPFMT_UNSIGNED) { afSetVirtualSampleFormat(file, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, sampleWidth); } printf("frame count: %lld\n", frameCount); printf("frame size: %d bytes\n", (int) frameSize); printf("channel count: %d\n", channelCount); printf("sample rate: %.2f Hz\n", sampleRate); buffer = malloc(BUFFERED_FRAME_COUNT * frameSize); outportconfig = alNewConfig(); setwidth(outportconfig, sampleWidth); setsampleformat(outportconfig, sampleFormat); alSetChannels(outportconfig, channelCount); count = afReadFrames(file, AF_DEFAULT_TRACK, buffer, BUFFERED_FRAME_COUNT); outport = alOpenPort("irixread", "w", outportconfig); setrate(outport, sampleRate); do { printf("count = %lld\n", count); alWriteFrames(outport, buffer, count); count = afReadFrames(file, AF_DEFAULT_TRACK, buffer, BUFFERED_FRAME_COUNT); } while (count > 0); waitport(outport); alClosePort(outport); alFreeConfig(outportconfig); afCloseFile(file); }
qboolean SNDDMA_Init(void) { ALconfig ac = NULL; ALpv pvbuf[2]; s_loadas8bit = Cvar_Get("s_loadas8bit", "16", CVAR_ARCHIVE); if ((int)s_loadas8bit->value) dma.samplebits = 8; else dma.samplebits = 16; if (dma.samplebits != 16) { Com_Printf("Don't currently support %i-bit data. Forcing 16-bit.\n", dma.samplebits); dma.samplebits = 16; Cvar_SetValue( "s_loadas8bit", false ); } s_khz = Cvar_Get("s_khz", "0", CVAR_ARCHIVE); switch ((int)s_khz->value) { case 48: dma.speed = AL_RATE_48000; break; case 44: dma.speed = AL_RATE_44100; break; case 32: dma.speed = AL_RATE_32000; break; case 22: dma.speed = AL_RATE_22050; break; case 16: dma.speed = AL_RATE_16000; break; case 11: dma.speed = AL_RATE_11025; break; case 8: dma.speed = AL_RATE_8000; break; default: dma.speed = AL_RATE_22050; Com_Printf("Don't currently support %i kHz sample rate. Using %i.\n", (int)s_khz->value, (int)(dma.speed/1000)); } sndchannels = Cvar_Get("sndchannels", "2", CVAR_ARCHIVE); dma.channels = (int)sndchannels->value; if (dma.channels != 2) Com_Printf("Don't currently support %i sound channels. Try 2.\n", sndchannels); /***********************/ ac = alNewConfig(); alSetChannels( ac, AL_STEREO ); alSetSampFmt( ac, AL_SAMPFMT_TWOSCOMP ); alSetQueueSize( ac, QSND_BUFFER_FRAMES ); if (dma.samplebits == 8) alSetWidth( ac, AL_SAMPLE_8 ); else alSetWidth( ac, AL_SAMPLE_16 ); sgisnd_aport = alOpenPort( "Quake", "w", ac ); if (!sgisnd_aport) { printf( "failed to open audio port!\n" ); } // set desired sample rate pvbuf[0].param = AL_MASTER_CLOCK; pvbuf[0].value.i = AL_CRYSTAL_MCLK_TYPE; pvbuf[1].param = AL_RATE; pvbuf[1].value.ll = alIntToFixed( dma.speed ); alSetParams( alGetResource( sgisnd_aport ), pvbuf, 2 ); if (pvbuf[1].sizeOut < 0) printf( "illegal sample rate %d\n", dma.speed ); sgisnd_frames_per_ns = dma.speed * 1.0e-9; dma.samples = sizeof(dma_buffer)/(dma.samplebits/8); dma.submission_chunk = 1; dma.buffer = (unsigned char *)dma_buffer; dma.samplepos = 0; alFreeConfig( ac ); return true; }
static int al_play (ao_instance_t * _instance, int flags, sample_t * _samples) { al_instance_t * instance = (al_instance_t *) _instance; int16_t int16_samples[256*6]; int chans = -1; #ifdef LIBDTS_DOUBLE convert_t samples[256 * 6]; int i; for (i = 0; i < 256 * 6; i++) samples[i] = _samples[i]; #else convert_t * samples = _samples; #endif chans = channels_multi (flags); flags &= DTS_CHANNEL_MASK | DTS_LFE; if (instance->set_params) { ALconfig config; ALpv params[2]; config = alNewConfig (); if (!config) { fprintf (stderr, "alNewConfig failed\n"); return 1; } if (alSetChannels (config, chans)) { fprintf (stderr, "alSetChannels failed\n"); return 1; } if (alSetConfig (instance->port, config)) { fprintf (stderr, "alSetConfig failed\n"); return 1; } alFreeConfig (config); params[0].param = AL_MASTER_CLOCK; params[0].value.i = AL_CRYSTAL_MCLK_TYPE; params[1].param = AL_RATE; params[1].value.ll = alIntToFixed (instance->sample_rate); if (alSetParams (alGetResource (instance->port), params, 2) < 0) { fprintf (stderr, "alSetParams failed\n"); return 1; } instance->flags = flags; instance->set_params = 0; } else if ((flags == DTS_DOLBY) && (instance->flags == DTS_STEREO)) { fprintf (stderr, "Switching from stereo to dolby surround\n"); instance->flags = DTS_DOLBY; } else if ((flags == DTS_STEREO) && (instance->flags == DTS_DOLBY)) { fprintf (stderr, "Switching from dolby surround to stereo\n"); instance->flags = DTS_STEREO; } else if (flags != instance->flags) return 1; convert2s16_multi (samples, int16_samples, flags); alWriteFrames (instance->port, int16_samples, 256); return 0; }
static int IRIXAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) { SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format); long width = 0; long fmt = 0; int valid = 0; /* !!! FIXME: Handle multiple devices and capture? */ /* Initialize all variables that we clean on shutdown */ this->hidden = (struct SDL_PrivateAudioData *) SDL_malloc((sizeof *this->hidden)); if (this->hidden == NULL) { SDL_OutOfMemory(); return 0; } SDL_memset(this->hidden, 0, (sizeof *this->hidden)); #ifdef OLD_IRIX_AUDIO { long audio_param[2]; audio_param[0] = AL_OUTPUT_RATE; audio_param[1] = this->spec.freq; valid = (ALsetparams(AL_DEFAULT_DEVICE, audio_param, 2) < 0); } #else { ALpv audio_param; audio_param.param = AL_RATE; audio_param.value.i = this->spec.freq; valid = (alSetParams(AL_DEFAULT_OUTPUT, &audio_param, 1) < 0); } #endif while ((!valid) && (test_format)) { valid = 1; this->spec.format = test_format; switch (test_format) { case AUDIO_S8: width = AL_SAMPLE_8; fmt = AL_SAMPFMT_TWOSCOMP; break; case AUDIO_S16SYS: width = AL_SAMPLE_16; fmt = AL_SAMPFMT_TWOSCOMP; break; case AUDIO_F32SYS: width = 0; /* not used here... */ fmt = AL_SAMPFMT_FLOAT; break; /* Docs say there is int24, but not int32.... */ default: valid = 0; test_format = SDL_NextAudioFormat(); break; } if (valid) { ALconfig audio_config = alNewConfig(); valid = 0; if (audio_config) { if (alSetChannels(audio_config, this->spec.channels) < 0) { if (this->spec.channels > 2) { /* can't handle > stereo? */ this->spec.channels = 2; /* try again below. */ } } if ((alSetSampFmt(audio_config, fmt) >= 0) && ((!width) || (alSetWidth(audio_config, width) >= 0)) && (alSetQueueSize(audio_config, this->spec.samples * 2) >= 0) && (alSetChannels(audio_config, this->spec.channels) >= 0)) { this->hidden->audio_port = alOpenPort("SDL audio", "w", audio_config); if (this->hidden->audio_port == NULL) { /* docs say AL_BAD_CHANNELS happens here, too. */ int err = oserror(); if (err == AL_BAD_CHANNELS) { this->spec.channels = 2; alSetChannels(audio_config, this->spec.channels); this->hidden->audio_port = alOpenPort("SDL audio", "w", audio_config); } } if (this->hidden->audio_port != NULL) { valid = 1; } } alFreeConfig(audio_config); } } } if (!valid) { IRIXAUDIO_CloseDevice(this); SDL_SetError("Unsupported audio format"); return 0; } /* Update the fragment size as size in bytes */ SDL_CalculateAudioSpec(&this->spec); /* Allocate mixing buffer */ this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->spec.size); if (this->hidden->mixbuf == NULL) { IRIXAUDIO_CloseDevice(this); SDL_OutOfMemory(); return 0; } SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size); /* We're ready to rock and roll. :-) */ return 1; }
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; }
static int AL_OpenAudio(_THIS, SDL_AudioSpec * spec) { Uint16 test_format = SDL_FirstAudioFormat(spec->format); long width = 0; long fmt = 0; int valid = 0; #ifdef OLD_IRIX_AUDIO { long audio_param[2]; audio_param[0] = AL_OUTPUT_RATE; audio_param[1] = spec->freq; valid = (ALsetparams(AL_DEFAULT_DEVICE, audio_param, 2) < 0); } #else { ALpv audio_param; audio_param.param = AL_RATE; audio_param.value.i = spec->freq; valid = (alSetParams(AL_DEFAULT_OUTPUT, &audio_param, 1) < 0); } #endif while ((!valid) && (test_format)) { valid = 1; spec->format = test_format; switch (test_format) { case AUDIO_S8: width = AL_SAMPLE_8; fmt = AL_SAMPFMT_TWOSCOMP; break; case AUDIO_S16SYS: width = AL_SAMPLE_16; fmt = AL_SAMPFMT_TWOSCOMP; break; default: valid = 0; test_format = SDL_NextAudioFormat(); break; } if (valid) { ALconfig audio_config = alNewConfig(); valid = 0; if (audio_config) { if (alSetChannels(audio_config, spec->channels) < 0) { if (spec->channels > 2) { /* can't handle > stereo? */ spec->channels = 2; /* try again below. */ } } if ((alSetSampFmt(audio_config, fmt) >= 0) && ((!width) || (alSetWidth(audio_config, width) >= 0)) && (alSetQueueSize(audio_config, spec->samples * 2) >= 0) && (alSetChannels(audio_config, spec->channels) >= 0)) { audio_port = alOpenPort("SDL audio", "w", audio_config); if (audio_port == NULL) { /* docs say AL_BAD_CHANNELS happens here, too. */ int err = oserror(); if (err == AL_BAD_CHANNELS) { spec->channels = 2; alSetChannels(audio_config, spec->channels); audio_port = alOpenPort("SDL audio", "w", audio_config); } } if (audio_port != NULL) { valid = 1; } } alFreeConfig(audio_config); } } } if (!valid) { SDL_SetError("Unsupported audio format"); return (-1); } /* Update the fragment size as size in bytes */ SDL_CalculateAudioSpec(spec); /* Allocate mixing buffer */ mixbuf = (Uint8 *) SDL_AllocAudioMem(spec->size); if (mixbuf == NULL) { SDL_OutOfMemory(); return (-1); } SDL_memset(mixbuf, spec->silence, spec->size); /* We're ready to rock and roll. :-) */ return (0); }
/* * 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; }
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; }