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.4KB

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