Advertisement
Kitomas

_kit_acodecPCM.h as of 2023-10-12

Oct 12th, 2023
700
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.97 KB | None | 0 0
  1. /**
  2.  * \file _kit_acodecPCM.h
  3.  * \brief Header file that contains stuff related to PCM data (used by both acodec and kmixer)
  4.  */
  5. #ifndef __KIT_ACODECPCM_H
  6. #define __KIT_ACODECPCM_H
  7.  
  8.  
  9. #include <SDL2/SDL.h>
  10.  
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14.  
  15.  
  16.  
  17.  
  18. //using the extension ".kpm" is preferred
  19.  //when saving kit_acodecPCM to a file
  20. #define KPCM_MAGIC (0x4D43506B) //= "kPCM"
  21.  
  22.  
  23.  
  24. /**
  25.  * \brief Stereo Uint8 samples
  26.  */
  27. typedef struct kit_acodecPCM_U_8S {
  28.   Uint8 l; ///< \brief Left audio channel
  29.   Uint8 r; ///< \brief Right audio channel
  30. } kit_acodecPCM_U_8S;
  31.  
  32. /**
  33.  * \brief Stereo Sint16 samples
  34.  */
  35. typedef struct kit_acodecPCM_I16S {
  36.   Sint16 l; ///< \brief Left audio channel
  37.   Sint16 r; ///< \brief Right audio channel
  38. } kit_acodecPCM_I16S;
  39.  
  40. /**
  41.  * \brief Stereo Sint32 samples
  42.  */
  43. typedef struct kit_acodecPCM_I32S {
  44.   Sint32 l; ///< \brief Left audio channel
  45.   Sint32 r; ///< \brief Right audio channel
  46. } kit_acodecPCM_I32S;
  47.  
  48. /**
  49.  * \brief Stereo float samples
  50.  */
  51. typedef struct kit_acodecPCM_F32S {
  52.   float l; ///< \brief Left audio channel
  53.   float r; ///< \brief Right audio channel
  54. } kit_acodecPCM_F32S;
  55.  
  56.  
  57. /**
  58.  * \brief A union of supported sample formats
  59.  */
  60. typedef union kit_acodecPCMSamples {
  61.   void*  data; ///< \brief Generic pointer
  62.   Uint8*  u_8; ///< \brief Mono Uint8 Samples
  63.   Sint16* i16; ///< \brief Mono Sint16 Samples
  64.   Sint32* i32; ///< \brief Mono Sint32 Samples
  65.   float*  f32; ///< \brief Mono float Samples
  66.   kit_acodecPCM_U_8S* u_8s; ///< \brief Stereo Uint8 samples
  67.   kit_acodecPCM_I16S* i16s; ///< \brief Stereo Sint16 samples
  68.   kit_acodecPCM_I32S* i32s; ///< \brief Stereo Sint32 samples
  69.   kit_acodecPCM_F32S* f32s; ///< \brief Stereo float samples
  70. } kit_acodecPCMSamples;
  71.  
  72.  
  73. /**
  74.  * \brief The struct that contains info about a PCM audio stream. \n
  75.  *        When saved as a file (usually as ".kpm"), the header's size will be 72 (0x48).
  76.  */
  77. typedef struct kit_acodecPCM {
  78.   Uint32           magic; ///< \brief (0x00) = 0x4D43506B = "kPCM" (no null terminator)
  79.   SDL_AudioFormat format; ///< \brief (0x04) The data format of the stream
  80.   Uint16      headerSize; ///< \brief (0x06) = sizeof(kit_acodecPCM)
  81.   Uint64        dataSize; ///< \brief (0x08) The size of the PCM buffer, in bytes
  82.   Uint64       loopStart; ///< \brief (0x10) Which sample to loop back to
  83.   Uint64         loopEnd; ///< \brief (0x18) Which sample to restart the loop on
  84.   Uint64      numSamples; ///< \brief (0x20) The number of sample frames in the stream
  85.   Uint32      sampleRate; ///< \brief (0x28) The stream's sample rate, in Hz
  86.   Uint32         bitRate; ///< \brief (0x2C) The audio's bit rate per second
  87.   Uint16       loopCount; ///< \brief (0x30) # of times to loop audio (65535 for infinite loop)
  88.   Uint16        channels; ///< \brief (0x32) # of interlaced channels in the stream (L&R for stereo)
  89.   Uint8     bitRemainder; ///< \brief (0x34) = bitsPerSample%8
  90.   Uint8        userflags; ///< \brief (0x35) User-defined (is just padding otherwise)
  91.   Uint16       uservalue; ///< \brief (0x36) User-defined (is just padding otherwise)
  92.   //while userdata and data are technically included in a .kpm file,
  93.    //they should appear as 0 within that file
  94.   void*         userdata; ///< \brief (0x38) User-defined pointer
  95.   union {
  96.     void*  data; ///< \brief = (void*)pcm_struct_pointer + pcm_struct_pointer->headerSize
  97.     Uint8*  u_8; ///< \brief Mono Uint8 Samples
  98.     Sint16* i16; ///< \brief Mono Sint16 Samples
  99.     Sint32* i32; ///< \brief Mono Sint32 Samples
  100.     float*  f32; ///< \brief Mono float Samples
  101.     kit_acodecPCM_U_8S* u_8s; ///< \brief Stereo Uint8 samples
  102.     kit_acodecPCM_I16S* i16s; ///< \brief Stereo Sint16 samples
  103.     kit_acodecPCM_I32S* i32s; ///< \brief Stereo Sint32 samples
  104.     kit_acodecPCM_F32S* f32s; ///< \brief Stereo float samples
  105.   }; ///< \brief (0x40) Sample data (PCM data should be contiguous with the struct itself)
  106. } kit_acodecPCM;
  107.  
  108.  
  109.  
  110.  
  111. #ifdef __cplusplus
  112. }
  113. #endif
  114.  
  115. #endif /* __KIT_ACODECPCM_H */
  116.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement