ijksdl_audio.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*****************************************************************************
  2. * ijksdl_audio.h
  3. *****************************************************************************
  4. *
  5. * Copyright (c) 2013 Bilibili
  6. * copyright (c) 2013 Zhang Rui <bbcallen@gmail.com>
  7. *
  8. * This file is part of ijkPlayer.
  9. *
  10. * ijkPlayer is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2.1 of the License, or (at your option) any later version.
  14. *
  15. * ijkPlayer is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with ijkPlayer; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. */
  24. #ifndef IJKSDL__IJKSDL_AUDIO_H
  25. #define IJKSDL__IJKSDL_AUDIO_H
  26. #include "ijksdl_stdinc.h"
  27. #include "ijksdl_endian.h"
  28. typedef uint16_t SDL_AudioFormat;
  29. #define SDL_AUDIO_MASK_BITSIZE (0xFF)
  30. #define SDL_AUDIO_MASK_DATATYPE (1<<8)
  31. #define SDL_AUDIO_MASK_ENDIAN (1<<12)
  32. #define SDL_AUDIO_MASK_SIGNED (1<<15)
  33. #define SDL_AUDIO_BITSIZE(x) (x & SDL_AUDIO_MASK_BITSIZE)
  34. #define SDL_AUDIO_ISFLOAT(x) (x & SDL_AUDIO_MASK_DATATYPE)
  35. #define SDL_AUDIO_ISBIGENDIAN(x) (x & SDL_AUDIO_MASK_ENDIAN)
  36. #define SDL_AUDIO_ISSIGNED(x) (x & SDL_AUDIO_MASK_SIGNED)
  37. #define SDL_AUDIO_ISINT(x) (!SDL_AUDIO_ISFLOAT(x))
  38. #define SDL_AUDIO_ISLITTLEENDIAN(x) (!SDL_AUDIO_ISBIGENDIAN(x))
  39. #define SDL_AUDIO_ISUNSIGNED(x) (!SDL_AUDIO_ISSIGNED(x))
  40. #define AUDIO_INVALID 0x0000
  41. #define AUDIO_U8 0x0008 /**< Unsigned 8-bit samples */
  42. #define AUDIO_S8 0x8008 /**< Signed 8-bit samples */
  43. #define AUDIO_U16LSB 0x0010 /**< Unsigned 16-bit samples */
  44. #define AUDIO_S16LSB 0x8010 /**< Signed 16-bit samples */
  45. #define AUDIO_U16MSB 0x1010 /**< As above, but big-endian byte order */
  46. #define AUDIO_S16MSB 0x9010 /**< As above, but big-endian byte order */
  47. #define AUDIO_U16 AUDIO_U16LSB
  48. #define AUDIO_S16 AUDIO_S16LSB
  49. #define AUDIO_S32LSB 0x8020 /**< 32-bit integer samples */
  50. #define AUDIO_S32MSB 0x9020 /**< As above, but big-endian byte order */
  51. #define AUDIO_S32 AUDIO_S32LSB
  52. #define AUDIO_F32LSB 0x8120 /**< 32-bit floating point samples */
  53. #define AUDIO_F32MSB 0x9120 /**< As above, but big-endian byte order */
  54. #define AUDIO_F32 AUDIO_F32LSB
  55. #if SDL_BYTEORDER == SDL_LIL_ENDIAN
  56. #define AUDIO_U16SYS AUDIO_U16LSB
  57. #define AUDIO_S16SYS AUDIO_S16LSB
  58. #define AUDIO_S32SYS AUDIO_S32LSB
  59. #define AUDIO_F32SYS AUDIO_F32LSB
  60. #else
  61. #define AUDIO_U16SYS AUDIO_U16MSB
  62. #define AUDIO_S16SYS AUDIO_S16MSB
  63. #define AUDIO_S32SYS AUDIO_S32MSB
  64. #define AUDIO_F32SYS AUDIO_F32MSB
  65. #endif
  66. #define SDL_MIX_MAXVOLUME (128)
  67. typedef void (*SDL_AudioCallback) (void *userdata, Uint8 * stream,
  68. int len);
  69. typedef struct SDL_AudioSpec
  70. {
  71. int freq; /**< DSP frequency -- samples per second */
  72. SDL_AudioFormat format; /**< Audio data format */
  73. Uint8 channels; /**< Number of channels: 1 mono, 2 stereo */
  74. Uint8 silence; /**< Audio buffer silence value (calculated) */
  75. Uint16 samples; /**< Audio buffer size in samples (power of 2) */
  76. Uint16 padding; /**< NOT USED. Necessary for some compile environments */
  77. Uint32 size; /**< Audio buffer size in bytes (calculated) */
  78. SDL_AudioCallback callback;
  79. void *userdata;
  80. } SDL_AudioSpec;
  81. void SDL_CalculateAudioSpec(SDL_AudioSpec * spec);
  82. void SDL_MixAudio(Uint8* dst,
  83. const Uint8* src,
  84. Uint32 len,
  85. int volume);
  86. #endif