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.

121 lines
4.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the dRowAudio JUCE module
  4. Copyright 2004-13 by dRowAudio.
  5. ------------------------------------------------------------------------------
  6. dRowAudio is provided under the terms of The MIT License (MIT):
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in all
  14. copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. SOFTWARE.
  22. ==============================================================================
  23. */
  24. #ifndef __DROWAUDIO_LOOPINGAUDIOSOURCE_H__
  25. #define __DROWAUDIO_LOOPINGAUDIOSOURCE_H__
  26. #include "../utility/dRowAudio_Utility.h"
  27. //==============================================================================
  28. /** A type of PositionalAudioSource that will read from a PositionableAudioSource
  29. and can loop between to set times.
  30. @see PositionableAudioSource, AudioTransportSource, BufferingAudioSource
  31. */
  32. class LoopingAudioSource : public PositionableAudioSource
  33. {
  34. public:
  35. //==============================================================================
  36. /** Creates an LoopingAudioFormatReaderSource for a given reader.
  37. @param sourceReader the reader to use as the data source
  38. @param deleteReaderWhenThisIsDeleted if true, the reader passed-in will be deleted
  39. when this object is deleted; if false it will be
  40. left up to the caller to manage its lifetime
  41. */
  42. LoopingAudioSource (PositionableAudioSource* const inputSource,
  43. const bool deleteInputWhenDeleted);
  44. /** Destructor. */
  45. ~LoopingAudioSource();
  46. //==============================================================================
  47. /** Sets the start and end times of the loop.
  48. This doesn't actually activate the loop, use setLoopBetweenTimes() to toggle this.
  49. */
  50. void setLoopTimes (double startTime, double endTime);
  51. /** Sets the arguments to the currently set start and end times.
  52. */
  53. void getLoopTimes (double& startTime, double& endTime);
  54. /** Enables the loop point set.
  55. */
  56. void setLoopBetweenTimes (bool shouldLoop);
  57. /** Returns true if the loop is activated.
  58. */
  59. bool getLoopBetweenTimes();
  60. //==============================================================================
  61. /** Implementation of the AudioSource method. */
  62. void prepareToPlay (int samplesPerBlockExpected, double sampleRate);
  63. /** Implementation of the AudioSource method. */
  64. void releaseResources();
  65. /** Implementation of the AudioSource method. */
  66. void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill);
  67. //==============================================================================
  68. /** Implements the PositionableAudioSource method. */
  69. void setNextReadPosition (int64 newPosition);
  70. /** Sets the next read position ignoring the loop bounds. */
  71. void setNextReadPositionIgnoringLoop (int64 newPosition);
  72. /** Implements the PositionableAudioSource method. */
  73. int64 getNextReadPosition() const;
  74. /** Implements the PositionableAudioSource method. */
  75. int64 getTotalLength() const;
  76. /** Implements the PositionableAudioSource method. */
  77. bool isLooping() const;
  78. private:
  79. //==============================================================================
  80. OptionalScopedPointer<PositionableAudioSource> input;
  81. CriticalSection loopPosLock;
  82. bool volatile isLoopingBetweenTimes;
  83. double loopStartTime, loopEndTime;
  84. int64 loopStartSample, loopEndSample;
  85. double currentSampleRate;
  86. AudioSourceChannelInfo tempInfo;
  87. AudioSampleBuffer tempBuffer;
  88. //==============================================================================
  89. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LoopingAudioSource);
  90. };
  91. #endif // __DROWAUDIO_LOOPINGAUDIOSOURCE_H__