Page 1 of 4 1234 LastLast
Results 1 to 10 of 34

Thread: DirectSound and output ILDA to sound card

  1. #1
    Join Date
    Jun 2010
    Posts
    16

    Default DirectSound and output ILDA to sound card

    Hi,
    My question orients to prorgammers mostly. I do very simple program for creating and playing laser show. Now it can create simple shows from existing ILDA-files. Also I did output to sound card via wave* win32 API functions (http://msdn.microsoft.com/en-us/library/aa909811.aspx). It was very simple as wave*-function allow to control of sound buffers manually. But I was noticed that some hardware manufacturers don't allow to play 6 audio channels when using wave*-function and it is nessesary to use DirectSound to avoid this problem.

    Using API of DirectSound is easy. But I don't have any idea about how to play frames serially. I don't know how to start to play next frame instantly after last previous frame stopped. May be someone have idea ho to do it?

    PS: short video how my program works

    Last edited by ArtDen; 07-22-2013 at 08:04.

  2. #2
    Join Date
    Feb 2009
    Location
    East Coast of Southern Virginia
    Posts
    536

    Default

    I wrote some code for the Win32 API about 8 years ago or so. The Win32 API basically had you setup a buffer that gets sent to the playback device. There was a windows message that was sent when the buffer was almost finished playing signalling you to queue up another buffer to play. I believe DirectSound works in a similar way?

    In that case it is similar in function to double buffering a video card. You buffer each frame up with 1 or more frames per buffer with no blank space in between the start of one frame and the beginning of the next. When it is time to send another buffer you create a buffer or write into an unused buffer (already created) and place the next set of frames to be played over the sound card. Keep in mind a frame may end in one buffer and continue in the next. The buffers were required by the API to be of a certain length and not variable length so the software needs to keep track of what is the buffer being played in order to seamlessly form the next one.

    Does that answer your question?

  3. #3
    Join Date
    Jun 2010
    Posts
    16

    Default

    Quote Originally Posted by cfavreau View Post
    I wrote some code for the Win32 API about 8 years ago or so. The Win32 API basically had you setup a buffer that gets sent to the playback device. There was a windows message that was sent when the buffer was almost finished playing signalling you to queue up another buffer to play.
    Yes. I use same way with two buffers and it works fine. But it works only for wave*-API.
    Quote Originally Posted by cfavreau View Post
    I believe DirectSound works in a similar way?
    It doesn't As I understood DirectSound controls sound buffers internally and there is no way to start other buffer instantly after first one has stopped. May be I'm mistaken. Therefore I ask this forum

  4. #4
    Join Date
    Feb 2009
    Location
    East Coast of Southern Virginia
    Posts
    536

    Default

    Doh.... I should have absorbed more of what you have written already. I apologize for that.

    Ok, I think I see what you are asking.

    See here for information on using "Streaming Buffers" with DirectSound.

    http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx

    Microsoft defines Streaming Buffers as "A streaming buffer plays a long sound that cannot all fit into the buffer at once. As the buffer plays, old data is periodically replaced with new data.". I believe this is what you are looking for.
    Last edited by cfavreau; 07-22-2013 at 12:08.

  5. #5
    Join Date
    Feb 2009
    Location
    East Coast of Southern Virginia
    Posts
    536

    Default

    BTW.... nice job on your software!

  6. #6
    Join Date
    Mar 2006
    Posts
    2,478

    Default

    Quote Originally Posted by ArtDen View Post
    ...some hardware manufacturers don't allow to play 6 audio channels when using wave*-function and it is nessesary to use DirectSound to avoid this problem.
    So long as the hardware has multiple stereo ports, and its supplied driver can open more than one of them, you do not need DirectSound. The wave callback function is called, being passed the handle for the port that called it. So long as you pass that to whatever code is filling your buffers for you, it can put the right data in them.

    Syncing between ports will be handled easily because each will be ready for new data in the same sequence the first lot got sent out. Most hardware will force all ports to the same sample rate, but for laser control and anything that wants them synced accurately, that's ideal. I'm not sure that DirectSound will make any difference here, it's down to the hardware and its own driver, whether you can handle multiple ports at once. I chose to use Echo Layla devices because they are intended to do this. I get awesome low latency, etc, with no need for ASIO, DirectSound, it's all pure C and Win32 API. I'm not making a laser controller, but a synthesiser, but no doubt that applies, it's got very similar needs. Echo's driver notes show that 'multi-client audio', which is their name for using different outputs to different ports at once, can use Wave for one port, ASIO for another, DirectSound for yet more, etc... So you can mix and match programs/outputs and ports, but all must be at same sample rate, and this is a driver and hardware capability, I doubt DirectSound can override the hardware driver and make it use multiple ports if it can't do that anyway.

    (Caveat Emptor... I haven't built multitimbrality into my synth yet, haven't actually done what I said would work! Just so you know. Got to be honest about that. But a look at the existing callback function makes it very clear that standard API can handle multiple ports, so long as driver and hardware can.)

  7. #7
    Join Date
    Mar 2010
    Location
    Raleigh, NC
    Posts
    2,293

    Default

    The soundcard driver I wrote for Spaghetti uses DirectSound. I am actually in the middle of rewriting in in C++ at the moment. PM me and I can probably help you out with any questions.

  8. #8
    Join Date
    Mar 2010
    Location
    Raleigh, NC
    Posts
    2,293

    Default

    Quote Originally Posted by The_Doctor View Post
    So long as the hardware has multiple stereo ports, and its supplied driver can open more than one of them, you do not need DirectSound. The wave callback function is called, being passed the handle for the port that called it. So long as you pass that to whatever code is filling your buffers for you, it can put the right data in them.

    Syncing between ports will be handled easily because each will be ready for new data in the same sequence the first lot got sent out. Most hardware will force all ports to the same sample rate, but for laser control and anything that wants them synced accurately, that's ideal. I'm not sure that DirectSound will make any difference here, it's down to the hardware and its own driver, whether you can handle multiple ports at once. I chose to use Echo Layla devices because they are intended to do this. I get awesome low latency, etc, with no need for ASIO, DirectSound, it's all pure C and Win32 API. I'm not making a laser controller, but a synthesiser, but no doubt that applies, it's got very similar needs. Echo's driver notes show that 'multi-client audio', which is their name for using different outputs to different ports at once, can use Wave for one port, ASIO for another, DirectSound for yet more, etc... So you can mix and match programs/outputs and ports, but all must be at same sample rate, and this is a driver and hardware capability, I doubt DirectSound can override the hardware driver and make it use multiple ports if it can't do that anyway.

    (Caveat Emptor... I haven't built multitimbrality into my synth yet, haven't actually done what I said would work! Just so you know. Got to be honest about that. But a look at the existing callback function makes it very clear that standard API can handle multiple ports, so long as driver and hardware can.)
    It really all depends on which platform you are on. It seems like Microsoft changes their audio pipeline with each OS. If you want super low latency you can go with what they call core audio now. DirectSound sits above that by so many layers. There is also XAudio and XAudio2. I think that XAudio2 is the current "general purpose" sound API that they recommend. I don't think MS even recommends using DirectSound at all anymore. But, if you need to support older OSes, you might need to.

    I also wrote a driver using ASIO and it worked pretty well. I didn't have hardware that had true ASIO drivers so I didn't see any real performance difference, though. If I wanted to create an OS independent driver I'd go with ASIO for sure.

    Original poster can email me for specifics but creating a streaming DirectSound driver is easy. Create two secondary buffers and set them up to notify you when they are empty. Alternate filling them based on the notifications events. As far as frames go, pick a maximum point size per frame and base your buffers on that size. (number of channels x bytes x etc = buffer size). Dealing with the different frame sizes is the challenge. I can look at my code and let you know exacyly how I handled it but I have to go because the pizza man came.

  9. #9
    Join Date
    Jun 2010
    Posts
    16

    Default

    Quote Originally Posted by cfavreau View Post
    See here for information on using "Streaming Buffers" with DirectSound.
    I already saw it and thought about it. Streaming buffers will bring delay between current played frame and shown frame depending of length of circular buffer. But I will use it if I don't find other ways.
    Quote Originally Posted by cfavreau View Post
    BTW.... nice job on your software!
    Thanks!
    Quote Originally Posted by The_Doctor View Post
    So long as the hardware has multiple stereo ports, and its supplied driver can open more than one of them, you do not need DirectSound
    Look here: http://microsoft.public.win32.progra...topen-possible.
    Quote Originally Posted by JohnYayas View Post
    Original poster can email me for specifics but creating a streaming DirectSound driver is easy
    Thanks, but I roughly know how to use streaming buffers. As I said I'm afraid of the delay in current played frame and laser projector picture when using streaming buffers. Or the delay is so small that it is not noticeable?

  10. #10
    Join Date
    Mar 2006
    Posts
    2,478

    Default

    Quote Originally Posted by ArtDen View Post
    That isn't the same thing. I took your meaning to be whether multiple ports can be opened at once. What you link to is about playing of a specific streamed wave format (5:1). If you're writing your own code there is nothing stopping you from unpacking that format and sending it as 3 separate stereo streams. Though as I said, that depends on your hardware and its driver.

    As JohnYayas said, DirectSound is a layer on top of the direct access to the sound system. About the only thing it is more direct than is the original Windows wave API. So again, it comes down to driver and hardware capability. You're not going to override that. If you have multiple ports available, the rest is a data conversion task.

    EDIT: If you use standard Wave API (works for me), and want low latency, try just two buffers sized at SampleRate/80 samples. That works very well for Layla (20 bit version). Other systems may want different, but as that works for one of the landmark hardware interfaces of the last 15 years, it's a good starting point. If you get glitches due to other demands on same system, raise buffer count (slightly), not size... If DirectSound isn't letting you get that much control of buffering, that's a great reason to avoid it.

    MORE EDIT: JohnYayas, point taken. I'm staying with W98 (long story with many good reasons). The API docs state it's workable for NT as well, so I imagine the code I'm using would still work on WXP. Haven't tried it though. Given that I read MS were chucking the entire MIDI API out of later operating systems (unless raging demand forced them to rethink that) I decided to stay with an OS that was cheap, easily paid for in multiple licenses, and came with full support for audio and MIDI. I'd consider ASIO for the same reasons you do, but I put that off for now because even though Layla has a decent ASIO driver, Wave performance is so excellent here that I really don't need to.

    Quote Originally Posted by JohnYayas View Post
    I have to go because the pizza man came.
    Not on the pizza, I trust...
    Last edited by The_Doctor; 07-22-2013 at 20:10.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •