本文整理汇总了C++中AUDIO_INITINFO函数的典型用法代码示例。如果您正苦于以下问题:C++ AUDIO_INITINFO函数的具体用法?C++ AUDIO_INITINFO怎么用?C++ AUDIO_INITINFO使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了AUDIO_INITINFO函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pa_solaris_auto_format
static int pa_solaris_auto_format(int fd, int mode, pa_sample_spec *ss) {
audio_info_t info;
AUDIO_INITINFO(&info);
if (mode != O_RDONLY) {
info.play.sample_rate = ss->rate;
info.play.channels = ss->channels;
switch (ss->format) {
case PA_SAMPLE_U8:
info.play.precision = 8;
info.play.encoding = AUDIO_ENCODING_LINEAR;
break;
case PA_SAMPLE_ALAW:
info.play.precision = 8;
info.play.encoding = AUDIO_ENCODING_ALAW;
break;
case PA_SAMPLE_ULAW:
info.play.precision = 8;
info.play.encoding = AUDIO_ENCODING_ULAW;
break;
case PA_SAMPLE_S16NE:
info.play.precision = 16;
info.play.encoding = AUDIO_ENCODING_LINEAR;
break;
default:
return -1;
}
}
if (mode != O_WRONLY) {
info.record.sample_rate = ss->rate;
info.record.channels = ss->channels;
switch (ss->format) {
case PA_SAMPLE_U8:
info.record.precision = 8;
info.record.encoding = AUDIO_ENCODING_LINEAR;
break;
case PA_SAMPLE_ALAW:
info.record.precision = 8;
info.record.encoding = AUDIO_ENCODING_ALAW;
break;
case PA_SAMPLE_ULAW:
info.record.precision = 8;
info.record.encoding = AUDIO_ENCODING_ULAW;
break;
case PA_SAMPLE_S16NE:
info.record.precision = 16;
info.record.encoding = AUDIO_ENCODING_LINEAR;
break;
default:
return -1;
}
}
if (ioctl(fd, AUDIO_SETINFO, &info) < 0) {
if (errno == EINVAL)
pa_log("AUDIO_SETINFO: Unsupported sample format.");
else
pa_log("AUDIO_SETINFO: %s", pa_cstrerror(errno));
return -1;
}
return 0;
}
示例2: Pa_QueryDevice
/*********************************************************************
* Try to open the named device.
* If it opens, try to set various rates and formats and fill in
* the device info structure.
*/
PaError Pa_QueryDevice( const char *deviceName, internalPortAudioDevice *pad )
{
int result = paHostError;
int tempDevHandle;
int numChannels, maxNumChannels;
int numSampleRates;
int sampleRate;
int numRatesToTry;
int ratesToTry[9] = {96000, 48000, 44100, 32000, 24000, 22050, 16000, 11025, 8000};
int i;
audio_info_t solaris_info;
audio_device_t device_info;
/* douglas:
we have to do this querying in a slightly different order. apparently
some sound cards will give you different info based on their settins.
e.g. a card might give you stereo at 22kHz but only mono at 44kHz.
the correct order for OSS is: format, channels, sample rate
*/
/*
to check a device for it's capabilities, it's probably better to use the
equivalent "-ctl"-descriptor - MR
*/
char devname[strlen(deviceName) + 4];
snprintf(devname,(strlen(deviceName) + 4),"%sctl",deviceName);
if ((tempDevHandle = open(devname, O_WRONLY|O_NONBLOCK)) == -1 )
{
DBUG(("Pa_QueryDevice: could not open %s\n", deviceName ));
return paHostError;
}
/* Ask OSS what formats are supported by the hardware. */
pad->pad_Info.nativeSampleFormats = 0;
AUDIO_INITINFO(&solaris_info);
/* SAM 12/31/01: Sparc native does mulaw, alaw and PCM.
I think PCM is signed. */
for (i = 8; i <= 32; i += 8) {
solaris_info.play.precision = i;
solaris_info.play.encoding = AUDIO_ENCODING_LINEAR;
/* If there are no errors, add the format. */
if (ioctl(tempDevHandle, AUDIO_SETINFO, &solaris_info) > -1) {
switch (i) {
case 8:
pad->pad_Info.nativeSampleFormats |= paInt8;
break;
case 16:
pad->pad_Info.nativeSampleFormats |= paInt16;
break;
case 24:
pad->pad_Info.nativeSampleFormats |= paInt24;
break;
case 32:
pad->pad_Info.nativeSampleFormats |= paInt32;
break;
}
}
}
maxNumChannels = 0;
for( numChannels = 1; numChannels <= 16; numChannels++ )
{
int temp = numChannels;
DBUG(("Pa_QueryDevice: use SNDCTL_DSP_CHANNELS, numChannels = %d\n", numChannels ))
AUDIO_INITINFO(&solaris_info);
solaris_info.play.channels = temp;
if (ioctl(tempDevHandle, AUDIO_SETINFO, &solaris_info) < 0)
{
/* ioctl() failed so bail out if we already have stereo */
if( numChannels > 2 ) break;
}
else
{
/* ioctl() worked but bail out if it does not support numChannels.
* We don't want to leave gaps in the numChannels supported.
*/
if( (numChannels > 2) && (temp != numChannels) ) break;
DBUG(("Pa_QueryDevice: temp = %d\n", temp ))
if( temp > maxNumChannels ) maxNumChannels = temp; /* Save maximum. */
}
}
pad->pad_Info.maxOutputChannels = maxNumChannels;
DBUG(("Pa_QueryDevice: maxNumChannels = %d\n", maxNumChannels))
/* FIXME - for now, assume maxInputChannels = maxOutputChannels.
* Eventually do separate queries for O_WRONLY and O_RDONLY
*/
pad->pad_Info.maxInputChannels = pad->pad_Info.maxOutputChannels;
DBUG(("Pa_QueryDevice: maxInputChannels = %d\n",
pad->pad_Info.maxInputChannels))
//.........这里部分代码省略.........
示例3: input_sound
static void input_sound(unsigned int sample_rate, unsigned int overlap,
const char *ifname)
{
audio_info_t audioinfo;
audio_info_t audioinfo2;
audio_device_t audiodev;
int fd;
short buffer[8192];
float fbuf[16384];
unsigned int fbuf_cnt = 0;
int i;
short *sp;
if ((fd = open(ifname ? ifname : "/dev/audio", O_RDONLY)) < 0) {
perror("open");
exit (10);
}
if (ioctl(fd, AUDIO_GETDEV, &audiodev) == -1) {
perror("ioctl: AUDIO_GETDEV");
exit (10);
}
AUDIO_INITINFO(&audioinfo);
audioinfo.record.sample_rate = sample_rate;
audioinfo.record.channels = 1;
audioinfo.record.precision = 16;
audioinfo.record.encoding = AUDIO_ENCODING_LINEAR;
/*audioinfo.record.gain = 0x20;
audioinfo.record.port = AUDIO_LINE_IN;
audioinfo.monitor_gain = 0;*/
if (ioctl(fd, AUDIO_SETINFO, &audioinfo) == -1) {
perror("ioctl: AUDIO_SETINFO");
exit (10);
}
if (ioctl(fd, I_FLUSH, FLUSHR) == -1) {
perror("ioctl: I_FLUSH");
exit (10);
}
if (ioctl(fd, AUDIO_GETINFO, &audioinfo2) == -1) {
perror("ioctl: AUDIO_GETINFO");
exit (10);
}
fprintf(stdout, "Audio device: name %s, ver %s, config %s, "
"sampling rate %d\n", audiodev.name, audiodev.version,
audiodev.config, audioinfo.record.sample_rate);
for (;;) {
i = read(fd, sp = buffer, sizeof(buffer));
if (i < 0 && errno != EAGAIN) {
perror("read");
exit(4);
}
if (!i)
break;
if (i > 0) {
if(integer_only)
{
fbuf_cnt = i/sizeof(buffer[0]);
}
else
{
for (; i >= sizeof(buffer[0]); i -= sizeof(buffer[0]), sp++)
fbuf[fbuf_cnt++] = (*sp) * (1.0/32768.0);
if (i)
fprintf(stderr, "warning: noninteger number of samples read\n");
}
if (fbuf_cnt > overlap) {
process_buffer(fbuf, buffer, fbuf_cnt-overlap);
memmove(fbuf, fbuf+fbuf_cnt-overlap, overlap*sizeof(fbuf[0]));
fbuf_cnt = overlap;
}
}
}
close(fd);
}
示例4: SUNAUDIO_OpenDevice
static int
SUNAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
{
const int flags = ((iscapture) ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT);
SDL_AudioFormat format = 0;
audio_info_t info;
/* We don't care what the devname is...we'll try to open anything. */
/* ...but default to first name in the list... */
if (devname == NULL) {
devname = SDL_GetAudioDeviceName(0, iscapture);
if (devname == NULL) {
return SDL_SetError("No such audio device");
}
}
/* Initialize all variables that we clean on shutdown */
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
if (this->hidden == NULL) {
return SDL_OutOfMemory();
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
/* Open the audio device */
this->hidden->audio_fd = open(devname, flags, 0);
if (this->hidden->audio_fd < 0) {
return SDL_SetError("Couldn't open %s: %s", devname, strerror(errno));
}
#ifdef AUDIO_SETINFO
int enc;
#endif
int desired_freq = this->spec.freq;
/* Determine the audio parameters from the AudioSpec */
switch (SDL_AUDIO_BITSIZE(this->spec.format)) {
case 8:
{ /* Unsigned 8 bit audio data */
this->spec.format = AUDIO_U8;
#ifdef AUDIO_SETINFO
enc = AUDIO_ENCODING_LINEAR8;
#endif
}
break;
case 16:
{ /* Signed 16 bit audio data */
this->spec.format = AUDIO_S16SYS;
#ifdef AUDIO_SETINFO
enc = AUDIO_ENCODING_LINEAR;
#endif
}
break;
default:
{
/* !!! FIXME: fallback to conversion on unsupported types! */
return SDL_SetError("Unsupported audio format");
}
}
this->hidden->audio_fmt = this->spec.format;
this->hidden->ulaw_only = 0; /* modern Suns do support linear audio */
#ifdef AUDIO_SETINFO
for (;;) {
audio_info_t info;
AUDIO_INITINFO(&info); /* init all fields to "no change" */
/* Try to set the requested settings */
info.play.sample_rate = this->spec.freq;
info.play.channels = this->spec.channels;
info.play.precision = (enc == AUDIO_ENCODING_ULAW)
? 8 : this->spec.format & 0xff;
info.play.encoding = enc;
if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) == 0) {
/* Check to be sure we got what we wanted */
if (ioctl(this->hidden->audio_fd, AUDIO_GETINFO, &info) < 0) {
return SDL_SetError("Error getting audio parameters: %s",
strerror(errno));
}
if (info.play.encoding == enc
&& info.play.precision == (this->spec.format & 0xff)
&& info.play.channels == this->spec.channels) {
/* Yow! All seems to be well! */
this->spec.freq = info.play.sample_rate;
break;
}
}
switch (enc) {
case AUDIO_ENCODING_LINEAR8:
/* unsigned 8bit apparently not supported here */
enc = AUDIO_ENCODING_LINEAR;
this->spec.format = AUDIO_S16SYS;
break; /* try again */
case AUDIO_ENCODING_LINEAR:
//.........这里部分代码省略.........
示例5: perror
FILE *out_file_open(char *outFile, int rate, int *channels)
{
FILE *fout=NULL;
/*Open output file*/
if (strlen(outFile)==0)
{
#if defined HAVE_SYS_SOUNDCARD_H
int audio_fd, format, stereo;
audio_fd=open("/dev/dsp", O_WRONLY);
if (audio_fd<0)
{
perror("Cannot open /dev/dsp");
exit(1);
}
format=AFMT_S16_NE;
// format=AFMT_S16_LE;
if (ioctl(audio_fd, SNDCTL_DSP_SETFMT, &format)==-1)
{
perror("SNDCTL_DSP_SETFMT");
close(audio_fd);
exit(1);
}
stereo=0;
if (*channels==2)
stereo=1;
if (ioctl(audio_fd, SNDCTL_DSP_STEREO, &stereo)==-1)
{
perror("SNDCTL_DSP_STEREO");
close(audio_fd);
exit(1);
}
if (stereo!=0)
{
if (*channels==1)
fprintf (stderr, "Cannot set mono mode, will decode in stereo\n");
*channels=2;
}
if (ioctl(audio_fd, SNDCTL_DSP_SPEED, &rate)==-1)
{
perror("SNDCTL_DSP_SPEED");
close(audio_fd);
exit(1);
}
fout = fdopen(audio_fd, "w");
printf ("/dev/dsp opened");
#elif defined HAVE_SYS_AUDIOIO_H
audio_info_t info;
int audio_fd;
audio_fd = open("/dev/audio", O_WRONLY);
if (audio_fd<0)
{
perror("Cannot open /dev/audio");
exit(1);
}
AUDIO_INITINFO(&info);
#ifdef AUMODE_PLAY /* NetBSD/OpenBSD */
info.mode = AUMODE_PLAY;
#endif
info.play.encoding = AUDIO_ENCODING_SLINEAR;
info.play.precision = 16;
info.play.sample_rate = rate;
info.play.channels = *channels;
if (ioctl(audio_fd, AUDIO_SETINFO, &info) < 0)
{
perror ("AUDIO_SETINFO");
exit(1);
}
fout = fdopen(audio_fd, "w");
#elif defined WIN32 || defined _WIN32
{
unsigned int speex_channels = *channels;
if (Set_WIN_Params (INVALID_FILEDESC, rate, SAMPLE_SIZE, speex_channels))
{
fprintf (stderr, "Can't access %s\n", "WAVE OUT");
exit(1);
}
}
#else
fprintf (stderr, "No soundcard support\n");
exit(1);
#endif
}
return fout;
}
示例6: sio_sun_setpar
static int
sio_sun_setpar(struct sio_hdl *sh, struct sio_par *par)
{
#define NRETRIES 8
struct sio_sun_hdl *hdl = (struct sio_sun_hdl *)sh;
struct audio_info aui;
unsigned int i, infr, ibpf, onfr, obpf;
unsigned int bufsz, round;
unsigned int rate, req_rate, prec, enc;
/*
* try to set parameters until the device accepts
* a common encoding and rate for play and record
*/
rate = par->rate;
prec = par->bits;
sio_sun_enctoinfo(hdl, &enc, par);
for (i = 0;; i++) {
if (i == NRETRIES) {
DPRINTF("sio_sun_setpar: couldn't set parameters\n");
hdl->sio.eof = 1;
return 0;
}
AUDIO_INITINFO(&aui);
if (hdl->sio.mode & SIO_PLAY) {
aui.play.sample_rate = rate;
aui.play.precision = prec;
aui.play.encoding = enc;
aui.play.channels = par->pchan;
}
if (hdl->sio.mode & SIO_REC) {
aui.record.sample_rate = rate;
aui.record.precision = prec;
aui.record.encoding = enc;
aui.record.channels = par->rchan;
}
DPRINTFN(2, "sio_sun_setpar: %i: trying pars = %u/%u/%u\n",
i, rate, prec, enc);
if (ioctl(hdl->fd, AUDIO_SETINFO, &aui) < 0 && errno != EINVAL) {
DPERROR("sio_sun_setpar: setinfo(pars)");
hdl->sio.eof = 1;
return 0;
}
if (ioctl(hdl->fd, AUDIO_GETINFO, &aui) < 0) {
DPERROR("sio_sun_setpar: getinfo(pars)");
hdl->sio.eof = 1;
return 0;
}
enc = (hdl->sio.mode & SIO_REC) ?
aui.record.encoding : aui.play.encoding;
switch (enc) {
case AUDIO_ENCODING_SLINEAR_LE:
case AUDIO_ENCODING_SLINEAR_BE:
case AUDIO_ENCODING_ULINEAR_LE:
case AUDIO_ENCODING_ULINEAR_BE:
case AUDIO_ENCODING_SLINEAR:
case AUDIO_ENCODING_ULINEAR:
break;
default:
DPRINTF("sio_sun_setpar: couldn't set linear encoding\n");
hdl->sio.eof = 1;
return 0;
}
if (hdl->sio.mode != (SIO_REC | SIO_PLAY))
break;
if (aui.play.sample_rate == aui.record.sample_rate &&
aui.play.precision == aui.record.precision &&
aui.play.encoding == aui.record.encoding)
break;
if (i < NRETRIES / 2) {
rate = aui.play.sample_rate;
prec = aui.play.precision;
enc = aui.play.encoding;
} else {
rate = aui.record.sample_rate;
prec = aui.record.precision;
enc = aui.record.encoding;
}
}
/*
* If the rate that the hardware is using is different than
* the requested rate, scale buffer sizes so they will be the
* same time duration as what was requested. This just gets
* the rates to use for scaling, that actual scaling is done
* later.
*/
rate = (hdl->sio.mode & SIO_REC) ? aui.record.sample_rate :
aui.play.sample_rate;
req_rate = rate;
if (par->rate && par->rate != ~0U)
req_rate = par->rate;
/*
* if block size and buffer size are not both set then
* set the blocksize to half the buffer size
*/
bufsz = par->appbufsz;
round = par->round;
if (bufsz != ~0U) {
//.........这里部分代码省略.........
示例7: ReportError
//PORTING: This function contains a ton of OS specific stuff. Hack and
// slash at will.
Error SoundCardPMO::Init(OutputInfo * info)
{
m_properlyInitialized = false;
if (!info)
{
info = myInfo;
}
else
{
// got info, so this is the beginning...
if ((audio_fd = open("/dev/audio", O_WRONLY, 0)) < 0)
{
if (errno == EBUSY)
{
ReportError("Audio device is busy. Please make sure that "
"another program is not using the device.");
return (Error) pmoError_DeviceOpenFailed;
}
else
{
ReportError("Cannot open audio device. Please make sure that "
"the audio device is properly configured.");
return (Error) pmoError_DeviceOpenFailed;
}
}
m_iDataSize = info->max_buffer_size;
}
int fd = audio_fd;
struct audio_info ainfo;
if (ioctl(audio_fd, AUDIO_GETINFO, &ainfo) < 0)
{
ReportError("Cannot get the flags on the audio device.");
return (Error) pmoError_IOCTL_F_GETFL;
}
audio_fd = fd;
channels = info->number_of_channels;
for (unsigned int i = 0; i < info->number_of_channels; ++i)
bufferp[i] = buffer + i;
// configure the device:
int play_precision = 16;
// int play_stereo = channels - 1;
int play_sample_rate = info->samples_per_second;
if (ioctl(audio_fd, I_FLUSH, FLUSHRW) == -1)
{
ReportError("Cannot reset the soundcard.");
return (Error) pmoError_IOCTL_SNDCTL_DSP_RESET;
}
AUDIO_INITINFO(&ainfo);
ainfo.play.precision = play_precision;
ainfo.play.channels = channels;
ainfo.play.sample_rate = play_sample_rate;
ainfo.play.encoding = AUDIO_ENCODING_LINEAR;
if (ioctl(audio_fd, AUDIO_SETINFO, &ainfo) == -1)
{
ReportError("Cannot set the soundcard's sampling speed.");
return (Error) pmoError_IOCTL_SNDCTL_DSP_SPEED;
}
myInfo->bits_per_sample = info->bits_per_sample;
myInfo->number_of_channels = info->number_of_channels;
myInfo->samples_per_second = info->samples_per_second;
myInfo->max_buffer_size = info->max_buffer_size;
m_properlyInitialized = true;
// PORTING: The GETOSPACE ioctl determines how much space the kernel's
// output buffer has. Your OS may not have this.
m_iTotalFragments = 2048; /* An arbitrary value of 2048. */
m_iOutputBufferSize = play_precision * m_iTotalFragments;
m_iBytesPerSample = info->number_of_channels * (info->bits_per_sample / 8);
return kError_NoErr;
}
示例8: rplay_audio_init
//.........这里部分代码省略.........
rplay_audio_table = dbri_table; /* use the dbri table */
}
else
{
report(REPORT_ERROR, "`%s' unknown audio device detected\n", d.name);
return -1;
}
/* Verify the precision and format. */
switch (rplay_audio_precision)
{
case 8:
if (rplay_audio_format != RPLAY_FORMAT_ULAW
&& rplay_audio_format != RPLAY_FORMAT_LINEAR_8)
{
report(REPORT_ERROR, "rplay_audio_init: can't use %d bits with format=%d\n",
rplay_audio_precision, rplay_audio_format);
return -1;
}
break;
case 16:
if (rplay_audio_format != RPLAY_FORMAT_LINEAR_16)
{
report(REPORT_ERROR, "rplay_audio_init: can't use %d bits with format=%d\n",
rplay_audio_precision, rplay_audio_format);
return -1;
}
break;
default:
report(REPORT_ERROR, "rplay_audio_init: `%d' unsupported audio precision\n",
rplay_audio_precision);
return -1;
}
AUDIO_INITINFO(&a);
switch (rplay_audio_format)
{
case RPLAY_FORMAT_ULAW:
a.play.encoding = AUDIO_ENCODING_ULAW;
break;
case RPLAY_FORMAT_LINEAR_8:
case RPLAY_FORMAT_LINEAR_16:
a.play.encoding = AUDIO_ENCODING_LINEAR;
break;
default:
report(REPORT_ERROR, "rplay_audio_init: unsupported audio format `%d'\n",
rplay_audio_format);
return -1;
}
/* Audio port. */
if (rplay_audio_port == RPLAY_AUDIO_PORT_NONE)
{
a.play.port = ~0; /* see AUDIO_INITINFO in /usr/include/sys/audioio.h. */
}
else
{
a.play.port = 0;
if (BIT(rplay_audio_port, RPLAY_AUDIO_PORT_LINEOUT))
{
#ifdef AUDIO_LINE_OUT
SET_BIT(a.play.port, AUDIO_LINE_OUT);
#else
CLR_BIT(rplay_audio_port, RPLAY_AUDIO_PORT_LINEOUT);
#endif
}
if (BIT(rplay_audio_port, RPLAY_AUDIO_PORT_HEADPHONE))
{
#ifdef AUDIO_HEADPHONE
SET_BIT(a.play.port, AUDIO_HEADPHONE);
#else
CLR_BIT(rplay_audio_port, RPLAY_AUDIO_PORT_HEADPHONE);
#endif
}
if (BIT(rplay_audio_port, RPLAY_AUDIO_PORT_SPEAKER))
{
#ifdef AUDIO_SPEAKER
SET_BIT(a.play.port, AUDIO_SPEAKER);
#endif
/* Assume speaker is okay. */
}
}
a.play.sample_rate = rplay_audio_sample_rate;
a.play.precision = rplay_audio_precision;
a.play.channels = rplay_audio_channels;
if (ioctl(rplay_audio_fd, AUDIO_SETINFO, &a) < 0)
{
report(REPORT_ERROR, "rplay_audio_init: AUDIO_SETINFO: %s\n", sys_err_str(errno));
return -1;
}
return 0;
}
示例9: DSP_OpenAudio
int
DSP_OpenAudio(_THIS, SDL_AudioSpec * spec)
{
char audiodev[1024];
#ifdef AUDIO_SETINFO
int enc;
#endif
int desired_freq = spec->freq;
/* Initialize our freeable variables, in case we fail */
audio_fd = -1;
mixbuf = NULL;
ulaw_buf = NULL;
/* Determine the audio parameters from the AudioSpec */
switch (SDL_AUDIO_BITSIZE(spec->format)) {
case 8:
{ /* Unsigned 8 bit audio data */
spec->format = AUDIO_U8;
#ifdef AUDIO_SETINFO
enc = AUDIO_ENCODING_LINEAR8;
#endif
}
break;
case 16:
{ /* Signed 16 bit audio data */
spec->format = AUDIO_S16SYS;
#ifdef AUDIO_SETINFO
enc = AUDIO_ENCODING_LINEAR;
#endif
}
break;
default:
{
/* !!! FIXME: fallback to conversion on unsupported types! */
SDL_SetError("Unsupported audio format");
return (-1);
}
}
audio_fmt = spec->format;
/* Open the audio device */
audio_fd = SDL_OpenAudioPath(audiodev, sizeof(audiodev), OPEN_FLAGS, 1);
if (audio_fd < 0) {
SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno));
return (-1);
}
ulaw_only = 0; /* modern Suns do support linear audio */
#ifdef AUDIO_SETINFO
for (;;) {
audio_info_t info;
AUDIO_INITINFO(&info); /* init all fields to "no change" */
/* Try to set the requested settings */
info.play.sample_rate = spec->freq;
info.play.channels = spec->channels;
info.play.precision = (enc == AUDIO_ENCODING_ULAW)
? 8 : spec->format & 0xff;
info.play.encoding = enc;
if (ioctl(audio_fd, AUDIO_SETINFO, &info) == 0) {
/* Check to be sure we got what we wanted */
if (ioctl(audio_fd, AUDIO_GETINFO, &info) < 0) {
SDL_SetError("Error getting audio parameters: %s",
strerror(errno));
return -1;
}
if (info.play.encoding == enc
&& info.play.precision == (spec->format & 0xff)
&& info.play.channels == spec->channels) {
/* Yow! All seems to be well! */
spec->freq = info.play.sample_rate;
break;
}
}
switch (enc) {
case AUDIO_ENCODING_LINEAR8:
/* unsigned 8bit apparently not supported here */
enc = AUDIO_ENCODING_LINEAR;
spec->format = AUDIO_S16SYS;
break; /* try again */
case AUDIO_ENCODING_LINEAR:
/* linear 16bit didn't work either, resort to µ-law */
enc = AUDIO_ENCODING_ULAW;
spec->channels = 1;
spec->freq = 8000;
spec->format = AUDIO_U8;
ulaw_only = 1;
break;
default:
/* oh well... */
SDL_SetError("Error setting audio parameters: %s",
strerror(errno));
//.........这里部分代码省略.........
示例10: xf86OSRingBell
void
xf86OSRingBell(int loudness, int pitch, int duration)
{
static short samples[BELL_SAMPLES];
static short silence[BELL_SAMPLES]; /* "The Sound of Silence" */
static int lastFreq;
int cnt;
int i;
int written;
int repeats;
int freq;
audio_info_t audioInfo;
struct iovec iov[IOV_MAX];
int iovcnt;
double ampl, cyclen, phase;
int audioFD;
if ((loudness <= 0) || (pitch <= 0) || (duration <= 0)) {
return;
}
lastFreq = 0;
memset(silence, 0, sizeof(silence));
audioFD = open(AUDIO_DEVICE, O_WRONLY | O_NONBLOCK);
if (audioFD == -1) {
xf86Msg(X_ERROR, "Bell: cannot open audio device \"%s\": %s\n",
AUDIO_DEVICE, strerror(errno));
return;
}
freq = pitch;
freq = min(freq, (BELL_RATE / 2) - 1);
freq = max(freq, 2 * BELL_HZ);
/*
* Ensure full waves per buffer
*/
freq -= freq % BELL_HZ;
if (freq != lastFreq) {
lastFreq = freq;
ampl = 16384.0;
cyclen = (double) freq / (double) BELL_RATE;
phase = 0.0;
for (i = 0; i < BELL_SAMPLES; i++) {
samples[i] = (short) (ampl * sin(2.0 * M_PI * phase));
phase += cyclen;
if (phase >= 1.0)
phase -= 1.0;
}
}
repeats = (duration + (BELL_MS / 2)) / BELL_MS;
repeats = max(repeats, BELL_MIN);
loudness = max(0, loudness);
loudness = min(loudness, 100);
#ifdef DEBUG
ErrorF("BELL : freq %d volume %d duration %d repeats %d\n",
freq, loudness, duration, repeats);
#endif
AUDIO_INITINFO(&audioInfo);
audioInfo.play.encoding = AUDIO_ENCODING_LINEAR;
audioInfo.play.sample_rate = BELL_RATE;
audioInfo.play.channels = 2;
audioInfo.play.precision = 16;
audioInfo.play.gain = min(AUDIO_MAX_GAIN, AUDIO_MAX_GAIN * loudness / 100);
if (ioctl(audioFD, AUDIO_SETINFO, &audioInfo) < 0){
xf86Msg(X_ERROR,
"Bell: AUDIO_SETINFO failed on audio device \"%s\": %s\n",
AUDIO_DEVICE, strerror(errno));
close(audioFD);
return;
}
iovcnt = 0;
for (cnt = 0; cnt <= repeats; cnt++) {
if (cnt == repeats) {
/* Insert a bit of silence so that multiple beeps are distinct and
* not compressed into a single tone.
*/
iov[iovcnt].iov_base = (char *) silence;
iov[iovcnt++].iov_len = sizeof(silence);
} else {
iov[iovcnt].iov_base = (char *) samples;
iov[iovcnt++].iov_len = sizeof(samples);
}
if ((iovcnt >= IOV_MAX) || (cnt == repeats)) {
written = writev(audioFD, iov, iovcnt);
if ((written < ((int)(sizeof(samples) * iovcnt)))) {
/* audio buffer was full! */
//.........这里部分代码省略.........
示例11: init
static int init(struct options *options)
{
char **parm = options->driver_parm;
audio_info_t ainfo;
int gain = 128;
int bsize = 32 * 1024;
parm_init(parm);
chkparm1("gain", gain = strtoul(token, NULL, 0));
chkparm1("buffer", bsize = strtoul(token, NULL, 0));
parm_end();
if ((audio_fd = open("/dev/sound", O_WRONLY)) == -1)
return -1;
/* try to open audioctldevice */
if ((audioctl_fd = open("/dev/audioctl", O_RDWR)) < 0) {
fprintf(stderr, "couldn't open audioctldevice\n");
close(audio_fd);
return -1;
}
/* empty buffers before change config */
ioctl(audio_fd, AUDIO_DRAIN, 0); /* drain everything out */
ioctl(audio_fd, AUDIO_FLUSH); /* flush audio */
ioctl(audioctl_fd, AUDIO_FLUSH); /* flush audioctl */
/* get audio parameters. */
if (ioctl(audioctl_fd, AUDIO_GETINFO, &ainfo) < 0) {
fprintf(stderr, "AUDIO_GETINFO failed!\n");
close(audio_fd);
close(audioctl_fd);
return -1;
}
close(audioctl_fd);
if (gain < AUDIO_MIN_GAIN)
gain = AUDIO_MIN_GAIN;
if (gain > AUDIO_MAX_GAIN)
gain = AUDIO_MAX_GAIN;
AUDIO_INITINFO(&ainfo);
ainfo.play.sample_rate = options->rate;
ainfo.play.channels = options->format & XMP_FORMAT_MONO ? 1 : 2;
if (options->format & XMP_FORMAT_8BIT) {
ainfo.play.precision = 8;
ainfo.play.precision = AUDIO_ENCODING_ULINEAR;
options->format |= XMP_FORMAT_UNSIGNED;
} else {
ainfo.play.precision = 16;
ainfo.play.precision = AUDIO_ENCODING_SLINEAR;
options->format &= ~XMP_FORMAT_UNSIGNED;
}
ainfo.play.gain = gain;
ainfo.play.buffer_size = bsize;
if (ioctl(audio_fd, AUDIO_SETINFO, &ainfo) == -1) {
close(audio_fd);
return -1;
}
return 0;
}
示例12: perror
FILE *out_file_open(char *outFile, int *wav_format, int rate, int mapping_family, int *channels)
{
FILE *fout=NULL;
/*Open output file*/
if (strlen(outFile)==0)
{
#if defined HAVE_SYS_SOUNDCARD_H
int audio_fd, format, stereo;
audio_fd=open("/dev/dsp", O_WRONLY);
if (audio_fd<0)
{
perror("Cannot open /dev/dsp");
quit(1);
}
format=AFMT_S16_NE;
if (ioctl(audio_fd, SNDCTL_DSP_SETFMT, &format)==-1)
{
perror("SNDCTL_DSP_SETFMT");
close(audio_fd);
quit(1);
}
stereo=0;
if (*channels==2)
stereo=1;
if (ioctl(audio_fd, SNDCTL_DSP_STEREO, &stereo)==-1)
{
perror("SNDCTL_DSP_STEREO");
close(audio_fd);
quit(1);
}
if (stereo!=0)
{
if (*channels==1)
fprintf (stderr, "Cannot set mono mode, will decode in stereo\n");
*channels=2;
}
if (ioctl(audio_fd, SNDCTL_DSP_SPEED, &rate)==-1)
{
perror("SNDCTL_DSP_SPEED");
close(audio_fd);
quit(1);
}
fout = fdopen(audio_fd, "w");
if(!fout)
{
perror("Cannot open output");
quit(1);
}
#elif defined HAVE_LIBSNDIO
struct sio_par par;
hdl = sio_open(NULL, SIO_PLAY, 0);
if (!hdl)
{
fprintf(stderr, "Cannot open sndio device\n");
quit(1);
}
sio_initpar(&par);
par.sig = 1;
par.bits = 16;
par.rate = rate;
par.pchan = *channels;
if (!sio_setpar(hdl, &par) || !sio_getpar(hdl, &par) ||
par.sig != 1 || par.bits != 16 || par.rate != rate) {
fprintf(stderr, "could not set sndio parameters\n");
quit(1);
}
*channels = par.pchan;
if (!sio_start(hdl)) {
fprintf(stderr, "could not start sndio\n");
quit(1);
}
#elif defined HAVE_SYS_AUDIOIO_H
audio_info_t info;
int audio_fd;
audio_fd = open("/dev/audio", O_WRONLY);
if (audio_fd<0)
{
perror("Cannot open /dev/audio");
quit(1);
}
AUDIO_INITINFO(&info);
#ifdef AUMODE_PLAY /* NetBSD/OpenBSD */
info.mode = AUMODE_PLAY;
#endif
info.play.encoding = AUDIO_ENCODING_SLINEAR;
info.play.precision = 16;
info.play.input_sample_rate = rate;
info.play.channels = *channels;
if (ioctl(audio_fd, AUDIO_SETINFO, &info) < 0)
{
perror ("AUDIO_SETINFO");
//.........这里部分代码省略.........
示例13: StartStream
//.........这里部分代码省略.........
ThreadPauseConfrm = false;
CloseThread = false;
StreamPause = false;
#ifndef USE_LIBAO
#ifdef WIN32
ThreadPauseEnable = true;
WaveOutThreadHandle = CreateThread(NULL, 0x00, &WaveOutThread, NULL, 0x00,
&WaveOutThreadID);
if(WaveOutThreadHandle == NULL)
return 0xC8; // CreateThread failed
CloseHandle(WaveOutThreadHandle);
RetVal = waveOutOpen(&hWaveOut, ((UINT)DeviceID - 1), &WaveFmt, 0x00, 0x00, CALLBACK_NULL);
if(RetVal != MMSYSERR_NOERROR)
#else
ThreadPauseEnable = false;
#ifdef __NetBSD__
hWaveOut = open("/dev/audio", O_WRONLY);
#else
hWaveOut = open("/dev/dsp", O_WRONLY);
#endif
if (hWaveOut < 0)
#endif
#else // ifdef USE_LIBAO
ao_initialize();
ThreadPauseEnable = false;
ao_fmt.bits = WaveFmt.wBitsPerSample;
ao_fmt.rate = WaveFmt.nSamplesPerSec;
ao_fmt.channels = WaveFmt.nChannels;
ao_fmt.byte_format = AO_FMT_NATIVE;
ao_fmt.matrix = NULL;
dev_ao = ao_open_live(ao_default_driver_id(), &ao_fmt, NULL);
if (dev_ao == NULL)
#endif
{
CloseThread = true;
return 0xC0; // waveOutOpen failed
}
WaveOutOpen = true;
//sprintf(TestStr, "Buffer 0,0:\t%p\nBuffer 0,1:\t%p\nBuffer 1,0:\t%p\nBuffer 1,1:\t%p\n",
// &BufferOut[0][0], &BufferOut[0][1], &BufferOut[1][0], &BufferOut[1][1]);
//AfxMessageBox(TestStr);
#ifndef USE_LIBAO
#ifdef WIN32
for (Cnt = 0x00; Cnt < AUDIOBUFFERU; Cnt ++)
{
WaveHdrOut[Cnt].lpData = BufferOut[Cnt]; // &BufferOut[Cnt][0x00];
WaveHdrOut[Cnt].dwBufferLength = BUFFERSIZE;
WaveHdrOut[Cnt].dwBytesRecorded = 0x00;
WaveHdrOut[Cnt].dwUser = 0x00;
WaveHdrOut[Cnt].dwFlags = 0x00;
WaveHdrOut[Cnt].dwLoops = 0x00;
WaveHdrOut[Cnt].lpNext = NULL;
WaveHdrOut[Cnt].reserved = 0x00;
RetVal = waveOutPrepareHeader(hWaveOut, &WaveHdrOut[Cnt], sizeof(WAVEHDR));
WaveHdrOut[Cnt].dwFlags |= WHDR_DONE;
}
#elif defined(__NetBSD__)
AUDIO_INITINFO(&AudioInfo);
AudioInfo.mode = AUMODE_PLAY;
AudioInfo.play.sample_rate = WaveFmt.nSamplesPerSec;
AudioInfo.play.channels = WaveFmt.nChannels;
AudioInfo.play.precision = WaveFmt.wBitsPerSample;
AudioInfo.play.encoding = AUDIO_ENCODING_SLINEAR;
RetVal = ioctl(hWaveOut, AUDIO_SETINFO, &AudioInfo);
if (RetVal)
printf("Error setting audio information!\n");
#else
ArgVal = (AUDIOBUFFERU << 16) | BUFSIZELD;
RetVal = ioctl(hWaveOut, SNDCTL_DSP_SETFRAGMENT, &ArgVal);
if (RetVal)
printf("Error setting Fragment Size!\n");
ArgVal = AFMT_S16_NE;
RetVal = ioctl(hWaveOut, SNDCTL_DSP_SETFMT, &ArgVal);
if (RetVal)
printf("Error setting Format!\n");
ArgVal = WaveFmt.nChannels;
RetVal = ioctl(hWaveOut, SNDCTL_DSP_CHANNELS, &ArgVal);
if (RetVal)
printf("Error setting Channels!\n");
ArgVal = WaveFmt.nSamplesPerSec;
RetVal = ioctl(hWaveOut, SNDCTL_DSP_SPEED, &ArgVal);
if (RetVal)
printf("Error setting Sample Rate!\n");
#endif
#endif // USE_LIBAO
if (SoundLog)
SaveFile(0x00000000, NULL);
PauseThread = false;
return 0x00;
}
示例14: adin_mic_open
/**
* Open the specified device and check capability of the opening device.
*
* @param devstr [in] device string to open
*
* @return TRUE on success, FALSE on failure.
*/
static boolean
adin_mic_open(char *devstr)
{
Audio_hdr Dev_hdr, old_hdr;
double vol;
/* open the device */
if ((afd = open(devstr, O_RDONLY)) == -1) {
if (errno == EBUSY) {
jlog("Error: adin_sun4: audio device %s is busy\n", devstr);
return(FALSE);
} else {
jlog("Error: adin_sun4: unable to open %s\n",devstr);
return(FALSE);
}
}
/* set recording port to microphone */
AUDIO_INITINFO(&ainfo);
ainfo.record.port = AUDIO_MICROPHONE;
if (ioctl(afd, AUDIO_SETINFO, &ainfo) == -1) {
jlog("Error: adin_sun4: failed to set recording port\n");
return(FALSE);
}
/* set recording parameters */
if (audio_get_record_config(afd, &Dev_hdr) != AUDIO_SUCCESS) {
jlog("Error: adin_sun4: failed to get recording config\n"); return(FALSE);
}
Dev_hdr.sample_rate = srate;
Dev_hdr.samples_per_unit = 1; /* ? I don't know this param. ? */
Dev_hdr.bytes_per_unit = 2;
Dev_hdr.channels = 1;
Dev_hdr.encoding = AUDIO_ENCODING_LINEAR;
if (audio_set_record_config(afd, &Dev_hdr) != AUDIO_SUCCESS) {
jlog("Error: adin_sun4: failed to set recording config\n"); return(FALSE);
}
/* set volume */
vol = (float)volume / (float)100;
if (audio_set_record_gain(afd, &vol) != AUDIO_SUCCESS) {
jlog("Error: adin_sun4: failed to set recording volume\n");
return(FALSE);
}
/* flush buffer */
if((ioctl(afd , I_FLUSH , FLUSHRW)) == -1) {
jlog("Error: adin_sun4: cannot flush input buffer\n");
return(FALSE);
}
/* setup polling */
pfd.fd = afd;
pfd.events = POLLIN;
#if 0
/* pause transfer */
if (audio_pause_record(afd) == AUDIO_ERR_NOEFFECT) {
jlog("Error: adin_sun4: cannot pause audio\n");
return(FALSE);
}
#endif
return(TRUE);
}
示例15: sun_audio_getinfo
static int sun_audio_getinfo(audio_info_t *auinfo)
{
AUDIO_INITINFO(auinfo);
return ioctl(audioctl_fd, AUDIO_GETINFO, auinfo);
}