Mercurial > sdl-ios-xcode
comparison src/audio/SDL_audio.c @ 1982:3b4ce57c6215
First shot at new audio data types (int32 and float32).
Notable changes:
- Converters between types are autogenerated. Instead of making multiple
passes over the data with seperate filters for endianess, size, signedness,
etc, converting between data types is always one specialized filter. This
simplifies SDL_BuildAudioCVT(), which otherwise had a million edge cases
with the new types, and makes the actually conversions more CPU cache
friendly. Left a stub for adding specific optimized versions of these
routines (SSE/MMX/Altivec, assembler, etc)
- Autogenerated converters are built by SDL/src/audio/sdlgenaudiocvt.pl. This
does not need to be run unless tweaking the code, and thus doesn't need
integration into the build system.
- Went through all the drivers and tried to weed out all the "Uint16"
references that are better specified with the new SDL_AudioFormat typedef.
- Cleaned out a bunch of hardcoded bitwise magic numbers and replaced them
with new SDL_AUDIO_* macros.
- Added initial float32 and int32 support code. Theoretically, existing
drivers will push these through converters to get the data they want to
feed to the hardware.
Still TODO:
- Optimize and debug new converters.
- Update the CoreAudio backend to accept float32 data directly.
- Other backends, too?
- SDL_LoadWAV() needs to be updated to support int32 and float32 .wav files
(both of which exist and can be generated by 'sox' for testing purposes).
- Update the mixer to handle new datatypes.
- Optionally update SDL_sound and SDL_mixer, etc.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Thu, 24 Aug 2006 12:10:46 +0000 |
parents | 542c78b6fb12 |
children | 7a3889fc9e5d |
comparison
equal
deleted
inserted
replaced
1981:3f21778e7433 | 1982:3b4ce57c6215 |
---|---|
284 return; | 284 return; |
285 } | 285 } |
286 SDL_mutexV(audio->mixer_lock); | 286 SDL_mutexV(audio->mixer_lock); |
287 } | 287 } |
288 | 288 |
289 static Uint16 | 289 static SDL_AudioFormat |
290 SDL_ParseAudioFormat(const char *string) | 290 SDL_ParseAudioFormat(const char *string) |
291 { | 291 { |
292 Uint16 format = 0; | 292 SDL_AudioFormat format = 0; |
293 | 293 |
294 switch (*string) { | 294 switch (*string) { |
295 case 'U': | 295 case 'U': |
296 ++string; | 296 ++string; |
297 format |= 0x0000; | 297 format |= 0x0000; |
738 audio->free(audio); | 738 audio->free(audio); |
739 current_audio = NULL; | 739 current_audio = NULL; |
740 } | 740 } |
741 } | 741 } |
742 | 742 |
743 #define NUM_FORMATS 6 | 743 #define NUM_FORMATS 10 |
744 static int format_idx; | 744 static int format_idx; |
745 static int format_idx_sub; | 745 static int format_idx_sub; |
746 static Uint16 format_list[NUM_FORMATS][NUM_FORMATS] = { | 746 static SDL_AudioFormat format_list[NUM_FORMATS][NUM_FORMATS] = { |
747 {AUDIO_U8, AUDIO_S8, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_U16LSB, | 747 {AUDIO_U8, AUDIO_S8, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_U16LSB, |
748 AUDIO_U16MSB}, | 748 AUDIO_U16MSB, AUDIO_S32LSB, AUDIO_S32MSB, AUDIO_F32LSB, AUDIO_F32MSB}, |
749 {AUDIO_S8, AUDIO_U8, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_U16LSB, | 749 {AUDIO_S8, AUDIO_U8, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_U16LSB, |
750 AUDIO_U16MSB}, | 750 AUDIO_U16MSB, AUDIO_S32LSB, AUDIO_S32MSB, AUDIO_F32LSB, AUDIO_F32MSB}, |
751 {AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_U16LSB, AUDIO_U16MSB, AUDIO_U8, | 751 {AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_U16LSB, AUDIO_U16MSB, AUDIO_S32LSB, |
752 AUDIO_S8}, | 752 AUDIO_S32MSB, AUDIO_F32LSB, AUDIO_F32MSB, AUDIO_U8, AUDIO_S8}, |
753 {AUDIO_S16MSB, AUDIO_S16LSB, AUDIO_U16MSB, AUDIO_U16LSB, AUDIO_U8, | 753 {AUDIO_S16MSB, AUDIO_S16LSB, AUDIO_U16MSB, AUDIO_U16LSB, AUDIO_S32MSB, |
754 AUDIO_S8}, | 754 AUDIO_S32LSB, AUDIO_F32MSB, AUDIO_F32LSB, AUDIO_U8, AUDIO_S8}, |
755 {AUDIO_U16LSB, AUDIO_U16MSB, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_U8, | 755 {AUDIO_U16LSB, AUDIO_U16MSB, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_S32LSB, |
756 AUDIO_S8}, | 756 AUDIO_S32MSB, AUDIO_F32LSB, AUDIO_F32MSB, AUDIO_U8, AUDIO_S8}, |
757 {AUDIO_U16MSB, AUDIO_U16LSB, AUDIO_S16MSB, AUDIO_S16LSB, AUDIO_U8, | 757 {AUDIO_U16MSB, AUDIO_U16LSB, AUDIO_S16MSB, AUDIO_S16LSB, AUDIO_S32MSB, |
758 AUDIO_S8}, | 758 AUDIO_S32LSB, AUDIO_F32MSB, AUDIO_F32LSB, AUDIO_U8, AUDIO_S8}, |
759 {AUDIO_S32LSB, AUDIO_S32MSB, AUDIO_U16LSB, AUDIO_U16MSB, AUDIO_S16LSB, | |
760 AUDIO_S16MSB, AUDIO_F32LSB, AUDIO_F32MSB, AUDIO_U8, AUDIO_S8}, | |
761 {AUDIO_S32MSB, AUDIO_S32LSB, AUDIO_U16MSB, AUDIO_U16LSB, AUDIO_S16MSB, | |
762 AUDIO_S16LSB, AUDIO_F32LSB, AUDIO_F32MSB, AUDIO_U8, AUDIO_S8}, | |
763 {AUDIO_F32LSB, AUDIO_F32MSB, AUDIO_S32LSB, AUDIO_S32MSB, AUDIO_U16LSB, | |
764 AUDIO_U16MSB, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_U8, AUDIO_S8}, | |
765 {AUDIO_F32MSB, AUDIO_F32LSB, AUDIO_S32MSB, AUDIO_S32LSB, AUDIO_U16MSB, | |
766 AUDIO_U16LSB, AUDIO_S16MSB, AUDIO_S16LSB, AUDIO_U8, AUDIO_S8}, | |
759 }; | 767 }; |
760 | 768 |
761 Uint16 | 769 SDL_AudioFormat |
762 SDL_FirstAudioFormat(Uint16 format) | 770 SDL_FirstAudioFormat(SDL_AudioFormat format) |
763 { | 771 { |
764 for (format_idx = 0; format_idx < NUM_FORMATS; ++format_idx) { | 772 for (format_idx = 0; format_idx < NUM_FORMATS; ++format_idx) { |
765 if (format_list[format_idx][0] == format) { | 773 if (format_list[format_idx][0] == format) { |
766 break; | 774 break; |
767 } | 775 } |
768 } | 776 } |
769 format_idx_sub = 0; | 777 format_idx_sub = 0; |
770 return (SDL_NextAudioFormat()); | 778 return (SDL_NextAudioFormat()); |
771 } | 779 } |
772 | 780 |
773 Uint16 | 781 SDL_AudioFormat |
774 SDL_NextAudioFormat(void) | 782 SDL_NextAudioFormat(void) |
775 { | 783 { |
776 if ((format_idx == NUM_FORMATS) || (format_idx_sub == NUM_FORMATS)) { | 784 if ((format_idx == NUM_FORMATS) || (format_idx_sub == NUM_FORMATS)) { |
777 return (0); | 785 return (0); |
778 } | 786 } |