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()
133 source->Reader(reader);
136 auto starting_frame = 1;
145 source->setVideoCache(videoCache);
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) {
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);
229 time_thread.stopThread(-1);
juce::AudioDeviceManager audioDeviceManager
Public device manager property.
This abstract class is the base class, used by all readers in libopenshot.
Source file for AudioPlaybackThread class.
Header file for global Settings class.
openshot::ReaderInfo info
Information about the current media file.
This class is used to expose any ReaderBase derived class as an AudioSource in JUCE.
This namespace is the default namespace for all code in the openshot library.
Singleton wrapper for AudioDeviceManager (to prevent multiple instances).
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)