static int set_channels(audio_output_t *ao, ALconfig config) { int ret; if(ao->channels == 2) ret = alSetChannels(config, AL_STEREO); else ret = alSetChannels(config, AL_MONO); if (ret < 0) error1("set_channels : %s",alGetErrorString(oserror())); return 0; }
static int audio_set_channels(struct audio_info_struct *ai, ALconfig config) { int ret; if(ai->channels == 2) ret = alSetChannels(config, AL_STEREO); else ret = alSetChannels(config, AL_MONO); if (ret < 0) fprintf(stderr,"audio_set_channels : %s\n",alGetErrorString(oserror())); return 0; }
void *OpenPlay(struct FFTSound *fftsound){ struct Sgiplay *sgiplay; sgiplay=malloc(sizeof(struct Sgiplay)); sgiplay->out_c = alNewConfig(); alSetQueueSize(sgiplay->out_c, _I); alSetSampFmt(sgiplay->out_c,AL_SAMPFMT_DOUBLE); alSetChannels(sgiplay->out_c, fftsound->samps_per_frame); sgiplay->out_port = alOpenPort("Ceres Play", "w", sgiplay->out_c); if(!sgiplay->out_port){ printf("Couldn't open output port: %s\n",alGetErrorString(oserror())); free(sgiplay); return NULL; } return sgiplay; }
Bool audriv_play_open(void) /* audio を演奏用に開き,いつでも audriv_write() により演奏可能な * 状態にします.既に開いている場合はなにも行いません. * 成功した場合は True を,失敗した場合は False を返します. */ { if(out) return True; if(audriv_al_set_width(out_config, play_encoding) < 0) { audriv_err(ALERROR); return False; } alSetChannels(out_config, play_nchannels); out = alOpenPort("audriv", "w", out_config); if(!out) { audriv_err(ALERROR); return False; } if(audriv_al_set_rate(out, play_sample_rate) == False) { audriv_err(ALERROR); alClosePort(out); out = NULL; return False; } alSetConfig(out, out_config); reset_samples = 0; play_counter = 0; return True; }
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); }
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_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) { 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; }
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; }
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() { LS_DATA ls_data; FILE *fp; double gains[MAX_CHANNELS]; int azimuth=-10; int elevation=14; double *gainptr, gain; short *inptr,*outptr; short out[BUFFER_LENGTH][MAX_CHANNELS]; ALconfig c; AFfilehandle fh; ALport p; short *in; long frames; int i,j,k; int numchannels = 8; /* change this according your output device*/ int ls_set_dim = 3; int ls_num = 8; int ls_dirs[MAX_FIELD_AM]={-30,0, 30,0, -45,45, 45,45, -90,0, 90,0, 180,0, 180,45}; /* change these according to your loudspeaker positioning*/ /* defining loudspeaker data */ define_loudspeakers(&ls_data, ls_set_dim, ls_num, ls_dirs); /* ls_data is a struct containing matrices etc ls_set_dim is 2 if loudspeakers are on a (horizontal) plane ls_set_dim is 3 if also elevated or descended loudpeakers exist ls_num is the number of loudspeakers ls_dirs is an array containing the angular directions of loudsp*/ /* gain factors for virtual source in direction (int azimuth, int elevation) */ vbap(gains, &ls_data, azimuth, elevation); /* panning monophonic stream float *in to multiple outputs float *out[] with gain factors float *gains */ /* input audio*/ if((fh=afOpenFile("myaiff.aiff","r",0))==NULL){ fprintf(stderr, "Could not open file myaiff.aiff\n"); exit(-1); } frames=AFgetframecnt(fh,AF_DEFAULT_TRACK); if(afGetChannels(fh, AF_DEFAULT_TRACK) != 1){ fprintf(stderr, "Supports only mono aiff-files\n"); exit(-1); } in= malloc(frames*sizeof(short)*2); afReadFrames(fh,AF_DEFAULT_TRACK,in,frames); /*opening the audio port*/ c = alNewConfig(); if (!c) { printf("Couldn't create ALconfig:%s\n", alGetErrorString(oserror())); exit(-1); } alSetChannels(c,numchannels); ALsetqueuesize(c,BUFFER_LENGTH); p = alOpenPort("alVBAP example","w",c); if (!p) { printf("port open failed:%s\n", alGetErrorString(oserror())); exit(-1); } fprintf(stderr,"\nPanning audio"); for(j=0;j<(frames/BUFFER_LENGTH);j++){ inptr = &(in[j*BUFFER_LENGTH]); /* audio to be panned */ outptr= out[0]; for (i=0; i<BUFFER_LENGTH; i++){ /* panning */ gainptr=gains; for (k=0; k<numchannels; k++){ *outptr++ = (short) ((double) *inptr * *gainptr++); } inptr++; } alWriteFrames(p, out, BUFFER_LENGTH); /* write frames */ fprintf(stderr,"."); } /*write rest samples out*/ inptr = &(in[j*BUFFER_LENGTH]); /* partial buffer */ outptr= out[0]; for (i=0; i<(frames-BUFFER_LENGTH*j); i++){ /* panning */ gainptr=gains; for (k=0; k<numchannels; k++){ *outptr++ = (short) ((double) *inptr * *gainptr++); } inptr++; } for (;i<BUFFER_LENGTH; i++){ /* zeros */ for (k=0; k<numchannels; k++){ *outptr++ = 0; } } alWriteFrames(p, out, BUFFER_LENGTH); /* write frames */ fprintf(stderr,"."); printf("\n\nDone!\n\n"); }
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; }