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.

65 lines
2.0KB

  1. /*
  2. monosynth.h: generic mono related synth functions
  3. copyright 1995-2008 by the mpg123 project - free software under the terms of the LGPL 2.1
  4. see COPYING and AUTHORS files in distribution or http://mpg123.org
  5. initially written by Michael Hipp, generalized by Thomas Orgis
  6. This header is used multiple times to create different variants of these functions.
  7. See decode.c and synth.h .
  8. Hint: BLOCK, MONO_NAME, MONO2STEREO_NAME, SYNTH_NAME and SAMPLE_T do vary.
  9. Thomas looked closely at the decode_1to1, decode_2to1 and decode_4to1 contents, seeing that they are too similar to be separate files.
  10. This is what resulted...
  11. Reason to separate this from synth.h:
  12. There are decoders that have a special synth_1to1 but still can use these generic derivations for the mono stuff.
  13. It generally makes a good deal of sense to set SYNTH_NAME to opt_synth_1to1(fr) (or opt_synth_2to1(fr), etc.).
  14. */
  15. /* Mono synth, wrapping over SYNTH_NAME */
  16. int MONO_NAME(real *bandPtr, mpg123_handle *fr)
  17. {
  18. SAMPLE_T samples_tmp[BLOCK];
  19. SAMPLE_T *tmp1 = samples_tmp;
  20. int i,ret;
  21. /* save buffer stuff, trick samples_tmp into there, decode, restore */
  22. unsigned char *samples = fr->buffer.data;
  23. int pnt = (int) fr->buffer.fill;
  24. fr->buffer.data = (unsigned char*) samples_tmp;
  25. fr->buffer.fill = 0;
  26. ret = SYNTH_NAME(bandPtr, 0, fr, 0); /* decode into samples_tmp */
  27. fr->buffer.data = samples; /* restore original value */
  28. /* now append samples from samples_tmp */
  29. samples += pnt; /* just the next mem in frame buffer */
  30. for(i=0;i<(BLOCK/2);i++)
  31. {
  32. *( (SAMPLE_T *)samples) = *tmp1;
  33. samples += sizeof(SAMPLE_T);
  34. tmp1 += 2;
  35. }
  36. fr->buffer.fill = pnt + (BLOCK/2)*sizeof(SAMPLE_T);
  37. return ret;
  38. }
  39. /* Mono to stereo synth, wrapping over SYNTH_NAME */
  40. int MONO2STEREO_NAME(real *bandPtr, mpg123_handle *fr)
  41. {
  42. int i,ret;
  43. unsigned char *samples = fr->buffer.data;
  44. ret = SYNTH_NAME(bandPtr,0,fr,1);
  45. samples += fr->buffer.fill - BLOCK*sizeof(SAMPLE_T);
  46. for(i=0;i<(BLOCK/2);i++)
  47. {
  48. ((SAMPLE_T *)samples)[1] = ((SAMPLE_T *)samples)[0];
  49. samples+=2*sizeof(SAMPLE_T);
  50. }
  51. return ret;
  52. }