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.

110 lines
2.2KB

  1. /*
  2. Copyright (C) 2011 Nasca Octavian Paul
  3. Author: Nasca Octavian Paul
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of version 2 of the GNU General Public License
  6. as published by the Free Software Foundation.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License (version 2) for more details.
  11. You should have received a copy of the GNU General Public License (version 2)
  12. along with this program; if not, write to the Free Software Foundation,
  13. Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  14. */
  15. #ifndef BINAURAL_BEATS
  16. #define BINAURAL_BEATS
  17. #include "FreeEdit.h"
  18. #include "globals.h"
  19. class AP{//allpass
  20. public:
  21. AP(REALTYPE a_=0.5){
  22. in1=in2=out1=out2=0.0;
  23. set(a_);
  24. };
  25. REALTYPE process(REALTYPE in){
  26. REALTYPE out=a*(in+out2)-in2;
  27. in2=in1;in1=in;
  28. out2=out1;out1=out;
  29. return out;
  30. };
  31. REALTYPE set(REALTYPE a_){
  32. a=a_*a_;
  33. };
  34. private:
  35. REALTYPE in1,in2,out1,out2;
  36. REALTYPE a;
  37. };
  38. class Hilbert{
  39. public:
  40. Hilbert(){
  41. for (int i=0;i<N;i++){
  42. apl[i].set(coefl[i]);
  43. apr[i].set(coefr[i]);
  44. };
  45. oldl=0.0;
  46. };
  47. void process(REALTYPE in, REALTYPE &out1, REALTYPE &out2){
  48. out1=oldl;
  49. out2=in;
  50. for (int i=0;i<N;i++){
  51. out1=apl[i].process(out1);
  52. out2=apr[i].process(out2);
  53. };
  54. oldl=in;
  55. };
  56. private:
  57. static const int N=4;
  58. static const REALTYPE coefl[];
  59. static const REALTYPE coefr[];
  60. AP apl[N],apr[N];
  61. REALTYPE oldl;
  62. };
  63. enum BB_STEREO_MODE{
  64. SM_LEFT_RIGHT=0,
  65. SM_RIGHT_LEFT=1,
  66. SM_SYMMETRIC=2
  67. };
  68. struct BinauralBeatsParameters{
  69. BinauralBeatsParameters(){
  70. stereo_mode=SM_LEFT_RIGHT;
  71. mono=0.5;
  72. };
  73. BB_STEREO_MODE stereo_mode;
  74. float mono;
  75. FreeEdit free_edit;
  76. void add2XML(XMLwrapper *xml);
  77. void getfromXML(XMLwrapper *xml);
  78. };
  79. class BinauralBeats{
  80. public:
  81. BinauralBeats(int samplerate_);
  82. void process(REALTYPE *smpsl,REALTYPE *smpsr,int nsmps,REALTYPE pos_percents);
  83. BinauralBeatsParameters pars;
  84. private:
  85. int samplerate;
  86. REALTYPE hilbert_t;
  87. Hilbert hl,hr;
  88. };
  89. #endif