/[pkgs]/devel/ClanLib06/ClanLib-0.6.5-alsa.patch
ViewVC logotype

Contents of /devel/ClanLib06/ClanLib-0.6.5-alsa.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations) (download) (as text)
Sun Mar 2 12:46:39 2008 UTC (20 months, 3 weeks ago) by jwrdegoede
Branch: MAIN
CVS Tags: F-12-split, ClanLib06-0_6_5-12_fc9, F-10-split, ClanLib06-0_6_5-13_fc10, ClanLib06-0_6_5-14_fc11, F-11-split, ClanLib06-0_6_5-15_fc12, F-9-split, HEAD
File MIME type: text/x-patch
* Sun Mar  2 2008 Hans de Goede <j.w.r.degoede@hhs.nl> 0.6.5-12
- Add support for audio output through alsa (original ClanLib only supports
  OSS??), this also adds support for using pulseaudio through alsa
1 diff -up /dev/null ClanLib-0.6.5/Sources/Sound/Sound/ClanSound/alsa.cpp
2 --- /dev/null 2008-03-02 13:00:58.162258534 +0100
3 +++ ClanLib-0.6.5/Sources/Sound/Sound/ClanSound/alsa.cpp 2008-03-02 13:32:17.000000000 +0100
4 @@ -0,0 +1,167 @@
5 +/*
6 +** ClanLib SDK
7 +** Copyright (c) 1997-2008 The ClanLib Team
8 +**
9 +** This software is provided 'as-is', without any express or implied
10 +** warranty. In no event will the authors be held liable for any damages
11 +** arising from the use of this software.
12 +**
13 +** Permission is granted to anyone to use this software for any purpose,
14 +** including commercial applications, and to alter it and redistribute it
15 +** freely, subject to the following restrictions:
16 +**
17 +** 1. The origin of this software must not be misrepresented; you must not
18 +** claim that you wrote the original software. If you use this software
19 +** in a product, an acknowledgment in the product documentation would be
20 +** appreciated but is not required.
21 +** 2. Altered source versions must be plainly marked as such, and must not be
22 +** misrepresented as being the original software.
23 +** 3. This notice may not be removed or altered from any source distribution.
24 +**
25 +** Note: Some of the libraries ClanLib may link to may have additional
26 +** requirements or restrictions.
27 +**
28 +** File Author(s):
29 +**
30 +** Magnus Norddahl
31 +** Hans de Goede
32 +** (if your name is missing here, please add it)
33 +*/
34 +
35 +#include "alsa.h"
36 +#include "API/Core/System/error.h"
37 +#include "API/Core/System/cl_assert.h"
38 +#include "API/Core/System/system.h"
39 +#include <iostream>
40 +
41 +#ifdef USE_CLANSOUND
42 +#ifdef __linux__
43 +
44 +/////////////////////////////////////////////////////////////////////////////
45 +// CL_SoundOutput_alsa construction:
46 +
47 +CL_SoundOutput_alsa::CL_SoundOutput_alsa() :
48 + frames_in_buffer(2048), frames_in_period(512)
49 +{
50 + int rc;
51 + snd_pcm_hw_params_t *hwparams;
52 + unsigned int mixing_frequency = 22050;
53 +
54 + rc = snd_pcm_open(&handle, "default", SND_PCM_STREAM_PLAYBACK, 0);
55 + if (rc < 0)
56 + {
57 + std::cout << "ClanSound: Warning, Couldn't open sound device, disabling sound\n";
58 + handle = NULL;
59 + return;
60 + }
61 +
62 + snd_pcm_hw_params_alloca(&hwparams);
63 + snd_pcm_hw_params_any(handle, hwparams);
64 + snd_pcm_hw_params_set_access(handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED);
65 + snd_pcm_hw_params_set_format(handle, hwparams, SND_PCM_FORMAT_S16);
66 + snd_pcm_hw_params_set_channels(handle, hwparams, 2);
67 + snd_pcm_hw_params_set_rate_near(handle, hwparams, &mixing_frequency, 0);
68 + snd_pcm_hw_params_set_buffer_size_near(handle, hwparams, &frames_in_buffer);
69 + frames_in_period = frames_in_buffer / 4;
70 + snd_pcm_hw_params_set_period_size_near(handle, hwparams, &frames_in_period, 0);
71 +
72 + rc = snd_pcm_hw_params(handle, hwparams);
73 + if (rc < 0)
74 + {
75 + std::cout << "ClanSound: Warning, Couldn't initialize sound device, disabling sound\n";
76 + snd_pcm_close(handle);
77 + handle = NULL;
78 + return;
79 + }
80 +
81 + snd_pcm_hw_params_get_period_size(hwparams, &frames_in_period, 0);
82 + snd_pcm_hw_params_get_rate(hwparams, &mixing_frequency, 0);
83 +
84 + float percent_wrong = mixing_frequency / (float) 22050;
85 + if (percent_wrong < 0.90 || percent_wrong > 1.10)
86 + {
87 + snd_pcm_close(handle);
88 + /* Taken from oss driver, maybe make this a warning too? */
89 + throw CL_Error("ClanSound: Mixing rate (22.05 kHz) not supported by soundcard.");
90 + }
91 +}
92 +
93 +CL_SoundOutput_alsa::~CL_SoundOutput_alsa()
94 +{
95 + if (handle) {
96 + snd_pcm_close(handle);
97 + handle = NULL;
98 + }
99 +}
100 +
101 +/////////////////////////////////////////////////////////////////////////////
102 +// CL_SoundOutput_alsa operations:
103 +
104 +void CL_SoundOutput_alsa::silence()
105 +{
106 + /* Note: not supported by all hardware! */
107 + if (handle)
108 + snd_pcm_pause(handle, 1);
109 +}
110 +
111 +bool CL_SoundOutput_alsa::is_full()
112 +{
113 + int rc;
114 + snd_pcm_sframes_t delay;
115 +
116 + if (handle == NULL) return false;
117 +
118 + rc = snd_pcm_delay(handle, &delay);
119 + if (rc < 0) {
120 + std::cout << "ClanSound: Warning, snd_pcm_delay() failed!?\n";
121 + return false;
122 + }
123 +
124 + /* See if there is more then one period free in the buffer */
125 + return delay > (snd_pcm_sframes_t)(frames_in_buffer - frames_in_period);
126 +}
127 +
128 +int CL_SoundOutput_alsa::get_frag_size()
129 +{
130 + return frames_in_period;
131 +}
132 +
133 +void CL_SoundOutput_alsa::write_fragment(short *data)
134 +{
135 + snd_pcm_sframes_t rc;
136 +
137 + if (handle == NULL) return;
138 +
139 + switch(snd_pcm_state(handle)) {
140 + case SND_PCM_STATE_XRUN:
141 + case SND_PCM_STATE_SUSPENDED:
142 + snd_pcm_prepare(handle);
143 + break;
144 + case SND_PCM_STATE_PAUSED:
145 + snd_pcm_pause(handle, 0);
146 + break;
147 + default:
148 + break;
149 + }
150 +
151 + rc = snd_pcm_writei(handle, data, frames_in_period);
152 + if (rc < 0)
153 + std::cout << "ClanSound: Warning, snd_pcm_writei() failed!\n";
154 +}
155 +
156 +void CL_SoundOutput_alsa::wait()
157 +{
158 + if(handle == NULL)
159 + {
160 + CL_System::sleep(100);
161 + return;
162 + }
163 + /* wait upto 1 second */
164 + snd_pcm_wait(handle, 1000);
165 +}
166 +
167 +/////////////////////////////////////////////////////////////////////////////
168 +// CL_SoundOutput_alsa implementation:
169 +
170 +#endif
171 +#endif
172 diff -up ClanLib-0.6.5/Sources/Sound/Sound/ClanSound/oss.h.alsa ClanLib-0.6.5/Sources/Sound/Sound/ClanSound/oss.h
173 --- ClanLib-0.6.5/Sources/Sound/Sound/ClanSound/oss.h.alsa 2001-09-08 21:24:21.000000000 +0200
174 +++ ClanLib-0.6.5/Sources/Sound/Sound/ClanSound/oss.h 2008-03-02 13:18:19.000000000 +0100
175 @@ -10,6 +10,8 @@
176 #ifndef header_oss
177 #define header_oss
178
179 +#include "alsa.h"
180 +
181 class CL_CSOutput
182 {
183 public:
184 @@ -35,6 +37,9 @@ public:
185 private:
186 int dev_dsp_fd;
187 int frag_size;
188 +#ifdef __linux__
189 + CL_SoundOutput_alsa *alsa;
190 +#endif
191 };
192
193 #endif
194 diff -up ClanLib-0.6.5/Sources/Sound/Sound/ClanSound/oss.cpp.alsa ClanLib-0.6.5/Sources/Sound/Sound/ClanSound/oss.cpp
195 --- ClanLib-0.6.5/Sources/Sound/Sound/ClanSound/oss.cpp.alsa 2002-07-02 22:56:33.000000000 +0200
196 +++ ClanLib-0.6.5/Sources/Sound/Sound/ClanSound/oss.cpp 2008-03-02 13:18:19.000000000 +0100
197 @@ -37,6 +37,14 @@ bool has_sound = true;
198
199 CL_CSOutput::CL_CSOutput()
200 {
201 +#ifdef __linux__
202 + alsa = new CL_SoundOutput_alsa();
203 + if (!alsa->handle) {
204 + delete alsa;
205 + alsa = NULL;
206 + } else
207 + return;
208 +#endif
209 dev_dsp_fd = open(DSP_DEVICE, O_WRONLY|O_NONBLOCK);
210 if (dev_dsp_fd == -1)
211 {
212 @@ -99,6 +107,13 @@ CL_CSOutput::CL_CSOutput()
213
214 CL_CSOutput::~CL_CSOutput()
215 {
216 +#ifdef __linux__
217 + if (alsa) {
218 + delete alsa;
219 + alsa = NULL;
220 + return;
221 + }
222 +#endif
223 if (dev_dsp_fd != -1) close(dev_dsp_fd);
224 }
225
226 @@ -106,12 +121,22 @@ void CL_CSOutput::silence()
227 // Called when we have no samples to play - and wants to tell the soundcard
228 // about this possible event.
229 {
230 +#ifdef __linux__
231 + if (alsa) {
232 + alsa->silence();
233 + return;
234 + }
235 +#endif
236 ioctl(dev_dsp_fd, SNDCTL_DSP_POST, 0);
237 }
238
239 bool CL_CSOutput::is_full()
240 // Returns true if all fragments are filled with data.
241 {
242 +#ifdef __linux__
243 + if (alsa)
244 + return alsa->is_full();
245 +#endif
246 if (!has_sound) return false;
247 audio_buf_info info;
248 int err = ioctl(dev_dsp_fd, SNDCTL_DSP_GETOSPACE, &info);
249 @@ -128,17 +153,33 @@ bool CL_CSOutput::is_full()
250 int CL_CSOutput::get_frag_size()
251 // Returns the buffer size used by device (returned as num [stereo] samples).
252 {
253 +#ifdef __linux__
254 + if (alsa)
255 + return alsa->get_frag_size();
256 +#endif
257 return frag_size/4;
258 }
259
260 void CL_CSOutput::write_fragment(short *data)
261 // Writes a fragment to the soundcard.
262 {
263 +#ifdef __linux__
264 + if (alsa) {
265 + alsa->write_fragment(data);
266 + return;
267 + }
268 +#endif
269 write(dev_dsp_fd, data, frag_size);
270 }
271
272 void CL_CSOutput::wait()
273 {
274 +#ifdef __linux__
275 + if (alsa) {
276 + alsa->wait();
277 + return;
278 + }
279 +#endif
280 if(!has_sound)
281 {
282 CL_System::sleep(100);
283 diff -up /dev/null ClanLib-0.6.5/Sources/Sound/Sound/ClanSound/alsa.h
284 --- /dev/null 2008-03-02 13:00:58.162258534 +0100
285 +++ ClanLib-0.6.5/Sources/Sound/Sound/ClanSound/alsa.h 2008-03-02 13:23:03.000000000 +0100
286 @@ -0,0 +1,75 @@
287 +/*
288 +** ClanLib SDK
289 +** Copyright (c) 1997-2008 The ClanLib Team
290 +**
291 +** This software is provided 'as-is', without any express or implied
292 +** warranty. In no event will the authors be held liable for any damages
293 +** arising from the use of this software.
294 +**
295 +** Permission is granted to anyone to use this software for any purpose,
296 +** including commercial applications, and to alter it and redistribute it
297 +** freely, subject to the following restrictions:
298 +**
299 +** 1. The origin of this software must not be misrepresented; you must not
300 +** claim that you wrote the original software. If you use this software
301 +** in a product, an acknowledgment in the product documentation would be
302 +** appreciated but is not required.
303 +** 2. Altered source versions must be plainly marked as such, and must not be
304 +** misrepresented as being the original software.
305 +** 3. This notice may not be removed or altered from any source distribution.
306 +**
307 +** Note: Some of the libraries ClanLib may link to may have additional
308 +** requirements or restrictions.
309 +**
310 +** File Author(s):
311 +**
312 +** Magnus Norddahl
313 +** Hans de Goede
314 +** (if your name is missing here, please add it)
315 +*/
316 +
317 +#ifndef header_soundoutput_alsa
318 +#define header_soundoutput_alsa
319 +
320 +#ifdef __linux__
321 +
322 +#include <alsa/asoundlib.h>
323 +
324 +class CL_SoundOutput_alsa
325 +{
326 +//! Construction:
327 +public:
328 + CL_SoundOutput_alsa();
329 +
330 + ~CL_SoundOutput_alsa();
331 +
332 +//! Attributes:
333 +public:
334 + snd_pcm_t *handle;
335 + snd_pcm_uframes_t frames_in_buffer;
336 + snd_pcm_uframes_t frames_in_period;
337 +
338 +//! Operations:
339 +public:
340 + //: Called when we have no samples to play - and wants to tell the soundcard
341 + //: about this possible event.
342 + void silence();
343 +
344 + //: Returns true if all fragments are filled with data.
345 + bool is_full();
346 +
347 + //: Returns the buffer size used by device (returned as num [stereo] samples).
348 + int get_frag_size();
349 +
350 + //: Writes a fragment to the soundcard.
351 + void write_fragment(short *data);
352 +
353 + //: Waits until output source isn't full anymore.
354 + void wait();
355 +
356 +//! Implementation:
357 +private:
358 +};
359 +
360 +#endif
361 +#endif
362 diff -up ClanLib-0.6.5/Setup/Unix/Makefile.sound.in.alsa ClanLib-0.6.5/Setup/Unix/Makefile.sound.in
363 --- ClanLib-0.6.5/Setup/Unix/Makefile.sound.in.alsa 2008-03-02 13:18:19.000000000 +0100
364 +++ ClanLib-0.6.5/Setup/Unix/Makefile.sound.in 2008-03-02 13:30:35.000000000 +0100
365 @@ -42,6 +42,7 @@ OBJF_SOUND_CLANSOUND = \
366 Libs/Intermediate/cardplayback_clan.o \
367 Libs/Intermediate/mixer.o \
368 Libs/Intermediate/oss.o \
369 + Libs/Intermediate/alsa.o \
370 Libs/Intermediate/cdaudio_linux.o
371
372 OBJF_SOUND_INTEL_ASM = \
373 @@ -51,8 +52,8 @@ OBJF_SOUND_ALL = $(OBJF_SOUND_GENERIC) $
374
375 Libs/libclanSound.so: Libs/libclanCore.so $(OBJF_SOUND_ALL)
376 @echo "Building Libs/libclanSound.so"
377 - @echo $(LINK_COMMAND) -Wl,-soname=libclanSound.so.$(D_VERSION_MAJOR) -o Libs/libclanSound.so.$(D_VERSION_MINOR) $(OBJF_SOUND_ALL) -L Libs -lclanCore
378 - @$(LINK_COMMAND) -Wl,-soname=libclanSound.so.$(D_VERSION_MAJOR) -o Libs/libclanSound.so.$(D_VERSION_MINOR) $(OBJF_SOUND_ALL) -L Libs -lclanCore
379 + @echo $(LINK_COMMAND) -Wl,-soname=libclanSound.so.$(D_VERSION_MAJOR) -o Libs/libclanSound.so.$(D_VERSION_MINOR) $(OBJF_SOUND_ALL) -L Libs -lclanCore -lasound
380 + @$(LINK_COMMAND) -Wl,-soname=libclanSound.so.$(D_VERSION_MAJOR) -o Libs/libclanSound.so.$(D_VERSION_MINOR) $(OBJF_SOUND_ALL) -L Libs -lclanCore -lasound
381 @ln -s -f libclanSound.so.$(D_VERSION_MINOR) Libs/libclanSound.so.$(D_VERSION_MAJOR)
382 @ln -s -f libclanSound.so.$(D_VERSION_MAJOR) Libs/libclanSound.so
383

admin@fedoraproject.org
ViewVC Help
Powered by ViewVC 1.1.2