An audio player for macOS 10.8 and newer. https://kode54.net/cog
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.

214 lines
5.2KB

  1. /*
  2. synth_ntom.h: ntom-resampling synth functions
  3. This header is used multiple times to create different variants of this function.
  4. Hint: MONO_NAME, MONO2STEREO_NAME, SYNTH_NAME and SAMPLE_T as well as WRITE_SAMPLE do vary.
  5. copyright 1995-2008 by the mpg123 project - free software under the terms of the LGPL 2.1
  6. see COPYING and AUTHORS files in distribution or http://mpg123.org
  7. initially written by Michael Hipp, generalized by Thomas Orgis
  8. Well, this is very simple resampling... you may or may not like what you hear.
  9. But it's cheap.
  10. But still, we don't implement a non-autoincrement version of this one.
  11. */
  12. /* Note: These mono functions would also work generically,
  13. it's just that they need a runtime calculation for the conversion loop...
  14. The fixed XtoY functions have the chance for loop unrolling... */
  15. int MONO_NAME(real *bandPtr, mpg123_handle *fr)
  16. {
  17. SAMPLE_T samples_tmp[8*64];
  18. SAMPLE_T *tmp1 = samples_tmp;
  19. size_t i;
  20. int ret;
  21. size_t pnt = fr->buffer.fill;
  22. unsigned char *samples = fr->buffer.data;
  23. fr->buffer.data = (unsigned char*) samples_tmp;
  24. fr->buffer.fill = 0;
  25. ret = SYNTH_NAME(bandPtr, 0, fr, 1);
  26. fr->buffer.data = samples;
  27. samples += pnt;
  28. for(i=0;i<(fr->buffer.fill/(2*sizeof(SAMPLE_T)));i++)
  29. {
  30. *( (SAMPLE_T *)samples) = *tmp1;
  31. samples += sizeof(SAMPLE_T);
  32. tmp1 += 2;
  33. }
  34. fr->buffer.fill = pnt + (fr->buffer.fill/2);
  35. return ret;
  36. }
  37. int MONO2STEREO_NAME(real *bandPtr, mpg123_handle *fr)
  38. {
  39. size_t i;
  40. int ret;
  41. size_t pnt1 = fr->buffer.fill;
  42. unsigned char *samples = fr->buffer.data + pnt1;
  43. ret = SYNTH_NAME(bandPtr, 0, fr, 1);
  44. for(i=0;i<((fr->buffer.fill-pnt1)/(2*sizeof(SAMPLE_T)));i++)
  45. {
  46. ((SAMPLE_T *)samples)[1] = ((SAMPLE_T *)samples)[0];
  47. samples+=2*sizeof(SAMPLE_T);
  48. }
  49. return ret;
  50. }
  51. int SYNTH_NAME(real *bandPtr,int channel, mpg123_handle *fr, int final)
  52. {
  53. static const int step = 2;
  54. SAMPLE_T *samples = (SAMPLE_T *) (fr->buffer.data + fr->buffer.fill);
  55. real *b0, **buf; /* (*buf)[0x110]; */
  56. int clip = 0;
  57. int bo1;
  58. int ntom;
  59. if(fr->have_eq_settings) do_equalizer(bandPtr,channel,fr->equalizer);
  60. if(!channel)
  61. {
  62. fr->bo--;
  63. fr->bo &= 0xf;
  64. buf = fr->real_buffs[0];
  65. ntom = (int)(fr->ntom_val[1] = fr->ntom_val[0]);
  66. }
  67. else
  68. {
  69. samples++;
  70. buf = fr->real_buffs[1];
  71. ntom = (int) fr->ntom_val[1];
  72. }
  73. if(fr->bo & 0x1)
  74. {
  75. b0 = buf[0];
  76. bo1 = fr->bo;
  77. dct64(buf[1]+((fr->bo+1)&0xf),buf[0]+fr->bo,bandPtr);
  78. }
  79. else
  80. {
  81. b0 = buf[1];
  82. bo1 = fr->bo+1;
  83. dct64(buf[0]+fr->bo,buf[1]+fr->bo+1,bandPtr);
  84. }
  85. {
  86. register int j;
  87. real *window = fr->decwin + 16 - bo1;
  88. for (j=16;j;j--,window+=0x10)
  89. {
  90. real sum;
  91. ntom += fr->ntom_step;
  92. if(ntom < NTOM_MUL)
  93. {
  94. window += 16;
  95. b0 += 16;
  96. continue;
  97. }
  98. sum = REAL_MUL_SYNTH(*window++, *b0++);
  99. sum -= REAL_MUL_SYNTH(*window++, *b0++);
  100. sum += REAL_MUL_SYNTH(*window++, *b0++);
  101. sum -= REAL_MUL_SYNTH(*window++, *b0++);
  102. sum += REAL_MUL_SYNTH(*window++, *b0++);
  103. sum -= REAL_MUL_SYNTH(*window++, *b0++);
  104. sum += REAL_MUL_SYNTH(*window++, *b0++);
  105. sum -= REAL_MUL_SYNTH(*window++, *b0++);
  106. sum += REAL_MUL_SYNTH(*window++, *b0++);
  107. sum -= REAL_MUL_SYNTH(*window++, *b0++);
  108. sum += REAL_MUL_SYNTH(*window++, *b0++);
  109. sum -= REAL_MUL_SYNTH(*window++, *b0++);
  110. sum += REAL_MUL_SYNTH(*window++, *b0++);
  111. sum -= REAL_MUL_SYNTH(*window++, *b0++);
  112. sum += REAL_MUL_SYNTH(*window++, *b0++);
  113. sum -= REAL_MUL_SYNTH(*window++, *b0++);
  114. while(ntom >= NTOM_MUL)
  115. {
  116. WRITE_SAMPLE(samples,sum,clip);
  117. samples += step;
  118. ntom -= NTOM_MUL;
  119. }
  120. }
  121. ntom += fr->ntom_step;
  122. if(ntom >= NTOM_MUL)
  123. {
  124. real sum;
  125. sum = REAL_MUL_SYNTH(window[0x0], b0[0x0]);
  126. sum += REAL_MUL_SYNTH(window[0x2], b0[0x2]);
  127. sum += REAL_MUL_SYNTH(window[0x4], b0[0x4]);
  128. sum += REAL_MUL_SYNTH(window[0x6], b0[0x6]);
  129. sum += REAL_MUL_SYNTH(window[0x8], b0[0x8]);
  130. sum += REAL_MUL_SYNTH(window[0xA], b0[0xA]);
  131. sum += REAL_MUL_SYNTH(window[0xC], b0[0xC]);
  132. sum += REAL_MUL_SYNTH(window[0xE], b0[0xE]);
  133. while(ntom >= NTOM_MUL)
  134. {
  135. WRITE_SAMPLE(samples,sum,clip);
  136. samples += step;
  137. ntom -= NTOM_MUL;
  138. }
  139. }
  140. b0-=0x10,window-=0x20;
  141. window += bo1<<1;
  142. for (j=15;j;j--,b0-=0x20,window-=0x10)
  143. {
  144. real sum;
  145. ntom += fr->ntom_step;
  146. if(ntom < NTOM_MUL)
  147. {
  148. window -= 16;
  149. b0 += 16;
  150. continue;
  151. }
  152. sum = REAL_MUL_SYNTH(-*(--window), *b0++);
  153. sum -= REAL_MUL_SYNTH(*(--window), *b0++);
  154. sum -= REAL_MUL_SYNTH(*(--window), *b0++);
  155. sum -= REAL_MUL_SYNTH(*(--window), *b0++);
  156. sum -= REAL_MUL_SYNTH(*(--window), *b0++);
  157. sum -= REAL_MUL_SYNTH(*(--window), *b0++);
  158. sum -= REAL_MUL_SYNTH(*(--window), *b0++);
  159. sum -= REAL_MUL_SYNTH(*(--window), *b0++);
  160. sum -= REAL_MUL_SYNTH(*(--window), *b0++);
  161. sum -= REAL_MUL_SYNTH(*(--window), *b0++);
  162. sum -= REAL_MUL_SYNTH(*(--window), *b0++);
  163. sum -= REAL_MUL_SYNTH(*(--window), *b0++);
  164. sum -= REAL_MUL_SYNTH(*(--window), *b0++);
  165. sum -= REAL_MUL_SYNTH(*(--window), *b0++);
  166. sum -= REAL_MUL_SYNTH(*(--window), *b0++);
  167. sum -= REAL_MUL_SYNTH(*(--window), *b0++);
  168. while(ntom >= NTOM_MUL)
  169. {
  170. WRITE_SAMPLE(samples,sum,clip);
  171. samples += step;
  172. ntom -= NTOM_MUL;
  173. }
  174. }
  175. }
  176. fr->ntom_val[channel] = ntom;
  177. if(final) fr->buffer.fill = ((unsigned char *) samples - fr->buffer.data - (channel ? sizeof(SAMPLE_T) : 0));
  178. return clip;
  179. }