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.

91 lines
3.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_AUDIOSUBSECTIONREADER_JUCEHEADER__
  19. #define __JUCE_AUDIOSUBSECTIONREADER_JUCEHEADER__
  20. #include "juce_AudioFormatReader.h"
  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. */
  32. class JUCE_API AudioSubsectionReader : public AudioFormatReader
  33. {
  34. public:
  35. //==============================================================================
  36. /** Creates a 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();
  52. //==============================================================================
  53. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  54. int64 startSampleInFile, int numSamples);
  55. void readMaxLevels (int64 startSample,
  56. int64 numSamples,
  57. float& lowestLeft,
  58. float& highestLeft,
  59. float& lowestRight,
  60. float& highestRight);
  61. private:
  62. //==============================================================================
  63. AudioFormatReader* const source;
  64. int64 startSample, length;
  65. const bool deleteSourceWhenDeleted;
  66. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioSubsectionReader);
  67. };
  68. #endif // __JUCE_AUDIOSUBSECTIONREADER_JUCEHEADER__