76 if (! transportSource->isPlaying())
104 position =
jmin (buffer->getNumSamples(),
static_cast<int> (
newPosition));
121 const int bufferSize = buffer->getNumSamples();
130 if (! playAcrossAllChannels)
141 position %= bufferSize;
148 bool looping =
false, playAcrossAllChannels;
153SoundPlayer::SoundPlayer()
154 : sampleRate (44100.0), bufferSize (512)
156 formatManager.registerBasicFormats();
157 player.setSource (&mixer);
183 if (reader !=
nullptr)
189 if (buffer !=
nullptr)
199 if (transport ==
nullptr)
228 double frequency = 440.0;
229 float amplitude = 0.5f;
236 newSound->setSample (0, i, amplitude * (
float)
std::sin (i * phasePerSample));
246 int numInputChannels,
248 int numOutputChannels,
254 numSamples, context);
259 if (device !=
nullptr)
void setNextReadPosition(int64 newPosition) override
Tells the stream to move to a new position.
void releaseResources() override
Allows the source to release anything it no longer needs after playback has stopped.
void setLooping(bool shouldLoop) override
Tells the source whether you'd like it to play in a loop.
void prepareToPlay(int, double) override
Tells the source to prepare for playing.
int64 getNextReadPosition() const override
Returns the position from which the next block will be returned.
void getNextAudioBlock(const AudioSourceChannelInfo &bufferToFill) override
Called repeatedly to fetch subsequent blocks of audio data.
int64 getTotalLength() const override
Returns the total length of the stream (in samples).
bool isLooping() const override
Returns true if this source is actually playing in a loop.
A multi-channel buffer containing floating point audio samples.
virtual void audioDeviceError(const String &errorMessage)
This can be overridden to be told if the device generates an error while operating.
Base class for an audio device with synchronised input and output channels.
virtual double getCurrentSampleRate()=0
Returns the sample rate that the device is currently using.
virtual int getCurrentBufferSizeSamples()=0
Returns the buffer size that the device is currently using.
void setSource(AudioSource *newSource)
Changes the current audio source to play from.
void audioDeviceIOCallbackWithContext(const float *const *inputChannelData, int totalNumInputChannels, float *const *outputChannelData, int totalNumOutputChannels, int numSamples, const AudioIODeviceCallbackContext &context) override
Implementation of the AudioIODeviceCallbackWithContext method.
void audioDeviceStopped() override
Implementation of the AudioIODeviceCallback method.
void audioDeviceAboutToStart(AudioIODevice *device) override
Implementation of the AudioIODeviceCallback method.
An AudioSource that takes a PositionableAudioSource and allows it to be played, stopped,...
void prepareToPlay(int samplesPerBlockExpected, double sampleRate) override
Implementation of the AudioSource method.
void setSource(PositionableAudioSource *newSource, int readAheadBufferSize=0, TimeSliceThread *readAheadThread=nullptr, double sourceSampleRateToCorrectFor=0.0, int maxNumChannels=2)
Sets the reader that is being used as the input source.
void start()
Starts playing (if a source has been selected).
Represents a local file or directory.
bool existsAsFile() const
Checks whether the file exists and is a file rather than a directory.
An AudioSource that mixes together the output of a set of other AudioSources.
void removeInputSource(AudioSource *input)
Removes an input source.
void removeAllInputs()
Removes all the input sources.
void addInputSource(AudioSource *newInput, bool deleteWhenRemoved)
Adds an input source to the mixer.
Holds a pointer to an object which can optionally be deleted when this pointer goes out of scope.
A type of AudioSource which can be repositioned.
void audioDeviceAboutToStart(AudioIODevice *) override
Called to indicate that the device is about to start calling back.
void play(const File &file)
Plays a sound from a file.
~SoundPlayer() override
Destructor.
void audioDeviceStopped() override
Called to indicate that the device has stopped.
void audioDeviceError(const String &errorMessage) override
This can be overridden to be told if the device generates an error while operating.
void playTestSound()
Plays a beep through the current audio device.
void audioDeviceIOCallbackWithContext(const float *const *, int, float *const *, int, int, const AudioIODeviceCallbackContext &) override
Processes a block of incoming and outgoing audio data.
Makes repeated callbacks to a virtual method at a specified time interval.
void startTimerHz(int timerFrequencyHz) noexcept
Starts the timer with an interval specified in Hertz.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
long long int64
A platform-independent 64-bit integer type.
Additional information that may be passed to the AudioIODeviceCallback.
Used by AudioSource::getNextAudioBlock().
void timerCallback() override
The user-defined callback routine that actually gets called periodically.
Commonly used mathematical constants.