JUCE
Public Member Functions | List of all members
SamplerSound Class Reference

A subclass of SynthesiserSound that represents a sampled audio clip. More...

Inheritance diagram for SamplerSound:

Public Member Functions

 SamplerSound (const String &name, AudioFormatReader &source, const BigInteger &midiNotes, int midiNoteForNormalPitch, double attackTimeSecs, double releaseTimeSecs, double maxSampleLengthSeconds)
 Creates a sampled sound from an audio reader. More...
 
 ~SamplerSound () override
 Destructor. More...
 
const StringgetName () const noexcept
 Returns the sample's name. More...
 
AudioBuffer< float > * getAudioData () const noexcept
 Returns the audio sample data. More...
 
void setEnvelopeParameters (ADSR::Parameters parametersToUse)
 Changes the parameters of the ADSR envelope which will be applied to the sample. More...
 
bool appliesToNote (int midiNoteNumber) override
 Returns true if this sound should be played when a given midi note is pressed. More...
 
bool appliesToChannel (int midiChannel) override
 Returns true if the sound should be triggered by midi events on a given channel. More...
 
- Public Member Functions inherited from SynthesiserSound
 ~SynthesiserSound () override
 Destructor. More...
 
- Public Member Functions inherited from ReferenceCountedObject
void incReferenceCount () noexcept
 Increments the object's reference count. More...
 
void decReferenceCount () noexcept
 Decreases the object's reference count. More...
 
bool decReferenceCountWithoutDeleting () noexcept
 Decreases the object's reference count. More...
 
int getReferenceCount () const noexcept
 Returns the object's current reference count. More...
 

Additional Inherited Members

- Public Types inherited from SynthesiserSound
using Ptr = ReferenceCountedObjectPtr< SynthesiserSound >
 The class is reference-counted, so this is a handy pointer class for it. More...
 
- Protected Member Functions inherited from SynthesiserSound
 SynthesiserSound ()
 
- Protected Member Functions inherited from ReferenceCountedObject
 ReferenceCountedObject ()=default
 Creates the reference-counted object (with an initial ref count of zero). More...
 
 ReferenceCountedObject (const ReferenceCountedObject &) noexcept
 Copying from another object does not affect this one's reference-count. More...
 
 ReferenceCountedObject (ReferenceCountedObject &&) noexcept
 Copying from another object does not affect this one's reference-count. More...
 
ReferenceCountedObjectoperator= (const ReferenceCountedObject &) noexcept
 Copying from another object does not affect this one's reference-count. More...
 
ReferenceCountedObjectoperator= (ReferenceCountedObject &&) noexcept
 Copying from another object does not affect this one's reference-count. More...
 
virtual ~ReferenceCountedObject ()
 Destructor. More...
 
void resetReferenceCount () noexcept
 Resets the reference count to zero without deleting the object. More...
 

Detailed Description

A subclass of SynthesiserSound that represents a sampled audio clip.

This is a pretty basic sampler, and just attempts to load the whole audio stream into memory.

To use it, create a Synthesiser, add some SamplerVoice objects to it, then give it some SampledSound objects to play.

See also
SamplerVoice, Synthesiser, SynthesiserSound

Constructor & Destructor Documentation

◆ SamplerSound()

SamplerSound::SamplerSound ( const String name,
AudioFormatReader source,
const BigInteger midiNotes,
int  midiNoteForNormalPitch,
double  attackTimeSecs,
double  releaseTimeSecs,
double  maxSampleLengthSeconds 
)

Creates a sampled sound from an audio reader.

This will attempt to load the audio from the source into memory and store it in this object.

Parameters
namea name for the sample
sourcethe audio to load. This object can be safely deleted by the caller after this constructor returns
midiNotesthe set of midi keys that this sound should be played on. This is used by the SynthesiserSound::appliesToNote() method
midiNoteForNormalPitchthe midi note at which the sample should be played with its natural rate. All other notes will be pitched up or down relative to this one
attackTimeSecsthe attack (fade-in) time, in seconds
releaseTimeSecsthe decay (fade-out) time, in seconds
maxSampleLengthSecondsa maximum length of audio to read from the audio source, in seconds

◆ ~SamplerSound()

SamplerSound::~SamplerSound ( )
override

Destructor.

Member Function Documentation

◆ getName()

const String& SamplerSound::getName ( ) const
noexcept

Returns the sample's name.

◆ getAudioData()

AudioBuffer<float>* SamplerSound::getAudioData ( ) const
noexcept

Returns the audio sample data.

This could return nullptr if there was a problem loading the data.

◆ setEnvelopeParameters()

void SamplerSound::setEnvelopeParameters ( ADSR::Parameters  parametersToUse)

Changes the parameters of the ADSR envelope which will be applied to the sample.

References SynthesiserSound::appliesToChannel(), and SynthesiserSound::appliesToNote().

◆ appliesToNote()

bool SamplerSound::appliesToNote ( int  midiNoteNumber)
overridevirtual

Returns true if this sound should be played when a given midi note is pressed.

The Synthesiser will use this information when deciding which sounds to trigger for a given note.

Implements SynthesiserSound.

◆ appliesToChannel()

bool SamplerSound::appliesToChannel ( int  midiChannel)
overridevirtual

Returns true if the sound should be triggered by midi events on a given channel.

The Synthesiser will use this information when deciding which sounds to trigger for a given note.

Implements SynthesiserSound.


The documentation for this class was generated from the following file: