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 }
static Bool audriv_al_set_rate(ALport port, unsigned long rate) { ALpv pv; int r; r = alGetResource(port); pv.param = AL_RATE; pv.value.ll = alIntToFixed(rate); if(alSetParams(r, &pv, 1) < 0) return False; return True; }
/* 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())); } }
/** * Initialize global audio interface to use microphone input. * * @param rate [in] sampling rate in Hz * * @return TRUE on success, FALSE on failure. */ static boolean adin_o2_setup_global(double rate) { int device; ALpv setPVbuf[4]; setPVbuf[0].param = AL_INTERFACE; setPVbuf[0].value.i = alGetResourceByName(AL_SYSTEM, "Microphone", AL_INTERFACE_TYPE); setPVbuf[1].param = AL_MASTER_CLOCK; setPVbuf[1].value.i = AL_CRYSTAL_MCLK_TYPE; setPVbuf[2].param = AL_RATE; setPVbuf[2].value.ll= alDoubleToFixed(rate); device = alGetResourceByName(AL_SYSTEM, "Microphone", AL_DEVICE_TYPE); if (alSetParams(device, setPVbuf, 3) < 0) { return FALSE; } else { 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; }
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; }
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; }
// 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; }
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); }
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; }
Bool audriv_set_play_volume(int volume) /* 演奏音量を 0 〜 255 の範囲内で設定します.0 は無音,255 は最大音量. * 0 未満は 0,255 を超える値は 255 に等価. * 成功した場合は True を,失敗した場合は False を返します. */ { #ifndef SGI_OLDAL double gain; ALfixed lrgain[2]; ALpv pv; int resource; if(volume < 0) volume = 0; else if(volume > 255) volume = 255; if(volume == 0) { if(out_ginfo.specialVals & AL_NEG_INFINITY_BIT) gain = alFixedToDouble(AL_NEG_INFINITY); else gain = alFixedToDouble(out_ginfo.min.ll); } else if(volume == 255) { gain = alFixedToDouble(out_ginfo.max.ll); } else { double min, max; min = alFixedToDouble(out_ginfo.min.ll); max = alFixedToDouble(out_ginfo.max.ll); gain = min + (max - min) * (volume - 1) * (1.0/255); if(gain < min) gain = min; else if(gain > max) gain = max; } if(out == NULL) resource = AL_DEFAULT_OUTPUT; else resource = alGetResource(out); lrgain[0] = lrgain[1] = alDoubleToFixed(gain); pv.param = AL_GAIN; pv.value.ptr = lrgain; pv.sizeIn = 2; if(alSetParams(resource, &pv, 1) < 0) { audriv_err(ALERROR); return False; } return True; #else long gain[4]; if(volume < 0) volume = 0; else if(volume > 255) volume = 255; gain[0] = AL_LEFT_SPEAKER_GAIN; gain[1] = volume; gain[2] = AL_RIGHT_SPEAKER_GAIN; gain[3] = volume; if(ALsetparams(AL_DEFAULT_DEVICE, gain, 4) < 0) { audriv_err(ALERROR); return False; } return True; #endif /* SGI_OLDAL */ }
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 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 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); }
/* * 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; }