📄 adin_na.c
字号:
/** * @file adin_na.c * @author Akinobu LEE * @date Sun Feb 13 19:40:56 2005 * * <JA> * @brief NetAudio掐蜗脱のサブル〖チン * * adin_netaudio.c 脱のサブ簇眶が年盗されていますˉ * * NetAudio のライブラリの dat_types.h が * libsent/include/sent/stddefs.h での年盗と办婶咀仆するため· * このようにサブル〖チン婶尸を尸违していますˉ * </JA> * <EN> * @brief Sub routines for NetAudio input * * This file defines sub functions for NetAudio input in adin_netaudio.c * * These functions are separated from adin_netaudio.c because some definitions * in NetAudio header "dat_types.h" conflicts with the * include header "sent/stddefs.h". * </EN> * * $Revision: 1.3 $ * *//* * Copyright (c) 1991-2006 Kawahara Lab., Kyoto University * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology * Copyright (c) 2005-2006 Julius project team, Nagoya Institute of Technology * All rights reserved */#include <sent/config.h>#include <stdio.h>#include <stdlib.h>/* sound header */#include <netaudio.h>#include <defaults.h>#define TRUE 1 ///< Should be the same definition in stddefs.h#define FALSE 0 ///< Should be the same definition in stddefs.htypedef short SP16; ///< Should be the same definition in stddefs.hstatic NAport *port; ///< NetAudio portstatic int need_swap = FALSE; ///< Incoming data is always BIG ENDIAN/** * Initialize NetAudio device. * * @param sfreq [in] sampling frequency * @param server_devname [in] server host name * * @return 1 on success, 0 on failure. */intNA_standby(int sfreq, char *server_devname){ NAinfo info; char *buf; int cnt; /* endian check --- incoming data is BE */#ifdef WORDS_BIGENDIAN need_swap = FALSE;#else /* LITTLE ENDIAN */ need_swap = TRUE;#endif /* WORDS_BIGENDIAN */ /* Initialize '.datlinkrc' processing */ /*InitDefaults(argv[0]);*/ /* Open connection to DAT-Link server on server_devname */ /* if NULL, env AUDIO_DEVICE is used instead. */ /* if AUDIO_DEVICE not specified, local port is used */ port = NAOpen(server_devname); if (port == NULL) { j_printerr("failed to open netaudio server on %s\n", server_devname); return(FALSE); } /* setup parameters */ NAGetDefaultInfo(&info); info.source = DL_ISRC_ALL; /* input source: all */ info.record.sampleRate = sfreq; /* DAT(48kHz)->some freq */ info.record.precision = 16; /* bits per sample */ info.record.encoding = NA_ENCODING_LINEAR; info.record.channels = NA_CHANNELS_LEFT; /* mono */ NASetInfo(port, &info); /* open a data connection for recording */ if (NAOpenData(port, NA_RECORD) == -1) { perror("cannot open data connection"); return(FALSE); } j_printerr("connected to netaudio server\n"); return(TRUE);}/** * Close port. (actually never used, just for reference...) * */static voidNA_close(){ /* Flush (delete) any buffered data for recording */ NAFlush(port, NA_RECORD); /* Close the data connection */ NACloseData(port, 0); /* Close connection */ NAClose(port);} /** * Begin recording. * */voidNA_start(){ NABegin(port, NA_RECORD);}/** * Pause the recording. * */voidNA_stop(){ NAPause(port, NA_RECORD, 1);}/** * @brief Read samples from NetAudio port. * * Try to read @a sampnum samples and returns actual number of recorded * samples currently available. This function will block until * at least some samples are obtained. * * @param buf [out] samples obtained in this function * @param sampnum [in] wanted number of samples to be read * * @return actural number of read samples, -1 if an error occured. */intNA_read(SP16 *buf, int sampnum){ int cnt; cnt = NARead(port, (char *)buf, sampnum * sizeof(SP16)) / sizeof(SP16); if (need_swap) swap_sample_bytes(buf, cnt); return(cnt);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -