how can i send sound to the speakers not the internal speaker but to the output?
how can i send sound to the speakers not the internal speaker but to the output?
To my knowledge, you can't do that with plain C. You would have to do something with DirectX (DirectSound) or some other library.
1978 Silver Anniversary Corvette
any popular or example libraries available? any free ones as well?
thnxq
Yeah, DirectX and then use DirectSound. It's a free download at microsoft's website.
1978 Silver Anniversary Corvette
On low level you would have to use the device driver of your soundcard. Easier is making use of the Win32 API functions. Take look at the MSDN library for an overview.
On very-low-level you would have to write a device driver for your soundcard and program the functions you need.
klausi
When I close my eyes nobody can see me...
![]()
Or on extreme-low level, you would have to create your own sound producing device and write software to control it.
Yes you can do this in C. However, for large buffer sizes you will need to make use of either XMS or EMS depending on whether you are in protected mode or not.
go to www.creative.com and click on the developers section. Then click on legacy sound programming and download the documentation for programming the SoundBlaster series of cards.
Note that this is only for DOS.
Bubba, would this be done in good ol' assembly?
1978 Silver Anniversary Corvette
Well....yeah it can be.
But I have coded a full sound system in C. Waiting to port to DJGPP. Current problem is the size of the DMA buffer and getting the linear address of the buffer, not the logical one that the CPU translates to the linear.
Bubba, can you explain DMA for me?
1978 Silver Anniversary Corvette
DMA is a nifty way to transfer data to and from memory transparent of the CPU. In other words, the CPU does not even know about the transfer which makes it very fast and also frees the CPU up to continue its pipeline and do what it does best -> run instructions.
However, there are some limitations to DMA. First any buffer that is to be used by the DMAC cannot cross a physical 64K boundary, and second, the DMA cannot transfer more than 64Kb of data at one time. Thanks to the DMA hard drives can shoot data to memory very fast and sound cards and other devices can too. In my sound programming, I allocate a DMA buffer of 256 bytes, but program the sound card for half of that transfer. At the 128 byte mark, a hardware interrupt is generated on the sound card's IRQ channel. I patch this vector, along with programming the PIC and some other things, and when the interrupt happens, I copy the next 128 byte chunk of data into the section that just played. If you always copy data into the buffer that just played, you can produce clickless sound output.
There are several modes for DMA transfer. Some popular ones are auto-initialized transfer and single cycle transfer. Auto-initialized is nice because you only program the DMAC chip once for the transfer length and the address of the buffer. It will increment that DMA channel's count register until it reaches the size of the transfer. After that, it wraps back around to 0 and keeps transferring data. As the programmer, you just have to place new data into the buffer and you will be able to transfer large amounts of data with one program of the DMAC. You just alter the contents of the buffer.
With single-cycle DMA, the DMA will transfer the data in the buffer until the length is reached at which time it stops. On sound cards, this will produce a noticeable click or pop in the sound if you forget to shut off the speaker prior to reaching the end of the transfer. Also, there will be a slight delay in the buffer throughput since you must reprogram the DMAC for the next transfer.
With newer DMA chips there are also burst modes and high speed DMA transfer modes. Hard drives and other speed critical devices use theses modes. You can also use these modes for sound transfers and SB cards do support these modes, but I've gotten excellent quality w/o using these modes.
But as you can see, DMA is very fast and very handy. Now you can see why sound can be played at the same time a million other things are happening. The DMAC chip is executing the loop and the transfer, not the CPU. Those bytes never go to the CPU, just to the DMA and then to memory. The only time the CPU is used is when a hardware interrupt is encountered and you load new data into the DMA buffer, or reprogram the DMA for another transfer - depending on the mode you are using. As I said I've achieved clickless sound output with just a 256 byte buffer. My sound system will play and mix in real-time an unlimited number of samples, but does start to suffer some distortion when over 10 sounds are being played at once.
For more information check out this link and click on the link to the 8237A DMAC data sheet.
http://support.intel.com/support/con...heral/spec.htm
Wow! That's a lot of information. You gave me a good idea of what it is and then I'll check out that link. Thanks, Bubba!
1978 Silver Anniversary Corvette