Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sound under Windows #9

SDLBugzilla opened this issue Feb 10, 2021 · 0 comments

Sound under Windows #9

SDLBugzilla opened this issue Feb 10, 2021 · 0 comments


Copy link

@SDLBugzilla SDLBugzilla commented Feb 10, 2021

This bug report was migrated from our old Bugzilla tracker.

Reported in version: don't know
Reported for operating system, platform: Windows (All), x86

Comments on the original bug report:

On 2006-01-24 00:20:44 +0000, Sam Lantinga wrote:

Date: Thu, 13 Mar 2003 11:56:55 -0500
From: Mark Aikens
Subject: [SDL] Sound under Windows


A couple friends and I wrote a game using pygame (which uses SDL) and it
runs great under Linux. However, when running it under Windows, the
music breaks up. Increasing the sound buffer size makes it better but
then the latency of sound effects is terrible.

I traced the problem to the SDL directsound audio driver and modified it
slightly to fix it on my machine. The patch also fixed the breakups on
one of my friend's Windows machine. My other friend reports that the
sound quality got worse with the patch though.

I'm not a DirectSound or Windows expert so maybe someone can explain
what is going on. I've included the patch in this message.



P.S. I'm not on the list so please CC me any replies.

Patch Description:
According to DirectX documentation, you're not supposed to write
between the play cursor and the write cursor, only after the write
cursor. Also enabled position notifications by default. Notifications
and polling were both tested and improved sound quality on my machine.

--- ../SDL-1.2.5.orig/src/audio/windx5/SDL_dx5audio.c 2002-08-24 13:30:49.000000000 -0400
+++ src/audio/windx5/SDL_dx5audio.c 2003-03-07 18:48:31.000000000 -0500
@@ -37,7 +37,7 @@
#include "SDL_dx5audio.h"

/* Define this if you want to use DirectX 6 DirectSoundNotify interface */

/* DirectX function pointers for audio */
@@ -261,7 +261,7 @@
Semi-busy wait, since we have no way of getting play notification
on a primary mixing buffer located in hardware (DirectX 5.0)

  •   result = IDirectSoundBuffer_GetCurrentPosition(mixbuf, &cursor, &junk);
  •   result = IDirectSoundBuffer_GetCurrentPosition(mixbuf, &junk, &cursor);
      if ( result != DS_OK ) {
              if ( result == DSERR_BUFFERLOST ) {

@@ -271,9 +271,8 @@

  •   cursor /= mixlen;
  •   while ( cursor == playing ) {
  •   while((cursor/mixlen) == playing) {
              /* FIXME: find out how much time is left and sleep that long */

@@ -299,12 +298,11 @@

            /* Find out where we are playing */
            result = IDirectSoundBuffer_GetCurrentPosition(mixbuf,
  •                                                           &cursor, &junk);
  •                                           &junk, &cursor);
              if ( result != DS_OK ) {
                      SetDSerror("DirectSound GetCurrentPosition", result);
  •           cursor /= mixlen;


@@ -353,7 +351,7 @@

    /* Figure out which blocks to fill next */
    locked_buf = NULL;
  •   result = IDirectSoundBuffer_GetCurrentPosition(mixbuf, &cursor, &junk);
  •   result = IDirectSoundBuffer_GetCurrentPosition(mixbuf, &junk, &cursor);
      if ( result == DSERR_BUFFERLOST ) {
              result = IDirectSoundBuffer_GetCurrentPosition(mixbuf,

@@ -498,7 +496,7 @@
static int CreateSecondary(LPDIRECTSOUND sndObj, HWND focus,
LPDIRECTSOUNDBUFFER *sndbuf, WAVEFORMATEX *wavefmt, Uint32 chunksize)

  •   const int numchunks = 2;
  •   const int numchunks = 8;
      HRESULT result;
      DSBUFFERDESC format;
      LPVOID pvAudioPtr1, pvAudioPtr2;

On 2006-01-27 11:23:21 +0000, Ryan C. Gordon wrote:

Setting Sam as "QA Contact" on all bugs (even resolved ones) so he'll definitely be in the loop to any further discussion here about SDL.


On 2006-06-23 05:05:57 +0000, Sam Lantinga wrote:

A variation on this patch is in subversion, and is ready for testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

No branches or pull requests

1 participant