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.

87 lines
3.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. namespace juce
  20. {
  21. //==============================================================================
  22. /**
  23. This class is used to wrap an AudioFormatReader and only read from a
  24. subsection of the file.
  25. So if you have a reader which can read a 1000 sample file, you could wrap it
  26. in one of these to only access, e.g. samples 100 to 200, and any samples
  27. outside that will come back as 0. Accessing sample 0 from this reader will
  28. actually read the first sample from the other's subsection, which might
  29. be at a non-zero position.
  30. @see AudioFormatReader
  31. @tags{Audio}
  32. */
  33. class JUCE_API AudioSubsectionReader : public AudioFormatReader
  34. {
  35. public:
  36. //==============================================================================
  37. /** Creates an AudioSubsectionReader for a given data source.
  38. @param sourceReader the source reader from which we'll be taking data
  39. @param subsectionStartSample the sample within the source reader which will be
  40. mapped onto sample 0 for this reader.
  41. @param subsectionLength the number of samples from the source that will
  42. make up the subsection. If this reader is asked for
  43. any samples beyond this region, it will return zero.
  44. @param deleteSourceWhenDeleted if true, the sourceReader object will be deleted when
  45. this object is deleted.
  46. */
  47. AudioSubsectionReader (AudioFormatReader* sourceReader,
  48. int64 subsectionStartSample,
  49. int64 subsectionLength,
  50. bool deleteSourceWhenDeleted);
  51. /** Destructor. */
  52. ~AudioSubsectionReader() override;
  53. //==============================================================================
  54. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  55. int64 startSampleInFile, int numSamples) override;
  56. void readMaxLevels (int64 startSample, int64 numSamples,
  57. Range<float>* results, int numChannelsToRead) override;
  58. private:
  59. //==============================================================================
  60. AudioFormatReader* const source;
  61. int64 startSample, length;
  62. const bool deleteSourceWhenDeleted;
  63. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioSubsectionReader)
  64. };
  65. } // namespace juce