/* * Open and initialize an audio port. */ static ALport sfxInitAudioPort(int init) { ALport ap; ALconfig audioPortConfig; long pvbuf[6]; if (init) { pvbuf[0] = AL_LEFT_SPEAKER_GAIN; pvbuf[2] = AL_RIGHT_SPEAKER_GAIN; pvbuf[4] = AL_OUTPUT_RATE; ALgetparams(AL_DEFAULT_DEVICE, pvbuf, 6L); currLeftGain = origLeftGain = pvbuf[1]; currRightGain = origRightGain = pvbuf[3]; origOutputRate = pvbuf[5]; sfxSetGainIndex((origLeftGain+origRightGain)/2); } /* * Configure and open audio port. */ audioPortConfig = ALnewconfig(); ALsetwidth(audioPortConfig, AL_SAMPLE_16); ALsetchannels(audioPortConfig, AL_STEREO); ALsetqueuesize(audioPortConfig, 16000); ap = ALopenport("spacetrek", "w", audioPortConfig); ALfreeconfig(audioPortConfig); return ap; }
int sound_init() { long pvbuf[2]; pvbuf[0] = AL_OUTPUT_COUNT; pvbuf[2] = AL_MONITOR_CTL; if (ALgetparams(AL_DEFAULT_DEVICE, pvbuf, 4) < 0) { fprintf(stderr,"sound driver : No audio hardware\n"); return 0; } pvbuf[0] = AL_OUTPUT_RATE; pvbuf[1] = 11025; if (ALsetparams(AL_DEFAULT_DEVICE,pvbuf,4) < 0) { fprintf(stderr,"sound driver : Could not set sample rate\n"); return 0; } ALseterrorhandler(0); audioconfig = ALnewconfig(); if (!audioconfig) { fprintf(stderr,"failed to create audio config\n"); return 0; } else if (ALsetchannels(audioconfig,AL_MONO)) { fprintf(stderr,"sound driver : could not set audio channels\n"); return 0; } else if (ALsetqueuesize(audioconfig,BUF_SIZE)) { fprintf(stderr,"sound driver : could not set audio que size\n"); ALfreeconfig(audioconfig); return 0; } else if (ALsetwidth (audioconfig, AL_SAMPLE_8)) { fprintf(stderr,"sound driver :could not set 8 bit samples\n"); ALfreeconfig(audioconfig); return 0; } audioport=ALopenport("Abuse sound driver","w",audioconfig); if (!audioport) { fprintf(stderr,"sound driver : could not open audio port\n"); ALfreeconfig(audioconfig); return 0; } int i=0,j; uchar *vd=volume_table; for (;i<32;i++) { for (j=0;j<256;j++,vd++) *vd=(j-128)*i/31+128; } return 1; }
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 void get_current_volumes(AudioDevice device) { long params[4]; params[0] = AL_LEFT_SPEAKER_GAIN; params[2] = AL_RIGHT_SPEAKER_GAIN; ALgetparams(device->device, params, 4); device->left_speaker_gain = params[1]; device->right_speaker_gain = params[3]; }
int sgi_audio_get_ogain(audio_desc_t ad) { long cmd[2]; UNUSED(ad); assert(audio_fd > 0); cmd[0] = AL_LEFT_SPEAKER_GAIN; ALgetparams(AL_DEFAULT_DEVICE, cmd, 2L); return (SGI_DEVICE_TO_RAT(cmd[1])); }
int sgi_audio_get_igain(audio_desc_t ad) { long cmd[2]; UNUSED(ad); assert(audio_fd > 0); cmd[0] = AL_LEFT_INPUT_ATTEN; ALgetparams(AL_DEFAULT_DEVICE, cmd, 2L); return (MAX_AMP - SGI_DEVICE_TO_RAT(cmd[1])); }
static int sgi_init(const char *param, int *speed, int *fragsize, int *fragnr, int *channels) { long chpars[] = { AL_OUTPUT_RATE, 0 }; int st; /* No stereo capability. */ *channels = 1; ALseterrorhandler(sgi_errorhandler); chpars[1] = *speed; st = ALsetparams(AL_DEFAULT_DEVICE, chpars, 2); if (st < 0) { return 1; } st = ALgetparams(AL_DEFAULT_DEVICE, chpars, 2); if (st < 0) { return 1; } *speed = chpars[1]; sgi_audioconfig = ALnewconfig(); if (!sgi_audioconfig) { return 1; } st = ALsetchannels(sgi_audioconfig, AL_MONO); if (st < 0) { goto fail; } st = ALsetwidth(sgi_audioconfig, AL_SAMPLE_16); if (st < 0) { goto fail; } st = ALsetqueuesize(sgi_audioconfig, *fragsize * *fragnr); if (st < 0) { goto fail; } sgi_audioport = ALopenport("outport", "w", sgi_audioconfig); if (!sgi_audioport) { goto fail; } return 0; fail: ALfreeconfig(sgi_audioconfig); sgi_audioconfig = NULL; return 1; }
/* * Check for external volume changes. */ static void sfxCheckVolume(void) { long pvbuf[6]; /* * Check to see if the volume was changed externally. */ pvbuf[0] = AL_LEFT_SPEAKER_GAIN; pvbuf[2] = AL_RIGHT_SPEAKER_GAIN; ALgetparams(AL_DEFAULT_DEVICE, pvbuf, 4L); if (pvbuf[1] != currLeftGain || pvbuf[3] != currRightGain) { origLeftGain = currLeftGain = pvbuf[1]; origRightGain = currRightGain = pvbuf[3]; sfxSetGainIndex((pvbuf[1] + pvbuf[3]) / 2); } return; }
static AudioContext audio_initialize (unsigned char *data, int length, int volume) { Lisp_Object audio_port_state[3]; static AudioContextRec desc; AudioContext ac; desc.ac_right_speaker_gain = desc.ac_left_speaker_gain = volume * 256 / 100; desc.ac_device = AL_DEFAULT_DEVICE; #if HAVE_SND_FILES if (LOOKING_AT_SND_HEADER_P (data)) { if (parse_snd_header (data, length, & desc)==-1) report_file_error ("decoding .snd header", Qnil); } else #endif { desc.ac_data = data; desc.ac_size = length; desc.ac_output_rate = DEFAULT_SAMPLING_RATE; desc.ac_nchan = DEFAULT_CHANNEL_COUNT; desc.ac_format = DEFAULT_FORMAT; desc.ac_write_chunk_function = write_mulaw_8_chunk; } /* Make sure that the audio port is reset to its initial characteristics after exit */ ALgetparams (desc.ac_device, saved_device_state, sizeof (saved_device_state) / sizeof (long)); audio_port_state[0] = make_int (saved_device_state[1]); audio_port_state[1] = make_int (saved_device_state[3]); audio_port_state[2] = make_int (saved_device_state[5]); record_unwind_protect (restore_audio_port, Fvector (3, &audio_port_state[0])); ac = initialize_audio_port (& desc); desc = * ac; return ac; }
int esd_audio_open() { ALconfig audioconfig; audioconfig = ALnewconfig(); rate_params[1] = esd_audio_rate; rate_params[3] = esd_audio_rate; if (!audioconfig) { printf( "Couldn't initialize new audio config\n" ); esd_audio_fd = -1; return esd_audio_fd; } else { long pvbuf[] = { AL_OUTPUT_COUNT, 0, AL_MONITOR_CTL, 0, AL_OUTPUT_RATE, 0 }; if (ALgetparams(AL_DEFAULT_DEVICE, pvbuf, 6) < 0) if (oserror() == AL_BAD_DEVICE_ACCESS) { esd_audio_fd = -1; return esd_audio_fd; } if (pvbuf[1] == 0 && pvbuf[3] == AL_MONITOR_OFF) { ALsetparams(AL_DEFAULT_DEVICE, rate_params, 2); } else if (pvbuf[5] != esd_audio_rate) { printf("audio device is already in use with wrong sample output rate\n"); esd_audio_fd = -1; return esd_audio_fd; } /* ALsetsampfmt(audioconfig, AL_SAMPFMT_TWOSCOMP); this is the default */ /* ALsetwidth(audioconfig, AL_SAMPLE_16); this is the default */ if ( (esd_audio_format & ESD_MASK_CHAN) == ESD_MONO) ALsetchannels(audioconfig, AL_MONO); /* else ALsetchannels(audioconfig, AL_STEREO); this is the default */ ALsetqueuesize(audioconfig, ESD_BUF_SIZE * 2); outaudioport = ALopenport("esd", "w", audioconfig); if (outaudioport == (ALport) 0) { switch (oserror()) { case AL_BAD_NO_PORTS: printf( "system is out of ports\n"); esd_audio_fd = -1; return esd_audio_fd; break; case AL_BAD_DEVICE_ACCESS: printf("couldn't access audio device\n"); esd_audio_fd = -1; return esd_audio_fd; break; case AL_BAD_OUT_OF_MEM: printf("out of memory\n"); esd_audio_fd = -1; return esd_audio_fd; break; } /* don't know how we got here, but it must be bad */ esd_audio_fd = -1; return esd_audio_fd; } ALsetfillpoint(outaudioport, ESD_BUF_SIZE); esd_audio_fd = ALgetfd(outaudioport); /* * If we are recording, open a second port to read from * and return that fd instead */ if ( (esd_audio_format & ESD_MASK_FUNC) == ESD_RECORD ) { inaudioport = ALopenport("esd", "r", audioconfig); if (inaudioport == (ALport) 0) { switch (oserror()) { case AL_BAD_NO_PORTS: printf( "system is out of ports\n"); esd_audio_fd = -1; return esd_audio_fd; break; case AL_BAD_DEVICE_ACCESS: printf("couldn't access audio device\n"); esd_audio_fd = -1; return esd_audio_fd; break; case AL_BAD_OUT_OF_MEM: printf("out of memory\n"); esd_audio_fd = -1; return esd_audio_fd; break; default: printf( "Unknown error opening port\n" ); } /* don't know how we got here, but it must be bad */ esd_audio_fd = -1; return esd_audio_fd; } ALsetfillpoint(inaudioport, ESD_BUF_SIZE); ALsetparams(AL_DEFAULT_DEVICE, (rate_params + 2), 2); esd_audio_fd = ALgetfd(inaudioport); } } return esd_audio_fd; }
/*--------------------------------------------------------------------------------------*/ PaError PaHost_OpenStream(internalPortAudioStream *past) { PaError result = paNoError; PaHostSoundControl *pahsc; unsigned int minNumBuffers; internalPortAudioDevice *padIN, *padOUT; /* For looking up native AL-numbers. */ ALconfig sgiALconfig = NULL; /* IRIX-datatype. */ long pvbuf[8]; /* To get/set hardware configs. */ long sr, ALqsize; DBUG(("PaHost_OpenStream() called.\n")); /* Alloc FASTMEM and init host data. */ if (!past) { ERR_RPT(("Streampointer NULL!\n")); result = paBadStreamPtr; goto done; } pahsc = (PaHostSoundControl*)PaHost_AllocateFastMemory(sizeof(PaHostSoundControl)); if (pahsc == NULL) { ERR_RPT(("FAST Memory allocation failed.\n")); /* Pass trough some ERR_RPT-exit- */ result = paInsufficientMemory; goto done; /* code (nothing will be freed). */ } memset(pahsc, 0, sizeof(PaHostSoundControl)); /* pahsc->pahsc_threadPID = -1; Should pahsc_threadPID be inited to */ past->past_DeviceData = (void*)pahsc; /* -1 instead of 0 ?? */ /*--------------------------------------------------- Allocate native buffers: --------*/ pahsc->pahsc_SamplesPerInputBuffer = past->past_FramesPerUserBuffer * /* Needed by the */ past->past_NumInputChannels; /* audio-thread. */ pahsc->pahsc_BytesPerInputBuffer = pahsc->pahsc_SamplesPerInputBuffer * sizeof(short); if (past->past_NumInputChannels > 0) /* Assumes short = 16 bits! */ { pahsc->pahsc_NativeInputBuffer = (short*)PaHost_AllocateFastMemory(pahsc->pahsc_BytesPerInputBuffer); if( pahsc->pahsc_NativeInputBuffer == NULL ) { ERR_RPT(("Fast memory allocation for input-buffer failed.\n")); result = paInsufficientMemory; goto done; } } pahsc->pahsc_SamplesPerOutputBuffer = past->past_FramesPerUserBuffer * /* Needed by the */ past->past_NumOutputChannels; /* audio-thread. */ pahsc->pahsc_BytesPerOutputBuffer = pahsc->pahsc_SamplesPerOutputBuffer * sizeof(short); if (past->past_NumOutputChannels > 0) /* Assumes short = 16 bits! */ { pahsc->pahsc_NativeOutputBuffer = (short*)PaHost_AllocateFastMemory(pahsc->pahsc_BytesPerOutputBuffer); if (pahsc->pahsc_NativeOutputBuffer == NULL) { ERR_RPT(("Fast memory allocation for output-buffer failed.\n")); result = paInsufficientMemory; goto done; } } /*------------------------------------------ Manipulate hardware if necessary and allowed: --*/ ALseterrorhandler(0); /* 0 = turn off the default error handler. */ pvbuf[0] = AL_INPUT_RATE; pvbuf[2] = AL_INPUT_COUNT; pvbuf[4] = AL_OUTPUT_RATE; /* TO FIX: rates may be logically, not always in Hz! */ pvbuf[6] = AL_OUTPUT_COUNT; sr = (long)(past->past_SampleRate + 0.5); /* Common for input and output :-) */ if (past->past_NumInputChannels > 0) /* We need to lookup the corre- */ { /* sponding native AL-number(s). */ padIN = Pa_GetInternalDevice(past->past_InputDeviceID); if (!padIN) { ERR_RPT(("Pa_GetInternalDevice() for input failed.\n")); result = paHostError; goto done; } if (ALgetparams(padIN->pad_ALdevice, &pvbuf[0], 4)) /* Although input and output will both be on */ goto sgiError; /* the same AL-device, the AL-library might */ if (pvbuf[1] != sr) /* contain more than AL_DEFAULT_DEVICE in */ { /* Rate different from current harware-rate? the future. Therefore 2 seperate queries. */ if (pvbuf[3] > 0) /* Means, there's other clients using AL-input-ports */ { ERR_RPT(("Sorry, not allowed to switch input-hardware to %ld Hz because \ another process is currently using input at %ld kHz.\n", sr, pvbuf[1])); result = paHostError; goto done; } pvbuf[1] = sr; /* Then set input-rate. */ if (ALsetparams(padIN->pad_ALdevice, &pvbuf[0], 2)) goto sgiError; /* WHETHER THIS SAMPLERATE WAS REALLY PRESENT IN OUR ARRAY OF RATES, */ } /* IS NOT CHECKED, AT LEAST NOT BY ME, WITHIN THIS FILE! Does PA do? */
void *Audio_Irix::open (AudioConfig& cfg, const char *) { // Copy input parameters. May later be replaced with driver defaults. _settings = cfg; _config = ALnewconfig(); // Set sample format ALsetsampfmt(_config, AL_SAMPFMT_TWOSCOMP); // stereo or mono mode _settings.channels = cfg.channels >= 2 ? 2 : 1; if (_settings.channels == 2) ALsetchannels(_config, AL_STEREO); else ALsetchannels(_config, AL_MONO); // 16 or 8 bit sample _settings.precision = cfg.precision >= 16 ? 16 : 8; if (_settings.precision == 16) ALsetwidth(_config, AL_SAMPLE_16); else ALsetwidth(_config, AL_SAMPLE_8); // Frequency long chpars[] = {AL_OUTPUT_RATE, 0}; if (cfg.frequency > 48000) chpars[1] = AL_RATE_48000; else if (cfg.frequency > 44100) chpars[1] = AL_RATE_44100; else if (cfg.frequency > 32000) chpars[1] = AL_RATE_32000; else if (cfg.frequency > 22050) chpars[1] = AL_RATE_22050; else if (cfg.frequency > 16000) chpars[1] = AL_RATE_16000; else chpars[1] = AL_RATE_11025; ALsetparams(AL_DEFAULT_DEVICE, chpars, 2); ALgetparams(AL_DEFAULT_DEVICE, chpars, 2); _settings.frequency = (uint_least32_t) chpars[1]; // Allocate sound buffers and set audio queue ALsetqueuesize(_config, chpars[1]); // open audio device _audio = ALopenport("SIDPLAY2 sound", "w", _config); if (_audio == NULL) { perror("AUDIO:"); _errorString = "ERROR: Could not open audio device.\n See standard error output."; ALfreeconfig(_config); return 0; } // Setup internal Config _settings.encoding = AUDIO_SIGNED_PCM; _settings.bufSize = (uint_least32_t) chpars[1]; // Update the users settings getConfig (cfg); // Allocate memory same size as buffer #ifdef HAVE_EXCEPTIONS _sampleBuffer = new(std::nothrow) int_least8_t[chpars[1]]; #else _sampleBuffer = new int_least8_t[chpars[1]]; #endif _errorString = "OK"; return (void *) _sampleBuffer; }
static AudioContext initialize_audio_port (AudioContext desc) { /* we can't use the same port for mono and stereo */ static AudioContextRec mono_port_state = { { 0, 0, 0, 0 }, { (ALport) 0, AFunknown, 1, 0 }, { (void *) 0, (unsigned long) 0 } }; #if HAVE_STEREO static AudioContextRec stereo_port_state = { { 0, 0, 0, 0 }, { (ALport) 0, AFunknown, 2, 0 }, { (void *) 0, (unsigned long) 0 } }; static AudioContext return_ac; switch (desc->ac_nchan) { case 1: return_ac = & mono_port_state; break; case 2: return_ac = & stereo_port_state; break; default: return (AudioContext) 0; } #else /* not HAVE_STEREO */ static AudioContext return_ac = & mono_port_state; #endif /* not HAVE_STEREO */ return_ac->device = desc->device; return_ac->buffer = desc->buffer; return_ac->ac_format = desc->ac_format; return_ac->ac_queue_size = desc->ac_queue_size; if (return_ac->ac_port==(ALport) 0) { if ((open_audio_port (return_ac, desc))==-1) { report_file_error ("Open audio port", Qnil); return (AudioContext) 0; } } else { ALconfig config = ALgetconfig (return_ac->ac_port); int changed = 0; long params[2]; params[0] = AL_OUTPUT_RATE; ALgetparams (return_ac->ac_device, params, 2); return_ac->ac_output_rate = params[1]; if (return_ac->ac_output_rate != desc->ac_output_rate) { return_ac->ac_output_rate = params[1] = desc->ac_output_rate; ALsetparams (return_ac->ac_device, params, 2); } if ((changed = set_output_format (config, return_ac->ac_format))==-1) return (AudioContext) 0; return_ac->ac_format = desc->ac_format; if (changed) ALsetconfig (return_ac->ac_port, config); } return_ac->ac_write_chunk_function = desc->ac_write_chunk_function; get_current_volumes (& return_ac->device); if (return_ac->ac_left_speaker_gain != desc->ac_left_speaker_gain || return_ac->ac_right_speaker_gain != desc->ac_right_speaker_gain) adjust_audio_volume (& desc->device); return return_ac; }