-#pragma once\r
-\r
-#include <vector>\r
-\r
-#include <stdint.h>\r
-\r
-#include <boost/range/iterator_range.hpp>\r
-\r
-namespace caspar { namespace core {\r
-\r
-static std::vector<int16_t> audio_32_to_16(const boost::iterator_range<int32_t*>& input)\r
-{ \r
- std::vector<int16_t> audio16(input.size());\r
- auto audio32_ptr = reinterpret_cast<const uint32_t*>(input.begin());\r
- auto audio16_ptr = reinterpret_cast<uint32_t*>(audio16.data());\r
- auto size = input.size()/2;\r
- for(int n = 0; n < size; ++n) \r
- audio16_ptr[n] = (audio32_ptr[n*2+1] & 0xffff0000) | (audio32_ptr[n*2+0] >> 16); \r
- return audio16;\r
-}\r
-\r
-static std::vector<int8_t> audio_32_to_24(const boost::iterator_range<int32_t*>& input)\r
-{ \r
- std::vector<int8_t> audio24(input.size()*3+16);\r
- auto audio32_ptr = reinterpret_cast<const uint32_t*>(input.begin());\r
- auto audio24_ptr = reinterpret_cast<uint8_t*>(audio24.data());\r
- auto size = input.size();\r
- for(int n = 0; n < size; ++n) \r
- *reinterpret_cast<uint32_t*>(audio24_ptr + n*3) = *(audio32_ptr + n) >> 8; \r
- audio24.resize(input.size());\r
- return audio24;\r
-}\r
-\r
+/*
+* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
+*
+* This file is part of CasparCG (www.casparcg.com).
+*
+* CasparCG is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* CasparCG is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
+*
+* Author: Robert Nagy, ronag89@gmail.com
+*/
+
+#pragma once
+
+#include <algorithm>
+#include <vector>
+#include <cstdint>
+
+#include <common/cache_aligned_vector.h>
+
+namespace caspar { namespace core {
+
+template<typename T>
+cache_aligned_vector<int8_t> audio_32_to_24(const T& audio_data)
+{
+ auto size = std::distance(std::begin(audio_data), std::end(audio_data));
+ auto input8 = reinterpret_cast<const int8_t*>(&(*std::begin(audio_data)));
+ auto output8 = cache_aligned_vector<int8_t>();
+
+ output8.reserve(size*3);
+ for(int n = 0; n < size; ++n)
+ {
+ output8.push_back(input8[n*4+1]);
+ output8.push_back(input8[n*4+2]);
+ output8.push_back(input8[n*4+3]);
+ }
+
+ return output8;
+}
+
+template<typename T>
+cache_aligned_vector<int16_t> audio_32_to_16(const T& audio_data)
+{
+ auto size = std::distance(std::begin(audio_data), std::end(audio_data));
+ auto input32 = &(*std::begin(audio_data));
+ auto output16 = cache_aligned_vector<int16_t> ();
+
+ output16.reserve(size);
+ for(int n = 0; n < size; ++n)
+ output16.push_back((input32[n] >> 16) & 0xFFFF);
+
+ return output16;
+}
+
}}
\ No newline at end of file