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.

75 lines
3.3KB

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