Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * \file _kit_acodecPCM.h
- * \brief Header file that contains stuff related to PCM data (used by both acodec and kmixer)
- */
- #ifndef __KIT_ACODECPCM_H
- #define __KIT_ACODECPCM_H
- #include <SDL2/SDL.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- //using the extension ".kpm" is preferred
- //when saving kit_acodecPCM to a file
- #define KPCM_MAGIC (0x4D43506B) //= "kPCM"
- /**
- * \brief Stereo Uint8 samples
- */
- typedef struct kit_acodecPCM_U_8S {
- Uint8 l; ///< \brief Left audio channel
- Uint8 r; ///< \brief Right audio channel
- } kit_acodecPCM_U_8S;
- /**
- * \brief Stereo Sint16 samples
- */
- typedef struct kit_acodecPCM_I16S {
- Sint16 l; ///< \brief Left audio channel
- Sint16 r; ///< \brief Right audio channel
- } kit_acodecPCM_I16S;
- /**
- * \brief Stereo Sint32 samples
- */
- typedef struct kit_acodecPCM_I32S {
- Sint32 l; ///< \brief Left audio channel
- Sint32 r; ///< \brief Right audio channel
- } kit_acodecPCM_I32S;
- /**
- * \brief Stereo float samples
- */
- typedef struct kit_acodecPCM_F32S {
- float l; ///< \brief Left audio channel
- float r; ///< \brief Right audio channel
- } kit_acodecPCM_F32S;
- /**
- * \brief A union of supported sample formats
- */
- typedef union kit_acodecPCMSamples {
- void* data; ///< \brief Generic pointer
- Uint8* u_8; ///< \brief Mono Uint8 Samples
- Sint16* i16; ///< \brief Mono Sint16 Samples
- Sint32* i32; ///< \brief Mono Sint32 Samples
- float* f32; ///< \brief Mono float Samples
- kit_acodecPCM_U_8S* u_8s; ///< \brief Stereo Uint8 samples
- kit_acodecPCM_I16S* i16s; ///< \brief Stereo Sint16 samples
- kit_acodecPCM_I32S* i32s; ///< \brief Stereo Sint32 samples
- kit_acodecPCM_F32S* f32s; ///< \brief Stereo float samples
- } kit_acodecPCMSamples;
- /**
- * \brief The struct that contains info about a PCM audio stream. \n
- * When saved as a file (usually as ".kpm"), the header's size will be 72 (0x48).
- */
- typedef struct kit_acodecPCM {
- Uint32 magic; ///< \brief (0x00) = 0x4D43506B = "kPCM" (no null terminator)
- SDL_AudioFormat format; ///< \brief (0x04) The data format of the stream
- Uint16 headerSize; ///< \brief (0x06) = sizeof(kit_acodecPCM)
- Uint64 dataSize; ///< \brief (0x08) The size of the PCM buffer, in bytes
- Uint64 loopStart; ///< \brief (0x10) Which sample to loop back to
- Uint64 loopEnd; ///< \brief (0x18) Which sample to restart the loop on
- Uint64 numSamples; ///< \brief (0x20) The number of sample frames in the stream
- Uint32 sampleRate; ///< \brief (0x28) The stream's sample rate, in Hz
- Uint32 bitRate; ///< \brief (0x2C) The audio's bit rate per second
- Uint16 loopCount; ///< \brief (0x30) # of times to loop audio (65535 for infinite loop)
- Uint16 channels; ///< \brief (0x32) # of interlaced channels in the stream (L&R for stereo)
- Uint8 bitRemainder; ///< \brief (0x34) = bitsPerSample%8
- Uint8 userflags; ///< \brief (0x35) User-defined (is just padding otherwise)
- Uint16 uservalue; ///< \brief (0x36) User-defined (is just padding otherwise)
- //while userdata and data are technically included in a .kpm file,
- //they should appear as 0 within that file
- void* userdata; ///< \brief (0x38) User-defined pointer
- union {
- void* data; ///< \brief = (void*)pcm_struct_pointer + pcm_struct_pointer->headerSize
- Uint8* u_8; ///< \brief Mono Uint8 Samples
- Sint16* i16; ///< \brief Mono Sint16 Samples
- Sint32* i32; ///< \brief Mono Sint32 Samples
- float* f32; ///< \brief Mono float Samples
- kit_acodecPCM_U_8S* u_8s; ///< \brief Stereo Uint8 samples
- kit_acodecPCM_I16S* i16s; ///< \brief Stereo Sint16 samples
- kit_acodecPCM_I32S* i32s; ///< \brief Stereo Sint32 samples
- kit_acodecPCM_F32S* f32s; ///< \brief Stereo float samples
- }; ///< \brief (0x40) Sample data (PCM data should be contiguous with the struct itself)
- } kit_acodecPCM;
- #ifdef __cplusplus
- }
- #endif
- #endif /* __KIT_ACODECPCM_H */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement