The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

84 lines
2.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef __AUDIOLIVESCROLLINGDISPLAY_H_4C3BD3A7__
  18. #define __AUDIOLIVESCROLLINGDISPLAY_H_4C3BD3A7__
  19. #include "../JuceDemoHeader.h"
  20. //==============================================================================
  21. /* This component scrolls a continuous waveform showing the audio that's
  22. coming into whatever audio inputs this object is connected to.
  23. */
  24. class LiveScrollingAudioDisplay : public AudioVisualiserComponent,
  25. public AudioIODeviceCallback
  26. {
  27. public:
  28. LiveScrollingAudioDisplay() : AudioVisualiserComponent (1)
  29. {
  30. setSamplesPerBlock (256);
  31. setBufferSize (1024);
  32. }
  33. //==============================================================================
  34. void audioDeviceAboutToStart (AudioIODevice*) override
  35. {
  36. clear();
  37. }
  38. void audioDeviceStopped() override
  39. {
  40. clear();
  41. }
  42. void audioDeviceIOCallback (const float** inputChannelData, int numInputChannels,
  43. float** outputChannelData, int numOutputChannels,
  44. int numberOfSamples) override
  45. {
  46. for (int i = 0; i < numberOfSamples; ++i)
  47. {
  48. float inputSample = 0;
  49. for (int chan = 0; chan < numInputChannels; ++chan)
  50. if (const float* inputChannel = inputChannelData[chan])
  51. inputSample += inputChannel[i]; // find the sum of all the channels
  52. inputSample *= 10.0f; // boost the level to make it more easily visible.
  53. pushSample (&inputSample, 1);
  54. }
  55. // We need to clear the output buffers before returning, in case they're full of junk..
  56. for (int j = 0; j < numOutputChannels; ++j)
  57. if (float* outputChannel = outputChannelData[j])
  58. zeromem (outputChannel, sizeof (float) * (size_t) numberOfSamples);
  59. }
  60. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LiveScrollingAudioDisplay)
  61. };
  62. #endif // __AUDIOLIVESCROLLINGDISPLAY_H_4C3BD3A7__