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.

89 lines
3.6KB

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