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.

90 lines
3.7KB

  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_JUCEHEADER__
  18. #define __JUCE_AUDIOSUBSECTIONREADER_JUCEHEADER__
  19. #include "juce_AudioFormatReader.h"
  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. */
  31. class JUCE_API AudioSubsectionReader : public AudioFormatReader
  32. {
  33. public:
  34. //==============================================================================
  35. /** Creates a AudioSubsectionReader for a given data source.
  36. @param sourceReader the source reader from which we'll be taking data
  37. @param subsectionStartSample the sample within the source reader which will be
  38. mapped onto sample 0 for this reader.
  39. @param subsectionLength the number of samples from the source that will
  40. make up the subsection. If this reader is asked for
  41. any samples beyond this region, it will return zero.
  42. @param deleteSourceWhenDeleted if true, the sourceReader object will be deleted when
  43. this object is deleted.
  44. */
  45. AudioSubsectionReader (AudioFormatReader* sourceReader,
  46. int64 subsectionStartSample,
  47. int64 subsectionLength,
  48. bool deleteSourceWhenDeleted);
  49. /** Destructor. */
  50. ~AudioSubsectionReader();
  51. //==============================================================================
  52. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  53. int64 startSampleInFile, int numSamples);
  54. void readMaxLevels (int64 startSample,
  55. int64 numSamples,
  56. float& lowestLeft,
  57. float& highestLeft,
  58. float& lowestRight,
  59. float& highestRight);
  60. private:
  61. //==============================================================================
  62. AudioFormatReader* const source;
  63. int64 startSample, length;
  64. const bool deleteSourceWhenDeleted;
  65. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioSubsectionReader)
  66. };
  67. #endif // __JUCE_AUDIOSUBSECTIONREADER_JUCEHEADER__