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 }
/* 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; }
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; }
// 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; }
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 */ }