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.

128 lines
3.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCETICE project - Copyright 2009 by Lucio Asnaghi.
  4. JUCETICE is based around the JUCE library - "Jules' Utility Class Extensions"
  5. Copyright 2007 by Julian Storer.
  6. ------------------------------------------------------------------------------
  7. JUCE and JUCETICE can be redistributed and/or modified under the terms of
  8. the GNU General Public License, as published by the Free Software Foundation;
  9. either version 2 of the License, or (at your option) any later version.
  10. JUCE and JUCETICE are distributed in the hope that they will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with JUCE and JUCETICE; if not, visit www.gnu.org/licenses or write to
  16. Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  17. Boston, MA 02111-1307 USA
  18. ==============================================================================
  19. */
  20. BEGIN_JUCE_NAMESPACE
  21. #if 0
  22. //==============================================================================
  23. SpectrumAnalyzerState::SpectrumAnalyzerState()
  24. : _fsamp (44100),
  25. _fsize (512),
  26. _inputA (-1),
  27. _inputB (-1),
  28. _dataA (0),
  29. _dataB (0),
  30. _dind (0),
  31. _size (8192),
  32. _step (2),
  33. _scnt (0)
  34. {
  35. }
  36. SpectrumAnalyzerState::~SpectrumAnalyzerState()
  37. {
  38. }
  39. //==============================================================================
  40. void SpectrumAnalyzerState::reset (double sampleRate, int samplesPerBlock)
  41. {
  42. _fsamp = sampleRate;
  43. _fsize = samplesPerBlock;
  44. _dind = 0;
  45. _scnt = 0;
  46. }
  47. //==============================================================================
  48. void SpectrumAnalyzerState::processNextBlock (AudioSampleBuffer& buffer)
  49. {
  50. const ScopedTryLock scopedTryLock (dataLock);
  51. if (scopedTryLock.isLocked() && _dataA)
  52. {
  53. float *pA, *pB;
  54. unsigned int m, n, nframes = buffer.getNumSamples();
  55. pA = (_inputA >= 0) ? buffer.getSampleData (0) : 0;
  56. pB = (_inputB >= 0) ? buffer.getSampleData (1) : 0;
  57. m = nframes;
  58. n = _size - _dind;
  59. if (m >= n)
  60. {
  61. if (pA) memcpy (_dataA + _dind, pA, sizeof(float) * n);
  62. else memset (_dataA + _dind, 0, sizeof(float) * n);
  63. if (pB) memcpy (_dataB + _dind, pB, sizeof(float) * n);
  64. else memset (_dataB + _dind, 0, sizeof(float) * n);
  65. m -= n;
  66. pA += n;
  67. pB += n;
  68. _dind = 0;
  69. }
  70. if (m)
  71. {
  72. if (pA) memcpy (_dataA + _dind, pA, sizeof(float) * m);
  73. else memset (_dataA + _dind, 0, sizeof(float) * m);
  74. if (pB) memcpy (_dataB + _dind, pB, sizeof(float) * m);
  75. else memset (_dataB + _dind, 0, sizeof(float) * m);
  76. _dind += m;
  77. }
  78. _scnt += nframes;
  79. int k = _scnt / _step;
  80. if (k) _scnt -= k * _step;
  81. }
  82. }
  83. //==============================================================================
  84. void SpectrumAnalyzerState::setDataBuffer (float* a, float* b, int ipsize, int ipstep)
  85. {
  86. const ScopedLock sl (dataLock);
  87. _dataA = a;
  88. _dataB = b;
  89. _inputA = a != 0;
  90. _inputB = b != 0;
  91. _size = ipsize;
  92. _step = ipstep;
  93. _dind = 0;
  94. _scnt = 0;
  95. }
  96. #endif
  97. END_JUCE_NAMESPACE