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.

74 lines
3.1KB

  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. AudioSubsectionReader::AudioSubsectionReader (AudioFormatReader* const source_,
  18. const int64 startSample_,
  19. const int64 length_,
  20. const bool deleteSourceWhenDeleted_)
  21. : AudioFormatReader (0, source_->getFormatName()),
  22. source (source_),
  23. startSample (startSample_),
  24. deleteSourceWhenDeleted (deleteSourceWhenDeleted_)
  25. {
  26. length = jmin (jmax ((int64) 0, source->lengthInSamples - startSample), length_);
  27. sampleRate = source->sampleRate;
  28. bitsPerSample = source->bitsPerSample;
  29. lengthInSamples = length;
  30. numChannels = source->numChannels;
  31. usesFloatingPointData = source->usesFloatingPointData;
  32. }
  33. AudioSubsectionReader::~AudioSubsectionReader()
  34. {
  35. if (deleteSourceWhenDeleted)
  36. delete source;
  37. }
  38. //==============================================================================
  39. bool AudioSubsectionReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  40. int64 startSampleInFile, int numSamples)
  41. {
  42. clearSamplesBeyondAvailableLength (destSamples, numDestChannels, startOffsetInDestBuffer,
  43. startSampleInFile, numSamples, length);
  44. return source->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer,
  45. startSampleInFile + startSample, numSamples);
  46. }
  47. void AudioSubsectionReader::readMaxLevels (int64 startSampleInFile,
  48. int64 numSamples,
  49. float& lowestLeft,
  50. float& highestLeft,
  51. float& lowestRight,
  52. float& highestRight)
  53. {
  54. startSampleInFile = jmax ((int64) 0, startSampleInFile);
  55. numSamples = jmax ((int64) 0, jmin (numSamples, length - startSampleInFile));
  56. source->readMaxLevels (startSampleInFile + startSample, numSamples,
  57. lowestLeft, highestLeft,
  58. lowestRight, highestRight);
  59. }