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.

115 lines
4.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_AUDIOSOURCEPLAYER_JUCEHEADER__
  19. #define __JUCE_AUDIOSOURCEPLAYER_JUCEHEADER__
  20. //==============================================================================
  21. /**
  22. Wrapper class to continuously stream audio from an audio source to an
  23. AudioIODevice.
  24. This object acts as an AudioIODeviceCallback, so can be attached to an
  25. output device, and will stream audio from an AudioSource.
  26. */
  27. class JUCE_API AudioSourcePlayer : public AudioIODeviceCallback
  28. {
  29. public:
  30. //==============================================================================
  31. /** Creates an empty AudioSourcePlayer. */
  32. AudioSourcePlayer();
  33. /** Destructor.
  34. Make sure this object isn't still being used by an AudioIODevice before
  35. deleting it!
  36. */
  37. virtual ~AudioSourcePlayer();
  38. //==============================================================================
  39. /** Changes the current audio source to play from.
  40. If the source passed in is already being used, this method will do nothing.
  41. If the source is not null, its prepareToPlay() method will be called
  42. before it starts being used for playback.
  43. If there's another source currently playing, its releaseResources() method
  44. will be called after it has been swapped for the new one.
  45. @param newSource the new source to use - this will NOT be deleted
  46. by this object when no longer needed, so it's the
  47. caller's responsibility to manage it.
  48. */
  49. void setSource (AudioSource* newSource);
  50. /** Returns the source that's playing.
  51. May return 0 if there's no source.
  52. */
  53. AudioSource* getCurrentSource() const noexcept { return source; }
  54. /** Sets a gain to apply to the audio data.
  55. @see getGain
  56. */
  57. void setGain (float newGain) noexcept;
  58. /** Returns the current gain.
  59. @see setGain
  60. */
  61. float getGain() const noexcept { return gain; }
  62. //==============================================================================
  63. /** Implementation of the AudioIODeviceCallback method. */
  64. void audioDeviceIOCallback (const float** inputChannelData,
  65. int totalNumInputChannels,
  66. float** outputChannelData,
  67. int totalNumOutputChannels,
  68. int numSamples);
  69. /** Implementation of the AudioIODeviceCallback method. */
  70. void audioDeviceAboutToStart (AudioIODevice* device);
  71. /** Implementation of the AudioIODeviceCallback method. */
  72. void audioDeviceStopped();
  73. private:
  74. //==============================================================================
  75. CriticalSection readLock;
  76. AudioSource* source;
  77. double sampleRate;
  78. int bufferSize;
  79. float* channels [128];
  80. float* outputChans [128];
  81. const float* inputChans [128];
  82. AudioSampleBuffer tempBuffer;
  83. float lastGain, gain;
  84. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioSourcePlayer);
  85. };
  86. #endif // __JUCE_AUDIOSOURCEPLAYER_JUCEHEADER__