You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

204 lines
5.4KB

  1. /*
  2. * this code is based on a52dec/libao/audio_out_oss.c
  3. * copyright (C) 2001 Arpad Gereoffy
  4. *
  5. * This file is part of a52dec, a free ATSC A-52 stream decoder.
  6. * See http://liba52.sourceforge.net/ for updates.
  7. *
  8. * a52dec is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * a52dec is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. static inline int16_t convert (int32_t i)
  23. {
  24. if (i > 0x43c07fff)
  25. return 32767;
  26. else if (i < 0x43bf8000)
  27. return -32768;
  28. else
  29. return i - 0x43c00000;
  30. }
  31. static int a52_resample_MONO_to_5_C(float * _f, int16_t * s16){
  32. int i;
  33. int32_t * f = (int32_t *) _f;
  34. for (i = 0; i < 256; i++) {
  35. s16[5*i] = s16[5*i+1] = s16[5*i+2] = s16[5*i+3] = 0;
  36. s16[5*i+4] = convert (f[i]);
  37. }
  38. return 5*256;
  39. }
  40. static int a52_resample_MONO_to_1_C(float * _f, int16_t * s16){
  41. int i;
  42. int32_t * f = (int32_t *) _f;
  43. for (i = 0; i < 256; i++) {
  44. s16[i] = convert (f[i]);
  45. }
  46. return 1*256;
  47. }
  48. static int a52_resample_STEREO_to_2_C(float * _f, int16_t * s16){
  49. int i;
  50. int32_t * f = (int32_t *) _f;
  51. for (i = 0; i < 256; i++) {
  52. s16[2*i] = convert (f[i]);
  53. s16[2*i+1] = convert (f[i+256]);
  54. }
  55. return 2*256;
  56. }
  57. static int a52_resample_3F_to_5_C(float * _f, int16_t * s16){
  58. int i;
  59. int32_t * f = (int32_t *) _f;
  60. for (i = 0; i < 256; i++) {
  61. s16[5*i] = convert (f[i]);
  62. s16[5*i+1] = convert (f[i+512]);
  63. s16[5*i+2] = s16[5*i+3] = 0;
  64. s16[5*i+4] = convert (f[i+256]);
  65. }
  66. return 5*256;
  67. }
  68. static int a52_resample_2F_2R_to_4_C(float * _f, int16_t * s16){
  69. int i;
  70. int32_t * f = (int32_t *) _f;
  71. for (i = 0; i < 256; i++) {
  72. s16[4*i] = convert (f[i]);
  73. s16[4*i+1] = convert (f[i+256]);
  74. s16[4*i+2] = convert (f[i+512]);
  75. s16[4*i+3] = convert (f[i+768]);
  76. }
  77. return 4*256;
  78. }
  79. static int a52_resample_3F_2R_to_5_C(float * _f, int16_t * s16){
  80. int i;
  81. int32_t * f = (int32_t *) _f;
  82. for (i = 0; i < 256; i++) {
  83. s16[5*i] = convert (f[i]);
  84. s16[5*i+1] = convert (f[i+512]);
  85. s16[5*i+2] = convert (f[i+768]);
  86. s16[5*i+3] = convert (f[i+1024]);
  87. s16[5*i+4] = convert (f[i+256]);
  88. }
  89. return 5*256;
  90. }
  91. static int a52_resample_MONO_LFE_to_6_C(float * _f, int16_t * s16){
  92. int i;
  93. int32_t * f = (int32_t *) _f;
  94. for (i = 0; i < 256; i++) {
  95. s16[6*i] = s16[6*i+1] = s16[6*i+2] = s16[6*i+3] = 0;
  96. s16[6*i+4] = convert (f[i+256]);
  97. s16[6*i+5] = convert (f[i]);
  98. }
  99. return 6*256;
  100. }
  101. static int a52_resample_STEREO_LFE_to_6_C(float * _f, int16_t * s16){
  102. int i;
  103. int32_t * f = (int32_t *) _f;
  104. for (i = 0; i < 256; i++) {
  105. s16[6*i] = convert (f[i+256]);
  106. s16[6*i+1] = convert (f[i+512]);
  107. s16[6*i+2] = s16[6*i+3] = s16[6*i+4] = 0;
  108. s16[6*i+5] = convert (f[i]);
  109. }
  110. return 6*256;
  111. }
  112. static int a52_resample_3F_LFE_to_6_C(float * _f, int16_t * s16){
  113. int i;
  114. int32_t * f = (int32_t *) _f;
  115. for (i = 0; i < 256; i++) {
  116. s16[6*i] = convert (f[i+256]);
  117. s16[6*i+1] = convert (f[i+768]);
  118. s16[6*i+2] = s16[6*i+3] = 0;
  119. s16[6*i+4] = convert (f[i+512]);
  120. s16[6*i+5] = convert (f[i]);
  121. }
  122. return 6*256;
  123. }
  124. static int a52_resample_2F_2R_LFE_to_6_C(float * _f, int16_t * s16){
  125. int i;
  126. int32_t * f = (int32_t *) _f;
  127. for (i = 0; i < 256; i++) {
  128. s16[6*i] = convert (f[i+256]);
  129. s16[6*i+1] = convert (f[i+512]);
  130. s16[6*i+2] = convert (f[i+768]);
  131. s16[6*i+3] = convert (f[i+1024]);
  132. s16[6*i+4] = 0;
  133. s16[6*i+5] = convert (f[i]);
  134. }
  135. return 6*256;
  136. }
  137. static int a52_resample_3F_2R_LFE_to_6_C(float * _f, int16_t * s16){
  138. int i;
  139. int32_t * f = (int32_t *) _f;
  140. for (i = 0; i < 256; i++) {
  141. s16[6*i] = convert (f[i+256]);
  142. s16[6*i+1] = convert (f[i+768]);
  143. s16[6*i+2] = convert (f[i+1024]);
  144. s16[6*i+3] = convert (f[i+1280]);
  145. s16[6*i+4] = convert (f[i+512]);
  146. s16[6*i+5] = convert (f[i]);
  147. }
  148. return 6*256;
  149. }
  150. static void* a52_resample_C(int flags, int ch){
  151. switch (flags) {
  152. case A52_MONO:
  153. if(ch==5) return a52_resample_MONO_to_5_C;
  154. if(ch==1) return a52_resample_MONO_to_1_C;
  155. break;
  156. case A52_CHANNEL:
  157. case A52_STEREO:
  158. case A52_DOLBY:
  159. if(ch==2) return a52_resample_STEREO_to_2_C;
  160. break;
  161. case A52_3F:
  162. if(ch==5) return a52_resample_3F_to_5_C;
  163. break;
  164. case A52_2F2R:
  165. if(ch==4) return a52_resample_2F_2R_to_4_C;
  166. break;
  167. case A52_3F2R:
  168. if(ch==5) return a52_resample_3F_2R_to_5_C;
  169. break;
  170. case A52_MONO | A52_LFE:
  171. if(ch==6) return a52_resample_MONO_LFE_to_6_C;
  172. break;
  173. case A52_CHANNEL | A52_LFE:
  174. case A52_STEREO | A52_LFE:
  175. case A52_DOLBY | A52_LFE:
  176. if(ch==6) return a52_resample_STEREO_LFE_to_6_C;
  177. break;
  178. case A52_3F | A52_LFE:
  179. if(ch==6) return a52_resample_3F_LFE_to_6_C;
  180. break;
  181. case A52_2F2R | A52_LFE:
  182. if(ch==6) return a52_resample_2F_2R_LFE_to_6_C;
  183. break;
  184. case A52_3F2R | A52_LFE:
  185. if(ch==6) return a52_resample_3F_2R_LFE_to_6_C;
  186. break;
  187. }
  188. return NULL;
  189. }