17 #include "../ReaderBase.h"
18 #include "../RendererBase.h"
19 #include "../AudioReaderSource.h"
20 #include "../AudioDevices.h"
21 #include "../Settings.h"
31 AudioDeviceManagerSingleton *AudioDeviceManagerSingleton::m_pInstance = NULL;
36 return AudioDeviceManagerSingleton::Instance(44100, 2);
48 auto selected_device = juce::String(
49 Settings::Instance()->PLAYBACK_AUDIO_DEVICE_NAME);
50 auto selected_type = juce::String(
51 Settings::Instance()->PLAYBACK_AUDIO_DEVICE_TYPE);
53 if (selected_type.isEmpty() && !selected_device.isEmpty()) {
55 for (
const auto t : mgr->getAvailableDeviceTypes()) {
56 for (
const auto n : t->getDeviceNames()) {
57 if (selected_device.trim().equalsIgnoreCase(n.trim())) {
58 selected_type = t->getTypeName();
62 if(!selected_type.isEmpty())
67 if (!selected_type.isEmpty())
68 m_pInstance->audioDeviceManager.setCurrentAudioDeviceType(selected_type,
true);
71 AudioDeviceManager::AudioDeviceSetup deviceSetup = AudioDeviceManager::AudioDeviceSetup();
72 deviceSetup.sampleRate = rate;
73 deviceSetup.inputChannels = 0;
74 deviceSetup.outputChannels = channels;
77 m_pInstance->audioDeviceManager.initialiseWithDefaultDevices (0, 2);
78 m_pInstance->defaultSampleRate = m_pInstance->audioDeviceManager.getCurrentAudioDevice()->getCurrentSampleRate();
81 juce::String audio_error = m_pInstance->audioDeviceManager.initialise (
91 if (audio_error.isNotEmpty()) {
92 m_pInstance->initialise_error = audio_error.toStdString();
94 m_pInstance->initialise_error =
"";
102 void AudioDeviceManagerSingleton::CloseAudioDevice()
105 audioDeviceManager.closeAudioDevice();
106 audioDeviceManager.removeAllChangeListeners();
107 audioDeviceManager.dispatchPendingMessages();
112 :
juce::Thread(
"audio-playback")
120 , time_thread(
"audio-buffer")
126 AudioPlaybackThread::~AudioPlaybackThread()
136 auto starting_frame = 1;
137 source =
new AudioReaderSource(reader, starting_frame);
152 std::shared_ptr<openshot::Frame> AudioPlaybackThread::getFrame()
154 if (source)
return source->
getFrame();
155 return std::shared_ptr<openshot::Frame>();
159 void AudioPlaybackThread::Seek(int64_t new_position)
162 source->
Seek(new_position);
167 void AudioPlaybackThread::Play() {
173 void AudioPlaybackThread::Stop() {
179 void AudioPlaybackThread::run()
181 while (!threadShouldExit())
183 if (source && !transport.isPlaying() && is_playing) {
189 audioInstance->audioDeviceManager.addAudioCallback(&player);
192 time_thread.startThread();
201 transport.setPosition(0);
202 transport.setGain(1.0);
205 mixer.addInputSource(&transport,
false);
206 player.setSource(&mixer);
211 while (!threadShouldExit() && transport.isPlaying() && is_playing)
212 std::this_thread::sleep_for(std::chrono::milliseconds(2));
219 transport.setSource(NULL);
221 player.setSource(NULL);
222 audioInstance->audioDeviceManager.removeAudioCallback(&player);
229 time_thread.stopThread(-1);
Source file for AudioPlaybackThread class.
Header file for global Settings class.
Singleton wrapper for AudioDeviceManager (to prevent multiple instances).
static AudioDeviceManagerSingleton * Instance()
Override with default sample rate & channels (44100, 2) and no preferred audio device.
juce::AudioDeviceManager audioDeviceManager
Public device manager property.
void Seek(int64_t new_position)
Seek to a specific frame.
void Reader(ReaderBase *audio_reader)
Set Reader.
std::shared_ptr< Frame > getFrame() const
Return the current frame object.
void setVideoCache(openshot::VideoCacheThread *newCache)
Set playback video cache thread (for pre-roll reference)
This abstract class is the base class, used by all readers in libopenshot.
openshot::ReaderInfo info
Information about the current media file.
This namespace is the default namespace for all code in the openshot library.
int channels
The number of audio channels used in the audio stream.
int sample_rate
The number of audio samples per second (44100 is a common sample rate)