1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
/*
* $Id$
*
* ***** BEGIN LGPL LICENSE BLOCK *****
*
* Copyright 2009 Jörg Hermann Müller
*
* This file is part of AudaSpace.
*
* AudaSpace is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* AudaSpace 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with AudaSpace. If not, see <http://www.gnu.org/licenses/>.
*
* ***** END LGPL LICENSE BLOCK *****
*/
#include "AUD_ChannelMapperFactory.h"
#include "AUD_ChannelMapperReader.h"
#include <cstring>
AUD_ChannelMapperFactory::AUD_ChannelMapperFactory(AUD_IReader* reader,
AUD_DeviceSpecs specs) :
AUD_MixerFactory(reader, specs)
{
memset(m_mapping, 0, sizeof(m_mapping));
}
AUD_ChannelMapperFactory::AUD_ChannelMapperFactory(AUD_IFactory* factory,
AUD_DeviceSpecs specs) :
AUD_MixerFactory(factory, specs)
{
memset(m_mapping, 0, sizeof(m_mapping));
}
AUD_ChannelMapperFactory::AUD_ChannelMapperFactory(AUD_DeviceSpecs specs) :
AUD_MixerFactory(specs)
{
memset(m_mapping, 0, sizeof(m_mapping));
}
AUD_ChannelMapperFactory::~AUD_ChannelMapperFactory()
{
for(int i = 1; i < 10; i++)
deleteMapping(i);
}
float** AUD_ChannelMapperFactory::getMapping(int ic)
{
ic--;
if(ic > 8 || ic < 0)
return 0;
if(m_mapping[ic])
{
int channels = -1;
while(m_mapping[ic][++channels] != 0);
if(channels != m_specs.channels)
deleteMapping(ic+1);
}
if(!m_mapping[ic])
{
int channels = m_specs.channels;
m_mapping[ic] = new float*[channels+1]; AUD_NEW("mapping")
m_mapping[ic][channels] = 0;
for(int i = 0; i < channels; i++)
{
m_mapping[ic][i] = new float[ic+1]; AUD_NEW("mapping")
for(int j = 0; j <= ic; j++)
m_mapping[ic][i][j] = ((i == j) || (channels == 1) ||
(ic == 0)) ? 1.0f : 0.0f;
}
}
return m_mapping[ic];
}
void AUD_ChannelMapperFactory::deleteMapping(int ic)
{
ic--;
if(ic > 8 || ic < 0)
return;
if(m_mapping[ic])
{
for(int i = 0; 1; i++)
{
if(m_mapping[ic][i] != 0)
{
delete[] m_mapping[ic][i]; AUD_DELETE("mapping")
}
else
break;
}
delete[] m_mapping[ic]; AUD_DELETE("mapping")
m_mapping[ic] = 0;
}
}
AUD_IReader* AUD_ChannelMapperFactory::createReader()
{
AUD_IReader* reader = getReader();
if(reader != 0)
{
int ic = reader->getSpecs().channels;
reader = new AUD_ChannelMapperReader(reader, getMapping(ic));
AUD_NEW("reader")
}
return reader;
}
|