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.

112 lines
4.4KB

  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_AUDIOFORMATREADERSOURCE_JUCEHEADER__
  19. #define __JUCE_AUDIOFORMATREADERSOURCE_JUCEHEADER__
  20. #include "juce_PositionableAudioSource.h"
  21. #include "../../threads/juce_Thread.h"
  22. #include "../audio_file_formats/juce_AudioFormatReader.h"
  23. #include "../dsp/juce_AudioSampleBuffer.h"
  24. #include "../../memory/juce_OptionalScopedPointer.h"
  25. //==============================================================================
  26. /**
  27. A type of AudioSource that will read from an AudioFormatReader.
  28. @see PositionableAudioSource, AudioTransportSource, BufferingAudioSource
  29. */
  30. class JUCE_API AudioFormatReaderSource : public PositionableAudioSource
  31. {
  32. public:
  33. //==============================================================================
  34. /** Creates an AudioFormatReaderSource for a given reader.
  35. @param sourceReader the reader to use as the data source - this must
  36. not be null
  37. @param deleteReaderWhenThisIsDeleted if true, the reader passed-in will be deleted
  38. when this object is deleted; if false it will be
  39. left up to the caller to manage its lifetime
  40. */
  41. AudioFormatReaderSource (AudioFormatReader* sourceReader,
  42. bool deleteReaderWhenThisIsDeleted);
  43. /** Destructor. */
  44. ~AudioFormatReaderSource();
  45. //==============================================================================
  46. /** Toggles loop-mode.
  47. If set to true, it will continuously loop the input source. If false,
  48. it will just emit silence after the source has finished.
  49. @see isLooping
  50. */
  51. void setLooping (bool shouldLoop);
  52. /** Returns whether loop-mode is turned on or not. */
  53. bool isLooping() const { return looping; }
  54. /** Returns the reader that's being used. */
  55. AudioFormatReader* getAudioFormatReader() const noexcept { return reader; }
  56. //==============================================================================
  57. /** Implementation of the AudioSource method. */
  58. void prepareToPlay (int samplesPerBlockExpected, double sampleRate);
  59. /** Implementation of the AudioSource method. */
  60. void releaseResources();
  61. /** Implementation of the AudioSource method. */
  62. void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill);
  63. //==============================================================================
  64. /** Implements the PositionableAudioSource method. */
  65. void setNextReadPosition (int64 newPosition);
  66. /** Implements the PositionableAudioSource method. */
  67. int64 getNextReadPosition() const;
  68. /** Implements the PositionableAudioSource method. */
  69. int64 getTotalLength() const;
  70. private:
  71. //==============================================================================
  72. OptionalScopedPointer<AudioFormatReader> reader;
  73. int64 volatile nextPlayPos;
  74. bool volatile looping;
  75. void readBufferSection (int start, int length, AudioSampleBuffer& buffer, int startSample);
  76. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioFormatReaderSource);
  77. };
  78. #endif // __JUCE_AUDIOFORMATREADERSOURCE_JUCEHEADER__