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.

85 lines
3.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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. #ifndef JUCE_AUDIOSUBSECTIONREADER_H_INCLUDED
  18. #define JUCE_AUDIOSUBSECTIONREADER_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. This class is used to wrap an AudioFormatReader and only read from a
  22. subsection of the file.
  23. So if you have a reader which can read a 1000 sample file, you could wrap it
  24. in one of these to only access, e.g. samples 100 to 200, and any samples
  25. outside that will come back as 0. Accessing sample 0 from this reader will
  26. actually read the first sample from the other's subsection, which might
  27. be at a non-zero position.
  28. @see AudioFormatReader
  29. */
  30. class JUCE_API AudioSubsectionReader : public AudioFormatReader
  31. {
  32. public:
  33. //==============================================================================
  34. /** Creates an AudioSubsectionReader for a given data source.
  35. @param sourceReader the source reader from which we'll be taking data
  36. @param subsectionStartSample the sample within the source reader which will be
  37. mapped onto sample 0 for this reader.
  38. @param subsectionLength the number of samples from the source that will
  39. make up the subsection. If this reader is asked for
  40. any samples beyond this region, it will return zero.
  41. @param deleteSourceWhenDeleted if true, the sourceReader object will be deleted when
  42. this object is deleted.
  43. */
  44. AudioSubsectionReader (AudioFormatReader* sourceReader,
  45. int64 subsectionStartSample,
  46. int64 subsectionLength,
  47. bool deleteSourceWhenDeleted);
  48. /** Destructor. */
  49. ~AudioSubsectionReader();
  50. //==============================================================================
  51. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  52. int64 startSampleInFile, int numSamples) override;
  53. void readMaxLevels (int64 startSample, int64 numSamples,
  54. float& lowestLeft, float& highestLeft,
  55. float& lowestRight, float& highestRight) override;
  56. private:
  57. //==============================================================================
  58. AudioFormatReader* const source;
  59. int64 startSample, length;
  60. const bool deleteSourceWhenDeleted;
  61. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioSubsectionReader)
  62. };
  63. #endif // JUCE_AUDIOSUBSECTIONREADER_H_INCLUDED