source: roaraudio/libroaresd/esdbasic.c @ 5823:f9f70dbaa376

Last change on this file since 5823:f9f70dbaa376 was 5823:f9f70dbaa376, checked in by phi, 11 years ago

updated copyright

File size: 3.8 KB
Line 
1//esdbasic.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2013
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/* 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) */
46int esd_open_sound( const char *host ) {
47 struct roar_connection con;
48 int fh;
49
50 if ( host == NULL )
51  host = roar_env_get("ESPEAKER");
52
53 if ( roar_simple_connect(&con, (char*) host, NULL) == -1 ) {
54  ROAR_DBG("esd_open_sound(*): roar_simple_connect() faild!");
55  return -1;
56 }
57
58 if ( (fh = roar_get_connection_fh(&con)) == -1 ) {
59  roar_disconnect(&con);
60  return -1;
61 }
62
63 return fh;
64}
65
66/* send the authorization cookie, create one if needed */
67int esd_send_auth( int sock ) {
68 (void) sock;
69 return 0;
70}
71
72/* closes fd, previously obtained by esd_open */
73int esd_close( int esd ) {
74 struct roar_vio_calls vio;
75
76 if ( roar_vio_open_fh_socket(&vio, esd) == -1 ) {
77  roar_err_update();
78  return -1;
79 }
80
81 if ( roar_vio_close(&vio) == -1 ) {
82  roar_err_update();
83  return -1;
84 }
85
86 return 0;
87}
88
89/* get the stream latency to esound (latency is number of samples  */
90/* at 44.1khz stereo 16 bit - you'll have to adjust if oyur input  */
91/* sampling rate is less (in bytes per second)                     */
92/* so if you're at 44.1khz stereo 16bit in your stream - your lag  */
93/* in bytes woudl be lag * 2 * 2 bytes (2 for stereo, 2 for 16bit) */
94/* if your stream is at 22.05 Khz it'll be double this - in mono   */
95/* double again ... etc.                                           */
96
97// TODO: FIXME: write something usefull here.
98int esd_get_latency(int esd) {
99#ifdef ROAR_HAVE_GETTIMEOFDAY
100 struct timeval         try, ans;
101 struct roar_message    m;
102 struct roar_connection con;
103
104 memset(&m, 0, sizeof(m));
105
106 m.cmd = ROAR_CMD_NOOP;
107 m.datalen = 0;
108
109 roar_connect_fh(&con, esd);
110
111 gettimeofday(&try, NULL);
112 roar_req(&con, &m, NULL);
113 gettimeofday(&ans, NULL);
114
115 while (ans.tv_sec > try.tv_sec) {
116  ans.tv_sec--;
117  ans.tv_usec += 1000000;
118 }
119 ans.tv_usec -= try.tv_usec;
120
121/*
122 1   -> 44100
123 0.5 -> 22050
124*/
125
126 return 441*ans.tv_usec/10000;
127#else
128 // don't know...
129 return 0;
130#endif
131}
132
133
134//ll
Note: See TracBrowser for help on using the repository browser.