File: dsp.c

package info (click to toggle)
muroard 0.1.14-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 420 kB
  • ctags: 424
  • sloc: ansic: 3,645; sh: 505; makefile: 113
file content (224 lines) | stat: -rw-r--r-- 4,913 bytes parent folder | download | duplicates (3)
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
//dsp.c:

/*
 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2013
 *
 *  This file is part of �RoarD,
 *  a sound server daemon for using the RoarAudio protocol.
 *  See README for details.
 *
 *  This file is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 3
 *  or (at your option) any later version as published by
 *  the Free Software Foundation.
 *
 *  RoarAudio 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 this software; see the file COPYING.  If not, write to
 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301, USA.
 *
 */

#include "muroard.h"

int muroard_dsp_mixer(int16_t * out, int16_t ** in, size_t num) {
 size_t i;
 size_t n;
 register int32_t s;

 switch (num) {
#ifdef MUROARD_FEATURE_OPTIMIZE
  case 0:
    muroard_memzero(out, muroard_state_member(abuffer_size));
   break;
/* This case can not happen as the waveform code will use zero-copy.
  case 1:
    memcpy(out, in[0], muroard_state_member(abuffer_size));
   break;
*/
  case 2:
    for (i  = 0; i < muroard_state_member(abuffer_size)/2; i++) {
     s      = 0;
     s     += in[0][i];
     s     += in[1][i];
     out[i] = s;
    }
   break;
  case 3:
    for (i  = 0; i < muroard_state_member(abuffer_size)/2; i++) {
     s      = 0;
     s     += in[0][i];
     s     += in[1][i];
     s     += in[2][i];
     out[i] = s;
    }
   break;
#endif
  default:
    for (i  = 0; i < muroard_state_member(abuffer_size)/2; i++) {
     s      = 0;
     for (n = 0; n < num; n++)
      s    += in[n][i];
     out[i] = s;
    }
   break;
 }

 return 0;
}

#ifdef MUROARD_FEATURE_UPMIX
void muroard_dsp_upmix(void * data, size_t samples) {
 int16_t * ds = data;
 int16_t * dd = data;
 ssize_t   i, c;
 register int32_t s;

 samples--;

#ifdef MUROARD_FEATURE_OPTIMIZE
 switch (muroard_state_member(sa_channels)) {
  case 1:
    return;
   break;
  case 2:
    for (i = samples*2 /* stereo */; i >= 0; i -= 2) {
     s = ds[i/2];
     dd[i+0] = s;
     dd[i+1] = s;
    }
   break;
  case 3:
    for (i = samples*3 /* 3 channel */; i >= 0; i -= 3) {
     s = ds[i/3];
     dd[i+0] = s;
     dd[i+1] = s;
     dd[i+2] = s;
    }
   break;
  case 4:
    for (i = samples*4 /* quad */; i >= 0; i -= 4) {
     s = ds[i/4];
     dd[i+0] = s;
     dd[i+1] = s;
     dd[i+2] = s;
     dd[i+3] = s;
    }
   break;
  default:
#endif
    for (i = samples; i >= 0; i--) {
     s = ds[i];
     for (c = 0; c < muroard_state_member(sa_channels); c++) {
      dd[i*muroard_state_member(sa_channels)+c] = s;
     }
    }
#ifdef MUROARD_FEATURE_OPTIMIZE
   break;
 }
#endif
}
#endif
#ifdef MUROARD_FEATURE_DOWNMIX
void muroard_dsp_downmix(void * data, size_t samples) {
 int16_t * ds = data;
 int16_t * dd = data;
 ssize_t   c;
 size_t    i;
 register int32_t s;

#ifdef MUROARD_FEATURE_OPTIMIZE
 switch (muroard_state_member(sa_channels)) {
  case 1:
    return;
   break;
  case 2:
    for (i = 0; i < samples*2; i += 2) {
     s  = ds[i + 0];
     s += ds[i + 1];
     dd[i/2] = s / 2;
    }
   break;
  case 3:
    for (i = 0; i < samples*3; i += 3) {
     s  = ds[i + 0];
     s += ds[i + 1];
     s += ds[i + 2];
     dd[i/3] = s / 3;
    }
   break;
  case 4:
    for (i = 0; i < samples*4; i += 4) {
     s  = ds[i + 0];
     s += ds[i + 1];
     s += ds[i + 2];
     s += ds[i + 3];
     dd[i/4] = s / 4;
    }
   break;
  default:
#endif
    for (i = 0; i < samples; i++) {
     s = 0;
     for (c = 0; c < muroard_state_member(sa_channels); c++) {
      s += ds[i*muroard_state_member(sa_channels) + c];
     }
     dd[i] = s / muroard_state_member(sa_channels);
    }
#ifdef MUROARD_FEATURE_OPTIMIZE
 }
#endif
}
#endif
#ifdef MUROARD_FEATURE_UPSCALE
void muroard_dsp_upscale(void * data, size_t samples) {
 char    * ds = data;
 int16_t * dd = data;
 ssize_t    i;

 samples--;

 for (i = samples; i >= 0; i--)
  dd[i] = ds[i] << 8;
}
#endif
#ifdef MUROARD_FEATURE_DOWNSCALE
void muroard_dsp_downscale(void * data, size_t samples) {
 int16_t * ds = data;
 char    * dd = data;
 size_t    i;

 for (i = 0; i < samples; i++)
  dd[i] = ds[i] >> 8;
}
#endif

#ifdef MUROARD_FEATURE_BYTE_SWAP
void muroard_dsp_swap16(int16_t * data, size_t samples) {
 register size_t i;

 for (i = 0; i < samples; i++) {
  data[i] = ((data[i] << 8) & 0xFF00) | ((data[i] >> 8) & 0x00FF);
 }
}
#endif

#ifdef MUROARD_FEATURE_VOLUME_CONTROL
void muroard_dsp_volume(int16_t * data, size_t samples, uint16_t volume) {
 register int_least32_t s;
 register size_t i;

 for (i = 0; i < samples; i++) {
  s  = data[i] * volume;
  s /= 65535;
  data[i] = s;
 }
}
#endif

//ll