Julius 4.2
libsent/src/adin/adin_na.c
説明を見る。
00001 
00029 /*
00030  * Copyright (c) 1991-2011 Kawahara Lab., Kyoto University
00031  * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology
00032  * Copyright (c) 2005-2011 Julius project team, Nagoya Institute of Technology
00033  * All rights reserved
00034  */
00035 
00036 #include <sent/config.h>
00037 
00038 #include <stdio.h>
00039 #include <stdlib.h>
00040 
00041 /* sound header */
00042 #include <netaudio.h>
00043 #include <defaults.h>
00044 #define TRUE 1                  ///< Should be the same definition in stddefs.h
00045 #define FALSE 0                 ///< Should be the same definition in stddefs.h
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   /* endian check --- incoming data is BE */
00067 #ifdef WORDS_BIGENDIAN
00068   need_swap = FALSE;
00069 #else  /* LITTLE ENDIAN */
00070   need_swap = TRUE;
00071 #endif /* WORDS_BIGENDIAN */
00072 
00073   /* Initialize '.datlinkrc' processing */
00074   /*InitDefaults(argv[0]);*/
00075 
00076   /* Open connection to DAT-Link server on server_devname */
00077   /* if NULL, env AUDIO_DEVICE is used instead. */
00078   /* if AUDIO_DEVICE not specified, local port is used */
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   /* setup parameters */
00086   NAGetDefaultInfo(&info);
00087   info.source            = DL_ISRC_ALL; /* input source: all */
00088   info.record.sampleRate = sfreq; /* DAT(48kHz)->some freq */
00089   info.record.precision  = 16;  /* bits per sample */
00090   info.record.encoding   = NA_ENCODING_LINEAR;
00091   info.record.channels   = NA_CHANNELS_LEFT; /* mono */
00092   NASetInfo(port, &info);
00093 
00094   /* open a data connection for recording */
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   /* Flush (delete) any buffered data for recording */
00113   NAFlush(port, NA_RECORD);
00114 
00115   /* Close the data connection */
00116   NACloseData(port, 0);
00117 
00118   /* Close connection */
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 }