2014-01-28 17:17:38 -06:00
|
|
|
/**
|
|
|
|
|
* @file
|
|
|
|
|
* @brief Header file for AudioReaderSource class
|
|
|
|
|
* @author Jonathan Thomas <jonathan@openshot.org>
|
|
|
|
|
*
|
2019-06-09 08:31:04 -04:00
|
|
|
* @ref License
|
|
|
|
|
*/
|
|
|
|
|
|
2021-10-16 01:26:26 -04:00
|
|
|
// Copyright (c) 2008-2019 OpenShot Studios, LLC
|
|
|
|
|
//
|
|
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
2014-01-28 17:17:38 -06:00
|
|
|
|
|
|
|
|
#ifndef OPENSHOT_AUDIOREADERSOURCE_H
|
|
|
|
|
#define OPENSHOT_AUDIOREADERSOURCE_H
|
|
|
|
|
|
|
|
|
|
#include "ReaderBase.h"
|
2021-09-18 04:16:30 -04:00
|
|
|
|
2021-10-27 14:34:05 -04:00
|
|
|
#include <AppConfig.h>
|
|
|
|
|
#include <juce_audio_basics/juce_audio_basics.h>
|
2014-01-28 17:17:38 -06:00
|
|
|
|
|
|
|
|
/// This namespace is the default namespace for all code in the openshot library
|
|
|
|
|
namespace openshot
|
|
|
|
|
{
|
2021-10-27 14:34:05 -04:00
|
|
|
class Frame;
|
2014-01-28 17:17:38 -06:00
|
|
|
/**
|
|
|
|
|
* @brief This class is used to expose any ReaderBase derived class as an AudioSource in JUCE.
|
|
|
|
|
*
|
|
|
|
|
* This allows any reader to play audio through JUCE (our audio framework).
|
|
|
|
|
*/
|
2019-10-27 03:56:13 -04:00
|
|
|
class AudioReaderSource : public juce::PositionableAudioSource
|
2014-01-28 17:17:38 -06:00
|
|
|
{
|
|
|
|
|
private:
|
2014-01-29 00:18:40 -06:00
|
|
|
int position; /// The position of the audio source (index of buffer)
|
|
|
|
|
bool repeat; /// Repeat the audio source when finished
|
|
|
|
|
int size; /// The size of the internal buffer
|
2021-08-24 04:21:55 -04:00
|
|
|
juce::AudioBuffer<float> *buffer; /// The audio sample buffer
|
2014-03-23 01:12:29 -05:00
|
|
|
int speed; /// The speed and direction to playback a reader (1=normal, 2=fast, 3=faster, -1=rewind, etc...)
|
2014-01-28 17:17:38 -06:00
|
|
|
|
|
|
|
|
ReaderBase *reader; /// The reader to pull samples from
|
2017-09-28 16:03:01 -05:00
|
|
|
int64_t frame_number; /// The current frame number
|
2017-08-20 17:37:39 -05:00
|
|
|
std::shared_ptr<Frame> frame; /// The current frame object that is being read
|
2017-09-28 16:03:01 -05:00
|
|
|
int64_t frame_position; /// The position of the current frame's buffer
|
2014-02-13 03:16:18 -06:00
|
|
|
double estimated_frame; /// The estimated frame position of the currently playing buffer
|
|
|
|
|
int estimated_samples_per_frame; /// The estimated samples per frame of video
|
2014-01-28 17:17:38 -06:00
|
|
|
|
|
|
|
|
/// Get more samples from the reader
|
|
|
|
|
void GetMoreSamplesFromReader();
|
|
|
|
|
|
2014-03-23 01:12:29 -05:00
|
|
|
/// Reverse an audio buffer (for backwards audio)
|
2021-08-24 04:21:55 -04:00
|
|
|
juce::AudioBuffer<float>* reverse_buffer(juce::AudioBuffer<float>* buffer);
|
2014-03-23 01:12:29 -05:00
|
|
|
|
2014-01-28 17:17:38 -06:00
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
/// @brief Constructor that reads samples from a reader
|
2015-02-04 23:56:43 -06:00
|
|
|
/// @param audio_reader This reader provides constant samples from a ReaderBase derived class
|
2014-01-28 17:17:38 -06:00
|
|
|
/// @param starting_frame_number This is the frame number to start reading samples from the reader.
|
2015-02-04 23:56:43 -06:00
|
|
|
/// @param buffer_size The max number of samples to keep in the buffer at one time.
|
2017-09-28 16:03:01 -05:00
|
|
|
AudioReaderSource(ReaderBase *audio_reader, int64_t starting_frame_number, int buffer_size);
|
2014-01-28 17:17:38 -06:00
|
|
|
|
|
|
|
|
/// Destructor
|
|
|
|
|
~AudioReaderSource();
|
|
|
|
|
|
|
|
|
|
/// @brief Get the next block of audio samples
|
|
|
|
|
/// @param info This struct informs us of which samples are needed next.
|
2019-10-27 03:56:13 -04:00
|
|
|
void getNextAudioBlock (const juce::AudioSourceChannelInfo& info);
|
2014-01-28 17:17:38 -06:00
|
|
|
|
|
|
|
|
/// Prepare to play this audio source
|
|
|
|
|
void prepareToPlay(int, double);
|
|
|
|
|
|
|
|
|
|
/// Release all resources
|
|
|
|
|
void releaseResources();
|
|
|
|
|
|
|
|
|
|
/// @brief Set the next read position of this source
|
|
|
|
|
/// @param newPosition The sample # to start reading from
|
2019-10-27 03:56:13 -04:00
|
|
|
void setNextReadPosition (juce::int64 newPosition);
|
2014-01-28 17:17:38 -06:00
|
|
|
|
|
|
|
|
/// Get the next read position of this source
|
2019-10-27 03:56:13 -04:00
|
|
|
juce::int64 getNextReadPosition() const;
|
2014-01-28 17:17:38 -06:00
|
|
|
|
|
|
|
|
/// Get the total length (in samples) of this audio source
|
2019-10-27 03:56:13 -04:00
|
|
|
juce::int64 getTotalLength() const;
|
2014-01-28 17:17:38 -06:00
|
|
|
|
|
|
|
|
/// Determines if this audio source should repeat when it reaches the end
|
|
|
|
|
bool isLooping() const;
|
|
|
|
|
|
|
|
|
|
/// @brief Set if this audio source should repeat when it reaches the end
|
|
|
|
|
/// @param shouldLoop Determines if the audio source should repeat when it reaches the end
|
|
|
|
|
void setLooping (bool shouldLoop);
|
|
|
|
|
|
|
|
|
|
/// Update the internal buffer used by this source
|
2021-08-24 04:21:55 -04:00
|
|
|
void setBuffer (juce::AudioBuffer<float> *audio_buffer);
|
2014-01-31 16:27:16 +08:00
|
|
|
|
|
|
|
|
const ReaderInfo & getReaderInfo() const { return reader->info; }
|
2014-03-23 01:12:29 -05:00
|
|
|
|
|
|
|
|
/// Return the current frame object
|
2017-08-20 17:37:39 -05:00
|
|
|
std::shared_ptr<Frame> getFrame() const { return frame; }
|
2014-03-23 01:12:29 -05:00
|
|
|
|
|
|
|
|
/// Get the estimate frame that is playing at this moment
|
2017-09-28 16:03:01 -05:00
|
|
|
int64_t getEstimatedFrame() const { return int64_t(estimated_frame); }
|
2014-03-23 01:12:29 -05:00
|
|
|
|
|
|
|
|
/// Set Speed (The speed and direction to playback a reader (1=normal, 2=fast, 3=faster, -1=rewind, etc...)
|
|
|
|
|
void setSpeed(int new_speed) { speed = new_speed; }
|
|
|
|
|
/// Get Speed (The speed and direction to playback a reader (1=normal, 2=fast, 3=faster, -1=rewind, etc...)
|
|
|
|
|
int getSpeed() const { return speed; }
|
|
|
|
|
|
|
|
|
|
/// Set Reader
|
|
|
|
|
void Reader(ReaderBase *audio_reader) { reader = audio_reader; }
|
|
|
|
|
/// Get Reader
|
|
|
|
|
ReaderBase* Reader() const { return reader; }
|
|
|
|
|
|
|
|
|
|
/// Seek to a specific frame
|
2017-09-28 16:03:01 -05:00
|
|
|
void Seek(int64_t new_position) { frame_number = new_position; estimated_frame = new_position; }
|
2014-03-23 01:12:29 -05:00
|
|
|
|
2014-01-28 17:17:38 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|