libsent/src/adin/adin_na.c

説明を見る。
00001 
00028 /*
00029  * Copyright (c) 1991-2006 Kawahara Lab., Kyoto University
00030  * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology
00031  * Copyright (c) 2005-2006 Julius project team, Nagoya Institute of Technology
00032  * All rights reserved
00033  */
00034 
00035 #include <sent/config.h>
00036 
00037 #include <stdio.h>
00038 #include <stdlib.h>
00039 
00040 /* sound header */
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   /* endian check --- incoming data is BE */
00066 #ifdef WORDS_BIGENDIAN
00067   need_swap = FALSE;
00068 #else  /* LITTLE ENDIAN */
00069   need_swap = TRUE;
00070 #endif /* WORDS_BIGENDIAN */
00071 
00072   /* Initialize '.datlinkrc' processing */
00073   /*InitDefaults(argv[0]);*/
00074 
00075   /* Open connection to DAT-Link server on server_devname */
00076   /* if NULL, env AUDIO_DEVICE is used instead. */
00077   /* if AUDIO_DEVICE not specified, local port is used */
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   /* setup parameters */
00085   NAGetDefaultInfo(&info);
00086   info.source            = DL_ISRC_ALL; /* input source: all */
00087   info.record.sampleRate = sfreq; /* DAT(48kHz)->some freq */
00088   info.record.precision  = 16;  /* bits per sample */
00089   info.record.encoding   = NA_ENCODING_LINEAR;
00090   info.record.channels   = NA_CHANNELS_LEFT; /* mono */
00091   NASetInfo(port, &info);
00092 
00093   /* open a data connection for recording */
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   /* 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 }

Juliusに対してTue Dec 26 16:19:28 2006に生成されました。  doxygen 1.5.0