[0] | 1 | //esdbasic.c: |
---|
| 2 | |
---|
[705] | 3 | /* |
---|
[3811] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2010 |
---|
[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 | |
---|
| 42 | /* opens channel, authenticates connection, and prefares for protos */ |
---|
| 43 | /* returns EsounD socket for communication, result < 0 = error */ |
---|
| 44 | /* server = listen socket (localhost:5001, 192.168.168.0:9999 */ |
---|
| 45 | /* rate, format = (bits | channels | stream | func) */ |
---|
| 46 | int esd_open_sound( const char *host ) { |
---|
| 47 | struct roar_connection con; |
---|
[1660] | 48 | int fh; |
---|
[0] | 49 | |
---|
[3241] | 50 | if ( host == NULL ) |
---|
| 51 | host = getenv("ESPEAKER"); |
---|
| 52 | |
---|
[73] | 53 | if ( roar_simple_connect(&con, (char*) host, NULL) == -1 ) { |
---|
[0] | 54 | ROAR_DBG("esd_open_sound(*): roar_simple_connect() faild!"); |
---|
| 55 | return -1; |
---|
| 56 | } |
---|
| 57 | |
---|
[1660] | 58 | if ( (fh = roar_get_connection_fh(&con)) == -1 ) { |
---|
| 59 | roar_disconnect(&con); |
---|
| 60 | return -1; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | return fh; |
---|
[0] | 64 | } |
---|
| 65 | |
---|
| 66 | /* send the authorization cookie, create one if needed */ |
---|
[73] | 67 | int esd_send_auth( int sock ) { |
---|
| 68 | return 0; |
---|
| 69 | } |
---|
[0] | 70 | |
---|
| 71 | /* closes fd, previously obtained by esd_open */ |
---|
| 72 | int esd_close( int esd ) { |
---|
| 73 | return roar_simple_close(esd); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | /* get the stream latency to esound (latency is number of samples */ |
---|
| 77 | /* at 44.1khz stereo 16 bit - you'll have to adjust if oyur input */ |
---|
| 78 | /* sampling rate is less (in bytes per second) */ |
---|
| 79 | /* so if you're at 44.1khz stereo 16bit in your stream - your lag */ |
---|
| 80 | /* in bytes woudl be lag * 2 * 2 bytes (2 for stereo, 2 for 16bit) */ |
---|
| 81 | /* if your stream is at 22.05 Khz it'll be double this - in mono */ |
---|
| 82 | /* double again ... etc. */ |
---|
[3875] | 83 | |
---|
| 84 | // TODO: FIXME: write something usefull here. |
---|
[0] | 85 | int esd_get_latency(int esd) { |
---|
[2821] | 86 | #ifdef ROAR_HAVE_GETTIMEOFDAY |
---|
[0] | 87 | struct timeval try, ans; |
---|
| 88 | struct roar_message m; |
---|
| 89 | struct roar_connection con; |
---|
| 90 | |
---|
[3875] | 91 | memset(&m, 0, sizeof(m)); |
---|
| 92 | |
---|
[0] | 93 | m.cmd = ROAR_CMD_NOOP; |
---|
| 94 | m.datalen = 0; |
---|
| 95 | |
---|
[1660] | 96 | roar_connect_fh(&con, esd); |
---|
[0] | 97 | |
---|
| 98 | gettimeofday(&try, NULL); |
---|
| 99 | roar_req(&con, &m, NULL); |
---|
| 100 | gettimeofday(&ans, NULL); |
---|
| 101 | |
---|
| 102 | while (ans.tv_sec > try.tv_sec) { |
---|
| 103 | ans.tv_sec--; |
---|
| 104 | ans.tv_usec += 1000000; |
---|
| 105 | } |
---|
| 106 | ans.tv_usec -= try.tv_usec; |
---|
| 107 | |
---|
| 108 | /* |
---|
| 109 | 1 -> 44100 |
---|
| 110 | 0.5 -> 22050 |
---|
| 111 | */ |
---|
| 112 | |
---|
| 113 | return 441*ans.tv_usec/10000; |
---|
[2821] | 114 | #else |
---|
| 115 | // don't know... |
---|
| 116 | return 0; |
---|
| 117 | #endif |
---|
[0] | 118 | } |
---|
| 119 | |
---|
| 120 | |
---|
| 121 | //ll |
---|