00001 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 #include <sent/config.h>
00037 
00038 #include <stdio.h>
00039 #include <stdlib.h>
00040 
00041 
00042 #include <netaudio.h>
00043 #include <defaults.h>
00044 #define TRUE 1                  
00045 #define FALSE 0                 
00046 typedef short SP16;             
00047 
00048 static NAport *port;            
00049 static int need_swap = FALSE;   
00050 
00059 int
00060 NA_standby(int sfreq, char *server_devname)
00061 {
00062   NAinfo info;
00063   char *buf;
00064   int cnt;
00065 
00066   
00067 #ifdef WORDS_BIGENDIAN
00068   need_swap = FALSE;
00069 #else  
00070   need_swap = TRUE;
00071 #endif 
00072 
00073   
00074   
00075 
00076   
00077   
00078   
00079   port = NAOpen(server_devname);
00080   if (port == NULL) {
00081     jlog("Error: adin_na: failed to open netaudio server on %s\n", server_devname);
00082     return(FALSE);
00083   }
00084 
00085   
00086   NAGetDefaultInfo(&info);
00087   info.source            = DL_ISRC_ALL; 
00088   info.record.sampleRate = sfreq; 
00089   info.record.precision  = 16;  
00090   info.record.encoding   = NA_ENCODING_LINEAR;
00091   info.record.channels   = NA_CHANNELS_LEFT; 
00092   NASetInfo(port, &info);
00093 
00094   
00095   if (NAOpenData(port, NA_RECORD) == -1) {
00096     jlog("Error: adin_na: failed to open data connection\n");
00097     return(FALSE);
00098   }
00099 
00100   jlog("Stat: adin_na: connected to netaudio server on %s\n", server_devname);
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 }