00001
00028
00029
00030
00031
00032
00033
00034
00035 #include <sent/config.h>
00036
00037 #include <stdio.h>
00038 #include <stdlib.h>
00039
00040
00041 #include <netaudio.h>
00042 #include <defaults.h>
00043 #define TRUE 1
00044 #define FALSE 0
00045 typedef short SP16;
00046
00047 static NAport *port;
00048 static int need_swap = FALSE;
00049
00058 int
00059 NA_standby(int sfreq, char *server_devname)
00060 {
00061 NAinfo info;
00062 char *buf;
00063 int cnt;
00064
00065
00066 #ifdef WORDS_BIGENDIAN
00067 need_swap = FALSE;
00068 #else
00069 need_swap = TRUE;
00070 #endif
00071
00072
00073
00074
00075
00076
00077
00078 port = NAOpen(server_devname);
00079 if (port == NULL) {
00080 j_printerr("failed to open netaudio server on %s\n", server_devname);
00081 return(FALSE);
00082 }
00083
00084
00085 NAGetDefaultInfo(&info);
00086 info.source = DL_ISRC_ALL;
00087 info.record.sampleRate = sfreq;
00088 info.record.precision = 16;
00089 info.record.encoding = NA_ENCODING_LINEAR;
00090 info.record.channels = NA_CHANNELS_LEFT;
00091 NASetInfo(port, &info);
00092
00093
00094 if (NAOpenData(port, NA_RECORD) == -1) {
00095 perror("cannot open data connection");
00096 return(FALSE);
00097 }
00098
00099 j_printerr("connected to netaudio server\n");
00100
00101 return(TRUE);
00102 }
00103
00108 static void
00109 NA_close()
00110 {
00111
00112
00113 NAFlush(port, NA_RECORD);
00114
00115
00116 NACloseData(port, 0);
00117
00118
00119 NAClose(port);
00120
00121 }
00122
00127 void
00128 NA_start()
00129 {
00130 NABegin(port, NA_RECORD);
00131 }
00132
00137 void
00138 NA_stop()
00139 {
00140 NAPause(port, NA_RECORD, 1);
00141 }
00142
00155 int
00156 NA_read(SP16 *buf, int sampnum)
00157 {
00158 int cnt;
00159 cnt = NARead(port, (char *)buf, sampnum * sizeof(SP16)) / sizeof(SP16);
00160 if (need_swap) swap_sample_bytes(buf, cnt);
00161 return(cnt);
00162 }