21 #include "../SDL_internal.h" 34 #include "../SDL_dataqueue.h" 37 #define DEBUG_AUDIOSTREAM 0 40 #define HAVE_SSE3_INTRINSICS 1 43 #if HAVE_SSE3_INTRINSICS 48 float *
dst = (
float *) cvt->
buf;
49 const float *
src = dst;
57 if ((((
size_t) dst) & 15) == 0) {
59 const __m128 divby2 = _mm_set1_ps(0.5
f);
61 _mm_store_ps(dst, _mm_mul_ps(_mm_hadd_ps(_mm_load_ps(
src), _mm_load_ps(
src+4)), divby2));
62 i -= 4;
src += 8; dst += 4;
68 *dst = (
src[0] +
src[1]) * 0.5
f;
83 float *
dst = (
float *) cvt->
buf;
84 const float *
src = dst;
91 *(dst++) = (
src[0] +
src[1]) * 0.5f;
105 float *
dst = (
float *) cvt->
buf;
106 const float *
src = dst;
113 for (
i = cvt->
len_cvt / (sizeof (
float) * 6);
i; --
i,
src += 6, dst += 2) {
114 const float front_center_distributed = src[2] * 0.5f;
115 dst[0] = (src[0] + front_center_distributed + src[4]) / 2.5
f;
116 dst[1] = (src[1] + front_center_distributed + src[5]) / 2.5
f;
130 float *
dst = (
float *) cvt->
buf;
131 const float *
src = dst;
137 for (
i = cvt->
len_cvt / (sizeof (
float) * 4);
i; --
i,
src += 4, dst += 2) {
138 dst[0] = (src[0] + src[2]) * 0.5
f;
139 dst[1] = (src[1] + src[3]) * 0.5
f;
153 float *
dst = (
float *) cvt->
buf;
154 const float *
src = dst;
160 for (
i = cvt->
len_cvt / (sizeof (
float) * 8);
i; --
i,
src += 8, dst += 6) {
161 const float surround_left_distributed = src[6] * 0.5f;
162 const float surround_right_distributed = src[7] * 0.5f;
163 dst[0] = (src[0] + surround_left_distributed) / 1.5
f;
164 dst[1] = (src[1] + surround_right_distributed) / 1.5
f;
165 dst[2] = src[2] / 1.5f;
166 dst[3] = src[3] / 1.5f;
167 dst[4] = (src[4] + surround_left_distributed) / 1.5
f;
168 dst[5] = (src[5] + surround_right_distributed) / 1.5
f;
183 float *
dst = (
float *) cvt->
buf;
184 const float *
src = dst;
192 for (
i = cvt->
len_cvt / (sizeof (
float) * 6);
i; --
i,
src += 6, dst += 4) {
193 const float front_center_distributed = src[2] * 0.5f;
194 dst[0] = (src[0] + front_center_distributed) / 1.5
f;
195 dst[1] = (src[1] + front_center_distributed) / 1.5
f;
196 dst[2] = src[4] / 1.5f;
197 dst[3] = src[5] / 1.5f;
212 const float *
src = (
const float *) (cvt->
buf + cvt->
len_cvt);
219 for (i = cvt->
len_cvt / sizeof (
float);
i; --
i) {
222 dst[0] = dst[1] = *
src;
238 const float *
src = (
const float *) (cvt->
buf + cvt->
len_cvt);
244 for (i = cvt->
len_cvt / (
sizeof(
float) * 2); i; --i) {
249 ce = (lf + rf) * 0.5
f;
251 dst[0] = lf + (lf - ce);
252 dst[1] = rf + (rf - ce);
271 float lf, rf, lb, rb, ce;
272 const float *
src = (
const float *) (cvt->
buf + cvt->
len_cvt);
279 for (i = cvt->
len_cvt / (
sizeof(
float) * 4); i; --i) {
286 ce = (lf + rf) * 0.5
f;
288 dst[0] = lf + (lf - ce);
289 dst[1] = rf + (rf - ce);
307 const float *
src = (
const float *) (cvt->
buf + cvt->
len_cvt);
315 for (i = cvt->
len_cvt / (
sizeof(
float) * 2); i; --i) {
337 float lf, rf, lb, rb, ls, rs;
339 const float *
src = (
const float *) (cvt->
buf + cvt->
len_cvt);
346 for (i = cvt->
len_cvt / (
sizeof(
float) * 6); i; --i) {
353 ls = (lf + lb) * 0.5
f;
354 rs = (rf + rb) * 0.5
f;
380 #define RESAMPLER_ZERO_CROSSINGS 5 381 #define RESAMPLER_BITS_PER_SAMPLE 16 382 #define RESAMPLER_SAMPLES_PER_ZERO_CROSSING (1 << ((RESAMPLER_BITS_PER_SAMPLE / 2) + 1)) 383 #define RESAMPLER_FILTER_SIZE ((RESAMPLER_SAMPLES_PER_ZERO_CROSSING * RESAMPLER_ZERO_CROSSINGS) + 1) 389 const double xdiv2 = x / 2.0;
396 if (diff < 1.0
e-21f) {
411 const int lenm1 = tablelen - 1;
412 const int lenm1div2 = lenm1 / 2;
416 for (i = 1; i < tablelen; i++) {
418 table[tablelen -
i] = (float) kaiser;
421 for (i = 1; i < tablelen; i++) {
424 diffs[i - 1] = table[
i] - table[i - 1];
440 const double dB = 80.0;
441 const double beta = 0.1102 * (dB - 8.7);
475 if (inrate == outrate) {
477 }
else if (inrate > outrate) {
486 const float *lpadding,
const float *rpadding,
487 const float *inbuf,
const int inbuflen,
488 float *outbuf,
const int outbuflen)
490 const double finrate = (double) inrate;
491 const double outtimeincr = 1.0 / ((float) outrate);
492 const double ratio = ((float) outrate) / ((float) inrate);
494 const int framelen = chans * (int)
sizeof (
float);
495 const int inframes = inbuflen / framelen;
496 const int wantedoutframes = (int) ((inbuflen / framelen) * ratio);
497 const int maxoutframes = outbuflen / framelen;
498 const int outframes =
SDL_min(wantedoutframes, maxoutframes);
500 double outtime = 0.0;
503 for (i = 0; i < outframes; i++) {
504 const int srcindex = (int) (outtime * inrate);
505 const double intime = ((double) srcindex) / finrate;
506 const double innexttime = ((double) (srcindex + 1)) / finrate;
507 const double interpolation1 = 1.0 - ((innexttime - outtime) / (innexttime - intime));
509 const double interpolation2 = 1.0 - interpolation1;
510 const int filterindex2 = (int) (interpolation2 * RESAMPLER_SAMPLES_PER_ZERO_CROSSING);
512 for (chan = 0; chan < chans; chan++) {
513 float outsample = 0.0f;
518 const int srcframe = srcindex -
j;
520 const float insample = (srcframe < 0) ? lpadding[((paddinglen + srcframe) * chans) + chan] : inbuf[(srcframe * chans) + chan];
525 const int srcframe = srcindex + 1 +
j;
527 const float insample = (srcframe >= inframes) ? rpadding[((srcframe - inframes) * chans) + chan] : inbuf[(srcframe * chans) + chan];
530 *(dst++) = outsample;
533 outtime += outtimeincr;
536 return outframes * chans *
sizeof (float);
547 return SDL_SetError(
"No buffer allocated for conversion");
566 printf(
"Converting byte order\n");
570 #define CASESWAP(b) \ 572 Uint##b *ptr = (Uint##b *) cvt->buf; \ 574 for (i = cvt->len_cvt / sizeof (*ptr); i; --i, ++ptr) { \ 575 *ptr = SDL_Swap##b(*ptr); \ 586 default:
SDL_assert(!
"unhandled byteswap datatype!");
break;
592 format &= ~SDL_AUDIO_MASK_ENDIAN;
606 if (filter ==
NULL) {
628 const Uint16 dst_bitsize = 32;
637 default:
SDL_assert(!
"Unexpected audio format!");
break;
641 return SDL_SetError(
"No conversion from source format to float available");
647 if (src_bitsize < dst_bitsize) {
648 const int mult = (dst_bitsize / src_bitsize);
651 }
else if (src_bitsize > dst_bitsize) {
652 cvt->
len_ratio /= (src_bitsize / dst_bitsize);
668 const Uint16 src_bitsize = 32;
676 default:
SDL_assert(!
"Unexpected audio format!");
break;
680 return SDL_SetError(
"No conversion from float to destination format available");
686 if (src_bitsize < dst_bitsize) {
687 const int mult = (dst_bitsize / src_bitsize);
690 }
else if (src_bitsize > dst_bitsize) {
691 cvt->
len_ratio /= (src_bitsize / dst_bitsize);
714 const float *
src = (
const float *) cvt->
buf;
715 const int srclen = cvt->
len_cvt;
719 float *
dst = (
float *) (cvt->
buf + srclen);
720 const int dstlen = (cvt->
len * cvt->
len_mult) - srclen;
727 padding = (
float *)
SDL_calloc(paddingsamples ? paddingsamples : 1,
sizeof (
float));
748 #define RESAMPLER_FUNCS(chans) \ 749 static void SDLCALL \ 750 SDL_ResampleCVT_c##chans(SDL_AudioCVT *cvt, SDL_AudioFormat format) { \ 751 SDL_ResampleCVT(cvt, chans, format); \ 758 #undef RESAMPLER_FUNCS 763 switch (dst_channels) {
764 case 1:
return SDL_ResampleCVT_c1;
765 case 2:
return SDL_ResampleCVT_c2;
766 case 4:
return SDL_ResampleCVT_c4;
767 case 6:
return SDL_ResampleCVT_c6;
768 case 8:
return SDL_ResampleCVT_c8;
777 const int src_rate,
const int dst_rate)
781 if (src_rate == dst_rate) {
786 if (filter ==
NULL) {
787 return SDL_SetError(
"No conversion available for these rates");
808 if (src_rate < dst_rate) {
809 const double mult = ((double) dst_rate) / ((double) src_rate);
813 cvt->
len_ratio /= ((double) src_rate) / ((double) dst_rate);
892 }
else if (src_rate == 0) {
894 }
else if (dst_rate == 0) {
899 printf(
"Build format %04x->%04x, channels %u->%u, rate %d->%d\n",
900 src_fmt, dst_fmt, src_channels, dst_channels, src_rate, dst_rate);
911 cvt->
rate_incr = ((double) dst_rate) / ((double) src_rate);
931 if (src_rate == dst_rate && src_channels == dst_channels) {
932 if (src_fmt == dst_fmt) {
952 if (src_channels < dst_channels) {
955 if ((src_channels == 1) && (dst_channels > 1)) {
964 if ((src_channels == 2) && (dst_channels >= 6)) {
973 if ((src_channels == 4) && (dst_channels >= 6)) {
982 if ((src_channels == 6) && (dst_channels == 8)) {
993 if ((src_channels == 2) && (dst_channels == 4)) {
1001 }
else if (src_channels > dst_channels) {
1005 if ((src_channels == 8) && (dst_channels <= 6)) {
1013 if ((src_channels == 6) && (dst_channels <= 2)) {
1021 if ((src_channels == 6) && (dst_channels == 4)) {
1029 if ((src_channels == 4) && (dst_channels <= 2)) {
1037 if ((src_channels == 2) && (dst_channels == 1)) {
1040 #if HAVE_SSE3_INTRINSICS 1042 filter = SDL_ConvertStereoToMono_SSE3;
1059 if (src_channels != dst_channels) {
1119 if (stream->work_buffer_len >= newlen) {
1120 ptr = stream->work_buffer_base;
1128 stream->work_buffer_base =
ptr;
1129 stream->work_buffer_len = newlen;
1132 offset = ((
size_t) ptr) & 15;
1133 return offset ? ptr + (16 -
offset) : ptr;
1136 #ifdef HAVE_LIBSAMPLERATE_H 1138 SDL_ResampleAudioStream_SRC(SDL_AudioStream *stream,
const void *_inbuf,
const int inbuflen,
void *_outbuf,
const int outbuflen)
1140 const float *inbuf = (
const float *) _inbuf;
1141 float *outbuf = (
float *) _outbuf;
1142 const int framelen =
sizeof(float) * stream->pre_resample_channels;
1143 SRC_STATE *
state = (SRC_STATE *)stream->resampler_state;
1147 SDL_assert(inbuf != ((
const float *) outbuf));
1149 data.data_in = (
float *)inbuf;
1150 data.input_frames = inbuflen / framelen;
1151 data.input_frames_used = 0;
1153 data.data_out = outbuf;
1154 data.output_frames = outbuflen / framelen;
1156 data.end_of_input = 0;
1157 data.src_ratio = stream->rate_incr;
1159 result = SRC_src_process(
state, &data);
1161 SDL_SetError(
"src_process() failed: %s", SRC_src_strerror(result));
1166 SDL_assert(data.input_frames_used == data.input_frames);
1168 return data.output_frames_gen * (
sizeof(float) * stream->pre_resample_channels);
1172 SDL_ResetAudioStreamResampler_SRC(SDL_AudioStream *stream)
1174 SRC_src_reset((SRC_STATE *)stream->resampler_state);
1178 SDL_CleanupAudioStreamResampler_SRC(SDL_AudioStream *stream)
1180 SRC_STATE *
state = (SRC_STATE *)stream->resampler_state;
1182 SRC_src_delete(state);
1185 stream->resampler_state =
NULL;
1186 stream->resampler_func =
NULL;
1187 stream->reset_resampler_func =
NULL;
1188 stream->cleanup_resampler_func =
NULL;
1192 SetupLibSampleRateResampling(SDL_AudioStream *stream)
1197 if (SRC_available) {
1198 state = SRC_src_new(SRC_converter, stream->pre_resample_channels, &result);
1200 SDL_SetError(
"src_new() failed: %s", SRC_src_strerror(result));
1205 SDL_CleanupAudioStreamResampler_SRC(stream);
1209 stream->resampler_state =
state;
1210 stream->resampler_func = SDL_ResampleAudioStream_SRC;
1211 stream->reset_resampler_func = SDL_ResetAudioStreamResampler_SRC;
1212 stream->cleanup_resampler_func = SDL_CleanupAudioStreamResampler_SRC;
1222 const Uint8 *inbufend = ((
const Uint8 *) _inbuf) + inbuflen;
1223 const float *inbuf = (
const float *) _inbuf;
1224 float *outbuf = (
float *) _outbuf;
1225 const int chans = (int) stream->pre_resample_channels;
1226 const int inrate = stream->src_rate;
1227 const int outrate = stream->dst_rate;
1228 const int paddingsamples = stream->resampler_padding_samples;
1229 const int paddingbytes = paddingsamples * sizeof (
float);
1230 float *lpadding = (
float *) stream->resampler_state;
1231 const float *rpadding = (
const float *) inbufend;
1232 const int cpy =
SDL_min(inbuflen, paddingbytes);
1235 SDL_assert(inbuf != ((
const float *) outbuf));
1237 retval =
SDL_ResampleAudio(chans, inrate, outrate, lpadding, rpadding, inbuf, inbuflen, outbuf, outbuflen);
1240 SDL_memcpy((lpadding + paddingsamples) - (cpy /
sizeof (
float)), inbufend - cpy, cpy);
1248 const int len = stream->resampler_padding_samples;
1249 SDL_memset(stream->resampler_state,
'\0', len * sizeof (
float));
1270 retval = (SDL_AudioStream *)
SDL_calloc(1,
sizeof (SDL_AudioStream));
1279 pre_resample_channels =
SDL_min(src_channels, dst_channels);
1282 retval->src_sample_frame_size = (
SDL_AUDIO_BITSIZE(src_format) / 8) * src_channels;
1286 retval->dst_sample_frame_size = (
SDL_AUDIO_BITSIZE(dst_format) / 8) * dst_channels;
1292 retval->rate_incr = ((double) dst_rate) / ((double) src_rate);
1294 retval->resampler_padding = (
float *)
SDL_calloc(retval->resampler_padding_samples ? retval->resampler_padding_samples : 1, sizeof (
float));
1296 if (retval->resampler_padding ==
NULL) {
1302 retval->staging_buffer_size = ((retval->resampler_padding_samples / retval->pre_resample_channels) * retval->src_sample_frame_size);
1303 if (retval->staging_buffer_size > 0) {
1304 retval->staging_buffer = (
Uint8 *)
SDL_malloc(retval->staging_buffer_size);
1305 if (retval->staging_buffer ==
NULL) {
1313 if (src_rate == dst_rate) {
1314 retval->cvt_before_resampling.needed =
SDL_FALSE;
1315 if (
SDL_BuildAudioCVT(&retval->cvt_after_resampling, src_format, src_channels, dst_rate, dst_format, dst_channels, dst_rate) < 0) {
1322 if (
SDL_BuildAudioCVT(&retval->cvt_before_resampling, src_format, src_channels, src_rate,
AUDIO_F32SYS, pre_resample_channels, src_rate) < 0) {
1327 #ifdef HAVE_LIBSAMPLERATE_H 1328 SetupLibSampleRateResampling(retval);
1331 if (!retval->resampler_func) {
1332 retval->resampler_state =
SDL_calloc(retval->resampler_padding_samples, sizeof (
float));
1333 if (!retval->resampler_state) {
1341 retval->resampler_state =
NULL;
1352 if (
SDL_BuildAudioCVT(&retval->cvt_after_resampling,
AUDIO_F32SYS, pre_resample_channels, dst_rate, dst_format, dst_channels, dst_rate) < 0) {
1359 if (!retval->queue) {
1374 int resamplebuflen = 0;
1375 int neededpaddingbytes;
1387 neededpaddingbytes = stream->resampler_padding_samples *
sizeof (float);
1388 paddingbytes = stream->first_run ? 0 : neededpaddingbytes;
1392 workbuflen = buflen;
1393 if (stream->cvt_before_resampling.needed) {
1394 workbuflen *= stream->cvt_before_resampling.len_mult;
1397 if (stream->dst_rate != stream->src_rate) {
1399 const int framesize = stream->pre_resample_channels *
sizeof (float);
1400 const int frames = workbuflen / framesize;
1401 resamplebuflen = ((int)
SDL_ceil(frames * stream->rate_incr)) * framesize;
1402 #if DEBUG_AUDIOSTREAM 1403 printf(
"AUDIOSTREAM: will resample %d bytes to %d (ratio=%.6f)\n", workbuflen, resamplebuflen, stream->rate_incr);
1405 workbuflen += resamplebuflen;
1408 if (stream->cvt_after_resampling.needed) {
1410 workbuflen *= stream->cvt_after_resampling.len_mult;
1413 workbuflen += neededpaddingbytes;
1415 #if DEBUG_AUDIOSTREAM 1416 printf(
"AUDIOSTREAM: Putting %d bytes of preconverted audio, need %d byte work buffer\n", buflen, workbuflen);
1424 resamplebuf = workbuf;
1426 SDL_memcpy(workbuf + paddingbytes, buf, buflen);
1428 if (stream->cvt_before_resampling.needed) {
1429 stream->cvt_before_resampling.buf = workbuf + paddingbytes;
1430 stream->cvt_before_resampling.len = buflen;
1434 buflen = stream->cvt_before_resampling.len_cvt;
1436 #if DEBUG_AUDIOSTREAM 1437 printf(
"AUDIOSTREAM: After initial conversion we have %d bytes\n", buflen);
1441 if (stream->dst_rate != stream->src_rate) {
1448 SDL_memcpy(workbuf, stream->resampler_padding, paddingbytes);
1449 buflen += paddingbytes;
1453 SDL_memcpy(stream->resampler_padding, workbuf + (buflen - neededpaddingbytes), neededpaddingbytes);
1455 resamplebuf = workbuf + buflen;
1457 if (buflen > neededpaddingbytes) {
1458 buflen = stream->resampler_func(stream, workbuf, buflen - neededpaddingbytes, resamplebuf, resamplebuflen);
1463 #if DEBUG_AUDIOSTREAM 1464 printf(
"AUDIOSTREAM: After resampling we have %d bytes\n", buflen);
1468 if (stream->cvt_after_resampling.needed && (buflen > 0)) {
1469 stream->cvt_after_resampling.buf = resamplebuf;
1470 stream->cvt_after_resampling.len = buflen;
1474 buflen = stream->cvt_after_resampling.len_cvt;
1476 #if DEBUG_AUDIOSTREAM 1477 printf(
"AUDIOSTREAM: After final conversion we have %d bytes\n", buflen);
1481 #if DEBUG_AUDIOSTREAM 1482 printf(
"AUDIOSTREAM: Final output is %d bytes\n", buflen);
1486 const int maxbytes = *maxputbytes;
1487 if (buflen > maxbytes)
1489 *maxputbytes -= buflen;
1507 #if DEBUG_AUDIOSTREAM 1508 printf(
"AUDIOSTREAM: wants to put %d preconverted bytes\n", buflen);
1515 }
else if (len == 0) {
1517 }
else if ((len % stream->src_sample_frame_size) != 0) {
1518 return SDL_SetError(
"Can't add partial sample frames");
1521 if (!stream->cvt_before_resampling.needed &&
1522 (stream->dst_rate == stream->src_rate) &&
1523 !stream->cvt_after_resampling.needed) {
1524 #if DEBUG_AUDIOSTREAM 1525 printf(
"AUDIOSTREAM: no conversion needed at all, queueing %d bytes.\n", len);
1536 if (!stream->staging_buffer_filled && len >= stream->staging_buffer_size) {
1541 if ((stream->staging_buffer_filled + len) < stream->staging_buffer_size) {
1542 SDL_memcpy(stream->staging_buffer + stream->staging_buffer_filled, buf, len);
1543 stream->staging_buffer_filled +=
len;
1548 amount = (stream->staging_buffer_size - stream->staging_buffer_filled);
1550 SDL_memcpy(stream->staging_buffer + stream->staging_buffer_filled, buf, amount);
1551 stream->staging_buffer_filled = 0;
1555 buf = (
void *)((
Uint8 *)buf + amount);
1567 #if DEBUG_AUDIOSTREAM 1568 printf(
"AUDIOSTREAM: flushing! staging_buffer_filled=%d bytes\n", stream->staging_buffer_filled);
1572 SDL_assert((stream->dst_rate != stream->src_rate) || (stream->staging_buffer_filled == 0));
1574 if (stream->staging_buffer_filled > 0) {
1579 const int filled = stream->staging_buffer_filled;
1580 int actual_input_frames = filled / stream->src_sample_frame_size;
1582 actual_input_frames += stream->resampler_padding_samples / stream->pre_resample_channels;
1584 if (actual_input_frames > 0) {
1586 int flush_remaining = ((int)
SDL_ceil(actual_input_frames * stream->rate_incr)) * stream->dst_sample_frame_size;
1589 printf(
"AUDIOSTREAM: flushing with padding to get max %d bytes!\n", flush_remaining);
1592 SDL_memset(stream->staging_buffer + filled,
'\0', stream->staging_buffer_size - filled);
1600 SDL_memset(stream->staging_buffer,
'\0', filled);
1607 stream->staging_buffer_filled = 0;
1617 #if DEBUG_AUDIOSTREAM 1618 printf(
"AUDIOSTREAM: want to get %d converted bytes\n", len);
1625 }
else if (len <= 0) {
1627 }
else if ((len % stream->dst_sample_frame_size) != 0) {
1628 return SDL_SetError(
"Can't request partial sample frames");
1648 if (stream->reset_resampler_func) {
1649 stream->reset_resampler_func(stream);
1652 stream->staging_buffer_filled = 0;
1661 if (stream->cleanup_resampler_func) {
1662 stream->cleanup_resampler_func(stream);
1666 SDL_free(stream->work_buffer_base);
1667 SDL_free(stream->resampler_padding);
static SDL_AudioFilter ChooseCVTResampler(const int dst_channels)
static int ResamplerPadding(const int inrate, const int outrate)
#define RESAMPLER_SAMPLES_PER_ZERO_CROSSING
#define LOG_DEBUG_CONVERT(from, to)
int SDL_AudioStreamAvailable(SDL_AudioStream *stream)
void SDL_FreeResampleFilter(void)
void(* SDL_CleanupAudioStreamResamplerFunc)(SDL_AudioStream *stream)
#define SDL_AUDIOCVT_MAX_FILTERS
Upper limit of filters in SDL_AudioCVT.
static void SDL_Convert71To51(SDL_AudioCVT *cvt, SDL_AudioFormat format)
GLenum GLsizei GLenum GLenum const void * table
SDL_AudioFormat src_format
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 SDL_AssertionHandler void SDL_SpinLock SDL_atomic_t int int return SDL_atomic_t return void void void return void return int return SDL_AudioSpec SDL_AudioSpec return int int return return int SDL_RWops int SDL_AudioSpec Uint8 Uint32 * e
int SDL_WriteToDataQueue(SDL_DataQueue *queue, const void *_data, const size_t _len)
#define SDL_AUDIO_ISBIGENDIAN(x)
GLint GLint GLint GLint GLint x
void SDL_ChooseAudioConverters(void)
int SDL_AudioStreamGet(SDL_AudioStream *stream, void *buf, int len)
SDL_AudioFilter SDL_Convert_F32_to_S32
SDL_AudioFormat dst_format
set set set set set set set set set set set set set set set set set set set set *set set set macro pixldst op &r &cond WK op &r &cond WK op &r &cond WK else op &m &cond &ia op &r &cond WK else op &m &cond &ia elseif elseif else error unsupported base if elseif elseif else error unsupported unaligned pixldst unaligned endm macro pixst base base else pixldst base endif endm macro PF ptr
static void SDL_Convert51ToStereo(SDL_AudioCVT *cvt, SDL_AudioFormat format)
static SDL_bool SDL_SupportedAudioFormat(const SDL_AudioFormat fmt)
SDL_AudioFilter SDL_Convert_S16_to_F32
SDL_AudioFilter SDL_Convert_U16_to_F32
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d ®2 endm macro vzip8 reg2 vzip d d ®2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld [DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp local skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
SDL_DataQueue * SDL_NewDataQueue(const size_t _packetlen, const size_t initialslack)
static void SDL_ConvertStereoToQuad(SDL_AudioCVT *cvt, SDL_AudioFormat format)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
SDL_AudioCVT cvt_after_resampling
Uint16 SDL_AudioFormat
Audio format flags.
static SDL_SpinLock ResampleFilterSpinlock
static float * ResamplerFilter
void SDL_FreeAudioStream(SDL_AudioStream *stream)
static void SDL_Convert51ToQuad(SDL_AudioCVT *cvt, SDL_AudioFormat format)
#define SDL_AUDIO_MASK_ENDIAN
#define SDL_InvalidParamError(param)
static int SDL_BuildAudioTypeCVTToFloat(SDL_AudioCVT *cvt, const SDL_AudioFormat src_fmt)
static int SDL_ResampleAudio(const int chans, const int inrate, const int outrate, const float *lpadding, const float *rpadding, const float *inbuf, const int inbuflen, float *outbuf, const int outbuflen)
static void SDL_Convert_Byteswap(SDL_AudioCVT *cvt, SDL_AudioFormat format)
static void kaiser_and_sinc(float *table, float *diffs, const int tablelen, const double beta)
static Uint8 * EnsureStreamBufferSize(SDL_AudioStream *stream, const int newlen)
static float * ResamplerFilterDifference
A structure to hold a set of audio conversion filters and buffers.
static double bessel(const double x)
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
#define SDL_AUDIO_ISFLOAT(x)
static void SDL_Convert51To71(SDL_AudioCVT *cvt, SDL_AudioFormat format)
static void SDL_ResetAudioStreamResampler(SDL_AudioStream *stream)
static int SDL_BuildAudioResampleCVT(SDL_AudioCVT *cvt, const int dst_channels, const int src_rate, const int dst_rate)
int resampler_padding_samples
int SDL_PrepareResampleFilter(void)
SDL_AudioFilter filters[SDL_AUDIOCVT_MAX_FILTERS+1]
int SDL_AudioStreamPut(SDL_AudioStream *stream, const void *buf, int len)
#define SDL_AUDIO_BITSIZE(x)
void(* SDL_ResetAudioStreamResamplerFunc)(SDL_AudioStream *stream)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int int in j)
int SDL_ConvertAudio(SDL_AudioCVT *cvt)
static int SDL_AudioStreamPutInternal(SDL_AudioStream *stream, const void *buf, int len, int *maxputbytes)
static void SDL_ResampleCVT(SDL_AudioCVT *cvt, const int chans, const SDL_AudioFormat format)
SDL_AudioFilter SDL_Convert_F32_to_S8
size_t SDL_ReadFromDataQueue(SDL_DataQueue *queue, void *_buf, const size_t _len)
static void SDL_ConvertQuadToStereo(SDL_AudioCVT *cvt, SDL_AudioFormat format)
int src_sample_frame_size
SDL_AudioStream * SDL_NewAudioStream(const SDL_AudioFormat src_format, const Uint8 src_channels, const int src_rate, const SDL_AudioFormat dst_format, const Uint8 dst_channels, const int dst_rate)
#define RESAMPLER_FUNCS(chans)
SDL_AudioFormat src_format
GLenum GLuint GLenum GLsizei const GLchar * buf
static int SDL_ResampleAudioStream(SDL_AudioStream *stream, const void *_inbuf, const int inbuflen, void *_outbuf, const int outbuflen)
#define RESAMPLER_FILTER_SIZE
int dst_sample_frame_size
SDL_AudioFilter SDL_Convert_F32_to_U8
int SDL_AudioStreamFlush(SDL_AudioStream *stream)
void(* SDL_AudioFilter)(struct SDL_AudioCVT *cvt, SDL_AudioFormat format)
SDL_AudioFilter SDL_Convert_S8_to_F32
SDL_ResetAudioStreamResamplerFunc reset_resampler_func
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)
static void SDL_ConvertQuadTo51(SDL_AudioCVT *cvt, SDL_AudioFormat format)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
#define SDL_assert(condition)
SDL_AudioFilter SDL_Convert_U8_to_F32
Uint8 pre_resample_channels
#define SDL_OutOfMemory()
static SDL_bool SDL_SupportedChannelCount(const int channels)
SDL_ResampleAudioStreamFunc resampler_func
void SDL_AudioStreamClear(SDL_AudioStream *stream)
void SDL_ClearDataQueue(SDL_DataQueue *queue, const size_t slack)
SDL_AudioFormat dst_format
SDL_AudioFilter SDL_Convert_F32_to_U16
SDL_CleanupAudioStreamResamplerFunc cleanup_resampler_func
SDL_AudioCVT cvt_before_resampling
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 void
static void SDL_ConvertMonoToStereo(SDL_AudioCVT *cvt, SDL_AudioFormat format)
size_t SDL_CountDataQueue(SDL_DataQueue *queue)
static void SDL_CleanupAudioStreamResampler(SDL_AudioStream *stream)
static int SDL_AddAudioCVTFilter(SDL_AudioCVT *cvt, const SDL_AudioFilter filter)
float * resampler_padding
static int SDL_BuildAudioTypeCVTFromFloat(SDL_AudioCVT *cvt, const SDL_AudioFormat dst_fmt)
static void SDL_ConvertStereoTo51(SDL_AudioCVT *cvt, SDL_AudioFormat format)
void SDL_FreeDataQueue(SDL_DataQueue *queue)
SDL_AudioFilter SDL_Convert_S32_to_F32
SDL_AudioFilter SDL_Convert_F32_to_S16
int staging_buffer_filled
static void SDL_ConvertStereoToMono(SDL_AudioCVT *cvt, SDL_AudioFormat format)
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
#define DEBUG_AUDIOSTREAM
int(* SDL_ResampleAudioStreamFunc)(SDL_AudioStream *stream, const void *inbuf, const int inbuflen, void *outbuf, const int outbuflen)