DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/libs/decoders/SDL_sound.h
00001 /*
00002  *  Modified SDL Sound API
00003  *  ----------------------
00004  *  The basic gist of SDL_sound is that you use an SDL_RWops to get sound data
00005  *  into this library, and SDL_sound will take that data, in one of several
00006  *  popular formats, and decode it into raw waveform data in the format of
00007  *  your choice. This gives you a nice abstraction for getting sound into your
00008  *  game or application; just feed it to SDL_sound, and it will handle
00009  *  decoding and converting, so you can just pass it to your SDL audio
00010  *  callback (or whatever). Since it gets data from an SDL_RWops, you can get
00011  *  the initial sound data from any number of sources: file, memory buffer,
00012  *  network connection, etc.
00013  *
00014  *  As the name implies, this library depends on SDL2: Simple Directmedia Layer,
00015  *  which is a powerful, free, and cross-platform multimedia library. It can
00016  *  be found at http://www.libsdl.org/
00017  *
00018  * Support is in place for the following sound formats:
00019  *   - .WAV/.W64 (Microsoft WAVfile RIFF and Sony Wave64 data, via the dr_wav single-header codec)
00020  *   - .MP3  (MPEG-1 Layer 3 support via the dr_mp3 single-header decoder)
00021  *   - .OGG  (Ogg Vorbis support via the std_vorbis single-header decoder)
00022  *   - .OPUS (Ogg Opus support via the Opusfile and SpeexDSP libraries)
00023  *   - .FLAC (Free Lossless Audio Codec support via the dr_flac single-header decoder)
00024  *
00025  *  Copyright (C) 2020       The DOSBox Team
00026  *  Copyright (C) 2018-2019  Kevin R. Croft <krcroft@gmail.com>
00027  *  Copyright (C) 2001-2017  Ryan C. Gordon <icculus@icculus.org>
00028  *
00029  *  This program is free software; you can redistribute it and/or modify
00030  *  it under the terms of the GNU General Public License as published by
00031  *  the Free Software Foundation; either version 2 of the License, or
00032  *  (at your option) any later version.
00033  *
00034  *  This program is distributed in the hope that it will be useful,
00035  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00036  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00037  *  GNU General Public License for more details.
00038  *
00039  *  You should have received a copy of the GNU General Public License along
00040  *  with this program; if not, write to the Free Software Foundation, Inc.,
00041  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00042  */
00043 
00044 #ifndef _INCLUDE_SDL_SOUND_H_
00045 #define _INCLUDE_SDL_SOUND_H_
00046 
00047 #include <SDL.h>
00048 #include <SDL_endian.h>
00049 
00050 #ifdef __cplusplus
00051 extern "C" {
00052 #endif
00053 
00054 #ifndef DOXYGEN_SHOULD_IGNORE_THIS
00055 
00056 #ifndef SDLCALL  /* may not be defined with older SDL releases. */
00057 #define SDLCALL
00058 #endif
00059 
00060 #ifdef SDL_SOUND_DLL_EXPORTS
00061 #  define SNDDECLSPEC __declspec(dllexport)
00062 #elif (__GNUC__ >= 3)
00063 #  define SNDDECLSPEC __attribute__((visibility("default")))
00064 #else
00065 #  define SNDDECLSPEC
00066 #endif
00067 
00068 #define SOUND_VER_MAJOR 1
00069 #define SOUND_VER_MINOR 0
00070 #define SOUND_VER_PATCH 1
00071 #endif
00072 
00073 
00088 typedef enum
00089 {
00090     SOUND_SAMPLEFLAG_NONE    = 0x0, 
00092     /* these are set at sample creation time... */
00093     SOUND_SAMPLEFLAG_CANSEEK = 0x1, 
00095     /* these are set during decoding... */
00096     SOUND_SAMPLEFLAG_EOF     = 0x2, 
00097     SOUND_SAMPLEFLAG_ERROR   = 0x4, 
00098     SOUND_SAMPLEFLAG_EAGAIN  = 0x8  
00099 } Sound_SampleFlags;
00100 
00113 typedef struct
00114 {
00115     Uint16 format;  
00116     Uint8 channels; 
00117     Uint32 rate;    
00118 } Sound_AudioInfo;
00119 
00120 
00140 typedef struct
00141 {
00142     const char **extensions; 
00143     const char *description; 
00144     const char *author;      
00145     const char *url;         
00146 } Sound_DecoderInfo;
00147 
00148 
00149 
00159 typedef struct
00160 {
00161     void *opaque;  
00162     const Sound_DecoderInfo *decoder;  
00163     Sound_AudioInfo desired;  
00164     Sound_AudioInfo actual;  
00165     Uint32 flags;  
00166 } Sound_Sample;
00167 
00168 
00182 typedef struct
00183 {
00184     int major; 
00185     int minor; 
00186     int patch; 
00187 } Sound_Version;
00188 
00189 
00190 /* functions and macros... */
00191 
00208 #define SOUND_VERSION(x) \
00209 { \
00210     (x)->major = SOUND_VER_MAJOR; \
00211     (x)->minor = SOUND_VER_MINOR; \
00212     (x)->patch = SOUND_VER_PATCH; \
00213 }
00214 
00215 
00245 SNDDECLSPEC void SDLCALL Sound_GetLinkedVersion(Sound_Version *ver);
00246 
00247 
00263 SNDDECLSPEC int SDLCALL Sound_Init(void);
00264 
00265 
00288 SNDDECLSPEC int SDLCALL Sound_Quit(void);
00289 
00290 
00323 SNDDECLSPEC const Sound_DecoderInfo ** SDLCALL Sound_AvailableDecoders(void);
00324 
00325 
00341 SNDDECLSPEC const char * SDLCALL Sound_GetError(void);
00342 
00343 
00352 SNDDECLSPEC void SDLCALL Sound_ClearError(void);
00353 
00354 
00427 SNDDECLSPEC Sound_Sample * SDLCALL Sound_NewSample(SDL_RWops *rw,
00428                                                    const char *ext,
00429                                                    Sound_AudioInfo *desired);
00430 
00461 SNDDECLSPEC Sound_Sample * SDLCALL Sound_NewSampleFromFile(const char *fname,
00462                                                       Sound_AudioInfo *desired);
00463 
00478 SNDDECLSPEC void SDLCALL Sound_FreeSample(Sound_Sample *sample);
00479 
00480 
00503 SNDDECLSPEC Sint32 SDLCALL Sound_GetDuration(Sound_Sample *sample);
00504 
00525 SNDDECLSPEC Uint32 SDLCALL Sound_Decode_Direct(Sound_Sample *sample, void* buffer, Uint32 desired_frames);
00526 
00558 SNDDECLSPEC int SDLCALL Sound_Rewind(Sound_Sample *sample);
00559 
00560 
00603 SNDDECLSPEC int SDLCALL Sound_Seek(Sound_Sample *sample, Uint32 ms);
00604 
00605 
00606 #ifdef __cplusplus
00607 }
00608 #endif
00609 
00610 #endif  /* !defined _INCLUDE_SDL_SOUND_H_ */
00611 
00612 /* end of SDL_sound.h ... */
00613