本文整理汇总了C++中SDL_FirstAudioFormat函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_FirstAudioFormat函数的具体用法?C++ SDL_FirstAudioFormat怎么用?C++ SDL_FirstAudioFormat使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_FirstAudioFormat函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AndroidAUD_OpenDevice
static int
AndroidAUD_OpenDevice(_THIS, const char *devname, int iscapture)
{
SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
int valid_datatype = 0;
//TODO: Sample rates etc
__android_log_print(ANDROID_LOG_INFO, "SDL", "AndroidAudio Open\n");
this->hidden = SDL_malloc(sizeof(*(this->hidden)));
if (!this->hidden) {
SDL_OutOfMemory();
return 0;
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
while ((!valid_datatype) && (test_format)) {
this->spec.format = test_format;
switch (test_format) {
case AUDIO_S8:
/*case AUDIO_S16LSB: */
valid_datatype = 1;
break;
default:
test_format = SDL_NextAudioFormat();
break;
}
}
return 1;
}
示例2: AndroidAUD_OpenDevice
static int
AndroidAUD_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
{
SDL_AudioFormat test_format;
if (iscapture) {
/* TODO: implement capture */
return SDL_SetError("Capture not supported on Android");
}
if (audioDevice != NULL) {
return SDL_SetError("Only one audio device at a time please!");
}
audioDevice = this;
this->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, (sizeof *this->hidden));
if (this->hidden == NULL) {
return SDL_OutOfMemory();
}
test_format = SDL_FirstAudioFormat(this->spec.format);
while (test_format != 0) { /* no "UNKNOWN" constant */
if ((test_format == AUDIO_U8) || (test_format == AUDIO_S16LSB)) {
this->spec.format = test_format;
break;
}
test_format = SDL_NextAudioFormat();
}
if (test_format == 0) {
/* Didn't find a compatible format :( */
return SDL_SetError("No compatible audio format!");
}
if (this->spec.channels > 1) {
this->spec.channels = 2;
} else {
this->spec.channels = 1;
}
if (this->spec.freq < 8000) {
this->spec.freq = 8000;
}
if (this->spec.freq > 48000) {
this->spec.freq = 48000;
}
/* TODO: pass in/return a (Java) device ID, also whether we're opening for input or output */
this->spec.samples = Android_JNI_OpenAudioDevice(this->spec.freq, this->spec.format == AUDIO_U8 ? 0 : 1, this->spec.channels, this->spec.samples);
SDL_CalculateAudioSpec(&this->spec);
if (this->spec.samples == 0) {
/* Init failed? */
return SDL_SetError("Java-side initialization failed!");
}
return 0;
}
示例3: ANDROIDAUDIO_OpenDevice
static int
ANDROIDAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
{
SDL_AudioFormat test_format;
SDL_assert((captureDevice == NULL) || !iscapture);
SDL_assert((audioDevice == NULL) || iscapture);
if (iscapture) {
captureDevice = this;
} else {
audioDevice = this;
}
this->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, (sizeof *this->hidden));
if (this->hidden == NULL) {
return SDL_OutOfMemory();
}
test_format = SDL_FirstAudioFormat(this->spec.format);
while (test_format != 0) { /* no "UNKNOWN" constant */
if ((test_format == AUDIO_U8) || (test_format == AUDIO_S16LSB)) {
this->spec.format = test_format;
break;
}
test_format = SDL_NextAudioFormat();
}
if (test_format == 0) {
/* Didn't find a compatible format :( */
return SDL_SetError("No compatible audio format!");
}
if (this->spec.channels > 1) {
this->spec.channels = 2;
} else {
this->spec.channels = 1;
}
if (this->spec.freq < 8000) {
this->spec.freq = 8000;
}
if (this->spec.freq > 48000) {
this->spec.freq = 48000;
}
/* TODO: pass in/return a (Java) device ID */
this->spec.samples = Android_JNI_OpenAudioDevice(iscapture, this->spec.freq, this->spec.format == AUDIO_U8 ? 0 : 1, this->spec.channels, this->spec.samples);
if (this->spec.samples == 0) {
/* Init failed? */
return SDL_SetError("Java-side initialization failed!");
}
SDL_CalculateAudioSpec(&this->spec);
return 0;
}
示例4: DSOUND_OpenDevice
static int
DSOUND_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
{
HRESULT result;
SDL_bool valid_format = SDL_FALSE;
SDL_bool tried_format = SDL_FALSE;
SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
LPGUID guid = (LPGUID) handle;
/* 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 */
result = pDirectSoundCreate8(guid, &this->hidden->sound, NULL);
if (result != DS_OK) {
DSOUND_CloseDevice(this);
return SetDSerror("DirectSoundCreate", result);
}
while ((!valid_format) && (test_format)) {
switch (test_format) {
case AUDIO_U8:
case AUDIO_S16:
case AUDIO_S32:
case AUDIO_F32:
tried_format = SDL_TRUE;
this->spec.format = test_format;
this->hidden->num_buffers = CreateSecondary(this, NULL);
if (this->hidden->num_buffers > 0) {
valid_format = SDL_TRUE;
}
break;
}
test_format = SDL_NextAudioFormat();
}
if (!valid_format) {
DSOUND_CloseDevice(this);
if (tried_format) {
return -1; /* CreateSecondary() should have called SDL_SetError(). */
}
return SDL_SetError("DirectSound: Unsupported audio format");
}
/* The buffer will auto-start playing in DSOUND_WaitDevice() */
this->hidden->mixlen = this->spec.size;
return 0; /* good to go. */
}
示例5: ANDROIDAUDIO_OpenDevice
static int
ANDROIDAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
{
SDL_AudioFormat test_format;
SDL_assert((captureDevice == NULL) || !iscapture);
SDL_assert((audioDevice == NULL) || iscapture);
if (iscapture) {
captureDevice = this;
} else {
audioDevice = this;
}
this->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, (sizeof *this->hidden));
if (this->hidden == NULL) {
return SDL_OutOfMemory();
}
test_format = SDL_FirstAudioFormat(this->spec.format);
while (test_format != 0) { /* no "UNKNOWN" constant */
if ((test_format == AUDIO_U8) ||
(test_format == AUDIO_S16) ||
(test_format == AUDIO_F32)) {
this->spec.format = test_format;
break;
}
test_format = SDL_NextAudioFormat();
}
if (test_format == 0) {
/* Didn't find a compatible format :( */
return SDL_SetError("No compatible audio format!");
}
if (Android_JNI_OpenAudioDevice(iscapture, &this->spec) < 0) {
return -1;
}
SDL_CalculateAudioSpec(&this->spec);
return 0;
}
示例6: NDSAUD_OpenDevice
static int
NDSAUD_OpenDevice(_THIS, const char *devname, int iscapture)
{
SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
int valid_datatype = 0;
this->hidden = SDL_malloc(sizeof(*(this->hidden)));
if (!this->hidden) {
SDL_OutOfMemory();
return 0;
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
while ((!valid_datatype) && (test_format)) {
this->spec.format = test_format;
switch (test_format) {
case AUDIO_S8:
/*case AUDIO_S16LSB: */
valid_datatype = 1;
break;
default:
test_format = SDL_NextAudioFormat();
break;
}
}
#if 0
/* set the generic sound parameters */
setGenericSound(22050, /* sample rate */
127, /* volume */
64, /* panning/balance */
0); /* sound format */
#endif
return 1;
}
示例7: PULSEAUDIO_OpenDevice
static int
PULSEAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
{
struct SDL_PrivateAudioData *h = NULL;
Uint16 test_format = 0;
pa_sample_spec paspec;
pa_buffer_attr paattr;
pa_channel_map pacmap;
pa_stream_flags_t flags = 0;
int state = 0;
/* 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));
h = this->hidden;
paspec.format = PA_SAMPLE_INVALID;
/* Try for a closest match on audio format */
for (test_format = SDL_FirstAudioFormat(this->spec.format);
(paspec.format == PA_SAMPLE_INVALID) && test_format;) {
#ifdef DEBUG_AUDIO
fprintf(stderr, "Trying format 0x%4.4x\n", test_format);
#endif
switch (test_format) {
case AUDIO_U8:
paspec.format = PA_SAMPLE_U8;
break;
case AUDIO_S16LSB:
paspec.format = PA_SAMPLE_S16LE;
break;
case AUDIO_S16MSB:
paspec.format = PA_SAMPLE_S16BE;
break;
case AUDIO_S32LSB:
paspec.format = PA_SAMPLE_S32LE;
break;
case AUDIO_S32MSB:
paspec.format = PA_SAMPLE_S32BE;
break;
case AUDIO_F32LSB:
paspec.format = PA_SAMPLE_FLOAT32LE;
break;
case AUDIO_F32MSB:
paspec.format = PA_SAMPLE_FLOAT32BE;
break;
default:
paspec.format = PA_SAMPLE_INVALID;
break;
}
if (paspec.format == PA_SAMPLE_INVALID) {
test_format = SDL_NextAudioFormat();
}
}
if (paspec.format == PA_SAMPLE_INVALID) {
PULSEAUDIO_CloseDevice(this);
return SDL_SetError("Couldn't find any hardware audio formats");
}
this->spec.format = test_format;
/* Calculate the final parameters for this audio specification */
#ifdef PA_STREAM_ADJUST_LATENCY
this->spec.samples /= 2; /* Mix in smaller chunck to avoid underruns */
#endif
SDL_CalculateAudioSpec(&this->spec);
/* Allocate mixing buffer */
h->mixlen = this->spec.size;
h->mixbuf = (Uint8 *) SDL_AllocAudioMem(h->mixlen);
if (h->mixbuf == NULL) {
PULSEAUDIO_CloseDevice(this);
return SDL_OutOfMemory();
}
SDL_memset(h->mixbuf, this->spec.silence, this->spec.size);
paspec.channels = this->spec.channels;
paspec.rate = this->spec.freq;
/* Reduced prebuffering compared to the defaults. */
#ifdef PA_STREAM_ADJUST_LATENCY
/* 2x original requested bufsize */
paattr.tlength = h->mixlen * 4;
paattr.prebuf = -1;
paattr.maxlength = -1;
/* -1 can lead to pa_stream_writable_size() >= mixlen never being true */
paattr.minreq = h->mixlen;
flags = PA_STREAM_ADJUST_LATENCY;
#else
paattr.tlength = h->mixlen*2;
paattr.prebuf = h->mixlen*2;
paattr.maxlength = h->mixlen*2;
paattr.minreq = h->mixlen;
#endif
/* The SDL ALSA output hints us that we use Windows' channel mapping */
/* http://bugzilla.libsdl.org/show_bug.cgi?id=110 */
//.........这里部分代码省略.........
示例8: DSP_OpenAudio
static int DSP_OpenAudio(_THIS, SDL_AudioSpec *spec)
{
char audiodev[1024];
int format;
int value;
Uint16 test_format;
/* Reset the timer synchronization flag */
frame_ticks = 0.0;
/* Open the audio device */
audio_fd = SDL_OpenAudioPath(audiodev, sizeof(audiodev), OPEN_FLAGS, 0);
if ( audio_fd < 0 ) {
SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno));
return(-1);
}
mixbuf = NULL;
#ifdef USE_BLOCKING_WRITES
/* Make the file descriptor use blocking writes with fcntl() */
{ long flags;
flags = fcntl(audio_fd, F_GETFL);
flags &= ~O_NONBLOCK;
if ( fcntl(audio_fd, F_SETFL, flags) < 0 ) {
SDL_SetError("Couldn't set audio blocking mode");
return(-1);
}
}
#endif
/* Get a list of supported hardware formats */
if ( ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &value) < 0 ) {
SDL_SetError("Couldn't get audio format list");
return(-1);
}
/* Try for a closest match on audio format */
format = 0;
for ( test_format = SDL_FirstAudioFormat(spec->format);
! format && test_format; ) {
#ifdef DEBUG_AUDIO
fprintf(stderr, "Trying format 0x%4.4x\n", test_format);
#endif
switch ( test_format ) {
case AUDIO_U8:
if ( value & AFMT_U8 ) {
format = AFMT_U8;
}
break;
case AUDIO_S8:
if ( value & AFMT_S8 ) {
format = AFMT_S8;
}
break;
case AUDIO_S16LSB:
if ( value & AFMT_S16_LE ) {
format = AFMT_S16_LE;
}
break;
case AUDIO_S16MSB:
if ( value & AFMT_S16_BE ) {
format = AFMT_S16_BE;
}
break;
case AUDIO_U16LSB:
if ( value & AFMT_U16_LE ) {
format = AFMT_U16_LE;
}
break;
case AUDIO_U16MSB:
if ( value & AFMT_U16_BE ) {
format = AFMT_U16_BE;
}
break;
default:
format = 0;
break;
}
if ( ! format ) {
test_format = SDL_NextAudioFormat();
}
}
if ( format == 0 ) {
SDL_SetError("Couldn't find any hardware audio formats");
return(-1);
}
spec->format = test_format;
/* Set the audio format */
value = format;
if ( (ioctl(audio_fd, SNDCTL_DSP_SETFMT, &value) < 0) ||
(value != format) ) {
SDL_SetError("Couldn't set audio format");
return(-1);
}
/* Set the number of channels of output */
value = spec->channels;
#ifdef SNDCTL_DSP_CHANNELS
if ( ioctl(audio_fd, SNDCTL_DSP_CHANNELS, &value) < 0 ) {
//.........这里部分代码省略.........
示例9: NAS_OpenAudio
static int NAS_OpenAudio(_THIS, SDL_AudioSpec *spec)
{
AuElement elms[3];
int buffer_size;
Uint16 test_format, format;
this->hidden->mixbuf = NULL;
/* Try for a closest match on audio format */
format = 0;
for ( test_format = SDL_FirstAudioFormat(spec->format);
! format && test_format; ) {
format = sdlformat_to_auformat(test_format);
if (format == AuNone) {
test_format = SDL_NextAudioFormat();
}
}
if ( format == 0 ) {
SDL_SetError("Couldn't find any hardware audio formats");
return(-1);
}
spec->format = test_format;
this->hidden->aud = AuOpenServer("", 0, NULL, 0, NULL, NULL);
if (this->hidden->aud == 0)
{
SDL_SetError("Couldn't open connection to NAS server");
return (-1);
}
this->hidden->dev = find_device(this, spec->channels);
if ((this->hidden->dev == AuNone) || (!(this->hidden->flow = AuCreateFlow(this->hidden->aud, NULL)))) {
AuCloseServer(this->hidden->aud);
this->hidden->aud = 0;
SDL_SetError("Couldn't find a fitting playback device on NAS server");
return (-1);
}
buffer_size = spec->freq;
if (buffer_size < 4096)
buffer_size = 4096;
if (buffer_size > 32768)
buffer_size = 32768; /* So that the buffer won't get unmanageably big. */
/* Calculate the final parameters for this audio specification */
SDL_CalculateAudioSpec(spec);
this2 = this->hidden;
AuMakeElementImportClient(elms, spec->freq, format, spec->channels, AuTrue,
buffer_size, buffer_size / 4, 0, NULL);
AuMakeElementExportDevice(elms+1, 0, this->hidden->dev, spec->freq,
AuUnlimitedSamples, 0, NULL);
AuSetElements(this->hidden->aud, this->hidden->flow, AuTrue, 2, elms, NULL);
AuRegisterEventHandler(this->hidden->aud, AuEventHandlerIDMask, 0, this->hidden->flow,
event_handler, (AuPointer) NULL);
AuStartFlow(this->hidden->aud, this->hidden->flow, NULL);
/* Allocate mixing buffer */
this->hidden->mixlen = spec->size;
this->hidden->mixbuf = (Uint8 *)SDL_AllocAudioMem(this->hidden->mixlen);
if ( this->hidden->mixbuf == NULL ) {
return(-1);
}
memset(this->hidden->mixbuf, spec->silence, spec->size);
/* Get the parent process id (we're the parent of the audio thread) */
this->hidden->parent = getpid();
/* We're ready to rock and roll. :-) */
return(0);
}
示例10: BSDAUDIO_OpenDevice
static int
BSDAUDIO_OpenDevice(_THIS, 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) {
SDL_SetError("No such audio device");
return 0;
}
}
/* 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));
/* Open the audio device */
this->hidden->audio_fd = open(devname, flags, 0);
if (this->hidden->audio_fd < 0) {
SDL_SetError("Couldn't open %s: %s", devname, strerror(errno));
return 0;
}
AUDIO_INITINFO(&info);
/* Calculate the final parameters for this audio specification */
SDL_CalculateAudioSpec(&this->spec);
/* Set to play mode */
info.mode = AUMODE_PLAY;
if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) < 0) {
BSDAUDIO_CloseDevice(this);
SDL_SetError("Couldn't put device into play mode");
return 0;
}
AUDIO_INITINFO(&info);
for (format = SDL_FirstAudioFormat(this->spec.format);
format; format = SDL_NextAudioFormat()) {
switch (format) {
case AUDIO_U8:
info.play.encoding = AUDIO_ENCODING_ULINEAR;
info.play.precision = 8;
break;
case AUDIO_S8:
info.play.encoding = AUDIO_ENCODING_SLINEAR;
info.play.precision = 8;
break;
case AUDIO_S16LSB:
info.play.encoding = AUDIO_ENCODING_SLINEAR_LE;
info.play.precision = 16;
break;
case AUDIO_S16MSB:
info.play.encoding = AUDIO_ENCODING_SLINEAR_BE;
info.play.precision = 16;
break;
case AUDIO_U16LSB:
info.play.encoding = AUDIO_ENCODING_ULINEAR_LE;
info.play.precision = 16;
break;
case AUDIO_U16MSB:
info.play.encoding = AUDIO_ENCODING_ULINEAR_BE;
info.play.precision = 16;
break;
default:
continue;
}
if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) == 0) {
break;
}
}
if (!format) {
BSDAUDIO_CloseDevice(this);
SDL_SetError("No supported encoding for 0x%x", this->spec.format);
return 0;
}
this->spec.format = format;
AUDIO_INITINFO(&info);
info.play.channels = this->spec.channels;
if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) == -1) {
this->spec.channels = 1;
}
AUDIO_INITINFO(&info);
info.play.sample_rate = this->spec.freq;
info.blocksize = this->spec.size;
info.hiwat = 5;
//.........这里部分代码省略.........
示例11: WINMM_OpenDevice
static int
WINMM_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
{
SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
int valid_datatype = 0;
MMRESULT result;
WAVEFORMATEX waveformat;
UINT devId = WAVE_MAPPER; /* WAVE_MAPPER == choose system's default */
UINT i;
if (handle != NULL) { /* specific device requested? */
/* -1 because we increment the original value to avoid NULL. */
const size_t val = ((size_t) handle) - 1;
devId = (UINT) val;
}
/* 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));
/* Initialize the wavebuf structures for closing */
for (i = 0; i < NUM_BUFFERS; ++i)
this->hidden->wavebuf[i].dwUser = 0xFFFF;
if (this->spec.channels > 2)
this->spec.channels = 2; /* !!! FIXME: is this right? */
while ((!valid_datatype) && (test_format)) {
switch (test_format) {
case AUDIO_U8:
case AUDIO_S16:
case AUDIO_S32:
case AUDIO_F32:
this->spec.format = test_format;
if (PrepWaveFormat(this, devId, &waveformat, iscapture)) {
valid_datatype = 1;
} else {
test_format = SDL_NextAudioFormat();
}
break;
default:
test_format = SDL_NextAudioFormat();
break;
}
}
if (!valid_datatype) {
WINMM_CloseDevice(this);
return SDL_SetError("Unsupported audio format");
}
/* Update the fragment size as size in bytes */
SDL_CalculateAudioSpec(&this->spec);
/* Open the audio device */
if (iscapture) {
result = waveInOpen(&this->hidden->hin, devId, &waveformat,
(DWORD_PTR) CaptureSound, (DWORD_PTR) this,
CALLBACK_FUNCTION);
} else {
result = waveOutOpen(&this->hidden->hout, devId, &waveformat,
(DWORD_PTR) FillSound, (DWORD_PTR) this,
CALLBACK_FUNCTION);
}
if (result != MMSYSERR_NOERROR) {
WINMM_CloseDevice(this);
return SetMMerror("waveOutOpen()", result);
}
#ifdef SOUND_DEBUG
/* Check the sound device we retrieved */
{
WAVEOUTCAPS caps;
result = waveOutGetDevCaps((UINT) this->hidden->hout,
&caps, sizeof(caps));
if (result != MMSYSERR_NOERROR) {
WINMM_CloseDevice(this);
return SetMMerror("waveOutGetDevCaps()", result);
}
printf("Audio device: %s\n", caps.szPname);
}
#endif
/* Create the audio buffer semaphore */
this->hidden->audio_sem =
CreateSemaphore(NULL, NUM_BUFFERS - 1, NUM_BUFFERS, NULL);
if (this->hidden->audio_sem == NULL) {
WINMM_CloseDevice(this);
return SDL_SetError("Couldn't create semaphore");
}
/* Create the sound buffers */
this->hidden->mixbuf =
(Uint8 *) SDL_malloc(NUM_BUFFERS * this->spec.size);
//.........这里部分代码省略.........
示例12: COREAUDIO_OpenDevice
static int
COREAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
{
fprintf(stderr, "OpenDevice\n");
AudioStreamBasicDescription strdesc;
SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
int valid_datatype = 0;
/* Initialize all variables that we clean on shutdown */
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
if (this->hidden == NULL) {
SDL_OutOfMemory();
fprintf(stderr, "OutOfMemory\n");
return (0);
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
/* Setup a AudioStreamBasicDescription with the requested format */
SDL_memset(&strdesc, '\0', sizeof(AudioStreamBasicDescription));
strdesc.mFormatID = kAudioFormatLinearPCM;
strdesc.mFormatFlags = kLinearPCMFormatFlagIsPacked;
strdesc.mChannelsPerFrame = this->spec.channels;
strdesc.mSampleRate = this->spec.freq;
strdesc.mFramesPerPacket = 1;
while ((!valid_datatype) && (test_format)) {
this->spec.format = test_format;
/* Just a list of valid SDL formats, so people don't pass junk here. */
switch (test_format) {
case AUDIO_U8:
case AUDIO_S8:
case AUDIO_U16LSB:
case AUDIO_S16LSB:
case AUDIO_U16MSB:
case AUDIO_S16MSB:
case AUDIO_S32LSB:
case AUDIO_S32MSB:
case AUDIO_F32LSB:
case AUDIO_F32MSB:
valid_datatype = 1;
strdesc.mBitsPerChannel = SDL_AUDIO_BITSIZE(this->spec.format);
if (SDL_AUDIO_ISBIGENDIAN(this->spec.format))
strdesc.mFormatFlags |= kLinearPCMFormatFlagIsBigEndian;
if (SDL_AUDIO_ISFLOAT(this->spec.format))
strdesc.mFormatFlags |= kLinearPCMFormatFlagIsFloat;
else if (SDL_AUDIO_ISSIGNED(this->spec.format))
strdesc.mFormatFlags |= kLinearPCMFormatFlagIsSignedInteger;
break;
}
}
if (!valid_datatype) { /* shouldn't happen, but just in case... */
COREAUDIO_CloseDevice(this);
fprintf(stderr, "Unsupported audio format\n");
return 0;
}
strdesc.mBytesPerFrame =
strdesc.mBitsPerChannel * strdesc.mChannelsPerFrame / 8;
strdesc.mBytesPerPacket =
strdesc.mBytesPerFrame * strdesc.mFramesPerPacket;
if (!prepare_audiounit(this, devname, iscapture, &strdesc)) {
COREAUDIO_CloseDevice(this);
fprintf(stderr, "prepare_audiounit failed\n");
return 0; /* prepare_audiounit() will call SDL_SetError()... */
}
return 1; /* good to go. */
}
示例13: QSA_OpenDevice
//.........这里部分代码省略.........
this->hidden->cardno, this->hidden->deviceno,
SND_PCM_OPEN_PLAYBACK);
} else {
status =
snd_pcm_open(&this->hidden->audio_handle,
this->hidden->cardno, this->hidden->deviceno,
SND_PCM_OPEN_CAPTURE);
}
}
/* Check if requested device is opened */
if (status < 0) {
this->hidden->audio_handle = NULL;
QSA_CloseDevice(this);
return QSA_SetError("snd_pcm_open", status);
}
if (!QSA_CheckBuggyCards(this, QSA_MMAP_WORKAROUND)) {
/* Disable QSA MMAP plugin for buggy audio drivers */
status =
snd_pcm_plugin_set_disable(this->hidden->audio_handle,
PLUGIN_DISABLE_MMAP);
if (status < 0) {
QSA_CloseDevice(this);
return QSA_SetError("snd_pcm_plugin_set_disable", status);
}
}
/* Try for a closest match on audio format */
format = 0;
/* can't use format as SND_PCM_SFMT_U8 = 0 in qsa */
found = 0;
for (test_format = SDL_FirstAudioFormat(this->spec.format); !found;) {
/* if match found set format to equivalent QSA format */
switch (test_format) {
case AUDIO_U8:
{
format = SND_PCM_SFMT_U8;
found = 1;
}
break;
case AUDIO_S8:
{
format = SND_PCM_SFMT_S8;
found = 1;
}
break;
case AUDIO_S16LSB:
{
format = SND_PCM_SFMT_S16_LE;
found = 1;
}
break;
case AUDIO_S16MSB:
{
format = SND_PCM_SFMT_S16_BE;
found = 1;
}
break;
case AUDIO_U16LSB:
{
format = SND_PCM_SFMT_U16_LE;
found = 1;
}
break;
示例14: DART_OpenAudio
int DART_OpenAudio(_THIS, SDL_AudioSpec *spec)
{
Uint16 test_format = SDL_FirstAudioFormat(spec->format);
int valid_datatype = 0;
MCI_AMP_OPEN_PARMS AmpOpenParms;
MCI_GENERIC_PARMS GenericParms;
int iDeviceOrd = 0;
int bOpenShared = 1;
int iBits = 16;
int iFreq = 44100;
int iChannels = 2;
int iNumBufs = 2;
int iBufSize;
int iOpenMode;
int iSilence;
int rc;
SDL_memset(&AmpOpenParms, 0, sizeof(MCI_AMP_OPEN_PARMS));
AmpOpenParms.pszDeviceType = (PSZ) (MCI_DEVTYPE_AUDIO_AMPMIX | (iDeviceOrd << 16));
iOpenMode = MCI_WAIT | MCI_OPEN_TYPE_ID;
if (bOpenShared) iOpenMode |= MCI_OPEN_SHAREABLE;
rc = mciSendCommand( 0, MCI_OPEN,
iOpenMode,
(PVOID) &AmpOpenParms, 0);
if (rc!=MCIERR_SUCCESS)
return (-1);
iDeviceOrd = AmpOpenParms.usDeviceID;
if (spec->channels > 2)
spec->channels = 2;
while ((!valid_datatype) && (test_format)) {
spec->format = test_format;
valid_datatype = 1;
switch (test_format) {
case AUDIO_U8:
iSilence = 0x80;
iBits = 8;
break;
case AUDIO_S16LSB:
iSilence = 0x00;
iBits = 16;
break;
default:
valid_datatype = 0;
test_format = SDL_NextAudioFormat();
break;
}
}
if (!valid_datatype) {
mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0);
SDL_SetError("Unsupported audio format");
return (-1);
}
iFreq = spec->freq;
iChannels = spec->channels;
SDL_CalculateAudioSpec(spec);
iBufSize = spec->size;
SDL_memset(&(_this->hidden->MixSetupParms), 0, sizeof(MCI_MIXSETUP_PARMS));
_this->hidden->MixSetupParms.ulBitsPerSample = iBits;
_this->hidden->MixSetupParms.ulFormatTag = MCI_WAVE_FORMAT_PCM;
_this->hidden->MixSetupParms.ulSamplesPerSec = iFreq;
_this->hidden->MixSetupParms.ulChannels = iChannels;
_this->hidden->MixSetupParms.ulFormatMode = MCI_PLAY;
_this->hidden->MixSetupParms.ulDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO;
_this->hidden->MixSetupParms.pmixEvent = DARTEventFunc;
rc = mciSendCommand (iDeviceOrd, MCI_MIXSETUP,
MCI_WAIT | MCI_MIXSETUP_QUERYMODE,
&(_this->hidden->MixSetupParms), 0);
if (rc!=MCIERR_SUCCESS)
{
mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0);
SDL_SetError("Audio device doesn't support requested audio format");
return(-1);
}
rc = mciSendCommand(iDeviceOrd, MCI_MIXSETUP,
MCI_WAIT | MCI_MIXSETUP_INIT,
&(_this->hidden->MixSetupParms), 0);
if (rc!=MCIERR_SUCCESS)
{
//.........这里部分代码省略.........
示例15: PULSE_OpenAudio
static int PULSE_OpenAudio(_THIS, SDL_AudioSpec *spec)
{
Uint16 test_format;
pa_sample_spec paspec;
pa_buffer_attr paattr;
pa_channel_map pacmap;
paspec.format = PA_SAMPLE_INVALID;
for ( test_format = SDL_FirstAudioFormat(spec->format); test_format; ) {
switch ( test_format ) {
case AUDIO_U8:
paspec.format = PA_SAMPLE_U8;
break;
case AUDIO_S16LSB:
paspec.format = PA_SAMPLE_S16LE;
break;
case AUDIO_S16MSB:
paspec.format = PA_SAMPLE_S16BE;
break;
}
if ( paspec.format != PA_SAMPLE_INVALID )
break;
}
if (paspec.format == PA_SAMPLE_INVALID ) {
SDL_SetError("Couldn't find any suitable audio formats");
return(-1);
}
spec->format = test_format;
paspec.channels = spec->channels;
paspec.rate = spec->freq;
/* Calculate the final parameters for this audio specification */
SDL_CalculateAudioSpec(spec);
/* Allocate mixing buffer */
mixlen = spec->size;
mixbuf = (Uint8 *)SDL_AllocAudioMem(mixlen);
if ( mixbuf == NULL ) {
return(-1);
}
SDL_memset(mixbuf, spec->silence, spec->size);
/* Reduced prebuffering compared to the defaults. */
paattr.tlength = mixlen;
paattr.minreq = mixlen;
paattr.fragsize = mixlen;
paattr.prebuf = mixlen;
paattr.maxlength = mixlen * 4;
/* The SDL ALSA output hints us that we use Windows' channel mapping */
/* http://bugzilla.libsdl.org/show_bug.cgi?id=110 */
SDL_NAME(pa_channel_map_init_auto)(
&pacmap, spec->channels, PA_CHANNEL_MAP_WAVEEX);
/* Connect to the PulseAudio server */
stream = SDL_NAME(pa_simple_new)(
SDL_getenv("PASERVER"), /* server */
get_progname(), /* application name */
PA_STREAM_PLAYBACK, /* playback mode */
SDL_getenv("PADEVICE"), /* device on the server */
"Simple DirectMedia Layer", /* stream description */
&paspec, /* sample format spec */
&pacmap, /* channel map */
&paattr, /* buffering attributes */
NULL /* error code */
);
if ( stream == NULL ) {
PULSE_CloseAudio(this);
SDL_SetError("Could not connect to PulseAudio");
return(-1);
}
/* Get the parent process id (we're the parent of the audio thread) */
parent = getpid();
return(0);
}