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