00001
00041
00042
00043
00044 #include <sp/spAudioLib.h>
00045
00046 #include <sent/stddefs.h>
00047 #include <sent/adin.h>
00048
00049 static spAudio audio = NULL;
00050 static long buffer_length = 256;
00051
00052 static float rate;
00053
00062 boolean
00063 adin_mic_standby(int sfreq, void *dummy)
00064 {
00065 rate = sfreq;
00066 if (adin_mic_start() == FALSE) return FALSE;
00067 if (adin_mic_stop() == FALSE) return FALSE;
00068 return TRUE;
00069 }
00070
00076 boolean
00077 adin_mic_begin()
00078 {
00079 if (audio == NULL) {
00080 audio = spInitAudio();
00081 }
00082 spSetAudioSampleRate(audio, rate);
00083 spSetAudioChannel(audio, 1);
00084 spSetAudioSampleBit(audio, 16);
00085 #ifdef SP_AUDIO_NONBLOCKING
00086 spSetAudioBlockingMode(audio, SP_AUDIO_NONBLOCKING);
00087 #endif
00088
00089 if (!spOpenAudioDevice(audio, "ro")) {
00090 jlog("Error: adin_sp: failed to open device\n");
00091 return FALSE;
00092 }
00093
00094 return TRUE;
00095 }
00096
00102 boolean
00103 adin_mic_end()
00104 {
00105 spCloseAudioDevice(audio);
00106 return TRUE;
00107 }
00108
00121 int
00122 adin_mic_read(SP16 *buf, int sampnum)
00123 {
00124 long nread;
00125
00126 #ifdef SP_AUDIO_NONBLOCKING
00127 nread = sampnum;
00128 #else
00129 if (sampnum <= buffer_length) {
00130 nread = sampnum;
00131 } else {
00132 nread = buffer_length;
00133 }
00134 #endif
00135 nread = spReadAudio(audio, (short *)buf, nread);
00136
00137 return nread;
00138 }