// 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; }
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; }
// 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 open_sgi(audio_output_t *ao) { int current_dev; ALport port = NULL; ALconfig config = alNewConfig(); ao->userptr = NULL; /* Test for correct completion */ if(config == 0) { error1("open_sgi: %s", alGetErrorString(oserror())); return -1; } /* Setup output device to specified device name. If there is no device name specified in ao structure, use the default for output */ if((ao->device) != NULL) { current_dev = alGetResourceByName(AL_SYSTEM, ao->device, AL_OUTPUT_DEVICE_TYPE); debug2("Dev: %s %i", ao->device, current_dev); if(!current_dev) { int i, numOut; char devname[32]; ALpv pv[1]; ALvalue *alvalues; error2("Invalid audio resource: %s (%s)", ao->device, alGetErrorString(oserror())); if((numOut= alQueryValues(AL_SYSTEM,AL_DEFAULT_OUTPUT,0,0,0,0))>=0) fprintf(stderr, "There are %d output devices on this system.\n", numOut); else { fprintf(stderr, "Can't find output devices. alQueryValues failed: %s\n", alGetErrorString(oserror())); goto open_sgi_bad; } alvalues = malloc(sizeof(ALvalue) * numOut); i = alQueryValues(AL_SYSTEM, AL_DEFAULT_OUTPUT, alvalues, numOut, pv, 0); if(i == -1) error1("alQueryValues: %s", alGetErrorString(oserror())); else { for(i=0; i < numOut; i++) { pv[0].param = AL_NAME; pv[0].value.ptr = devname; pv[0].sizeIn = 32; alGetParams(alvalues[i].i, pv, 1); fprintf(stderr, "%i: %s\n", i, devname); } } free(alvalues); goto open_sgi_bad; } if(alSetDevice(config, current_dev) < 0) { error1("open: alSetDevice : %s",alGetErrorString(oserror())); goto open_sgi_bad; } } else current_dev = AL_DEFAULT_OUTPUT; /* Set the device */ if(alSetDevice(config, current_dev) < 0) { error1("open_sgi: %s", alGetErrorString(oserror())); goto open_sgi_bad; } /* Set port parameters */ if(alSetQueueSize(config, 131069) < 0) { error1("open_sgi: setting audio buffer failed: %s", alGetErrorString(oserror())); goto open_sgi_bad; } if( set_format(ao, config) < 0 || set_rate(ao, config) < 0 || set_channels(ao, config) < 0 ) goto open_sgi_bad; /* Open the audio port */ port = alOpenPort("mpg123-VSC", "w", config); if(port == NULL) { error1("Unable to open audio channel: %s", alGetErrorString(oserror())); goto open_sgi_bad; } ao->userptr = (void*)port; alFreeConfig(config); return 1; open_sgi_bad: /* clean up and return error */ alFreeConfig(config); return -1; }