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.

80 lines
2.8KB

  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. #pragma once
  18. #include "../JuceDemoHeader.h"
  19. //==============================================================================
  20. /* This component scrolls a continuous waveform showing the audio that's
  21. coming into whatever audio inputs this object is connected to.
  22. */
  23. class LiveScrollingAudioDisplay : public AudioVisualiserComponent,
  24. public AudioIODeviceCallback
  25. {
  26. public:
  27. LiveScrollingAudioDisplay() : AudioVisualiserComponent (1)
  28. {
  29. setSamplesPerBlock (256);
  30. setBufferSize (1024);
  31. }
  32. //==============================================================================
  33. void audioDeviceAboutToStart (AudioIODevice*) override
  34. {
  35. clear();
  36. }
  37. void audioDeviceStopped() override
  38. {
  39. clear();
  40. }
  41. void audioDeviceIOCallback (const float** inputChannelData, int numInputChannels,
  42. float** outputChannelData, int numOutputChannels,
  43. int numberOfSamples) override
  44. {
  45. for (int i = 0; i < numberOfSamples; ++i)
  46. {
  47. float inputSample = 0;
  48. for (int chan = 0; chan < numInputChannels; ++chan)
  49. if (const float* inputChannel = inputChannelData[chan])
  50. inputSample += inputChannel[i]; // find the sum of all the channels
  51. inputSample *= 10.0f; // boost the level to make it more easily visible.
  52. pushSample (&inputSample, 1);
  53. }
  54. // We need to clear the output buffers before returning, in case they're full of junk..
  55. for (int j = 0; j < numOutputChannels; ++j)
  56. if (float* outputChannel = outputChannelData[j])
  57. zeromem (outputChannel, sizeof (float) * (size_t) numberOfSamples);
  58. }
  59. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LiveScrollingAudioDisplay)
  60. };