Specification.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*******************************************************************************
  2. * Copyright 2009-2016 Jörg Müller
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. ******************************************************************************/
  16. #pragma once
  17. /**
  18. * @file Specification.h
  19. * @ingroup respec
  20. * Defines all important macros and basic data structures for stream format descriptions.
  21. */
  22. #include "Audaspace.h"
  23. /// The size of a format in bytes.
  24. #define AUD_FORMAT_SIZE(format) (format & 0x0F)
  25. /// The size of a sample in the specified device format in bytes.
  26. #define AUD_DEVICE_SAMPLE_SIZE(specs) (specs.channels * (specs.format & 0x0F))
  27. /// The size of a sample in the specified format in bytes.
  28. #define AUD_SAMPLE_SIZE(specs) (specs.channels * sizeof(sample_t))
  29. /// Compares two audio data specifications.
  30. #define AUD_COMPARE_SPECS(s1, s2) ((s1.rate == s2.rate) && (s1.channels == s2.channels))
  31. /// Returns the bit for a channel mask.
  32. #define AUD_CHANNEL_BIT(channel) (0x01 << channel)
  33. AUD_NAMESPACE_BEGIN
  34. /**
  35. * The format of a sample.
  36. * The last 4 bit save the byte count of the format.
  37. */
  38. enum SampleFormat
  39. {
  40. FORMAT_INVALID = 0x00, /// Invalid sample format.
  41. FORMAT_U8 = 0x01, /// 1 byte unsigned byte.
  42. FORMAT_S16 = 0x12, /// 2 byte signed integer.
  43. FORMAT_S24 = 0x13, /// 3 byte signed integer.
  44. FORMAT_S32 = 0x14, /// 4 byte signed integer.
  45. FORMAT_FLOAT32 = 0x24, /// 4 byte float.
  46. FORMAT_FLOAT64 = 0x28 /// 8 byte float.
  47. };
  48. /// The channel count.
  49. enum Channels
  50. {
  51. CHANNELS_INVALID = 0, /// Invalid channel count.
  52. CHANNELS_MONO = 1, /// Mono.
  53. CHANNELS_STEREO = 2, /// Stereo.
  54. CHANNELS_STEREO_LFE = 3, /// Stereo with LFE channel.
  55. CHANNELS_SURROUND4 = 4, /// 4 channel surround sound.
  56. CHANNELS_SURROUND5 = 5, /// 5 channel surround sound.
  57. CHANNELS_SURROUND51 = 6, /// 5.1 surround sound.
  58. CHANNELS_SURROUND61 = 7, /// 6.1 surround sound.
  59. CHANNELS_SURROUND71 = 8 /// 7.1 surround sound.
  60. };
  61. /// The channel names.
  62. enum Channel
  63. {
  64. CHANNEL_FRONT_LEFT = 0,
  65. CHANNEL_FRONT_RIGHT,
  66. CHANNEL_FRONT_CENTER,
  67. CHANNEL_LFE,
  68. CHANNEL_REAR_LEFT,
  69. CHANNEL_REAR_RIGHT,
  70. CHANNEL_REAR_CENTER,
  71. CHANNEL_SIDE_LEFT,
  72. CHANNEL_SIDE_RIGHT,
  73. CHANNEL_MAX
  74. };
  75. /**
  76. * The sample rate tells how many samples are played back within one second.
  77. * Some exotic formats may use other sample rates than provided here.
  78. */
  79. enum DefaultSampleRate
  80. {
  81. RATE_INVALID = 0, /// Invalid sample rate.
  82. RATE_8000 = 8000, /// 8000 Hz.
  83. RATE_16000 = 16000, /// 16000 Hz.
  84. RATE_11025 = 11025, /// 11025 Hz.
  85. RATE_22050 = 22050, /// 22050 Hz.
  86. RATE_32000 = 32000, /// 32000 Hz.
  87. RATE_44100 = 44100, /// 44100 Hz.
  88. RATE_48000 = 48000, /// 48000 Hz.
  89. RATE_88200 = 88200, /// 88200 Hz.
  90. RATE_96000 = 96000, /// 96000 Hz.
  91. RATE_192000 = 192000 /// 192000 Hz.
  92. };
  93. /// Sample rate type.
  94. typedef double SampleRate;
  95. /// Specification of a sound source.
  96. struct Specs
  97. {
  98. /// Sample rate in Hz.
  99. SampleRate rate;
  100. /// Channel count.
  101. Channels channels;
  102. };
  103. /// Specification of a sound device.
  104. struct DeviceSpecs
  105. {
  106. /// Sample format.
  107. SampleFormat format;
  108. union
  109. {
  110. struct
  111. {
  112. /// Sample rate in Hz.
  113. SampleRate rate;
  114. /// Channel count.
  115. Channels channels;
  116. };
  117. Specs specs;
  118. };
  119. };
  120. AUD_NAMESPACE_END