source: roaraudio/libroaresd/esdbasic.c @ 1660:99bfd21f00ef

Last change on this file since 1660:99bfd21f00ef was 1660:99bfd21f00ef, checked in by phi, 15 years ago

changed name of fh in con struct to fh, this should all apps requiring the private member to fail to build, added function to get fh, change code to use them both everythere

File size: 3.3 KB
Line 
1//esdbasic.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008
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, 675 Mass Ave, Cambridge, MA 02139, USA.
26 *
27 *  NOTE for everyone want's to change something and send patches:
28 *  read README and HACKING! There a addition information on
29 *  the license of this document you need to read before you send
30 *  any patches.
31 *
32 *  NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc
33 *  or libpulse*:
34 *  The libs libroaresd, libroararts and libroarpulse link this libroar
35 *  and are therefore GPL. Because of this it may be illigal to use
36 *  them with any software that uses libesd, libartsc or libpulse*.
37 */
38
39#include "libroaresd.h"
40
41/* opens channel, authenticates connection, and prefares for protos */
42/* returns EsounD socket for communication, result < 0 = error */
43/* server = listen socket (localhost:5001, 192.168.168.0:9999 */
44/* rate, format = (bits | channels | stream | func) */
45int esd_open_sound( const char *host ) {
46 struct roar_connection con;
47 int fh;
48
49 if ( roar_simple_connect(&con, (char*) host, NULL) == -1 ) {
50  ROAR_DBG("esd_open_sound(*): roar_simple_connect() faild!");
51  return -1;
52 }
53
54 if ( (fh = roar_get_connection_fh(&con)) == -1 ) {
55  roar_disconnect(&con);
56  return -1;
57 }
58
59 return fh;
60}
61
62/* send the authorization cookie, create one if needed */
63int esd_send_auth( int sock ) {
64 return 0;
65}
66
67/* closes fd, previously obtained by esd_open */
68int esd_close( int esd ) {
69 return roar_simple_close(esd);
70}
71
72/* get the stream latency to esound (latency is number of samples  */
73/* at 44.1khz stereo 16 bit - you'll have to adjust if oyur input  */
74/* sampling rate is less (in bytes per second)                     */
75/* so if you're at 44.1khz stereo 16bit in your stream - your lag  */
76/* in bytes woudl be lag * 2 * 2 bytes (2 for stereo, 2 for 16bit) */
77/* if your stream is at 22.05 Khz it'll be double this - in mono   */
78/* double again ... etc.                                           */
79int esd_get_latency(int esd) {
80 struct timeval         try, ans;
81 struct roar_message    m;
82 struct roar_connection con;
83
84 m.cmd = ROAR_CMD_NOOP;
85 m.datalen = 0;
86
87 roar_connect_fh(&con, esd);
88
89 gettimeofday(&try, NULL);
90 roar_req(&con, &m, NULL);
91 gettimeofday(&ans, NULL);
92
93 while (ans.tv_sec > try.tv_sec) {
94  ans.tv_sec--;
95  ans.tv_usec += 1000000;
96 }
97 ans.tv_usec -= try.tv_usec;
98
99/*
100 1   -> 44100
101 0.5 -> 22050
102*/
103
104 return 441*ans.tv_usec/10000;
105}
106
107
108//ll
Note: See TracBrowser for help on using the repository browser.