[0] | 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 | |
---|
[73] | 12 | if ( roar_simple_connect(&con, (char*) host, NULL) == -1 ) { |
---|
[0] | 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 */ |
---|
[73] | 21 | int esd_send_auth( int sock ) { |
---|
| 22 | return 0; |
---|
| 23 | } |
---|
[0] | 24 | |
---|
| 25 | /* closes fd, previously obtained by esd_open */ |
---|
| 26 | int 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. */ |
---|
| 37 | int 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 |
---|