[0] | 1 | //esdstream.c: |
---|
| 2 | |
---|
[705] | 3 | /* |
---|
[4708] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2011 |
---|
[705] | 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 |
---|
[3517] | 25 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 26 | * Boston, MA 02110-1301, USA. |
---|
[705] | 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 | |
---|
[0] | 40 | #include "libroaresd.h" |
---|
| 41 | |
---|
[628] | 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 | |
---|
[0] | 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 */ |
---|
[5226] | 52 | |
---|
| 53 | static int libroaresd_stream(esd_format_t format, int rate, const char *host, const char *name, int dir) { |
---|
[73] | 54 | int channels; |
---|
| 55 | int bits; |
---|
[627] | 56 | int codec = ROAR_CODEC_DEFAULT; |
---|
[5226] | 57 | struct roar_stream s; |
---|
[0] | 58 | |
---|
[631] | 59 | if ( (format & ESD_BITS16) ) { |
---|
| 60 | bits = 16; |
---|
| 61 | } else { |
---|
[628] | 62 | bits = 8; |
---|
| 63 | codec = CODEC_DEF_8BIT; |
---|
[0] | 64 | } |
---|
| 65 | |
---|
| 66 | if ( (format & ESD_MONO) ) { |
---|
| 67 | channels = 1; |
---|
| 68 | } else { |
---|
| 69 | channels = 2; |
---|
| 70 | } |
---|
| 71 | |
---|
[5226] | 72 | return roar_simple_stream_obj(&s, rate, channels, bits, codec, (char*)host, dir, (char*)name); |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | int esd_play_stream( esd_format_t format, int rate, |
---|
| 76 | const char *host, const char *name ) { |
---|
| 77 | return libroaresd_stream(format, rate, host, name, ROAR_DIR_PLAY); |
---|
[0] | 78 | } |
---|
| 79 | |
---|
| 80 | int esd_play_stream_fallback( esd_format_t format, int rate, |
---|
| 81 | const char *host, const char *name ) { |
---|
[73] | 82 | int r; |
---|
| 83 | |
---|
| 84 | if ( (r = esd_play_stream(format, rate, host, name)) != -1 ) { |
---|
| 85 | return r; |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | return esd_play_stream(format, rate, "+fork", name); |
---|
[0] | 89 | } |
---|
| 90 | |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | int esd_monitor_stream( esd_format_t format, int rate, |
---|
| 94 | const char *host, const char *name ) { |
---|
[5226] | 95 | return libroaresd_stream(format, rate, host, name, ROAR_DIR_MONITOR); |
---|
[0] | 96 | } |
---|
| 97 | /* int esd_monitor_stream_fallback( esd_format_t format, int rate ); */ |
---|
| 98 | int esd_record_stream( esd_format_t format, int rate, |
---|
[3649] | 99 | const char *host, const char *name ) { |
---|
[5226] | 100 | return libroaresd_stream(format, rate, host, name, ROAR_DIR_RECORD); |
---|
[3649] | 101 | } |
---|
[0] | 102 | int esd_record_stream_fallback( esd_format_t format, int rate, |
---|
[3649] | 103 | const char *host, const char *name ) { |
---|
| 104 | int r; |
---|
| 105 | |
---|
| 106 | if ( (r = esd_record_stream(format, rate, host, name)) != -1 ) { |
---|
| 107 | return r; |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | return esd_record_stream(format, rate, "+fork", name); |
---|
| 111 | } |
---|
[0] | 112 | int esd_filter_stream( esd_format_t format, int rate, |
---|
| 113 | const char *host, const char *name ) { |
---|
[5226] | 114 | return libroaresd_stream(format, rate, host, name, ROAR_DIR_FILTER); |
---|
[0] | 115 | } |
---|
| 116 | |
---|
| 117 | |
---|
| 118 | //ll |
---|