src/audio/windx5/SDL_dx5audio.c
branchSDL-1.3
changeset 1701 442248d4e738
parent 1668 4da1ee79c9af
     1.1 --- a/src/audio/windx5/SDL_dx5audio.c	Fri Jun 23 08:40:46 2006 +0000
     1.2 +++ b/src/audio/windx5/SDL_dx5audio.c	Fri Jun 23 08:48:24 2006 +0000
     1.3 @@ -263,7 +263,7 @@
     1.4      /* Semi-busy wait, since we have no way of getting play notification
     1.5         on a primary mixing buffer located in hardware (DirectX 5.0)
     1.6       */
     1.7 -    result = IDirectSoundBuffer_GetCurrentPosition(mixbuf, &cursor, &junk);
     1.8 +    result = IDirectSoundBuffer_GetCurrentPosition(mixbuf, &junk, &cursor);
     1.9      if (result != DS_OK) {
    1.10          if (result == DSERR_BUFFERLOST) {
    1.11              IDirectSoundBuffer_Restore(mixbuf);
    1.12 @@ -273,11 +273,10 @@
    1.13  #endif
    1.14          return;
    1.15      }
    1.16 -    cursor /= mixlen;
    1.17  
    1.18 -    while (cursor == playing) {
    1.19 +    while ((cursor / mixlen) == lastchunk) {
    1.20          /* FIXME: find out how much time is left and sleep that long */
    1.21 -        SDL_Delay(10);
    1.22 +        SDL_Delay(1);
    1.23  
    1.24          /* Try to restore a lost sound buffer */
    1.25          IDirectSoundBuffer_GetStatus(mixbuf, &status);
    1.26 @@ -301,12 +300,11 @@
    1.27  
    1.28          /* Find out where we are playing */
    1.29          result = IDirectSoundBuffer_GetCurrentPosition(mixbuf,
    1.30 -                                                       &cursor, &junk);
    1.31 +                                                       &junk, &cursor);
    1.32          if (result != DS_OK) {
    1.33              SetDSerror("DirectSound GetCurrentPosition", result);
    1.34              return;
    1.35          }
    1.36 -        cursor /= mixlen;
    1.37      }
    1.38  }
    1.39  
    1.40 @@ -358,18 +356,31 @@
    1.41  
    1.42      /* Figure out which blocks to fill next */
    1.43      locked_buf = NULL;
    1.44 -    result = IDirectSoundBuffer_GetCurrentPosition(mixbuf, &cursor, &junk);
    1.45 +    result = IDirectSoundBuffer_GetCurrentPosition(mixbuf, &junk, &cursor);
    1.46      if (result == DSERR_BUFFERLOST) {
    1.47          IDirectSoundBuffer_Restore(mixbuf);
    1.48          result = IDirectSoundBuffer_GetCurrentPosition(mixbuf,
    1.49 -                                                       &cursor, &junk);
    1.50 +                                                       &junk, &cursor);
    1.51      }
    1.52      if (result != DS_OK) {
    1.53          SetDSerror("DirectSound GetCurrentPosition", result);
    1.54          return (NULL);
    1.55      }
    1.56      cursor /= mixlen;
    1.57 -    playing = cursor;
    1.58 +#ifdef DEBUG_SOUND
    1.59 +    /* Detect audio dropouts */
    1.60 +    {
    1.61 +        DWORD spot = cursor;
    1.62 +        if (spot < lastchunk) {
    1.63 +            spot += NUM_BUFFERS;
    1.64 +        }
    1.65 +        if (spot > lastchunk + 1) {
    1.66 +            fprintf(stderr, "Audio dropout, missed %d fragments\n",
    1.67 +                    (spot - (lastchunk + 1)));
    1.68 +        }
    1.69 +    }
    1.70 +#endif
    1.71 +    lastchunk = cursor;
    1.72      cursor = (cursor + 1) % NUM_BUFFERS;
    1.73      cursor *= mixlen;
    1.74  
    1.75 @@ -511,7 +522,7 @@
    1.76                  LPDIRECTSOUNDBUFFER * sndbuf, WAVEFORMATEX * wavefmt,
    1.77                  Uint32 chunksize)
    1.78  {
    1.79 -    const int numchunks = 2;
    1.80 +    const int numchunks = 8;
    1.81      HRESULT result;
    1.82      DSBUFFERDESC format;
    1.83      LPVOID pvAudioPtr1, pvAudioPtr2;
    1.84 @@ -563,10 +574,9 @@
    1.85  
    1.86      /* Silence the initial audio buffer */
    1.87      result = IDirectSoundBuffer_Lock(*sndbuf, 0, format.dwBufferBytes,
    1.88 -                                     (LPVOID *) & pvAudioPtr1,
    1.89 -                                     &dwAudioBytes1,
    1.90 -                                     (LPVOID *) & pvAudioPtr2,
    1.91 -                                     &dwAudioBytes2, DSBLOCK_ENTIREBUFFER);
    1.92 +                                     (LPVOID *) & pvAudioPtr1, &dwAudioBytes1,
    1.93 +                                     (LPVOID *) & pvAudioPtr2, &dwAudioBytes2,
    1.94 +                                     DSBLOCK_ENTIREBUFFER);
    1.95      if (result == DS_OK) {
    1.96          if (wavefmt->wBitsPerSample == 8) {
    1.97              SDL_memset(pvAudioPtr1, 0x80, dwAudioBytes1);
    1.98 @@ -706,7 +716,7 @@
    1.99  #endif
   1.100  
   1.101      /* The buffer will auto-start playing in DX5_WaitAudio() */
   1.102 -    playing = 0;
   1.103 +    lastchunk = 0;
   1.104      mixlen = spec->size;
   1.105  
   1.106  #ifdef USE_POSITION_NOTIFY