2 * copyright (c) 2010 Sveriges Television AB <info@casparcg.com>
\r
4 * This file is part of CasparCG.
\r
6 * CasparCG is free software: you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation, either version 3 of the License, or
\r
9 * (at your option) any later version.
\r
11 * CasparCG is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
\r
21 #include "../../StdAfx.h"
\r
23 #include "oal_frame_consumer.h"
\r
25 #include "../../frame/gpu_frame.h"
\r
26 #include "../../frame/frame_format.h"
\r
28 #include <SFML/Audio.hpp>
\r
30 #include <boost/circular_buffer.hpp>
\r
31 #include <boost/foreach.hpp>
\r
33 #include <windows.h>
\r
35 namespace caspar{ namespace audio{
\r
37 class sound_channel : public sf::SoundStream
\r
40 sound_channel() : internal_chunks_(5), silence_(1920*2, 0)
\r
42 external_chunks_.set_capacity(3);
\r
43 sf::SoundStream::Initialize(2, 48000);
\r
48 external_chunks_.clear();
\r
49 external_chunks_.push(nullptr);
\r
53 void push(const gpu_frame_ptr& frame)
\r
55 if(frame->audio_data().empty())
\r
56 frame->audio_data() = silence_;
\r
58 //if(!external_chunks_.try_push(frame))
\r
60 //CASPAR_LOG(debug) << "Sound Buffer Overrun";
\r
61 external_chunks_.push(frame);
\r
64 if(GetStatus() != Playing && external_chunks_.size() >= 3)
\r
72 external_chunks_.clear();
\r
76 bool OnGetData(sf::SoundStream::Chunk& data)
\r
78 gpu_frame_ptr frame;
\r
79 //if(!external_chunks_.try_pop(frame))
\r
81 //CASPAR_LOG(trace) << "Sound Buffer Underrun";
\r
82 external_chunks_.pop(frame);
\r
85 if(frame == nullptr)
\r
87 external_chunks_.clear();
\r
91 internal_chunks_.push_back(frame);
\r
92 //SetVolume(pChunk->volume());
\r
93 data.Samples = reinterpret_cast<sf::Int16*>(frame->audio_data().data());
\r
94 data.NbSamples = frame->audio_data().size();
\r
98 std::vector<short> silence_;
\r
99 boost::circular_buffer<gpu_frame_ptr> internal_chunks_;
\r
100 tbb::concurrent_bounded_queue<gpu_frame_ptr> external_chunks_;
\r
102 typedef std::shared_ptr<sound_channel> sound_channelPtr;
\r
104 struct oal_frame_consumer::implementation : boost::noncopyable
\r
106 implementation(const frame_format_desc& format_desc) : format_desc_(format_desc)
\r
110 void push(const gpu_frame_ptr& frame)
\r
112 channel_.push(frame);
\r
115 sound_channel channel_;
\r
117 caspar::frame_format_desc format_desc_;
\r
120 oal_frame_consumer::oal_frame_consumer(const caspar::frame_format_desc& format_desc) : impl_(new implementation(format_desc)){}
\r
121 const caspar::frame_format_desc& oal_frame_consumer::get_frame_format_desc() const{return impl_->format_desc_;}
\r
122 void oal_frame_consumer::prepare(const gpu_frame_ptr& frame){impl_->push(frame);}
\r