/*\r
-* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>\r
*\r
-* This file is part of CasparCG.\r
+* This file is part of CasparCG (www.casparcg.com).\r
*\r
-* CasparCG is free software: you can redistribute it and/or modify\r
-* it under the terms of the GNU General Public License as published by\r
-* the Free Software Foundation, either version 3 of the License, or\r
-* (at your option) any later version.\r
+* CasparCG is free software: you can redistribute it and/or modify\r
+* it under the terms of the GNU General Public License as published by\r
+* the Free Software Foundation, either version 3 of the License, or\r
+* (at your option) any later version.\r
*\r
-* CasparCG is distributed in the hope that it will be useful,\r
-* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-* GNU General Public License for more details.\r
-\r
-* You should have received a copy of the GNU General Public License\r
-* along with CasparCG. If not, see <http://www.gnu.org/licenses/>.\r
+* CasparCG is distributed in the hope that it will be useful,\r
+* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+* GNU General Public License for more details.\r
+*\r
+* You should have received a copy of the GNU General Public License\r
+* along with CasparCG. If not, see <http://www.gnu.org/licenses/>.\r
*\r
+* Author: Robert Nagy, ronag89@gmail.com\r
*/\r
+\r
#include "../../stdafx.h"\r
\r
#include "audio_mixer.h"\r
\r
-#include <core/mixer/write_frame.h>\r
-#include <core/producer/frame/frame_transform.h>\r
-\r
-#include <tbb/cache_aligned_allocator.h>\r
+#include <core/mixer/gpu/write_frame.h>\r
+#include <core/frame/frame_transform.h>\r
+#include <common/diagnostics/graph.h>\r
\r
#include <boost/range/adaptors.hpp>\r
#include <boost/range/distance.hpp>\r
\r
struct audio_stream\r
{\r
- frame_transform transform;\r
+ frame_transform prev_transform;\r
audio_buffer_ps audio_data;\r
};\r
\r
-struct audio_mixer::implementation\r
+struct audio_mixer::impl : boost::noncopyable\r
{\r
std::stack<core::frame_transform> transform_stack_;\r
std::map<const void*, audio_stream> audio_streams_;\r
std::vector<audio_item> items_;\r
- std::vector<size_t> audio_cadence_;\r
+ std::vector<int> audio_cadence_;\r
video_format_desc format_desc_;\r
\r
public:\r
- implementation()\r
- : format_desc_(video_format_desc::get(video_format::invalid))\r
+ impl()\r
{\r
transform_stack_.push(core::frame_transform());\r
}\r
\r
- void begin(core::basic_frame& frame)\r
+ void begin(core::draw_frame& frame)\r
{\r
transform_stack_.push(transform_stack_.top()*frame.get_frame_transform());\r
}\r
format_desc_ = format_desc;\r
} \r
\r
- std::map<const void*, audio_stream> next_audio_streams_;\r
+ std::map<const void*, audio_stream> next_audio_streams;\r
\r
BOOST_FOREACH(auto& item, items_)\r
{ \r
const auto it = audio_streams_.find(item.tag);\r
if(it != audio_streams_.end())\r
{ \r
- prev_transform = it->second.transform;\r
+ prev_transform = it->second.prev_transform;\r
next_audio = std::move(it->second.audio_data);\r
}\r
-\r
- if(prev_transform.volume < 0.001 && next_transform.volume < 0.001)\r
- continue;\r
- \r
+ \r
const float prev_volume = static_cast<float>(prev_transform.volume);\r
const float next_volume = static_cast<float>(next_transform.volume);\r
\r
for(size_t n = 0; n < item.audio_data.size(); ++n)\r
next_audio.push_back(item.audio_data[n] * (prev_volume + (n/format_desc_.audio_channels) * alpha));\r
\r
- next_audio_streams_[item.tag].transform = std::move(next_transform); // Store all active tags, inactive tags will be removed at the end.\r
- next_audio_streams_[item.tag].audio_data = std::move(next_audio); \r
+ next_audio_streams[item.tag].prev_transform = std::move(next_transform); // Store all active tags, inactive tags will be removed at the end.\r
+ next_audio_streams[item.tag].audio_data = std::move(next_audio); \r
} \r
\r
items_.clear();\r
\r
- audio_streams_ = std::move(next_audio_streams_);\r
+ audio_streams_ = std::move(next_audio_streams);\r
\r
if(audio_streams_.empty()) \r
audio_streams_[nullptr].audio_data = audio_buffer_ps(audio_cadence_.front(), 0.0f);\r
std::vector<float> result_ps(audio_cadence_.front(), 0.0f);\r
BOOST_FOREACH(auto& stream, audio_streams_ | boost::adaptors::map_values)\r
{\r
+ //CASPAR_LOG(debug) << stream.audio_data.size() << L" : " << result_ps.size();\r
+\r
+ if(stream.audio_data.size() < result_ps.size())\r
+ {\r
+ stream.audio_data.resize(result_ps.size(), 0.0f);\r
+ CASPAR_LOG(trace) << L"[audio_mixer] Appended zero samples";\r
+ }\r
+\r
auto out = boost::range::transform(result_ps, stream.audio_data, std::begin(result_ps), std::plus<float>());\r
stream.audio_data.erase(std::begin(stream.audio_data), std::begin(stream.audio_data) + std::distance(std::begin(result_ps), out));\r
} \r
\r
audio_buffer result;\r
result.reserve(result_ps.size());\r
- boost::range::transform(result_ps, std::back_inserter(result), [](float sample){return static_cast<int32_t>(sample);}); \r
+ boost::range::transform(result_ps, std::back_inserter(result), [](float sample){return static_cast<int32_t>(sample);}); \r
+ \r
return result;\r
}\r
};\r
\r
-audio_mixer::audio_mixer() : impl_(new implementation()){}\r
-void audio_mixer::begin(core::basic_frame& frame){impl_->begin(frame);}\r
+audio_mixer::audio_mixer() : impl_(new impl()){}\r
+void audio_mixer::begin(core::draw_frame& frame){impl_->begin(frame);}\r
void audio_mixer::visit(core::write_frame& frame){impl_->visit(frame);}\r
void audio_mixer::end(){impl_->end();}\r
-audio_buffer audio_mixer::mix(const video_format_desc& format_desc){return impl_->mix(format_desc);}\r
-audio_mixer& audio_mixer::operator=(audio_mixer&& other)\r
-{\r
- impl_ = std::move(other.impl_);\r
- return *this;\r
-}\r
+audio_buffer audio_mixer::operator()(const video_format_desc& format_desc){return impl_->mix(format_desc);}\r
\r
}}
\ No newline at end of file