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) */ |
---|
9 | int esd_open_sound( const char *host ) { |
---|
10 | struct roar_connection con; |
---|
11 | |
---|
12 | if ( roar_simple_connect(&con, 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 */ |
---|
21 | int esd_send_auth( int sock ); |
---|
22 | |
---|
23 | /* closes fd, previously obtained by esd_open */ |
---|
24 | int esd_close( int esd ) { |
---|
25 | return roar_simple_close(esd); |
---|
26 | } |
---|
27 | |
---|
28 | /* get the stream latency to esound (latency is number of samples */ |
---|
29 | /* at 44.1khz stereo 16 bit - you'll have to adjust if oyur input */ |
---|
30 | /* sampling rate is less (in bytes per second) */ |
---|
31 | /* so if you're at 44.1khz stereo 16bit in your stream - your lag */ |
---|
32 | /* in bytes woudl be lag * 2 * 2 bytes (2 for stereo, 2 for 16bit) */ |
---|
33 | /* if your stream is at 22.05 Khz it'll be double this - in mono */ |
---|
34 | /* double again ... etc. */ |
---|
35 | int esd_get_latency(int esd) { |
---|
36 | struct timeval try, ans; |
---|
37 | struct roar_message m; |
---|
38 | struct roar_connection con; |
---|
39 | |
---|
40 | m.cmd = ROAR_CMD_NOOP; |
---|
41 | m.datalen = 0; |
---|
42 | |
---|
43 | con.fh = esd; |
---|
44 | |
---|
45 | gettimeofday(&try, NULL); |
---|
46 | roar_req(&con, &m, NULL); |
---|
47 | gettimeofday(&ans, NULL); |
---|
48 | |
---|
49 | while (ans.tv_sec > try.tv_sec) { |
---|
50 | ans.tv_sec--; |
---|
51 | ans.tv_usec += 1000000; |
---|
52 | } |
---|
53 | ans.tv_usec -= try.tv_usec; |
---|
54 | |
---|
55 | /* |
---|
56 | 1 -> 44100 |
---|
57 | 0.5 -> 22050 |
---|
58 | */ |
---|
59 | |
---|
60 | return 441*ans.tv_usec/10000; |
---|
61 | } |
---|
62 | |
---|
63 | |
---|
64 | //ll |
---|