Added SDL_AUDIO_BYTESIZE
parent
544351c98e
commit
53122593f8
|
@ -84,6 +84,7 @@ typedef Uint16 SDL_AudioFormat;
|
|||
#define SDL_AUDIO_MASK_BIG_ENDIAN (1<<12)
|
||||
#define SDL_AUDIO_MASK_SIGNED (1<<15)
|
||||
#define SDL_AUDIO_BITSIZE(x) ((x) & SDL_AUDIO_MASK_BITSIZE)
|
||||
#define SDL_AUDIO_BYTESIZE(x) (SDL_AUDIO_BITSIZE(x) / 8)
|
||||
#define SDL_AUDIO_ISFLOAT(x) ((x) & SDL_AUDIO_MASK_FLOAT)
|
||||
#define SDL_AUDIO_ISBIGENDIAN(x) ((x) & SDL_AUDIO_MASK_BIG_ENDIAN)
|
||||
#define SDL_AUDIO_ISLITTLEENDIAN(x) (!SDL_AUDIO_ISBIGENDIAN(x))
|
||||
|
|
|
@ -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.
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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'];
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -513,7 +513,7 @@ static void StreamThing_ontick(Thing *thing, Uint64 now)
|
|||
if (!available || (SDL_GetAudioStreamFormat(thing->data.stream.stream, NULL, &spec) < 0)) {
|
||||
DestroyThingInPoof(thing);
|
||||
} else {
|
||||
const int ticksleft = (int) ((((Uint64) ((available / (SDL_AUDIO_BITSIZE(spec.format) / 8)) / spec.channels)) * 1000) / spec.freq);
|
||||
const int ticksleft = (int) ((((Uint64) ((available / SDL_AUDIO_BYTESIZE(spec.format)) / spec.channels)) * 1000) / spec.freq);
|
||||
const float pct = thing->data.stream.total_ticks ? (((float) (ticksleft)) / ((float) thing->data.stream.total_ticks)) : 0.0f;
|
||||
thing->progress = 1.0f - pct;
|
||||
}
|
||||
|
@ -553,7 +553,7 @@ static void StreamThing_ondrop(Thing *thing, int button, float x, float y)
|
|||
SDL_UnbindAudioStream(thing->data.stream.stream); /* unbind from current device */
|
||||
if (thing->line_connected_to->what == THING_LOGDEV_CAPTURE) {
|
||||
SDL_FlushAudioStream(thing->data.stream.stream);
|
||||
thing->data.stream.total_ticks = (int) (((((Uint64) (SDL_GetAudioStreamAvailable(thing->data.stream.stream) / (SDL_AUDIO_BITSIZE(spec->format) / 8))) / spec->channels) * 1000) / spec->freq);
|
||||
thing->data.stream.total_ticks = (int) (((((Uint64) (SDL_GetAudioStreamAvailable(thing->data.stream.stream) / SDL_AUDIO_BYTESIZE(spec->format))) / spec->channels) * 1000) / spec->freq);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -596,7 +596,7 @@ static Thing *CreateStreamThing(const SDL_AudioSpec *spec, const Uint8 *buf, con
|
|||
if (buf && buflen) {
|
||||
SDL_PutAudioStreamData(thing->data.stream.stream, buf, (int) buflen);
|
||||
SDL_FlushAudioStream(thing->data.stream.stream);
|
||||
thing->data.stream.total_ticks = (int) (((((Uint64) (SDL_GetAudioStreamAvailable(thing->data.stream.stream) / (SDL_AUDIO_BITSIZE(spec->format) / 8))) / spec->channels) * 1000) / spec->freq);
|
||||
thing->data.stream.total_ticks = (int) (((((Uint64) (SDL_GetAudioStreamAvailable(thing->data.stream.stream) / SDL_AUDIO_BYTESIZE(spec->format))) / spec->channels) * 1000) / spec->freq);
|
||||
}
|
||||
thing->ontick = StreamThing_ontick;
|
||||
thing->ondrag = StreamThing_ondrag;
|
||||
|
|
|
@ -292,7 +292,7 @@ static void loop(void)
|
|||
|
||||
if (SDL_GetAudioStreamFormat(stream, &src_spec, &dst_spec) == 0) {
|
||||
available_bytes = SDL_GetAudioStreamAvailable(stream);
|
||||
available_seconds = (float)available_bytes / (float)(SDL_AUDIO_BITSIZE(dst_spec.format) / 8 * dst_spec.freq * dst_spec.channels);
|
||||
available_seconds = (float)available_bytes / (float)(SDL_AUDIO_BYTESIZE(dst_spec.format) * dst_spec.freq * dst_spec.channels);
|
||||
|
||||
/* keep it looping. */
|
||||
if (auto_loop && (available_seconds < 10.0f)) {
|
||||
|
|
|
@ -712,8 +712,8 @@ static int audio_convertAudio(void *arg)
|
|||
int src_samplesize, dst_samplesize;
|
||||
int src_silence, dst_silence;
|
||||
|
||||
src_samplesize = (SDL_AUDIO_BITSIZE(spec1.format) / 8) * spec1.channels;
|
||||
dst_samplesize = (SDL_AUDIO_BITSIZE(spec2.format) / 8) * spec2.channels;
|
||||
src_samplesize = SDL_AUDIO_BYTESIZE(spec1.format) * spec1.channels;
|
||||
dst_samplesize = SDL_AUDIO_BYTESIZE(spec2.format) * spec2.channels;
|
||||
|
||||
src_len = l * src_samplesize;
|
||||
SDLTest_Log("Creating dummy sample buffer of %i length (%i bytes)", l, src_len);
|
||||
|
|
Loading…
Reference in New Issue