DirectXTK icon indicating copy to clipboard operation
DirectXTK copied to clipboard

Solution to memory limitations and scope design of dxtk sound.

Open willWallace-RIT opened this issue 6 months ago • 6 comments

Not necessarily an issue and it is possible to figure out from the outlined code but I ran into a problem of being inconvenienced by dxtk's sound scope design. What I did was add an "instancing" class for a map that by string name of sound , creates a new sound memory object within scope when necessary prior to playing the sound. Let me know if anyone is interested in a code snippet. (blasterofdisaster for Michaelsoft reference)

willWallace-RIT avatar Jul 04 '25 18:07 willWallace-RIT

Can you please explain the scenario a bit more and what limitation you are hitting?

walbourn avatar Jul 05 '25 17:07 walbourn

The audio class by design is set up to be created and cleaned up within the scope of a loop method. But when you have multiple sound or method calls within that loop sound becomes a bit of a hassle plus requires quite a few lines to play sound effects. To get around it but maintain an isolated scope, I created a method and incorporated a map structure to create quick "instances" based on a map of preset sound information and then plays that sound. The sound presets in a global scope but the sound created and played stays within the scope of wherever one is in the loop.

On Sat, Jul 5, 2025 at 1:28 PM Chuck Walbourn @.***> wrote:

walbourn left a comment (microsoft/DirectXTK#569) https://github.com/microsoft/DirectXTK/issues/569#issuecomment-3039452121

Can you please explain the scenario a bit more and what limitation you are hitting?

— Reply to this email directly, view it on GitHub https://github.com/microsoft/DirectXTK/issues/569#issuecomment-3039452121, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANC44FVMUNOV2PDO6YG7DE33HADKZAVCNFSM6AAAAACAZ5TAWSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTAMZZGQ2TEMJSGE . You are receiving this because you authored the thread.Message ID: @.***>

willWallace-RIT avatar Jul 05 '25 21:07 willWallace-RIT

In the DirectX Tool Kit for Audio design, there are 'one-shot' sounds that are just triggered and played through to completion, and then there are 'instanced' sounds which are generally used for loops, 3D positioning, etc.

Are you trying to do some kind of 'looped' one-shot?

walbourn avatar Jul 08 '25 21:07 walbourn

It was probably was the need for a loop that caused the issue. I used an FSM in the game loop to handle arcade menu,game, and game over in a way that music would loop while needing to be one shot. It was a fairly rapidly made prototype so a continuous a sound thread might have been a better solution but using both a sound and instance map allowed for a one line refactored start and cleanup methods within the loop for sound.

This was dxtk for dx11 so it is possible things changed so I'll doublecheck.

willWallace-RIT avatar Jul 08 '25 22:07 willWallace-RIT

The reason the design doesn't have looped one-shots is that by design, one shots have a play duration and end and then automatically clean themselves up. The whole purpose of 'one-shots' is that you can just trigger them and they will play and then cleanup on their own.

Would you expect a loop count to work or were you really running the sound as an infinite loop?

walbourn avatar Jul 08 '25 22:07 walbourn

This was a fairly short term but longer than a game jam type of project in duration so a lot of decisions were based on if it appeared to work against fairly limited testing but the intent was if the music was on in a state it would loop forever until a player switched states.

On Tue, Jul 8, 2025 at 6:46 PM Chuck Walbourn @.***> wrote:

walbourn left a comment (microsoft/DirectXTK#569) https://github.com/microsoft/DirectXTK/issues/569#issuecomment-3050483123

The reason the design doesn't have looped one-shots is that by design, one shots have a play duration and end and then automatically clean themselves up. The whole purpose of 'one-shots' is that you can just trigger them and they will play and then cleanup on their own.

Would you expect a loop count to work or were you really running the sound as an infinite loop?

— Reply to this email directly, view it on GitHub https://github.com/microsoft/DirectXTK/issues/569#issuecomment-3050483123, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANC44FWCJIQWLXUJBDD3TA33HRC5LAVCNFSM6AAAAACAZ5TAWSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTANJQGQ4DGMJSGM . You are receiving this because you authored the thread.Message ID: @.***>

willWallace-RIT avatar Jul 09 '25 22:07 willWallace-RIT