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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
|
commit b4697bcfd6567f704e01927fdaf77f3ab5b9112b
Author: Slávek Banko <slavek.banko@axis.cz>
Date: Thu Oct 15 04:46:45 2015 +0200
Rename completely from polyp to pulse
Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index 635db2e..838fb28 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -116,7 +116,7 @@ if( WITH_OSS_SINK )
endif( WITH_OSS_SINK )
-##### check polyp support #######################
+##### check pulse support #######################
if( WITH_PULSE_SINK )
diff --git a/PACKAGING b/PACKAGING
index da75139..8cbd9f1 100644
--- a/PACKAGING
+++ b/PACKAGING
@@ -7,9 +7,9 @@ Take especially note of the following:
- If you wish to install plugins in a non-standard place, you can change the
AKODE_SEARCHDIR definition in lib/pluginhandler.cpp.
- You SHOULD not install sinks for backends you don't use. Thus jack_sink
- should only be installed when jackd is available, polyp_sink only when
- the polypaudio server is used and alsa_sink only when using a Linux kernel
+ should only be installed when jackd is available, pulse_sink only when
+ the PulseAudio server is used and alsa_sink only when using a Linux kernel
with ALSA drivers.
When using direct aKode playback sinks will be autodetected by loading and
- probing plugins in this order: polyp, jack, alsa, oss
+ probing plugins in this order: pulse, jack, alsa, oss
diff --git a/akode/PACKAGING b/akode/PACKAGING
index da75139..8cbd9f1 100644
--- a/akode/PACKAGING
+++ b/akode/PACKAGING
@@ -7,9 +7,9 @@ Take especially note of the following:
- If you wish to install plugins in a non-standard place, you can change the
AKODE_SEARCHDIR definition in lib/pluginhandler.cpp.
- You SHOULD not install sinks for backends you don't use. Thus jack_sink
- should only be installed when jackd is available, polyp_sink only when
- the polypaudio server is used and alsa_sink only when using a Linux kernel
+ should only be installed when jackd is available, pulse_sink only when
+ the PulseAudio server is used and alsa_sink only when using a Linux kernel
with ALSA drivers.
When using direct aKode playback sinks will be autodetected by loading and
- probing plugins in this order: polyp, jack, alsa, oss
+ probing plugins in this order: pulse, jack, alsa, oss
diff --git a/akode/configure.in.in b/akode/configure.in.in
index 80338d5..80d0114 100644
--- a/akode/configure.in.in
+++ b/akode/configure.in.in
@@ -270,24 +270,24 @@ AC_SUBST(JACK_LIBADD)
AC_SUBST(JACK_LDFLAGS)
fi
-AC_ARG_WITH(polypaudio,AC_HELP_STRING([--with-polypaudio],[Enable Polypaudio server support @<:@default=check@:>@]),[polypaudio_test="$withval"],[polypaudio_test="yes"])
-
-if test "x$polypaudio_test" = "xyes" ; then
-AC_MSG_CHECKING(for Polypaudio 0.7 or later)
-if $PKG_CONFIG --atleast-version 0.7 polyplib-simple >/dev/null 2>&1 ; then
- POLYP_CFLAGS="`$PKG_CONFIG --cflags polyplib-simple`"
- POLYP_LIBADD="`$PKG_CONFIG --libs-only-l polyplib-simple`"
- POLYP_LDFLAGS="`$PKG_CONFIG --libs-only-L polyplib-simple`"
- have_polyp=yes
+AC_ARG_WITH(pulseaudio,AC_HELP_STRING([--with-pulseaudio],[Enable PulseAudio server support @<:@default=check@:>@]),[pulseaudio_test="$withval"],[pulseaudio_test="yes"])
+
+if test "x$pulseaudio_test" = "xyes" ; then
+AC_MSG_CHECKING(for pulseaudio 0.9.2 or later)
+if $PKG_CONFIG --atleast-version 0.9.2 libpulse-simple >/dev/null 2>&1 ; then
+ PULSE_CFLAGS="`$PKG_CONFIG --cflags libpulse-simple`"
+ PULSE_LIBADD="`$PKG_CONFIG --libs-only-l libpulse-simple`"
+ PULSE_LDFLAGS="`$PKG_CONFIG --libs-only-L libpulse-simple`"
+ have_pulse=yes
AC_MSG_RESULT(yes)
- AC_DEFINE(HAVE_LIBPOLYP, 1,
- [Define if you have polyplib (required if you want Polypaudio server support)])
+ AC_DEFINE(HAVE_LIBPULSE, 1,
+ [Define if you have libpulse (required if you want PulseAudio server support)])
else
AC_MSG_RESULT(not installed)
fi
-AC_SUBST(POLYP_CFLAGS)
-AC_SUBST(POLYP_LIBADD)
-AC_SUBST(POLYP_LDFLAGS)
+AC_SUBST(PULSE_CFLAGS)
+AC_SUBST(PULSE_LIBADD)
+AC_SUBST(PULSE_LDFLAGS)
fi
AC_ARG_WITH(ffmpeg,AC_HELP_STRING([--with-ffmpeg],[Enable experimental FFMPEG decoder support @<:@default=check@:>@]),[ffmpeg_test="$withval"],[ffmpeg_test="yes"])
@@ -482,7 +482,7 @@ AM_CONDITIONAL(include_alsa_sink, test x$have_alsa = xyes)
AM_CONDITIONAL(include_oss_sink, test x$have_oss = xyes)
AM_CONDITIONAL(include_sun_sink, test x$have_sun = xyes)
AM_CONDITIONAL(include_jack_sink, test x$have_jack = xyes)
-AM_CONDITIONAL(include_polyp_sink, test x$have_polyp = xyes)
+AM_CONDITIONAL(include_pulse_sink, test x$have_pulse = xyes)
AM_CONDITIONAL(include_ffmpeg_decoder, test x$have_ffmpeg = xyes)
AC_MSG_CHECKING(for compilable aKode)
diff --git a/akode/lib/auto_sink.cpp b/akode/lib/auto_sink.cpp
index bcc1250..bee17b1 100644
--- a/akode/lib/auto_sink.cpp
+++ b/akode/lib/auto_sink.cpp
@@ -65,8 +65,8 @@ AutoSink::~AutoSink()
bool AutoSink::open()
{
// Try Polypaudio
- if (getenv("POLYP_SERVER"))
- if (m_data->tryOpen("polyp")) return true;
+ if (getenv("PULSE_SERVER"))
+ if (m_data->tryOpen("pulse")) return true;
// Try Jack
if (m_data->tryOpen("jack")) return true;
// Try ALSA
diff --git a/akode/plugins/CMakeLists.txt b/akode/plugins/CMakeLists.txt
index 6e11f1a..89bcfd1 100644
--- a/akode/plugins/CMakeLists.txt
+++ b/akode/plugins/CMakeLists.txt
@@ -15,7 +15,7 @@
tde_conditional_add_subdirectory( WITH_ALSA_SINK alsa_sink )
tde_conditional_add_subdirectory( WITH_JACK_SINK jack_sink )
tde_conditional_add_subdirectory( WITH_OSS_SINK oss_sink )
-tde_conditional_add_subdirectory( WITH_PULSE_SINK polyp_sink )
+tde_conditional_add_subdirectory( WITH_PULSE_SINK pulse_sink )
tde_conditional_add_subdirectory( WITH_SUN_SINK sun_sink )
tde_conditional_add_subdirectory( WITH_FFMPEG_DECODER ffmpeg_decoder )
diff --git a/akode/plugins/Makefile.am b/akode/plugins/Makefile.am
index 74f27e5..4a13c85 100644
--- a/akode/plugins/Makefile.am
+++ b/akode/plugins/Makefile.am
@@ -32,12 +32,12 @@ if include_jack_sink
AKODE_JACK_SINK=jack_sink
endif
-if include_polyp_sink
-AKODE_POLYP_SINK=polyp_sink
+if include_pulse_sink
+AKODE_PULSE_SINK=pulse_sink
endif
SUBDIRS= $(AKODE_MPC_DECODER) $(AKODE_XIPH_DECODER) \
$(AKODE_MPEG_DECODER) $(AKODE_FFMPEG_DECODER) \
$(AKODE_ALSA_SINK) $(AKODE_OSS_SINK) $(AKODE_SUN_SINK) \
- $(AKODE_JACK_SINK) $(AKODE_POLYP_SINK) \
+ $(AKODE_JACK_SINK) $(AKODE_PULSE_SINK) \
$(AKODE_SRC_RESAMPLER)
diff --git a/akode/plugins/polyp_sink/CMakeLists.txt b/akode/plugins/polyp_sink/CMakeLists.txt
deleted file mode 100644
index 28a940e..0000000
--- a/akode/plugins/polyp_sink/CMakeLists.txt
+++ /dev/null
@@ -1,32 +0,0 @@
-#################################################
-#
-# (C) 2015 Slávek Banko
-# slavek (DOT) banko (AT) axis.cz
-#
-# Improvements and feedback are welcome
-#
-# This file is released under GPL >= 2
-#
-#################################################
-
-include_directories(
- ${CMAKE_BINARY_DIR}
- ${CMAKE_BINARY_DIR}/akode/lib
- ${CMAKE_SOURCE_DIR}/akode/lib
- ${CMAKE_CURRENT_BINARY_DIR}
- ${CMAKE_CURRENT_SOURCE_DIR}
- ${PULSE_INCLUDE_DIRS}
-)
-
-
-##### library ###################################
-
-set( target libakode_polyp_sink )
-
-tde_add_library(
- ${target} MODULE
- SOURCES polyp_sink.cpp
- LINK akode-shared ${PULSE_LIBRARIES}
- DESTINATION ${LIB_INSTALL_DIR}
-)
-
diff --git a/akode/plugins/polyp_sink/Makefile.am b/akode/plugins/polyp_sink/Makefile.am
deleted file mode 100644
index a58b04c..0000000
--- a/akode/plugins/polyp_sink/Makefile.am
+++ /dev/null
@@ -1,7 +0,0 @@
-INCLUDES = -I$(top_srcdir)/akode/lib -I$(top_builddir)/akode/lib $(PULSE_CFLAGS) $(all_includes)
-
-lib_LTLIBRARIES = libakode_polyp_sink.la
-
-libakode_polyp_sink_la_SOURCES = polyp_sink.cpp
-libakode_polyp_sink_la_LDFLAGS = -module -avoid-version -no-undefined $(PULSE_LDFLAGS)
-libakode_polyp_sink_la_LIBADD = ../../lib/libakode.la $(PULSE_LIBADD)
diff --git a/akode/plugins/polyp_sink/polyp_sink.cpp b/akode/plugins/polyp_sink/polyp_sink.cpp
deleted file mode 100644
index b48b63e..0000000
--- a/akode/plugins/polyp_sink/polyp_sink.cpp
+++ /dev/null
@@ -1,143 +0,0 @@
-/* aKode: Polyp-Sink
-
- Copyright (C) 2004 Allan Sandfeld Jensen <kde@carewolf.com>
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public
- License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
-
- This library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public License
- along with this library; see the file COPYING.LIB. If not, write to
- the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
- Boston, MA 02110-1301, USA.
-*/
-
-#include "config.h"
-
-#ifdef HAVE_STDINT_H
-#include <stdint.h>
-#elif defined(HAVE_INTTYPES_H)
-#include <inttypes.h>
-#endif
-#include <pulse/simple.h>
-
-#include "audioframe.h"
-#include "audiobuffer.h"
-#include "polyp_sink.h"
-
-#include <iostream>
-
-namespace aKode {
-
-extern "C" { PolypSinkPlugin polyp_sink; };
-
-struct PolypSink::private_data
-{
- private_data() : server(0), error(false) {};
-
- pa_simple *server;
- pa_sample_spec sample_spec;
-
- bool error;
-
- AudioConfiguration config;
-};
-
-PolypSink::PolypSink()
-{
- m_data = new private_data;
- m_data->sample_spec.rate = 44100;
- m_data->sample_spec.channels = 2;
- m_data->sample_spec.format = PA_SAMPLE_S16NE;
-}
-
-bool PolypSink::open() {
- int error = 0;
- m_data->server = pa_simple_new(0, "akode-client", PA_STREAM_PLAYBACK, 0, "", &m_data->sample_spec, 0, 0, &error );
- if (!m_data->server || error != 0) {
- m_data->error = true;
- close();
- std::cout << "Cannot open client\n";
- return false;
- }
-
-
- return true;
-}
-
-void PolypSink::close() {
- if (m_data->server) {
- pa_simple_free(m_data->server);
- m_data->server = 0;
- }
-}
-
-PolypSink::~PolypSink()
-{
- close();
- delete m_data;
-}
-
-int PolypSink::setAudioConfiguration(const AudioConfiguration* config)
-{
- if (m_data->error) return -1;
-
- int res = 0;
- if (*config == m_data->config) return 0;
- m_data->config = *config;
-
- if (config->channel_config != MonoStereo ) return -1;
- m_data->sample_spec.channels = config->channels;
-
- if (config->sample_width != 16) {
- res = 1;
- m_data->config.sample_width = 16;
- }
-
- m_data->sample_spec.rate = config->sample_rate;
-
- // create new connection
- close();
- open();
-
- return res;
-}
-
-const AudioConfiguration* PolypSink::audioConfiguration() const
-{
- return &m_data->config;
-}
-
-bool PolypSink::writeFrame(AudioFrame* frame)
-{
- if ( m_data->error ) return false;
-
- if ( frame->channels != m_data->config.channels || frame->sample_rate != m_data->config.sample_rate)
- {
- if (setAudioConfiguration(frame)!=0)
- return false;
- }
-
- int channels = m_data->config.channels;
- int length = frame->length;
-
- int16_t *buffer = new int16_t[length*channels];
- int16_t** data = (int16_t**)frame->data;
- for(int i = 0; i<length; i++)
- for(int j=0; j<channels; j++)
- buffer[i*channels+j] = data[j][i];
-
- int error = 0;
- pa_simple_write(m_data->server, buffer, channels*length*2, &error);
- delete[] buffer;
-
- return (error == 0);
-}
-
-} // namespace
diff --git a/akode/plugins/polyp_sink/polyp_sink.h b/akode/plugins/polyp_sink/polyp_sink.h
deleted file mode 100644
index e279ff6..0000000
--- a/akode/plugins/polyp_sink/polyp_sink.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/* aKode: Polyp-Sink
-
- Copyright (C) 2004 Allan Sandfeld Jensen <kde@carewolf.com>
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public
- License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
-
- This library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public License
- along with this library; see the file COPYING.LIB. If not, write to
- the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
- Boston, MA 02110-1301, USA.
-*/
-
-#ifndef _AKODE_POLYP_SINK_H
-#define _AKODE_POLYP_SINK_H
-
-#include "sink.h"
-
-#include "akode_export.h"
-
-namespace aKode {
-
-class AudioConfiguration;
-class AudioFrame;
-
-class PolypSink : public Sink {
-public:
- PolypSink();
- ~PolypSink();
- bool open();
- void close();
- int setAudioConfiguration(const AudioConfiguration *config);
- const AudioConfiguration* audioConfiguration() const;
- // Writes blocking
- bool writeFrame(AudioFrame *frame);
-
- struct private_data;
-private:
- private_data *m_data;
-};
-
-class PolypSinkPlugin : public SinkPlugin {
-public:
- virtual PolypSink* openSink() {
- return new PolypSink();
- }
-};
-
-extern "C" AKODE_EXPORT PolypSinkPlugin polyp_sink;
-
-} // namespace
-
-#endif
diff --git a/akode/plugins/pulse_sink/CMakeLists.txt b/akode/plugins/pulse_sink/CMakeLists.txt
new file mode 100644
index 0000000..04026d3
--- /dev/null
+++ b/akode/plugins/pulse_sink/CMakeLists.txt
@@ -0,0 +1,32 @@
+#################################################
+#
+# (C) 2015 Slávek Banko
+# slavek (DOT) banko (AT) axis.cz
+#
+# Improvements and feedback are welcome
+#
+# This file is released under GPL >= 2
+#
+#################################################
+
+include_directories(
+ ${CMAKE_BINARY_DIR}
+ ${CMAKE_BINARY_DIR}/akode/lib
+ ${CMAKE_SOURCE_DIR}/akode/lib
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${PULSE_INCLUDE_DIRS}
+)
+
+
+##### library ###################################
+
+set( target libakode_pulse_sink )
+
+tde_add_library(
+ ${target} MODULE
+ SOURCES pulse_sink.cpp
+ LINK akode-shared ${PULSE_LIBRARIES}
+ DESTINATION ${LIB_INSTALL_DIR}
+)
+
diff --git a/akode/plugins/pulse_sink/Makefile.am b/akode/plugins/pulse_sink/Makefile.am
new file mode 100644
index 0000000..9f38245
--- /dev/null
+++ b/akode/plugins/pulse_sink/Makefile.am
@@ -0,0 +1,7 @@
+INCLUDES = -I$(top_srcdir)/akode/lib -I$(top_builddir)/akode/lib $(PULSE_CFLAGS) $(all_includes)
+
+lib_LTLIBRARIES = libakode_pulse_sink.la
+
+libakode_pulse_sink_la_SOURCES = pulse_sink.cpp
+libakode_pulse_sink_la_LDFLAGS = -module -avoid-version -no-undefined $(PULSE_LDFLAGS)
+libakode_pulse_sink_la_LIBADD = ../../lib/libakode.la $(PULSE_LIBADD)
diff --git a/akode/plugins/pulse_sink/pulse_sink.cpp b/akode/plugins/pulse_sink/pulse_sink.cpp
new file mode 100644
index 0000000..395bfb3
--- /dev/null
+++ b/akode/plugins/pulse_sink/pulse_sink.cpp
@@ -0,0 +1,143 @@
+/* aKode: Pulse-Sink
+
+ Copyright (C) 2004 Allan Sandfeld Jensen <kde@carewolf.com>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "config.h"
+
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#elif defined(HAVE_INTTYPES_H)
+#include <inttypes.h>
+#endif
+#include <pulse/simple.h>
+
+#include "audioframe.h"
+#include "audiobuffer.h"
+#include "pulse_sink.h"
+
+#include <iostream>
+
+namespace aKode {
+
+extern "C" { PulseSinkPlugin pulse_sink; };
+
+struct PulseSink::private_data
+{
+ private_data() : server(0), error(false) {};
+
+ pa_simple *server;
+ pa_sample_spec sample_spec;
+
+ bool error;
+
+ AudioConfiguration config;
+};
+
+PulseSink::PulseSink()
+{
+ m_data = new private_data;
+ m_data->sample_spec.rate = 44100;
+ m_data->sample_spec.channels = 2;
+ m_data->sample_spec.format = PA_SAMPLE_S16NE;
+}
+
+bool PulseSink::open() {
+ int error = 0;
+ m_data->server = pa_simple_new(0, "akode-client", PA_STREAM_PLAYBACK, 0, "", &m_data->sample_spec, 0, 0, &error );
+ if (!m_data->server || error != 0) {
+ m_data->error = true;
+ close();
+ std::cout << "Cannot open client\n";
+ return false;
+ }
+
+
+ return true;
+}
+
+void PulseSink::close() {
+ if (m_data->server) {
+ pa_simple_free(m_data->server);
+ m_data->server = 0;
+ }
+}
+
+PulseSink::~PulseSink()
+{
+ close();
+ delete m_data;
+}
+
+int PulseSink::setAudioConfiguration(const AudioConfiguration* config)
+{
+ if (m_data->error) return -1;
+
+ int res = 0;
+ if (*config == m_data->config) return 0;
+ m_data->config = *config;
+
+ if (config->channel_config != MonoStereo ) return -1;
+ m_data->sample_spec.channels = config->channels;
+
+ if (config->sample_width != 16) {
+ res = 1;
+ m_data->config.sample_width = 16;
+ }
+
+ m_data->sample_spec.rate = config->sample_rate;
+
+ // create new connection
+ close();
+ open();
+
+ return res;
+}
+
+const AudioConfiguration* PulseSink::audioConfiguration() const
+{
+ return &m_data->config;
+}
+
+bool PulseSink::writeFrame(AudioFrame* frame)
+{
+ if ( m_data->error ) return false;
+
+ if ( frame->channels != m_data->config.channels || frame->sample_rate != m_data->config.sample_rate)
+ {
+ if (setAudioConfiguration(frame)!=0)
+ return false;
+ }
+
+ int channels = m_data->config.channels;
+ int length = frame->length;
+
+ int16_t *buffer = new int16_t[length*channels];
+ int16_t** data = (int16_t**)frame->data;
+ for(int i = 0; i<length; i++)
+ for(int j=0; j<channels; j++)
+ buffer[i*channels+j] = data[j][i];
+
+ int error = 0;
+ pa_simple_write(m_data->server, buffer, channels*length*2, &error);
+ delete[] buffer;
+
+ return (error == 0);
+}
+
+} // namespace
diff --git a/akode/plugins/pulse_sink/pulse_sink.h b/akode/plugins/pulse_sink/pulse_sink.h
new file mode 100644
index 0000000..e890e4a
--- /dev/null
+++ b/akode/plugins/pulse_sink/pulse_sink.h
@@ -0,0 +1,60 @@
+/* aKode: Pulse-Sink
+
+ Copyright (C) 2004 Allan Sandfeld Jensen <kde@carewolf.com>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef _AKODE_PULSE_SINK_H
+#define _AKODE_PULSE_SINK_H
+
+#include "sink.h"
+
+#include "akode_export.h"
+
+namespace aKode {
+
+class AudioConfiguration;
+class AudioFrame;
+
+class PulseSink : public Sink {
+public:
+ PulseSink();
+ ~PulseSink();
+ bool open();
+ void close();
+ int setAudioConfiguration(const AudioConfiguration *config);
+ const AudioConfiguration* audioConfiguration() const;
+ // Writes blocking
+ bool writeFrame(AudioFrame *frame);
+
+ struct private_data;
+private:
+ private_data *m_data;
+};
+
+class PulseSinkPlugin : public SinkPlugin {
+public:
+ virtual PulseSink* openSink() {
+ return new PulseSink();
+ }
+};
+
+extern "C" AKODE_EXPORT PulseSinkPlugin pulse_sink;
+
+} // namespace
+
+#endif
|