speakers

This is a discussion on speakers within the C Programming forums, part of the General Programming Boards category; how can i send sound to the speakers not the internal speaker but to the output?...

  1. #1
    Unregistered
    Guest

    speakers

    how can i send sound to the speakers not the internal speaker but to the output?

  2. #2
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    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

  3. #3
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    any popular or example libraries available? any free ones as well?

    thnxq

  4. #4
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Yeah, DirectX and then use DirectSound. It's a free download at microsoft's website.
    1978 Silver Anniversary Corvette

  5. #5
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    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.

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    197
    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...

  7. #7
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386


    Or on extreme-low level, you would have to create your own sound producing device and write software to control it.

  8. #8
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    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.

  9. #9
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Bubba, would this be done in good ol' assembly?
    1978 Silver Anniversary Corvette

  10. #10
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    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.

  11. #11
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Bubba, can you explain DMA for me?
    1978 Silver Anniversary Corvette

  12. #12
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    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

  13. #13
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Cellphones and Speakers
    By SlyMaelstrom in forum Tech Board
    Replies: 5
    Last Post: 07-10-2006, 02:20 PM
  2. Replies: 4
    Last Post: 01-07-2006, 06:17 PM
  3. switch left/right speakers
    By MisterSako in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 12-23-2004, 09:43 AM
  4. test 5.1 speakers
    By dayknight in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 11-11-2004, 05:49 PM
  5. Getting all my speakers to play
    By Eber Kain in forum Tech Board
    Replies: 6
    Last Post: 09-30-2002, 07:55 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21