source: roaraudio/libroaresd/esdbasic.c @ 632:468ce09813a2

Last change on this file since 632:468ce09813a2 was 73:7eb32a675a95, checked in by phi, 16 years ago

added some more simple things, including fallback support via +fork

File size: 1.6 KB
Line 
1//esdbasic.c:
2
3#include "libroaresd.h"
4
5/* opens channel, authenticates connection, and prefares for protos */
6/* returns EsounD socket for communication, result < 0 = error */
7/* server = listen socket (localhost:5001, 192.168.168.0:9999 */
8/* rate, format = (bits | channels | stream | func) */
9int esd_open_sound( const char *host ) {
10 struct roar_connection con;
11
12 if ( roar_simple_connect(&con, (char*) host, NULL) == -1 ) {
13  ROAR_DBG("esd_open_sound(*): roar_simple_connect() faild!");
14  return -1;
15 }
16
17 return con.fh;
18}
19
20/* send the authorization cookie, create one if needed */
21int esd_send_auth( int sock ) {
22 return 0;
23}
24
25/* closes fd, previously obtained by esd_open */
26int esd_close( int esd ) {
27 return roar_simple_close(esd);
28}
29
30/* get the stream latency to esound (latency is number of samples  */
31/* at 44.1khz stereo 16 bit - you'll have to adjust if oyur input  */
32/* sampling rate is less (in bytes per second)                     */
33/* so if you're at 44.1khz stereo 16bit in your stream - your lag  */
34/* in bytes woudl be lag * 2 * 2 bytes (2 for stereo, 2 for 16bit) */
35/* if your stream is at 22.05 Khz it'll be double this - in mono   */
36/* double again ... etc.                                           */
37int esd_get_latency(int esd) {
38 struct timeval         try, ans;
39 struct roar_message    m;
40 struct roar_connection con;
41
42 m.cmd = ROAR_CMD_NOOP;
43 m.datalen = 0;
44
45 con.fh = esd;
46
47 gettimeofday(&try, NULL);
48 roar_req(&con, &m, NULL);
49 gettimeofday(&ans, NULL);
50
51 while (ans.tv_sec > try.tv_sec) {
52  ans.tv_sec--;
53  ans.tv_usec += 1000000;
54 }
55 ans.tv_usec -= try.tv_usec;
56
57/*
58 1   -> 44100
59 0.5 -> 22050
60*/
61
62 return 441*ans.tv_usec/10000;
63}
64
65
66//ll
Note: See TracBrowser for help on using the repository browser.