1 | //esdstream.c: |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2011 |
---|
5 | * The code (may) include prototypes and comments (and maybe |
---|
6 | * other code fragements) from EsounD. |
---|
7 | * They are mostly copyrighted by Eric B. Mitchell (aka 'Ricdude) |
---|
8 | * <ericmit@ix.netcom.com>. For more information see AUTHORS.esd. |
---|
9 | * |
---|
10 | * This file is part of libroaresd a part of RoarAudio, |
---|
11 | * a cross-platform sound system for both, home and professional use. |
---|
12 | * See README for details. |
---|
13 | * |
---|
14 | * This file is free software; you can redistribute it and/or modify |
---|
15 | * it under the terms of the GNU General Public License version 3 |
---|
16 | * as published by the Free Software Foundation. |
---|
17 | * |
---|
18 | * RoarAudio is distributed in the hope that it will be useful, |
---|
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
21 | * GNU General Public License for more details. |
---|
22 | * |
---|
23 | * You should have received a copy of the GNU General Public License |
---|
24 | * along with this software; see the file COPYING. If not, write to |
---|
25 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
26 | * Boston, MA 02110-1301, USA. |
---|
27 | * |
---|
28 | * NOTE for everyone want's to change something and send patches: |
---|
29 | * read README and HACKING! There a addition information on |
---|
30 | * the license of this document you need to read before you send |
---|
31 | * any patches. |
---|
32 | * |
---|
33 | * NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc |
---|
34 | * or libpulse*: |
---|
35 | * The libs libroaresd, libroararts and libroarpulse link this libroar |
---|
36 | * and are therefore GPL. Because of this it may be illigal to use |
---|
37 | * them with any software that uses libesd, libartsc or libpulse*. |
---|
38 | */ |
---|
39 | |
---|
40 | #include "libroaresd.h" |
---|
41 | |
---|
42 | #if BYTE_ORDER == BIG_ENDIAN |
---|
43 | #define CODEC_DEF_8BIT ROAR_CODEC_PCM_U_BE |
---|
44 | #elif BYTE_ORDER == LITTLE_ENDIAN |
---|
45 | #define CODEC_DEF_8BIT ROAR_CODEC_PCM_U_LE |
---|
46 | #else |
---|
47 | #define CODEC_DEF_8BIT ROAR_CODEC_PCM_U_PDP |
---|
48 | #endif |
---|
49 | |
---|
50 | /* open a socket for playing, monitoring, or recording as a stream */ |
---|
51 | /* the *_fallback functions try to open /dev/dsp if there's no EsounD */ |
---|
52 | |
---|
53 | static int libroaresd_stream(esd_format_t format, int rate, const char *host, const char *name, int dir) { |
---|
54 | struct roar_vio_calls calls; |
---|
55 | int channels; |
---|
56 | int bits; |
---|
57 | int codec = ROAR_CODEC_DEFAULT; |
---|
58 | int fh; |
---|
59 | int ret = -1; |
---|
60 | |
---|
61 | if ( (format & ESD_BITS16) ) { |
---|
62 | bits = 16; |
---|
63 | } else { |
---|
64 | bits = 8; |
---|
65 | codec = CODEC_DEF_8BIT; |
---|
66 | } |
---|
67 | |
---|
68 | if ( (format & ESD_MONO) ) { |
---|
69 | channels = 1; |
---|
70 | } else { |
---|
71 | channels = 2; |
---|
72 | } |
---|
73 | |
---|
74 | if ( roar_vio_simple_stream(&calls, rate, channels, bits, codec, host, dir, name, -1) == -1 ) |
---|
75 | return -1; |
---|
76 | |
---|
77 | if ( roar_vio_ctl(&calls, ROAR_VIO_CTL_GET_FH, &fh) != -1 ) |
---|
78 | if ( fh != -1 ) |
---|
79 | ret = dup(fh); |
---|
80 | |
---|
81 | roar_vio_close(&calls); |
---|
82 | |
---|
83 | return ret; |
---|
84 | } |
---|
85 | |
---|
86 | int esd_play_stream( esd_format_t format, int rate, |
---|
87 | const char *host, const char *name ) { |
---|
88 | return libroaresd_stream(format, rate, host, name, ROAR_DIR_PLAY); |
---|
89 | } |
---|
90 | |
---|
91 | int esd_play_stream_fallback( esd_format_t format, int rate, |
---|
92 | const char *host, const char *name ) { |
---|
93 | int r; |
---|
94 | |
---|
95 | if ( (r = esd_play_stream(format, rate, host, name)) != -1 ) { |
---|
96 | return r; |
---|
97 | } |
---|
98 | |
---|
99 | return esd_play_stream(format, rate, "+fork", name); |
---|
100 | } |
---|
101 | |
---|
102 | |
---|
103 | |
---|
104 | int esd_monitor_stream( esd_format_t format, int rate, |
---|
105 | const char *host, const char *name ) { |
---|
106 | return libroaresd_stream(format, rate, host, name, ROAR_DIR_MONITOR); |
---|
107 | } |
---|
108 | /* int esd_monitor_stream_fallback( esd_format_t format, int rate ); */ |
---|
109 | int esd_record_stream( esd_format_t format, int rate, |
---|
110 | const char *host, const char *name ) { |
---|
111 | return libroaresd_stream(format, rate, host, name, ROAR_DIR_RECORD); |
---|
112 | } |
---|
113 | int esd_record_stream_fallback( esd_format_t format, int rate, |
---|
114 | const char *host, const char *name ) { |
---|
115 | int r; |
---|
116 | |
---|
117 | if ( (r = esd_record_stream(format, rate, host, name)) != -1 ) { |
---|
118 | return r; |
---|
119 | } |
---|
120 | |
---|
121 | return esd_record_stream(format, rate, "+fork", name); |
---|
122 | } |
---|
123 | int esd_filter_stream( esd_format_t format, int rate, |
---|
124 | const char *host, const char *name ) { |
---|
125 | return libroaresd_stream(format, rate, host, name, ROAR_DIR_FILTER); |
---|
126 | } |
---|
127 | |
---|
128 | |
---|
129 | //ll |
---|