OpenShot Library | libopenshot-audio  0.1.9
juce_AudioSourcePlayer.h
1 
2 /** @weakgroup juce_audio_devices-sources
3  * @{
4  */
5 /*
6  ==============================================================================
7 
8  This file is part of the JUCE library.
9  Copyright (c) 2017 - ROLI Ltd.
10 
11  JUCE is an open source library subject to commercial or open-source
12  licensing.
13 
14  The code included in this file is provided under the terms of the ISC license
15  http://www.isc.org/downloads/software-support-policy/isc-license. Permission
16  To use, copy, modify, and/or distribute this software for any purpose with or
17  without fee is hereby granted provided that the above copyright notice and
18  this permission notice appear in all copies.
19 
20  JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21  EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22  DISCLAIMED.
23 
24  ==============================================================================
25 */
26 
27 namespace juce
28 {
29 
30 //==============================================================================
31 /**
32  Wrapper class to continuously stream audio from an audio source to an
33  AudioIODevice.
34 
35  This object acts as an AudioIODeviceCallback, so can be attached to an
36  output device, and will stream audio from an AudioSource.
37 
38  @tags{Audio}
39 */
41 {
42 public:
43  //==============================================================================
44  /** Creates an empty AudioSourcePlayer. */
46 
47  /** Destructor.
48 
49  Make sure this object isn't still being used by an AudioIODevice before
50  deleting it!
51  */
52  ~AudioSourcePlayer() override;
53 
54  //==============================================================================
55  /** Changes the current audio source to play from.
56 
57  If the source passed in is already being used, this method will do nothing.
58  If the source is not null, its prepareToPlay() method will be called
59  before it starts being used for playback.
60 
61  If there's another source currently playing, its releaseResources() method
62  will be called after it has been swapped for the new one.
63 
64  @param newSource the new source to use - this will NOT be deleted
65  by this object when no longer needed, so it's the
66  caller's responsibility to manage it.
67  */
68  void setSource (AudioSource* newSource);
69 
70  /** Returns the source that's playing.
71  May return nullptr if there's no source.
72  */
73  AudioSource* getCurrentSource() const noexcept { return source; }
74 
75  /** Sets a gain to apply to the audio data.
76  @see getGain
77  */
78  void setGain (float newGain) noexcept;
79 
80  /** Returns the current gain.
81  @see setGain
82  */
83  float getGain() const noexcept { return gain; }
84 
85  //==============================================================================
86  /** Implementation of the AudioIODeviceCallback method. */
87  void audioDeviceIOCallback (const float** inputChannelData,
88  int totalNumInputChannels,
89  float** outputChannelData,
90  int totalNumOutputChannels,
91  int numSamples) override;
92 
93  /** Implementation of the AudioIODeviceCallback method. */
94  void audioDeviceAboutToStart (AudioIODevice* device) override;
95 
96  /** Implementation of the AudioIODeviceCallback method. */
97  void audioDeviceStopped() override;
98 
99  /** An alternative method for initialising the source without an AudioIODevice. */
100  void prepareToPlay (double sampleRate, int blockSize);
101 
102 private:
103  //==============================================================================
104  CriticalSection readLock;
105  AudioSource* source = nullptr;
106  double sampleRate = 0;
107  int bufferSize = 0;
108  float* channels[128];
109  float* outputChans[128];
110  const float* inputChans[128];
111  AudioBuffer<float> tempBuffer;
112  float lastGain = 1.0f, gain = 1.0f;
113 
114  JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioSourcePlayer)
115 };
116 
117 } // namespace juce
118 
119 /** @}*/
One of these is passed to an AudioIODevice object to stream the audio data in and out...
#define JUCE_API
This macro is added to all JUCE public class declarations.
AudioSource * getCurrentSource() const noexcept
Returns the source that&#39;s playing.
Base class for objects that can produce a continuous stream of audio.
Wrapper class to continuously stream audio from an audio source to an AudioIODevice.
Base class for an audio device with synchronised input and output channels.
A re-entrant mutex.
float getGain() const noexcept
Returns the current gain.