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.

80 lines
3.2KB

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