surroundopl.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Adplug - Replayer for many OPL2/OPL3 audio file formats.
  3. * Copyright (C) 1999 - 2010 Simon Peter, <dn.tlp@gmx.net>, et al.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2.1 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. *
  19. * surroundopl.h - Wrapper class to provide a surround/harmonic effect
  20. * for another OPL emulator, by Adam Nielsen <malvineous@shikadi.net>
  21. *
  22. * Stereo harmonic algorithm by Adam Nielsen <malvineous@shikadi.net>
  23. * Please give credit if you use this algorithm elsewhere :-)
  24. */
  25. #ifndef H_ADPLUG_SURROUNDOPL
  26. #define H_ADPLUG_SURROUNDOPL
  27. //#include <stdint.h> // for uintxx_t
  28. #include "opl.h"
  29. // The right-channel is increased in frequency by itself divided by this amount.
  30. // The right value should not noticeably change the pitch, but it should provide
  31. // a nice stereo harmonic effect.
  32. // This value should be well tuned to get best sound quality.
  33. // Currently, 384.0 is the best choice. (**sdlpal_tune, not used now**)
  34. #define FREQ_OFFSET 384.0//128.0//96.0
  35. // Number of FNums away from the upper/lower limit before switching to the next
  36. // block (octave.) By rights it should be zero, but for some reason this seems
  37. // to cut it to close and the transposed OPL doesn't hit the right note all the
  38. // time. Setting it higher means it will switch blocks sooner and that seems
  39. // to help. Don't set it too high or it'll get stuck in an infinite loop if
  40. // one block is too high and the adjacent block is too low ;-)
  41. #define NEWBLOCK_LIMIT 32
  42. class CSurroundopl: public Copl
  43. {
  44. private:
  45. Copl *a, *b;
  46. short *lbuf, *rbuf;
  47. double freq_offset, opl_freq;
  48. unsigned char iFMReg[256];
  49. unsigned char iTweakedFMReg[256];
  50. unsigned char iCurrentTweakedBlock[9]; // Current value of the Block in the tweaked OPL chip
  51. unsigned char iCurrentFNum[9]; // Current value of the FNum in the tweaked OPL chip
  52. short bufsize;
  53. bool use16bit;
  54. public:
  55. CSurroundopl(Copl *a, Copl *b, bool use16bit, double opl_freq, double freq_offset);
  56. ~CSurroundopl();
  57. void update(short *buf, int samples);
  58. void write(int reg, int val);
  59. void init();
  60. };
  61. #endif