/tags/dev-20001205/FreeSpeech/audio_blocks/src/ILTF.cc

# · C++ · 133 lines · 67 code · 27 blank · 39 comment · 11 complexity · 6d46438763b4eedd5de94c246ade24f8 MD5 · raw file

  1. // Copyright (C) 1999 Jean-Marc Valin
  2. //
  3. // This program is free software; you can redistribute it and/or modify
  4. // it under the terms of the GNU General Public License as published by
  5. // the Free Software Foundation; either version 2, or (at your option)
  6. // any later version.
  7. //
  8. // This program is distributed in the hope that it will be useful, but
  9. // WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. // General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this file. If not, write to the Free Software Foundation,
  15. // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16. #include "FrameOperation.h"
  17. #include "Buffer.h"
  18. #include "Vector.h"
  19. #include <stdlib.h>
  20. #include <math.h>
  21. class ILTF;
  22. DECLARE_NODE(ILTF)
  23. /*Node
  24. * @name ILTF
  25. * @category Signal:DSP
  26. * @description No description available
  27. * @input_name INPUT
  28. * @input_description No description available
  29. * @input_name FILTER
  30. * @input_description No description available
  31. * @output_name OUTPUT
  32. * @output_description No description available
  33. * @parameter_name LENGTH
  34. * @parameter_description No description available
  35. END*/
  36. //float *i_heap = ((float *)malloc( sizeof(float) * 2048))+2047;
  37. class ILTF : public FrameOperation {
  38. int inputID;
  39. int inputLength;
  40. int filterID;
  41. int noncausal;
  42. bool continuous;
  43. public:
  44. ILTF(string nodeName, ParameterSet params)
  45. : FrameOperation(nodeName, params)
  46. {
  47. inputID = addInput("INPUT");
  48. filterID = addInput("FILTER");
  49. if (parameters.exist("INPUTLENGTH"))
  50. inputLength = dereference_cast<int> (parameters.get("INPUTLENGTH"));
  51. else inputLength = dereference_cast<int> (parameters.get("LENGTH"));
  52. }
  53. ~ILTF() {}
  54. virtual void specificInitialize()
  55. {
  56. outputs[outputID].lookBack += 1;
  57. this->FrameOperation::specificInitialize();
  58. }
  59. void calculate(int output_id, int count, Buffer &out)
  60. {
  61. NodeInput input = inputs[inputID];
  62. ObjectRef inputValue = input.node->getOutput(input.outputID, count);
  63. NodeInput filterInput = inputs[filterID];
  64. ObjectRef filterValue = filterInput.node->getOutput(filterInput.outputID, count);
  65. Vector<float> &output = object_cast<Vector<float> > (out[count]);
  66. if (inputValue->status != Object::valid)
  67. {
  68. output.status = inputValue->status;
  69. return;
  70. }
  71. const Vector<float> &in = object_cast<Vector<float> > (inputValue);
  72. const Vector<float> &filter = object_cast<Vector<float> > (filterValue);
  73. const Vector<float> *past;
  74. bool can_look_back = false;
  75. if (count > 0)
  76. {
  77. ObjectRef pastInputValue = this->getOutput(outputID, count-1);
  78. if (pastInputValue->status == Object::valid)
  79. {
  80. can_look_back=true;
  81. past = &object_cast<Vector<float> > (pastInputValue);
  82. }
  83. }
  84. //int size = filter.size();
  85. int delay = floor(.5+filter[1]);
  86. //filter[0]=1;
  87. for (int i=0;i<outputLength;i++)
  88. output[i]=in[i];
  89. if (can_look_back)
  90. {
  91. for (int i=0;i<delay;i++)
  92. //output[i] -= (*past)[inputLength+i-delay];
  93. output[i] += filter[0]*(*past)[inputLength+i-delay];
  94. }
  95. for (int i=delay;i<outputLength;i++)
  96. //output[i] -= in[i-delay];
  97. output[i] += filter[0]*output[i-delay];
  98. output.status = Object::valid;
  99. }
  100. };