1 | //esdstream.c: |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2010 |
---|
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 | int esd_play_stream( esd_format_t format, int rate, |
---|
53 | const char *host, const char *name ) { |
---|
54 | int channels; |
---|
55 | int bits; |
---|
56 | int codec = ROAR_CODEC_DEFAULT; |
---|
57 | |
---|
58 | if ( (format & ESD_BITS16) ) { |
---|
59 | bits = 16; |
---|
60 | } else { |
---|
61 | bits = 8; |
---|
62 | codec = CODEC_DEF_8BIT; |
---|
63 | } |
---|
64 | |
---|
65 | if ( (format & ESD_MONO) ) { |
---|
66 | channels = 1; |
---|
67 | } else { |
---|
68 | channels = 2; |
---|
69 | } |
---|
70 | |
---|
71 | return roar_simple_play(rate, channels, bits, codec, (char*)host, (char*) name); |
---|
72 | } |
---|
73 | |
---|
74 | int esd_play_stream_fallback( esd_format_t format, int rate, |
---|
75 | const char *host, const char *name ) { |
---|
76 | int r; |
---|
77 | |
---|
78 | if ( (r = esd_play_stream(format, rate, host, name)) != -1 ) { |
---|
79 | return r; |
---|
80 | } |
---|
81 | |
---|
82 | return esd_play_stream(format, rate, "+fork", name); |
---|
83 | } |
---|
84 | |
---|
85 | |
---|
86 | |
---|
87 | int esd_monitor_stream( esd_format_t format, int rate, |
---|
88 | const char *host, const char *name ) { |
---|
89 | int channels; |
---|
90 | int bits; |
---|
91 | int codec = ROAR_CODEC_DEFAULT; |
---|
92 | |
---|
93 | ROAR_DBG("esd_monitor_stream(format=%x, rate=%i, host='%s', name='%s') = ?", format, rate, host, name); |
---|
94 | |
---|
95 | if ( (format & ESD_BITS16) ) { |
---|
96 | bits = 16; |
---|
97 | } else { |
---|
98 | bits = 8; |
---|
99 | codec = CODEC_DEF_8BIT; |
---|
100 | } |
---|
101 | |
---|
102 | if ( (format & ESD_MONO) ) { |
---|
103 | channels = 1; |
---|
104 | } else { |
---|
105 | channels = 2; |
---|
106 | } |
---|
107 | |
---|
108 | return roar_simple_monitor(rate, channels, bits, codec, (char*)host, (char*)name); |
---|
109 | } |
---|
110 | /* int esd_monitor_stream_fallback( esd_format_t format, int rate ); */ |
---|
111 | int esd_record_stream( esd_format_t format, int rate, |
---|
112 | const char *host, const char *name ) { |
---|
113 | int channels; |
---|
114 | int bits; |
---|
115 | int codec = ROAR_CODEC_DEFAULT; |
---|
116 | |
---|
117 | ROAR_DBG("esd_record_stream(format=%x, rate=%i, host='%s', name='%s') = ?", format, rate, host, name); |
---|
118 | |
---|
119 | if ( (format & ESD_BITS16) ) { |
---|
120 | bits = 16; |
---|
121 | } else { |
---|
122 | bits = 8; |
---|
123 | codec = CODEC_DEF_8BIT; |
---|
124 | } |
---|
125 | |
---|
126 | if ( (format & ESD_MONO) ) { |
---|
127 | channels = 1; |
---|
128 | } else { |
---|
129 | channels = 2; |
---|
130 | } |
---|
131 | |
---|
132 | return roar_simple_record(rate, channels, bits, codec, (char*)host, (char*)name); |
---|
133 | } |
---|
134 | int esd_record_stream_fallback( esd_format_t format, int rate, |
---|
135 | const char *host, const char *name ) { |
---|
136 | int r; |
---|
137 | |
---|
138 | if ( (r = esd_record_stream(format, rate, host, name)) != -1 ) { |
---|
139 | return r; |
---|
140 | } |
---|
141 | |
---|
142 | return esd_record_stream(format, rate, "+fork", name); |
---|
143 | } |
---|
144 | int esd_filter_stream( esd_format_t format, int rate, |
---|
145 | const char *host, const char *name ) { |
---|
146 | int channels; |
---|
147 | int bits; |
---|
148 | int codec = ROAR_CODEC_DEFAULT; |
---|
149 | |
---|
150 | if ( (format & ESD_BITS16) ) { |
---|
151 | bits = 16; |
---|
152 | } else { |
---|
153 | bits = 8; |
---|
154 | codec = CODEC_DEF_8BIT; |
---|
155 | } |
---|
156 | |
---|
157 | if ( (format & ESD_MONO) ) { |
---|
158 | channels = 1; |
---|
159 | } else { |
---|
160 | channels = 2; |
---|
161 | } |
---|
162 | |
---|
163 | return roar_simple_filter(rate, channels, bits, codec, (char*)host, (char*)name); |
---|
164 | } |
---|
165 | |
---|
166 | |
---|
167 | //ll |
---|