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.

75 lines
2.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE examples.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. The code included in this file is provided under the terms of the ISC license
  6. http://www.isc.org/downloads/software-support-policy/isc-license. Permission
  7. To use, copy, modify, and/or distribute this software for any purpose with or
  8. without fee is hereby granted provided that the above copyright notice and
  9. this permission notice appear in all copies.
  10. THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES,
  11. WHETHER EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR
  12. PURPOSE, ARE DISCLAIMED.
  13. ==============================================================================
  14. */
  15. #pragma once
  16. //==============================================================================
  17. /* This component scrolls a continuous waveform showing the audio that's
  18. coming into whatever audio inputs this object is connected to.
  19. */
  20. class LiveScrollingAudioDisplay final : public AudioVisualiserComponent,
  21. public AudioIODeviceCallback
  22. {
  23. public:
  24. LiveScrollingAudioDisplay() : AudioVisualiserComponent (1)
  25. {
  26. setSamplesPerBlock (256);
  27. setBufferSize (1024);
  28. }
  29. //==============================================================================
  30. void audioDeviceAboutToStart (AudioIODevice*) override
  31. {
  32. clear();
  33. }
  34. void audioDeviceStopped() override
  35. {
  36. clear();
  37. }
  38. void audioDeviceIOCallbackWithContext (const float* const* inputChannelData, int numInputChannels,
  39. float* const* outputChannelData, int numOutputChannels,
  40. int numberOfSamples, const AudioIODeviceCallbackContext& context) override
  41. {
  42. ignoreUnused (context);
  43. for (int i = 0; i < numberOfSamples; ++i)
  44. {
  45. float inputSample = 0;
  46. for (int chan = 0; chan < numInputChannels; ++chan)
  47. if (const float* inputChannel = inputChannelData[chan])
  48. inputSample += inputChannel[i]; // find the sum of all the channels
  49. inputSample *= 10.0f; // boost the level to make it more easily visible.
  50. pushSample (&inputSample, 1);
  51. }
  52. // We need to clear the output buffers before returning, in case they're full of junk..
  53. for (int j = 0; j < numOutputChannels; ++j)
  54. if (float* outputChannel = outputChannelData[j])
  55. zeromem (outputChannel, (size_t) numberOfSamples * sizeof (float));
  56. }
  57. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LiveScrollingAudioDisplay)
  58. };