OpenShot Library | OpenShotAudio 0.2.2
juce_Sampler.h
1
2/** @weakgroup juce_audio_formats-sampler
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 By using JUCE, you agree to the terms of both the JUCE 5 End-User License
15 Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
16 27th April 2017).
17
18 End User License Agreement: www.juce.com/juce-5-licence
19 Privacy Policy: www.juce.com/juce-5-privacy-policy
20
21 Or: You may also use this code under the terms of the GPL v3 (see
22 www.gnu.org/licenses).
23
24 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
25 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
26 DISCLAIMED.
27
28 ==============================================================================
29*/
30
31namespace juce
32{
33
34//==============================================================================
35/**
36 A subclass of SynthesiserSound that represents a sampled audio clip.
37
38 This is a pretty basic sampler, and just attempts to load the whole audio stream
39 into memory.
40
41 To use it, create a Synthesiser, add some SamplerVoice objects to it, then
42 give it some SampledSound objects to play.
43
44 @see SamplerVoice, Synthesiser, SynthesiserSound
45
46 @tags{Audio}
47*/
49{
50public:
51 //==============================================================================
52 /** Creates a sampled sound from an audio reader.
53
54 This will attempt to load the audio from the source into memory and store
55 it in this object.
56
57 @param name a name for the sample
58 @param source the audio to load. This object can be safely deleted by the
59 caller after this constructor returns
60 @param midiNotes the set of midi keys that this sound should be played on. This
61 is used by the SynthesiserSound::appliesToNote() method
62 @param midiNoteForNormalPitch the midi note at which the sample should be played
63 with its natural rate. All other notes will be pitched
64 up or down relative to this one
65 @param attackTimeSecs the attack (fade-in) time, in seconds
66 @param releaseTimeSecs the decay (fade-out) time, in seconds
67 @param maxSampleLengthSeconds a maximum length of audio to read from the audio
68 source, in seconds
69 */
70 SamplerSound (const String& name,
71 AudioFormatReader& source,
72 const BigInteger& midiNotes,
73 int midiNoteForNormalPitch,
74 double attackTimeSecs,
75 double releaseTimeSecs,
76 double maxSampleLengthSeconds);
77
78 /** Destructor. */
79 ~SamplerSound() override;
80
81 //==============================================================================
82 /** Returns the sample's name */
83 const String& getName() const noexcept { return name; }
84
85 /** Returns the audio sample data.
86 This could return nullptr if there was a problem loading the data.
87 */
88 AudioBuffer<float>* getAudioData() const noexcept { return data.get(); }
89
90 //==============================================================================
91 /** Changes the parameters of the ADSR envelope which will be applied to the sample. */
92 void setEnvelopeParameters (ADSR::Parameters parametersToUse) { params = parametersToUse; }
93
94 //==============================================================================
95 bool appliesToNote (int midiNoteNumber) override;
96 bool appliesToChannel (int midiChannel) override;
97
98private:
99 //==============================================================================
100 friend class SamplerVoice;
101
102 String name;
103 std::unique_ptr<AudioBuffer<float>> data;
104 double sourceSampleRate;
105 BigInteger midiNotes;
106 int length = 0, midiRootNote = 0;
107
108 ADSR::Parameters params;
109
110 JUCE_LEAK_DETECTOR (SamplerSound)
111};
112
113
114//==============================================================================
115/**
116 A subclass of SynthesiserVoice that can play a SamplerSound.
117
118 To use it, create a Synthesiser, add some SamplerVoice objects to it, then
119 give it some SampledSound objects to play.
120
121 @see SamplerSound, Synthesiser, SynthesiserVoice
122
123 @tags{Audio}
124*/
126{
127public:
128 //==============================================================================
129 /** Creates a SamplerVoice. */
130 SamplerVoice();
131
132 /** Destructor. */
133 ~SamplerVoice() override;
134
135 //==============================================================================
136 bool canPlaySound (SynthesiserSound*) override;
137
138 void startNote (int midiNoteNumber, float velocity, SynthesiserSound*, int pitchWheel) override;
139 void stopNote (float velocity, bool allowTailOff) override;
140
141 void pitchWheelMoved (int newValue) override;
142 void controllerMoved (int controllerNumber, int newValue) override;
143
144 void renderNextBlock (AudioBuffer<float>&, int startSample, int numSamples) override;
146
147private:
148 //==============================================================================
149 double pitchRatio = 0;
150 double sourceSamplePosition = 0;
151 float lgain = 0, rgain = 0;
152
153 ADSR adsr;
154
155 JUCE_LEAK_DETECTOR (SamplerVoice)
156};
157
158} // namespace juce
159
160/** @}*/
A very simple ADSR envelope class.
Definition: juce_ADSR.h:41
Reads samples from an audio file stream.
An arbitrarily large integer class.
A subclass of SynthesiserSound that represents a sampled audio clip.
Definition: juce_Sampler.h:49
AudioBuffer< float > * getAudioData() const noexcept
Returns the audio sample data.
Definition: juce_Sampler.h:88
void setEnvelopeParameters(ADSR::Parameters parametersToUse)
Changes the parameters of the ADSR envelope which will be applied to the sample.
Definition: juce_Sampler.h:92
const String & getName() const noexcept
Returns the sample's name.
Definition: juce_Sampler.h:83
A subclass of SynthesiserVoice that can play a SamplerSound.
Definition: juce_Sampler.h:126
The JUCE String class!
Definition: juce_String.h:43
Describes one of the sounds that a Synthesiser can play.
Represents a voice that a Synthesiser can use to play a SynthesiserSound.
virtual void renderNextBlock(AudioBuffer< float > &outputBuffer, int startSample, int numSamples)=0
Renders the next block of data for this voice.
Holds the parameters being used by an ADSR object.
Definition: juce_ADSR.h:57
#define JUCE_API
This macro is added to all JUCE public class declarations.