Skip to content

Commit 49d597e

Browse files
committed
Add libzita-resampler as a dependency and use it on ogg voice samples.
This doesn't fix the real problem with GH-72, but it does paper over it enough so that we can release.
1 parent 9350209 commit 49d597e

23 files changed

+1913
-2
lines changed

AUTHORS.TXT

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ luabind - http://www.rasterbar.com/products/luabind.html
3232
guichan - http://guichan.sourceforge.net/
3333
googletest - http://code.google.com/p/googletest/
3434
googlemock - http://code.google.com/p/googlemock/
35+
zita-resampler - http://kokkinizita.linuxaudio.org/linuxaudio/zita-resampler/resampler.
3536

3637
Libraries depended on (and are not included)
3738
-------------------------------------------------------------------------

COPYING.TXT

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ III) Libraries included unmodified in the rlvm distribution:
3333
g) Guichan
3434
h) SDL_image
3535
i) SDL_mixer
36+
j) zita-resampler
3637

3738
IV) Libraries linked against by rlvm (but not included in the distribution)
3839
a) boost.org license
@@ -450,6 +451,23 @@ You should have received a copy of the GNU Library General Public
450451
License along with this library; if not, write to the Free
451452
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
452453

454+
------------------------------------------------------- [ zita-resampler ]
455+
456+
Copyright (C) 2006-2011 Fons Adriaensen <[email protected]>
457+
458+
This program is free software; you can redistribute it and/or modify
459+
it under the terms of the GNU General Public License as published by
460+
the Free Software Foundation; either version 3 of the License, or
461+
(at your option) any later version.
462+
463+
This program is distributed in the hope that it will be useful,
464+
but WITHOUT ANY WARRANTY; without even the implied warranty of
465+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
466+
GNU General Public License for more details.
467+
468+
You should have received a copy of the GNU General Public License
469+
along with this program. If not, see <http://www.gnu.org/licenses/>.
470+
453471
-------------------------------------------------------------------------
454472
Part IV: Libraries linked against by rlvm
455473
-------------------------------------------------------------------------

SConscript

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,14 @@ libsystemsdl_files = [
212212
"src/systems/sdl/sdl_utils.cc",
213213
"src/systems/sdl/shaders.cc",
214214
"src/systems/sdl/texture.cc",
215+
216+
# Parts of zresample
217+
"src/systems/sdl/resample.cc",
218+
"src/systems/sdl/audiofile.cc",
219+
"src/systems/sdl/dither.cc",
220+
"src/systems/sdl/zresample.cc",
221+
222+
# Parts of pygame.
215223
"vendor/pygame/alphablit.cc"
216224
]
217225

SConstruct

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def CheckForSystemLibrary(config, library_dict, componentlist):
211211
lib_name = library_dict['library']
212212
print "(Using included version of %s)" % lib_name
213213
componentlist.append(lib_name)
214-
config.Define("HAVE_LIB" + lib_name, 1,
214+
config.Define("HAVE_LIB" + lib_name.replace("-", "_"), 1,
215215
"Define to 1 if you have the `%s' library." % lib_name)
216216

217217

@@ -233,6 +233,8 @@ VerifyLibrary(config, 'ogg', 'ogg/ogg.h')
233233
VerifyLibrary(config, 'vorbis', 'vorbis/codec.h')
234234
VerifyLibrary(config, 'vorbisfile', 'vorbis/vorbisfile.h')
235235

236+
VerifyLibrary(config, 'sndfile', 'sndfile.h')
237+
236238
# In short, we do this because the SCons configuration system doesn't give me
237239
# enough control over the test program. Even if the libraries are installed,
238240
# they won't compile because SCons outputs "int main()" instead of "int
@@ -246,6 +248,11 @@ else:
246248

247249
# Libraries we need, but will use a local copy if not installed.
248250
local_sdl_libraries = [
251+
{
252+
'include' : 'zita-resampler/resampler.h',
253+
'library' : 'zita-resampler',
254+
'function' : '',
255+
},
249256
{
250257
"include" : 'GL/glew.h',
251258
"library" : 'GLEW',

debian/control

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ Build-Depends: debhelper (>= 7.0.50~), libsdl1.2-dev, libfreetype6-dev,
99
libboost-serialization-dev, libboost-date-time-dev,
1010
libboost-iostreams-dev, libboost-program-options-dev,
1111
libboost-thread-dev, libguichan-dev,
12-
zlib1g-dev, libsdl-ttf2.0-dev, libgtk2.0-dev
12+
zlib1g-dev, libsdl-ttf2.0-dev, libgtk2.0-dev,
13+
libzita-resampler-dev
1314
Homepage: http://rlvm.net
1415

1516
Package: rlvm

src/systems/sdl/audiofile.cc

Lines changed: 270 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,270 @@
1+
// ----------------------------------------------------------------------------
2+
//
3+
// Copyright (C) 2006-2011 Fons Adriaensen <[email protected]>
4+
//
5+
// This program is free software; you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation; either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// This program is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
//
18+
// ----------------------------------------------------------------------------
19+
20+
21+
#include <stdlib.h>
22+
#include <string.h>
23+
#include "audiofile.h"
24+
25+
26+
Audiofile::Audiofile (void)
27+
{
28+
reset ();
29+
}
30+
31+
32+
Audiofile::~Audiofile (void)
33+
{
34+
close ();
35+
}
36+
37+
38+
void Audiofile::reset (void)
39+
{
40+
_sndfile = 0;
41+
_mode = MODE_NONE;
42+
_type = TYPE_OTHER;
43+
_form = FORM_OTHER;
44+
_rate = 0;
45+
_chan = 0;
46+
_size = 0;
47+
_dith_type = 0;
48+
_dith_proc = 0;
49+
_dith_buff = 0;
50+
}
51+
52+
53+
int Audiofile::open_read (const char *name)
54+
{
55+
SF_INFO I;
56+
57+
if (_mode) return ERR_MODE;
58+
reset ();
59+
60+
if ((_sndfile = sf_open (name, SFM_READ, &I)) == 0) return ERR_OPEN;
61+
62+
_mode = MODE_READ;
63+
64+
switch (I.format & SF_FORMAT_TYPEMASK)
65+
{
66+
case SF_FORMAT_CAF:
67+
_type = TYPE_CAF;
68+
break;
69+
case SF_FORMAT_WAV:
70+
_type = TYPE_WAV;
71+
break;
72+
case SF_FORMAT_WAVEX:
73+
if (sf_command (_sndfile, SFC_WAVEX_GET_AMBISONIC, 0, 0) == SF_AMBISONIC_B_FORMAT)
74+
_type = TYPE_AMB;
75+
else
76+
_type = TYPE_WAV;
77+
}
78+
79+
switch (I.format & SF_FORMAT_SUBMASK)
80+
{
81+
case SF_FORMAT_PCM_16:
82+
_form = FORM_16BIT;
83+
break;
84+
case SF_FORMAT_PCM_24:
85+
_form = FORM_24BIT;
86+
break;
87+
case SF_FORMAT_PCM_32:
88+
_form = FORM_32BIT;
89+
break;
90+
case SF_FORMAT_FLOAT:
91+
_form = FORM_FLOAT;
92+
break;
93+
}
94+
95+
_rate = I.samplerate;
96+
_chan = I.channels;
97+
_size = I.frames;
98+
99+
return 0;
100+
}
101+
102+
103+
int Audiofile::open_write (const char *name, int type, int form, int rate, int chan)
104+
{
105+
SF_INFO I;
106+
107+
if (_mode) return ERR_MODE;
108+
if (!rate || !chan) return ERR_OPEN;
109+
reset ();
110+
111+
switch (type)
112+
{
113+
case TYPE_CAF:
114+
I.format = SF_FORMAT_CAF;
115+
break;
116+
case TYPE_WAV:
117+
case TYPE_AMB:
118+
I.format = (chan > 2) ? SF_FORMAT_WAVEX : SF_FORMAT_WAV;
119+
break;
120+
default:
121+
return ERR_TYPE;
122+
}
123+
124+
switch (form)
125+
{
126+
case FORM_16BIT:
127+
I.format |= SF_FORMAT_PCM_16;
128+
break;
129+
case FORM_24BIT:
130+
I.format |= SF_FORMAT_PCM_24;
131+
break;
132+
case FORM_32BIT:
133+
I.format |= SF_FORMAT_PCM_32;
134+
break;
135+
case FORM_FLOAT:
136+
I.format |= SF_FORMAT_FLOAT;
137+
break;
138+
default:
139+
return ERR_FORM;
140+
}
141+
142+
I.samplerate = rate;
143+
I.channels = chan;
144+
I.sections = 1;
145+
146+
if ((_sndfile = sf_open (name, SFM_WRITE, &I)) == 0) return ERR_OPEN;
147+
148+
if (type == TYPE_AMB)
149+
{
150+
sf_command (_sndfile, SFC_WAVEX_SET_AMBISONIC, 0, SF_AMBISONIC_B_FORMAT);
151+
}
152+
153+
_mode = MODE_WRITE;
154+
_type = type;
155+
_form = form;
156+
_rate = rate;
157+
_chan = chan;
158+
159+
return 0;
160+
}
161+
162+
163+
int Audiofile::set_dither (int type)
164+
{
165+
if (_mode != MODE_WRITE) return ERR_MODE;
166+
if (_form != FORM_16BIT) return ERR_FORM;
167+
if (type != DITHER_NONE)
168+
{
169+
if (_dith_type == DITHER_NONE)
170+
{
171+
_dith_proc = new Dither [_chan];
172+
_dith_buff = new int16_t [_chan * BUFFSIZE];
173+
}
174+
}
175+
_dith_type = type;
176+
return 0;
177+
}
178+
179+
180+
int Audiofile::close (void)
181+
{
182+
if (_sndfile) sf_close (_sndfile);
183+
delete[] _dith_proc;
184+
delete[] _dith_buff;
185+
reset ();
186+
return 0;
187+
}
188+
189+
190+
int Audiofile::seek (uint32_t posit)
191+
{
192+
if (!_sndfile) return ERR_MODE;
193+
if (sf_seek (_sndfile, posit, SEEK_SET) != posit) return ERR_SEEK;
194+
return 0;
195+
}
196+
197+
198+
int Audiofile::read (float *data, uint32_t frames)
199+
{
200+
if (_mode != MODE_READ) return ERR_MODE;
201+
return sf_readf_float (_sndfile, data, frames);
202+
}
203+
204+
205+
int Audiofile::write (float *data, uint32_t frames)
206+
{
207+
int i;
208+
uint32_t k, n, r;
209+
float *p, v;
210+
int16_t *q;
211+
Dither *D;
212+
213+
if (_mode != MODE_WRITE) return ERR_MODE;
214+
if (_dith_type == DITHER_NONE)
215+
{
216+
if (_form != FORM_FLOAT)
217+
{
218+
for (i = 0; i < _chan; i++)
219+
{
220+
p = data + i;
221+
for (k = 0; k < frames; k++)
222+
{
223+
v = *p;
224+
if (v > 1.0f) v = 1.0f;
225+
else if (v < -1.0f) v = -1.0f;
226+
*p = v;
227+
p += _chan;
228+
}
229+
}
230+
}
231+
return sf_writef_float (_sndfile, data, frames);
232+
}
233+
else
234+
{
235+
n = 0;
236+
while (frames)
237+
{
238+
k = (frames > BUFFSIZE) ? BUFFSIZE : frames;
239+
p = data;
240+
q = _dith_buff;
241+
D = _dith_proc;
242+
for (i = 0; i < _chan; i++)
243+
{
244+
switch (_dith_type)
245+
{
246+
case DITHER_RECT:
247+
D->proc_rectangular (p, q, _chan, k);
248+
break;
249+
case DITHER_TRIA:
250+
D->proc_triangular (p, q, _chan, k);
251+
break;
252+
case DITHER_LIPS:
253+
D->proc_lipschitz (p, q, _chan, k);
254+
break;
255+
}
256+
p++;
257+
q++;
258+
D++;
259+
}
260+
r = sf_writef_short (_sndfile, _dith_buff, k);
261+
n += r;
262+
if (r != k) return n;
263+
data += k * _chan;
264+
frames -= k;
265+
}
266+
}
267+
return 0;
268+
}
269+
270+

0 commit comments

Comments
 (0)