32 int midiNoteForNormalPitch,
33 double attackTimeSecs,
34 double releaseTimeSecs,
35 double maxSampleLengthSeconds)
37 sourceSampleRate (source.sampleRate),
39 midiRootNote (midiNoteForNormalPitch)
44 (
int) (maxSampleLengthSeconds * sourceSampleRate));
48 source.
read (data.get(), 0, length + 4, 0,
true,
true);
50 params.attack =
static_cast<float> (attackTimeSecs);
51 params.release =
static_cast<float> (releaseTimeSecs);
61 return midiNotes[midiNoteNumber];
75 return dynamic_cast<const SamplerSound*
> (sound) !=
nullptr;
82 pitchRatio = std::pow (2.0, (midiNoteNumber - sound->midiRootNote) / 12.0)
85 sourceSamplePosition = 0.0;
121 auto& data = *playingSound->data;
122 const float*
const inL = data.getReadPointer (0);
123 const float*
const inR = data.getNumChannels() > 1 ? data.getReadPointer (1) :
nullptr;
128 while (--numSamples >= 0)
130 auto pos = (int) sourceSamplePosition;
131 auto alpha = (float) (sourceSamplePosition - pos);
132 auto invAlpha = 1.0f - alpha;
135 float l = (inL[pos] * invAlpha + inL[pos + 1] * alpha);
136 float r = (inR !=
nullptr) ? (inR[pos] * invAlpha + inR[pos + 1] * alpha)
141 l *= lgain * envelopeValue;
142 r *= rgain * envelopeValue;
151 *outL++ += (l + r) * 0.5f;
154 sourceSamplePosition += pitchRatio;
156 if (sourceSamplePosition > playingSound->length)
void setSampleRate(double newSampleRate) noexcept
float getNextSample() noexcept
void setParameters(const Parameters &newParameters)
Type * getWritePointer(int channelNumber) noexcept
int getNumChannels() const noexcept
bool appliesToChannel(int midiChannel) override
SamplerSound(const String &name, AudioFormatReader &source, const BigInteger &midiNotes, int midiNoteForNormalPitch, double attackTimeSecs, double releaseTimeSecs, double maxSampleLengthSeconds)
bool appliesToNote(int midiNoteNumber) override
void startNote(int midiNoteNumber, float velocity, SynthesiserSound *, int pitchWheel) override
void controllerMoved(int controllerNumber, int newValue) override
bool canPlaySound(SynthesiserSound *) override
void renderNextBlock(AudioBuffer< float > &, int startSample, int numSamples) override
void pitchWheelMoved(int newValue) override
void stopNote(float velocity, bool allowTailOff) override
double getSampleRate() const noexcept
SynthesiserSound::Ptr getCurrentlyPlayingSound() const noexcept