Added SDL_AUDIO_BYTESIZE

This commit is contained in:
Brick
2023-09-05 23:02:37 +01:00
committed by Sam Lantinga
parent 544351c98e
commit 53122593f8
12 changed files with 21 additions and 20 deletions

View File

@@ -766,7 +766,7 @@ SDL_bool SDL_OutputAudioThreadIterate(SDL_AudioDevice *device)
case MIXSTRATEGY_MIX: {
//SDL_Log("MIX STRATEGY: MIX");
float *mix_buffer = (float *) ((device->spec.format == SDL_AUDIO_F32) ? device_buffer : device->mix_buffer);
const int needed_samples = buffer_size / (SDL_AUDIO_BITSIZE(device->spec.format) / 8);
const int needed_samples = buffer_size / SDL_AUDIO_BYTESIZE(device->spec.format);
const int work_buffer_size = needed_samples * sizeof (float);
SDL_AudioSpec outspec;
@@ -832,7 +832,7 @@ SDL_bool SDL_OutputAudioThreadIterate(SDL_AudioDevice *device)
void SDL_OutputAudioThreadShutdown(SDL_AudioDevice *device)
{
SDL_assert(!device->iscapture);
const int samples = (device->buffer_size / (SDL_AUDIO_BITSIZE(device->spec.format) / 8)) / device->spec.channels;
const int samples = (device->buffer_size / SDL_AUDIO_BYTESIZE(device->spec.format)) / device->spec.channels;
// Wait for the audio to drain. !!! FIXME: don't bother waiting if device is lost.
SDL_Delay(((samples * 1000) / device->spec.freq) * 2);
current_audio.impl.ThreadDeinit(device);
@@ -1261,7 +1261,7 @@ static int GetDefaultSampleFramesFromFreq(int freq)
void SDL_UpdatedAudioDeviceFormat(SDL_AudioDevice *device)
{
device->silence_value = SDL_GetSilenceValueForFormat(device->spec.format);
device->buffer_size = device->sample_frames * (SDL_AUDIO_BITSIZE(device->spec.format) / 8) * device->spec.channels;
device->buffer_size = device->sample_frames * SDL_AUDIO_BYTESIZE(device->spec.format) * device->spec.channels;
device->work_buffer_size = device->sample_frames * sizeof (float) * device->spec.channels;
device->work_buffer_size = SDL_max(device->buffer_size, device->work_buffer_size); // just in case we end up with a 64-bit audio format at some point.
}

View File

@@ -1048,8 +1048,8 @@ void ConvertAudio(int num_frames, const void *src, SDL_AudioFormat src_format, i
// Calculate the largest frame size needed to convert between the two formats.
static int CalculateMaxFrameSize(SDL_AudioFormat src_format, int src_channels, SDL_AudioFormat dst_format, int dst_channels)
{
const int src_format_size = SDL_AUDIO_BITSIZE(src_format) / 8;
const int dst_format_size = SDL_AUDIO_BITSIZE(dst_format) / 8;
const int src_format_size = SDL_AUDIO_BYTESIZE(src_format);
const int dst_format_size = SDL_AUDIO_BYTESIZE(dst_format);
const int max_app_format_size = SDL_max(src_format_size, dst_format_size);
const int max_format_size = SDL_max(max_app_format_size, sizeof (float)); // ConvertAudio and ResampleAudio use floats.
const int max_channels = SDL_max(src_channels, dst_channels);
@@ -1058,7 +1058,7 @@ static int CalculateMaxFrameSize(SDL_AudioFormat src_format, int src_channels, S
static int GetAudioSpecFrameSize(const SDL_AudioSpec* spec)
{
return (SDL_AUDIO_BITSIZE(spec->format) / 8) * spec->channels;
return SDL_AUDIO_BYTESIZE(spec->format) * spec->channels;
}
static Sint64 GetStreamResampleRate(SDL_AudioStream* stream, int src_freq)

View File

@@ -355,7 +355,7 @@ static int ALSA_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buf
{
SDL_assert(buffer == device->hidden->mixbuf);
Uint8 *sample_buf = device->hidden->mixbuf;
const int frame_size = ((SDL_AUDIO_BITSIZE(device->spec.format)) / 8) *
const int frame_size = SDL_AUDIO_BYTESIZE(device->spec.format) *
device->spec.channels;
snd_pcm_uframes_t frames_left = (snd_pcm_uframes_t) (buflen / frame_size);
@@ -402,7 +402,7 @@ static Uint8 *ALSA_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
static int ALSA_CaptureFromDevice(SDL_AudioDevice *device, void *buffer, int buflen)
{
Uint8 *sample_buf = (Uint8 *)buffer;
const int frame_size = ((SDL_AUDIO_BITSIZE(device->spec.format)) / 8) *
const int frame_size = SDL_AUDIO_BYTESIZE(device->spec.format) *
device->spec.channels;
const int total_frames = buflen / frame_size;
snd_pcm_uframes_t frames_left = total_frames;

View File

@@ -38,7 +38,7 @@ static Uint8 *EMSCRIPTENAUDIO_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_
static int EMSCRIPTENAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size)
{
const int framelen = (SDL_AUDIO_BITSIZE(device->spec.format) / 8) * device->spec.channels;
const int framelen = SDL_AUDIO_BYTESIZE(device->spec.format) * device->spec.channels;
MAIN_THREAD_EM_ASM({
var SDL3 = Module['SDL3'];
var numChannels = SDL3.audio.currentOutputBuffer['numberOfChannels'];

View File

@@ -161,7 +161,7 @@ static int N3DSAUDIO_OpenDevice(SDL_AudioDevice *device)
SDL_memset(device->hidden->waveBuf, 0, sizeof(ndspWaveBuf) * NUM_BUFFERS);
const int sample_frame_size = device->spec.channels * (SDL_AUDIO_BITSIZE(device->spec.format) / 8);
const int sample_frame_size = device->spec.channels * SDL_AUDIO_BYTESIZE(device->spec.format);
for (unsigned i = 0; i < NUM_BUFFERS; i++) {
device->hidden->waveBuf[i].data_vaddr = data_vaddr;
device->hidden->waveBuf[i].nsamples = device->buffer_size / sample_frame_size;

View File

@@ -130,7 +130,7 @@ static void NETBSDAUDIO_WaitDevice(SDL_AudioDevice *device)
SDL_AudioDeviceDisconnected(device);
return;
}
const size_t remain = (size_t)((iscapture ? info.record.seek : info.play.seek) * (SDL_AUDIO_BITSIZE(device->spec.format) / 8));
const size_t remain = (size_t)((iscapture ? info.record.seek : info.play.seek) * SDL_AUDIO_BYTESIZE(device->spec.format));
if (!iscapture && (remain >= device->buffer_size)) {
SDL_Delay(10);
} else if (iscapture && (remain < device->buffer_size)) {
@@ -181,7 +181,7 @@ static void NETBSDAUDIO_FlushCapture(SDL_AudioDevice *device)
struct SDL_PrivateAudioData *h = device->hidden;
audio_info_t info;
if (ioctl(device->hidden->audio_fd, AUDIO_GETINFO, &info) == 0) {
size_t remain = (size_t)(info.record.seek * (SDL_AUDIO_BITSIZE(device->spec.format) / 8));
size_t remain = (size_t)(info.record.seek * SDL_AUDIO_BYTESIZE(device->spec.format));
while (remain > 0) {
char buf[512];
const size_t len = SDL_min(sizeof(buf), remain);

View File

@@ -1108,7 +1108,7 @@ static int PIPEWIRE_OpenDevice(SDL_AudioDevice *device)
}
/* Size of a single audio frame in bytes */
priv->stride = (SDL_AUDIO_BITSIZE(device->spec.format) / 8) * device->spec.channels;
priv->stride = SDL_AUDIO_BYTESIZE(device->spec.format) * device->spec.channels;
if (device->sample_frames < min_period) {
device->sample_frames = min_period;

View File

@@ -621,7 +621,7 @@ static int mgmtthrtask_PrepDevice(void *userdata)
return -1;
}
device->hidden->framesize = (SDL_AUDIO_BITSIZE(device->spec.format) / 8) * device->spec.channels;
device->hidden->framesize = SDL_AUDIO_BYTESIZE(device->spec.format) * device->spec.channels;
if (device->iscapture) {
IAudioCaptureClient *capture = NULL;