]> git.sesse.net Git - casparcg/blob - core/mixer/audio/audio_util.h
[executor] Execute remaining tasks at shutdown.
[casparcg] / core / mixer / audio / audio_util.h
1 /*
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
3 *
4 * This file is part of CasparCG (www.casparcg.com).
5 *
6 * CasparCG is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * CasparCG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * Author: Robert Nagy, ronag89@gmail.com
20 */
21
22 #pragma once
23
24 #include <algorithm>
25 #include <vector>
26 #include <cstdint>
27
28 #include <common/cache_aligned_vector.h>
29
30 namespace caspar { namespace core {
31         
32 template<typename T>
33 cache_aligned_vector<int8_t> audio_32_to_24(const T& audio_data)
34 {       
35         auto size               = std::distance(std::begin(audio_data), std::end(audio_data));
36         auto input8             = reinterpret_cast<const int8_t*>(&(*std::begin(audio_data)));
37         auto output8    = cache_aligned_vector<int8_t>();
38                         
39         output8.reserve(size*3);
40         for(int n = 0; n < size; ++n)
41         {
42                 output8.push_back(input8[n*4+1]);
43                 output8.push_back(input8[n*4+2]);
44                 output8.push_back(input8[n*4+3]);
45         }
46
47         return output8;
48 }
49
50 template<typename T>
51 cache_aligned_vector<int16_t> audio_32_to_16(const T& audio_data)
52 {       
53         auto size               = std::distance(std::begin(audio_data), std::end(audio_data));
54         auto input32    = &(*std::begin(audio_data));
55         auto output16   = cache_aligned_vector<int16_t> ();
56                         
57         output16.reserve(size);
58         for(int n = 0; n < size; ++n)
59                 output16.push_back((input32[n] >> 16) & 0xFFFF);
60
61         return output16;
62 }
63
64 }}