Date: Thu, 13 Aug 1998 13:20:06 -0500 (CDT) From: Ethan Brodsky Subject: Re: Sound card programming On Thu, 13 Aug 1998, somebody wrote: > Again I want to sample the line in or mic and get an unsigned integer > back. I don't want or need 5 thousand samples in one second and I don't > want wav or voc files. I want to sample maybe 1000 samples in one second > tops. 16 bit only. The problem is that what you want to do isn't directly supported by SB cards. Reading samples one at a time from the sound card is called "Direct Mode" and is only supported for reading eight bit mono audio. Creative Labs never implemented commands to do it for sixteen bit audio or stereo. It's also very CPU intensive, though you would have no problem reading at 1ksample/second. If I needed something like that, I would begin with a standard DMA recording program such as sb16snd. Cut out all the program to write data to disk, since you don't need to do that. Then write code that reads the current position from the DMA controller. You can use that to get the address of the most recent sample. You still need to keep the circular buffer (though you could get away with a small one *), but you can get samples whenever you want. While writing this, I thought of another solution. Instead of having a large buffer and picking out the most recent sample, why not use a one-sample buffer. Program the DMA controller for autoinitialized DMA on a buffer of one word. You can program the DSP for a larger block size (that way you won't get as many interrupts), or just read from 2xF in the inner loop to keep the sound card going. The most recent sample should always be in that memory location. The only problem might be if you try to read in the middle of an update, but I think that the DMA controller locks the bus for the full duration of the memory write, so you should be ok. If you want a bit of filtering to get rid of high-frequency noise, use a slightly larger buffer and average all the samples in the buffer to get your value. Ethan Brodsky ---- Ethan Brodsky UW FutureCar Team Paradigm - 1998 FutureCar Challenge Winner