Clang-Tidy fixes (#6725)

(cherry picked from commit 3c501b963d)
This commit is contained in:
Pierre Wendling
2022-12-01 16:07:03 -05:00
committed by Sam Lantinga
parent e29c0661cc
commit d0bbfdbfb8
179 changed files with 1260 additions and 1101 deletions

View File

@@ -394,7 +394,7 @@ static int add_audio_device(const char *name, SDL_AudioSpec *spec, void *handle,
return SDL_OutOfMemory();
}
SDL_snprintf(replacement, len, "%s (%d)", name, dupenum + 1);
(void)SDL_snprintf(replacement, len, "%s (%d)", name, dupenum + 1);
item->dupenum = dupenum;
item->name = replacement;
}
@@ -658,6 +658,10 @@ void SDL_ClearQueuedAudio(SDL_AudioDeviceID devid)
current_audio.impl.UnlockDevice(device);
}
#if SDL_AUDIO_DRIVER_ANDROID
extern void Android_JNI_AudioSetThreadPriority(int, int);
#endif
/* The general mixing thread function */
static int SDLCALL SDL_RunAudio(void *devicep)
{
@@ -672,7 +676,6 @@ static int SDLCALL SDL_RunAudio(void *devicep)
#if SDL_AUDIO_DRIVER_ANDROID
{
/* Set thread priority to THREAD_PRIORITY_AUDIO */
extern void Android_JNI_AudioSetThreadPriority(int, int);
Android_JNI_AudioSetThreadPriority(device->iscapture, device->id);
}
#else
@@ -773,7 +776,6 @@ static int SDLCALL SDL_CaptureAudio(void *devicep)
#if SDL_AUDIO_DRIVER_ANDROID
{
/* Set thread priority to THREAD_PRIORITY_AUDIO */
extern void Android_JNI_AudioSetThreadPriority(int, int);
Android_JNI_AudioSetThreadPriority(device->iscapture, device->id);
}
#else
@@ -1187,6 +1189,19 @@ static void close_audio_device(SDL_AudioDevice *device)
SDL_free(device);
}
static Uint16
GetDefaultSamplesFromFreq(int freq)
{
/* Pick a default of ~46 ms at desired frequency */
/* !!! FIXME: remove this when the non-Po2 resampling is in. */
const Uint16 max_sample = (freq / 1000) * 46;
Uint16 current_sample = 1;
while (current_sample < max_sample) {
current_sample *= 2;
}
return current_sample;
}
/*
* Sanity check desired AudioSpec for SDL_OpenAudio() in (orig).
* Fills in a sanitized copy in (prepared).
@@ -1197,23 +1212,33 @@ static int prepare_audiospec(const SDL_AudioSpec *orig, SDL_AudioSpec *prepared)
SDL_copyp(prepared, orig);
if (orig->freq == 0) {
static const int DEFAULT_FREQ = 22050;
const char *env = SDL_getenv("SDL_AUDIO_FREQUENCY");
if ((!env) || ((prepared->freq = SDL_atoi(env)) == 0)) {
prepared->freq = 22050; /* a reasonable default */
if (env != NULL) {
int freq = SDL_atoi(env);
prepared->freq = freq != 0 ? freq : DEFAULT_FREQ;
} else {
prepared->freq = DEFAULT_FREQ;
}
}
if (orig->format == 0) {
const char *env = SDL_getenv("SDL_AUDIO_FORMAT");
if ((!env) || ((prepared->format = SDL_ParseAudioFormat(env)) == 0)) {
prepared->format = AUDIO_S16; /* a reasonable default */
if (env != NULL) {
const SDL_AudioFormat format = SDL_ParseAudioFormat(env);
prepared->format = format != 0 ? format : AUDIO_S16;
} else {
prepared->format = AUDIO_S16;
}
}
if (orig->channels == 0) {
const char *env = SDL_getenv("SDL_AUDIO_CHANNELS");
if ((!env) || ((prepared->channels = (Uint8)SDL_atoi(env)) == 0)) {
prepared->channels = 2; /* a reasonable default */
if (env != NULL) {
Uint8 channels = (Uint8)SDL_atoi(env);
prepared->channels = channels != 0 ? channels : 2;
} else {
prepared->channels = 2;
}
} else if (orig->channels > 8) {
SDL_SetError("Unsupported number of audio channels.");
@@ -1222,15 +1247,11 @@ static int prepare_audiospec(const SDL_AudioSpec *orig, SDL_AudioSpec *prepared)
if (orig->samples == 0) {
const char *env = SDL_getenv("SDL_AUDIO_SAMPLES");
if ((!env) || ((prepared->samples = (Uint16)SDL_atoi(env)) == 0)) {
/* Pick a default of ~46 ms at desired frequency */
/* !!! FIXME: remove this when the non-Po2 resampling is in. */
const int samples = (prepared->freq / 1000) * 46;
int power2 = 1;
while (power2 < samples) {
power2 *= 2;
}
prepared->samples = power2;
if (env != NULL) {
Uint16 samples = (Uint16)SDL_atoi(env);
prepared->samples = samples != 0 ? samples : GetDefaultSamplesFromFreq(prepared->freq);
} else {
prepared->samples = GetDefaultSamplesFromFreq(prepared->freq);
}
}
@@ -1488,7 +1509,7 @@ static SDL_AudioDeviceID open_audio_device(const char *devname, int iscapture,
const size_t stacksize = is_internal_thread ? 64 * 1024 : 0;
char threadname[64];
SDL_snprintf(threadname, sizeof(threadname), "SDLAudio%c%d", (iscapture) ? 'C' : 'P', (int)device->id);
(void)SDL_snprintf(threadname, sizeof threadname, "SDLAudio%c%" SDL_PRIu32, (iscapture) ? 'C' : 'P', device->id);
device->thread = SDL_CreateThreadInternal(iscapture ? SDL_CaptureAudio : SDL_RunAudio, threadname, stacksize, device);
if (device->thread == NULL) {

View File

@@ -208,7 +208,7 @@ static int SDL_ResampleAudio(const int chans, const int inrate, const int outrat
const int paddinglen = ResamplerPadding(inrate, outrate);
const int framelen = chans * (int)sizeof(float);
const int inframes = inbuflen / framelen;
const int wantedoutframes = (int)((inbuflen / framelen) * ratio); /* outbuflen isn't total to write, it's total available. */
const int wantedoutframes = (int)(inframes * ratio); /* outbuflen isn't total to write, it's total available. */
const int maxoutframes = outbuflen / framelen;
const int outframes = SDL_min(wantedoutframes, maxoutframes);
ResampleFloatType outtime = 0.0f;
@@ -233,7 +233,7 @@ static int SDL_ResampleAudio(const int chans, const int inrate, const int outrat
const int srcframe = srcindex - j;
/* !!! FIXME: we can bubble this conditional out of here by doing a pre loop. */
const float insample = (srcframe < 0) ? lpadding[((paddinglen + srcframe) * chans) + chan] : inbuf[(srcframe * chans) + chan];
outsample += (float)(insample * (ResamplerFilter[filterindex1 + (j * RESAMPLER_SAMPLES_PER_ZERO_CROSSING)] + (interpolation1 * ResamplerFilterDifference[filterindex1 + (j * RESAMPLER_SAMPLES_PER_ZERO_CROSSING)])));
outsample += (insample * (ResamplerFilter[filterindex1 + (j * RESAMPLER_SAMPLES_PER_ZERO_CROSSING)] + (interpolation1 * ResamplerFilterDifference[filterindex1 + (j * RESAMPLER_SAMPLES_PER_ZERO_CROSSING)])));
}
/* Do the right wing! */
@@ -242,7 +242,7 @@ static int SDL_ResampleAudio(const int chans, const int inrate, const int outrat
const int srcframe = srcindex + 1 + j;
/* !!! FIXME: we can bubble this conditional out of here by doing a post loop. */
const float insample = (srcframe >= inframes) ? rpadding[((srcframe - inframes) * chans) + chan] : inbuf[(srcframe * chans) + chan];
outsample += (float)(insample * (ResamplerFilter[filterindex2 + jsamples] + (interpolation2 * ResamplerFilterDifference[filterindex2 + jsamples])));
outsample += (insample * (ResamplerFilter[filterindex2 + jsamples] + (interpolation2 * ResamplerFilterDifference[filterindex2 + jsamples])));
}
*(dst++) = outsample;
@@ -316,7 +316,7 @@ static void SDLCALL SDL_Convert_Byteswap(SDL_AudioCVT *cvt, SDL_AudioFormat form
}
}
static int SDL_AddAudioCVTFilter(SDL_AudioCVT *cvt, const SDL_AudioFilter filter)
static int SDL_AddAudioCVTFilter(SDL_AudioCVT *cvt, SDL_AudioFilter filter)
{
if (cvt->filter_index >= SDL_AUDIOCVT_MAX_FILTERS) {
return SDL_SetError("Too many filters needed for conversion, exceeded maximum of %d", SDL_AUDIOCVT_MAX_FILTERS);
@@ -376,7 +376,8 @@ static int SDL_BuildAudioTypeCVTToFloat(SDL_AudioCVT *cvt, const SDL_AudioFormat
cvt->len_mult *= mult;
cvt->len_ratio *= mult;
} else if (src_bitsize > dst_bitsize) {
cvt->len_ratio /= (src_bitsize / dst_bitsize);
const int div = (src_bitsize / dst_bitsize);
cvt->len_ratio /= div;
}
retval = 1; /* added a converter. */
@@ -674,8 +675,8 @@ static SDL_bool SDL_SupportedChannelCount(const int channels)
*/
int SDL_BuildAudioCVT(SDL_AudioCVT *cvt,
SDL_AudioFormat src_fmt, Uint8 src_channels, int src_rate,
SDL_AudioFormat dst_fmt, Uint8 dst_channels, int dst_rate)
SDL_AudioFormat src_format, Uint8 src_channels, int src_rate,
SDL_AudioFormat dst_format, Uint8 dst_channels, int dst_rate)
{
SDL_AudioFilter channel_converter = NULL;
@@ -687,10 +688,10 @@ int SDL_BuildAudioCVT(SDL_AudioCVT *cvt,
/* Make sure we zero out the audio conversion before error checking */
SDL_zerop(cvt);
if (!SDL_SupportedAudioFormat(src_fmt)) {
if (!SDL_SupportedAudioFormat(src_format)) {
return SDL_SetError("Invalid source format");
}
if (!SDL_SupportedAudioFormat(dst_fmt)) {
if (!SDL_SupportedAudioFormat(dst_format)) {
return SDL_SetError("Invalid destination format");
}
if (!SDL_SupportedChannelCount(src_channels)) {
@@ -714,12 +715,12 @@ int SDL_BuildAudioCVT(SDL_AudioCVT *cvt,
#if DEBUG_CONVERT
SDL_Log("SDL_AUDIO_CONVERT: Build format %04x->%04x, channels %u->%u, rate %d->%d\n",
src_fmt, dst_fmt, src_channels, dst_channels, src_rate, dst_rate);
src_format, dst_format, src_channels, dst_channels, src_rate, dst_rate);
#endif
/* Start off with no conversion necessary */
cvt->src_format = src_fmt;
cvt->dst_format = dst_fmt;
cvt->src_format = src_format;
cvt->dst_format = dst_format;
cvt->needed = 0;
cvt->filter_index = 0;
SDL_zeroa(cvt->filters);
@@ -746,13 +747,13 @@ int SDL_BuildAudioCVT(SDL_AudioCVT *cvt,
/* see if we can skip float conversion entirely. */
if (src_rate == dst_rate && src_channels == dst_channels) {
if (src_fmt == dst_fmt) {
if (src_format == dst_format) {
return 0;
}
/* just a byteswap needed? */
if ((src_fmt & ~SDL_AUDIO_MASK_ENDIAN) == (dst_fmt & ~SDL_AUDIO_MASK_ENDIAN)) {
if (SDL_AUDIO_BITSIZE(dst_fmt) == 8) {
if ((src_format & ~SDL_AUDIO_MASK_ENDIAN) == (dst_format & ~SDL_AUDIO_MASK_ENDIAN)) {
if (SDL_AUDIO_BITSIZE(dst_format) == 8) {
return 0;
}
if (SDL_AddAudioCVTFilter(cvt, SDL_Convert_Byteswap) < 0) {
@@ -764,7 +765,7 @@ int SDL_BuildAudioCVT(SDL_AudioCVT *cvt,
}
/* Convert data types, if necessary. Updates (cvt). */
if (SDL_BuildAudioTypeCVTToFloat(cvt, src_fmt) < 0) {
if (SDL_BuildAudioTypeCVTToFloat(cvt, src_format) < 0) {
return -1; /* shouldn't happen, but just in case... */
}
@@ -820,7 +821,7 @@ int SDL_BuildAudioCVT(SDL_AudioCVT *cvt,
}
/* Move to final data type. */
if (SDL_BuildAudioTypeCVTFromFloat(cvt, dst_fmt) < 0) {
if (SDL_BuildAudioTypeCVTFromFloat(cvt, dst_format) < 0) {
return -1; /* shouldn't happen, but just in case... */
}
@@ -862,7 +863,7 @@ struct _SDL_AudioStream
SDL_CleanupAudioStreamResamplerFunc cleanup_resampler_func;
};
static Uint8 *EnsureStreamBufferSize(SDL_AudioStream *stream, const int newlen)
static Uint8 *EnsureStreamBufferSize(SDL_AudioStream *stream, int newlen)
{
Uint8 *ptr;
size_t offset;
@@ -870,7 +871,7 @@ static Uint8 *EnsureStreamBufferSize(SDL_AudioStream *stream, const int newlen)
if (stream->work_buffer_len >= newlen) {
ptr = stream->work_buffer_base;
} else {
ptr = (Uint8 *)SDL_realloc(stream->work_buffer_base, newlen + 32);
ptr = (Uint8 *)SDL_realloc(stream->work_buffer_base, (size_t)newlen + 32);
if (ptr == NULL) {
SDL_OutOfMemory();
return NULL;
@@ -1006,7 +1007,7 @@ SDL_NewAudioStream(const SDL_AudioFormat src_format,
const Uint8 dst_channels,
const int dst_rate)
{
const int packetlen = 4096; /* !!! FIXME: good enough for now. */
int packetlen = 4096; /* !!! FIXME: good enough for now. */
Uint8 pre_resample_channels;
SDL_AudioStream *retval;
@@ -1092,7 +1093,7 @@ SDL_NewAudioStream(const SDL_AudioFormat src_format,
}
}
retval->queue = SDL_NewDataQueue(packetlen, packetlen * 2);
retval->queue = SDL_NewDataQueue(packetlen, (size_t)packetlen * 2);
if (!retval->queue) {
SDL_FreeAudioStream(retval);
return NULL; /* SDL_NewDataQueue should have called SDL_SetError. */
@@ -1384,7 +1385,7 @@ void SDL_AudioStreamClear(SDL_AudioStream *stream)
if (stream == NULL) {
SDL_InvalidParamError("stream");
} else {
SDL_ClearDataQueue(stream->queue, stream->packetlen * 2);
SDL_ClearDataQueue(stream->queue, (size_t)stream->packetlen * 2);
if (stream->reset_resampler_func) {
stream->reset_resampler_func(stream);
}

View File

@@ -86,8 +86,11 @@ static void SDL_EnumUnixAudioDevices_Internal(const int iscapture, const int cla
}
/* Figure out what our audio device is */
if (((audiodev = SDL_getenv("SDL_PATH_DSP")) == NULL) &&
((audiodev = SDL_getenv("AUDIODEV")) == NULL)) {
audiodev = SDL_getenv("SDL_PATH_DSP");
if (audiodev == NULL) {
audiodev = SDL_getenv("AUDIODEV");
}
if (audiodev == NULL) {
if (classic) {
audiodev = _PATH_DEV_AUDIO;
} else {
@@ -106,8 +109,8 @@ static void SDL_EnumUnixAudioDevices_Internal(const int iscapture, const int cla
if (SDL_strlen(audiodev) < (sizeof(audiopath) - 3)) {
int instance = 0;
while (instance <= 64) {
SDL_snprintf(audiopath, SDL_arraysize(audiopath),
"%s%d", audiodev, instance);
(void)SDL_snprintf(audiopath, SDL_arraysize(audiopath),
"%s%d", audiodev, instance);
instance++;
test_device(iscapture, audiopath, flags, test);
}

View File

@@ -1198,7 +1198,7 @@ static void SDLCALL SDL_Convert_F32_to_S8_NEON(SDL_AudioCVT *cvt, SDL_AudioForma
static void SDLCALL SDL_Convert_F32_to_U8_NEON(SDL_AudioCVT *cvt, SDL_AudioFormat format)
{
const float *src = (const float *)cvt->buf;
Uint8 *dst = (Uint8 *)cvt->buf;
Uint8 *dst = cvt->buf;
int i;
LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_U8 (using NEON)");

View File

@@ -549,20 +549,20 @@ static int MS_ADPCM_DecodeBlockHeader(ADPCM_DecoderState *state)
cstate[c].coeff2 = ddata->coeff[coeffindex * 2 + 1];
/* Initial delta value. */
o = channels + c * 2;
o = (size_t)channels + c * 2;
cstate[c].delta = state->block.data[o] | ((Uint16)state->block.data[o + 1] << 8);
/* Load the samples from the header. Interestingly, the sample later in
* the output stream comes first.
*/
o = channels * 3 + c * 2;
o = (size_t)channels * 3 + c * 2;
sample = state->block.data[o] | ((Sint32)state->block.data[o + 1] << 8);
if (sample >= 0x8000) {
sample -= 0x10000;
}
state->output.data[state->output.pos + channels] = (Sint16)sample;
o = channels * 5 + c * 2;
o = (size_t)channels * 5 + c * 2;
sample = state->block.data[o] | ((Sint32)state->block.data[o + 1] << 8);
if (sample >= 0x8000) {
sample -= 0x10000;
@@ -965,7 +965,7 @@ static int IMA_ADPCM_DecodeBlockData(ADPCM_DecoderState *state)
size_t i;
int retval = 0;
const Uint32 channels = state->channels;
const size_t subblockframesize = channels * 4;
const size_t subblockframesize = (size_t)channels * 4;
Uint64 bytesrequired;
Uint32 c;

View File

@@ -379,8 +379,9 @@ static void ALSA_PlayDevice(_THIS)
status = ALSA_snd_pcm_recover(this->hidden->pcm_handle, status, 0);
if (status < 0) {
/* Hmm, not much we can do - abort */
fprintf(stderr, "ALSA write failed (unrecoverable): %s\n",
ALSA_snd_strerror(status));
SDL_LogError(SDL_LOG_CATEGORY_AUDIO,
"ALSA write failed (unrecoverable): %s\n",
ALSA_snd_strerror(status));
SDL_OpenedAudioDeviceDisconnected(this);
return;
}
@@ -427,8 +428,9 @@ static int ALSA_CaptureFromDevice(_THIS, void *buffer, int buflen)
status = ALSA_snd_pcm_recover(this->hidden->pcm_handle, status, 0);
if (status < 0) {
/* Hmm, not much we can do - abort */
fprintf(stderr, "ALSA read failed (unrecoverable): %s\n",
ALSA_snd_strerror(status));
SDL_LogError(SDL_LOG_CATEGORY_AUDIO,
"ALSA read failed (unrecoverable): %s\n",
ALSA_snd_strerror(status));
return -1;
}
continue;
@@ -511,9 +513,9 @@ static int ALSA_set_buffer_size(_THIS, snd_pcm_hw_params_t *params)
ALSA_snd_pcm_hw_params_get_buffer_size(hwparams, &bufsize);
fprintf(stderr,
"ALSA: period size = %ld, periods = %u, buffer size = %lu\n",
persize, periods, bufsize);
SDL_LogError(SDL_LOG_CATEGORY_AUDIO,
"ALSA: period size = %ld, periods = %u, buffer size = %lu\n",
persize, periods, bufsize);
}
return 0;
@@ -739,7 +741,8 @@ static void add_device(const int iscapture, const char *name, void *hint, ALSA_D
/* some strings have newlines, like "HDA NVidia, HDMI 0\nHDMI Audio Output".
just chop the extra lines off, this seems to get a reasonable device
name without extra details. */
if ((ptr = SDL_strchr(desc, '\n')) != NULL) {
ptr = SDL_strchr(desc, '\n');
if (ptr != NULL) {
*ptr = '\0';
}

View File

@@ -102,17 +102,20 @@ static void build_device_list(int iscapture, addDevFn addfn, void *addfndata)
result = AudioObjectGetPropertyDataSize(kAudioObjectSystemObject,
&devlist_address, 0, NULL, &size);
if (result != kAudioHardwareNoError)
if (result != kAudioHardwareNoError) {
return;
}
devs = (AudioDeviceID *)alloca(size);
if (devs == NULL)
if (devs == NULL) {
return;
}
result = AudioObjectGetPropertyData(kAudioObjectSystemObject,
&devlist_address, 0, NULL, &size, devs);
if (result != kAudioHardwareNoError)
if (result != kAudioHardwareNoError) {
return;
}
max = size / sizeof(AudioDeviceID);
for (i = 0; i < max; i++) {
@@ -141,12 +144,14 @@ static void build_device_list(int iscapture, addDevFn addfn, void *addfndata)
};
result = AudioObjectGetPropertyDataSize(dev, &addr, 0, NULL, &size);
if (result != noErr)
if (result != noErr) {
continue;
}
buflist = (AudioBufferList *)SDL_malloc(size);
if (buflist == NULL)
if (buflist == NULL) {
continue;
}
result = AudioObjectGetPropertyData(dev, &addr, 0, NULL,
&size, buflist);
@@ -161,8 +166,9 @@ static void build_device_list(int iscapture, addDevFn addfn, void *addfndata)
SDL_free(buflist);
if (spec.channels == 0)
if (spec.channels == 0) {
continue;
}
size = sizeof(sampleRate);
result = AudioObjectGetPropertyData(dev, &freqaddr, 0, NULL, &size, &sampleRate);
@@ -172,8 +178,9 @@ static void build_device_list(int iscapture, addDevFn addfn, void *addfndata)
size = sizeof(CFStringRef);
result = AudioObjectGetPropertyData(dev, &nameaddr, 0, NULL, &size, &cfstr);
if (result != kAudioHardwareNoError)
if (result != kAudioHardwareNoError) {
continue;
}
len = CFStringGetMaximumSizeForEncoding(CFStringGetLength(cfstr),
kCFStringEncodingUTF8);
@@ -540,8 +547,9 @@ static void outputCallback(void *inUserData, AudioQueueRef inAQ, AudioQueueBuffe
if (SDL_AudioStreamAvailable(this->stream) > 0) {
int got;
UInt32 len = SDL_AudioStreamAvailable(this->stream);
if (len > remaining)
if (len > remaining) {
len = remaining;
}
got = SDL_AudioStreamGet(this->stream, ptr, len);
SDL_assert((got < 0) || (got == len));
if (got != len) {
@@ -985,7 +993,7 @@ static int audioqueue_thread(void *arg)
}
if (!this->iscapture) { /* Drain off any pending playback. */
const CFTimeInterval secs = (((this->spec.size / (SDL_AUDIO_BITSIZE(this->spec.format) / 8)) / this->spec.channels) / ((CFTimeInterval)this->spec.freq)) * 2.0;
const CFTimeInterval secs = (((this->spec.size / (SDL_AUDIO_BITSIZE(this->spec.format) / 8.0)) / this->spec.channels) / ((CFTimeInterval)this->spec.freq)) * 2.0;
CFRunLoopRunInMode(kCFRunLoopDefaultMode, secs, 0);
}
@@ -1084,13 +1092,15 @@ static int COREAUDIO_OpenDevice(_THIS, const char *devname)
}
this->spec.format = test_format;
strdesc->mBitsPerChannel = SDL_AUDIO_BITSIZE(test_format);
if (SDL_AUDIO_ISBIGENDIAN(test_format))
if (SDL_AUDIO_ISBIGENDIAN(test_format)) {
strdesc->mFormatFlags |= kLinearPCMFormatFlagIsBigEndian;
}
if (SDL_AUDIO_ISFLOAT(test_format))
if (SDL_AUDIO_ISFLOAT(test_format)) {
strdesc->mFormatFlags |= kLinearPCMFormatFlagIsFloat;
else if (SDL_AUDIO_ISSIGNED(test_format))
} else if (SDL_AUDIO_ISSIGNED(test_format)) {
strdesc->mFormatFlags |= kLinearPCMFormatFlagIsSignedInteger;
}
strdesc->mBytesPerFrame = strdesc->mChannelsPerFrame * strdesc->mBitsPerChannel / 8;
strdesc->mBytesPerPacket = strdesc->mBytesPerFrame * strdesc->mFramesPerPacket;
@@ -1230,12 +1240,14 @@ static int COREAUDIO_GetDefaultAudioInfo(char **name, SDL_AudioSpec *spec, int i
spec->freq = (int)sampleRate;
result = AudioObjectGetPropertyDataSize(devid, &bufaddr, 0, NULL, &size);
if (result != noErr)
if (result != noErr) {
return SDL_SetError("%s: Default Device Data Size not found", "coreaudio");
}
buflist = (AudioBufferList *)SDL_malloc(size);
if (buflist == NULL)
if (buflist == NULL) {
return SDL_SetError("%s: Default Device Buffer List not found", "coreaudio");
}
result = AudioObjectGetPropertyData(devid, &bufaddr, 0, NULL,
&size, buflist);

View File

@@ -199,8 +199,8 @@ static int DSP_OpenDevice(_THIS, const char *devname)
SDL_CalculateAudioSpec(&this->spec);
/* Determine the power of two of the fragment size */
for (frag_spec = 0; (0x01U << frag_spec) < this->spec.size; ++frag_spec)
;
for (frag_spec = 0; (0x01U << frag_spec) < this->spec.size; ++frag_spec) {
}
if ((0x01U << frag_spec) != this->spec.size) {
return SDL_SetError("Fragment size must be a power of two");
}

View File

@@ -162,7 +162,7 @@ static int jackProcessPlaybackCallback(jack_nframes_t nframes, void *arg)
for (channelsi = 0; channelsi < total_channels; channelsi++) {
float *dst = (float *)JACK_jack_port_get_buffer(ports[channelsi], nframes);
if (dst) {
const float *src = ((float *)this->hidden->iobuffer) + channelsi;
const float *src = this->hidden->iobuffer + channelsi;
int framesi;
for (framesi = 0; framesi < total_frames; framesi++) {
*(dst++) = *src;
@@ -202,7 +202,7 @@ static int jackProcessCaptureCallback(jack_nframes_t nframes, void *arg)
for (channelsi = 0; channelsi < total_channels; channelsi++) {
const float *src = (const float *)JACK_jack_port_get_buffer(ports[channelsi], nframes);
if (src) {
float *dst = ((float *)this->hidden->iobuffer) + channelsi;
float *dst = this->hidden->iobuffer + channelsi;
int framesi;
for (framesi = 0; framesi < total_frames; framesi++) {
*dst = *(src++);
@@ -312,6 +312,7 @@ static int JACK_OpenDevice(_THIS, const char *devname)
}
}
if (channels == 0) {
SDL_free(audio_ports);
return SDL_SetError("No physical JACK ports available");
}
@@ -327,36 +328,42 @@ static int JACK_OpenDevice(_THIS, const char *devname)
this->hidden->iosem = SDL_CreateSemaphore(0);
if (!this->hidden->iosem) {
SDL_free(audio_ports);
return -1; /* error was set by SDL_CreateSemaphore */
}
this->hidden->iobuffer = (float *)SDL_calloc(1, this->spec.size);
if (!this->hidden->iobuffer) {
SDL_free(audio_ports);
return SDL_OutOfMemory();
}
/* Build SDL's ports, which we will connect to the device ports. */
this->hidden->sdlports = (jack_port_t **)SDL_calloc(channels, sizeof(jack_port_t *));
if (this->hidden->sdlports == NULL) {
SDL_free(audio_ports);
return SDL_OutOfMemory();
}
for (i = 0; i < channels; i++) {
char portname[32];
SDL_snprintf(portname, sizeof(portname), "sdl_jack_%s_%d", sdlportstr, i);
(void)SDL_snprintf(portname, sizeof(portname), "sdl_jack_%s_%d", sdlportstr, i);
this->hidden->sdlports[i] = JACK_jack_port_register(client, portname, JACK_DEFAULT_AUDIO_TYPE, sdlportflags, 0);
if (this->hidden->sdlports[i] == NULL) {
SDL_free(audio_ports);
return SDL_SetError("jack_port_register failed");
}
}
if (JACK_jack_set_process_callback(client, callback, this) != 0) {
SDL_free(audio_ports);
return SDL_SetError("JACK: Couldn't set process callback");
}
JACK_jack_on_shutdown(client, jackShutdownCallback, this);
if (JACK_jack_activate(client) != 0) {
SDL_free(audio_ports);
return SDL_SetError("Failed to activate JACK client");
}
@@ -366,6 +373,7 @@ static int JACK_OpenDevice(_THIS, const char *devname)
const char *srcport = iscapture ? devports[audio_ports[i]] : sdlport;
const char *dstport = iscapture ? sdlport : devports[audio_ports[i]];
if (JACK_jack_connect(client, srcport, dstport) != 0) {
SDL_free(audio_ports);
return SDL_SetError("Couldn't connect JACK ports: %s => %s", srcport, dstport);
}
}

View File

@@ -144,11 +144,8 @@ static int pipewire_dlsym(const char *fn, void **addr)
static int load_pipewire_library()
{
if ((pipewire_handle = SDL_LoadObject(pipewire_library))) {
return 0;
}
return -1;
pipewire_handle = SDL_LoadObject(pipewire_library);
return pipewire_handle != NULL ? 0 : -1;
}
static void unload_pipewire_library()
@@ -966,7 +963,8 @@ static void output_callback(void *data)
}
/* See if a buffer is available */
if ((pw_buf = PIPEWIRE_pw_stream_dequeue_buffer(stream)) == NULL) {
pw_buf = PIPEWIRE_pw_stream_dequeue_buffer(stream);
if (pw_buf == NULL) {
return;
}
@@ -1035,8 +1033,8 @@ static void input_callback(void *data)
}
spa_buf = pw_buf->buffer;
if ((src = (Uint8 *)spa_buf->datas[0].data) == NULL) {
(src = (Uint8 *)spa_buf->datas[0].data);
if (src == NULL) {
return;
}
@@ -1179,7 +1177,9 @@ static int PIPEWIRE_OpenDevice(_THIS, const char *devname)
return SDL_SetError("Pipewire: Failed to set audio format parameters");
}
if ((this->hidden = priv = SDL_calloc(1, sizeof(struct SDL_PrivateAudioData))) == NULL) {
priv = SDL_calloc(1, sizeof(struct SDL_PrivateAudioData));
this->hidden = priv;
if (priv == NULL) {
return SDL_OutOfMemory();
}
@@ -1191,7 +1191,7 @@ static int PIPEWIRE_OpenDevice(_THIS, const char *devname)
this->spec.size = this->spec.samples * priv->stride;
}
SDL_snprintf(thread_name, sizeof(thread_name), "SDLAudio%c%ld", (iscapture) ? 'C' : 'P', (long)this->handle);
(void)SDL_snprintf(thread_name, sizeof(thread_name), "SDLAudio%c%ld", (iscapture) ? 'C' : 'P', (long)this->handle);
priv->loop = PIPEWIRE_pw_thread_loop_new(thread_name, NULL);
if (priv->loop == NULL) {
return SDL_SetError("Pipewire: Failed to create stream loop (%i)", errno);
@@ -1234,7 +1234,8 @@ static int PIPEWIRE_OpenDevice(_THIS, const char *devname)
const struct io_node *node;
PIPEWIRE_pw_thread_loop_lock(hotplug_loop);
if ((node = io_list_get_by_id(node_id))) {
node = io_list_get_by_id(node_id);
if (node != NULL) {
PIPEWIRE_pw_properties_set(props, PW_KEY_TARGET_OBJECT, node->path);
}
PIPEWIRE_pw_thread_loop_unlock(hotplug_loop);

View File

@@ -180,7 +180,8 @@ static int SNDIO_CaptureFromDevice(_THIS, void *buffer, int buflen)
/* Emulate a blocking read */
r = SNDIO_sio_read(this->hidden->dev, buffer, buflen);
while (r == 0 && !SNDIO_sio_eof(this->hidden->dev)) {
if ((nfds = SNDIO_sio_pollfd(this->hidden->dev, this->hidden->pfd, POLLIN)) <= 0 || poll(this->hidden->pfd, nfds, INFTIM) < 0) {
nfds = SNDIO_sio_pollfd(this->hidden->dev, this->hidden->pfd, POLLIN);
if (nfds <= 0 || poll(this->hidden->pfd, nfds, INFTIM) < 0) {
return -1;
}
revents = SNDIO_sio_revents(this->hidden->dev, this->hidden->pfd);
@@ -237,16 +238,18 @@ static int SNDIO_OpenDevice(_THIS, const char *devname)
this->hidden->mixlen = this->spec.size;
/* Capture devices must be non-blocking for SNDIO_FlushCapture */
if ((this->hidden->dev =
SNDIO_sio_open(devname != NULL ? devname : SIO_DEVANY,
iscapture ? SIO_REC : SIO_PLAY, iscapture)) == NULL) {
this->hidden->dev = SNDIO_sio_open(devname != NULL ? devname : SIO_DEVANY,
iscapture ? SIO_REC : SIO_PLAY, iscapture);
if (this->hidden->dev == NULL) {
return SDL_SetError("sio_open() failed");
}
/* Allocate the pollfd array for capture devices */
if (iscapture && (this->hidden->pfd =
SDL_malloc(sizeof(struct pollfd) * SNDIO_sio_nfds(this->hidden->dev))) == NULL) {
return SDL_OutOfMemory();
if (iscapture) {
this->hidden->pfd = SDL_malloc(sizeof(struct pollfd) * SNDIO_sio_nfds(this->hidden->dev));
if (this->hidden->pfd == NULL) {
return SDL_OutOfMemory();
}
}
SNDIO_sio_initpar(&par);
@@ -282,23 +285,23 @@ static int SNDIO_OpenDevice(_THIS, const char *devname)
return SDL_SetError("%s: Unsupported audio format", "sndio");
}
if ((par.bps == 4) && (par.sig) && (par.le))
if ((par.bps == 4) && (par.sig) && (par.le)) {
this->spec.format = AUDIO_S32LSB;
else if ((par.bps == 4) && (par.sig) && (!par.le))
} else if ((par.bps == 4) && (par.sig) && (!par.le)) {
this->spec.format = AUDIO_S32MSB;
else if ((par.bps == 2) && (par.sig) && (par.le))
} else if ((par.bps == 2) && (par.sig) && (par.le)) {
this->spec.format = AUDIO_S16LSB;
else if ((par.bps == 2) && (par.sig) && (!par.le))
} else if ((par.bps == 2) && (par.sig) && (!par.le)) {
this->spec.format = AUDIO_S16MSB;
else if ((par.bps == 2) && (!par.sig) && (par.le))
} else if ((par.bps == 2) && (!par.sig) && (par.le)) {
this->spec.format = AUDIO_U16LSB;
else if ((par.bps == 2) && (!par.sig) && (!par.le))
} else if ((par.bps == 2) && (!par.sig) && (!par.le)) {
this->spec.format = AUDIO_U16MSB;
else if ((par.bps == 1) && (par.sig))
} else if ((par.bps == 1) && (par.sig)) {
this->spec.format = AUDIO_S8;
else if ((par.bps == 1) && (!par.sig))
} else if ((par.bps == 1) && (!par.sig)) {
this->spec.format = AUDIO_U8;
else {
} else {
return SDL_SetError("sndio: Got unsupported hardware audio format.");
}