int audriv_get_play_volume(void) /* 演奏音量を 0 〜 255 内で得ます.0 は無音,255 は最大音量. * 失敗すると -1 を返し,そうでない場合は 0 〜 255 内の音量を返します. */ { #ifndef SGI_OLDAL ALfixed lrgain[2]; ALpv pv; double gain, l, r, min, max; int volume; int resource; min = alFixedToDouble(out_ginfo.min.ll); max = alFixedToDouble(out_ginfo.max.ll); pv.param = AL_GAIN; pv.value.ptr = lrgain; pv.sizeIn = 2; if(out == NULL) resource = AL_DEFAULT_OUTPUT; else resource = alGetResource(out); if(alGetParams(resource, &pv, 1) < 0) { audriv_err(ALERROR); return -1; } l = alFixedToDouble(lrgain[0]); r = alFixedToDouble(lrgain[1]); if(l < min) l = min; else if(l > max) l = max; if(r < min) r = min; else if(r > max) r = max; gain = (l + r) / 2; volume = (gain - min) * 256 / (max - min); if(volume < 0) volume = 0; else if(volume > 255) volume = 255; return volume; #else long gain[4]; int volume; gain[0] = AL_LEFT_SPEAKER_GAIN; gain[2] = AL_RIGHT_SPEAKER_GAIN; if(ALgetparams(AL_DEFAULT_DEVICE, gain, 4) < 0) { audriv_err(ALERROR); return -1; } volume = (gain[1] + gain[3]) / 2; if(volume < 0) volume = 0; else if(volume > 255) volume = 255; return volume; #endif /* SGI_OLDAL */ }
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())); } }
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; }
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; }
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 */ }