Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

windows: improved AVI sound sync (solution for the 32kHz issue)

By: a guest on Jan 30th, 2011  |  syntax: Diff  |  size: 2.20 KB  |  views: 60  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. From d987fc88103f5623b504785b9ee0f53921fa61de Mon Sep 17 00:00:00 2001
  2. From: gocha <gochaism@gmail.com>
  3. Date: Sun, 30 Jan 2011 15:52:07 +0900
  4. Subject: [PATCH] windows: improved AVI sound sync
  5.  
  6. ---
  7.  win32/win32.cpp |   19 +++++++++++++------
  8.  1 files changed, 13 insertions(+), 6 deletions(-)
  9.  
  10. diff --git a/win32/win32.cpp b/win32/win32.cpp
  11. index 8672d5a..1f1dad1 100644
  12. --- a/win32/win32.cpp
  13. +++ b/win32/win32.cpp
  14. @@ -201,6 +201,7 @@
  15.  #include <io.h>
  16.  //#define DEBUGGER
  17.  
  18. +#include <math.h>
  19.  #ifndef max
  20.  #define max(a, b) (((a) > (b)) ? (a) : (b))
  21.  #endif
  22. @@ -219,7 +220,8 @@ bool8 do_frame_adjust=false;
  23.  static uint8* avi_buffer = NULL;
  24.  static uint8* avi_sound_buffer = NULL;
  25.  static int avi_sound_bytes_per_sample = 0;
  26. -static int avi_sound_samples_per_update = 0;
  27. +static double avi_sound_samples_per_update = 0;
  28. +static double avi_sound_samples_error = 0;
  29.  static int avi_width = 0;
  30.  static int avi_height = 0;
  31.  static int avi_pitch = 0;
  32. @@ -1415,12 +1417,13 @@ void DoAVIOpen(const TCHAR* filename)
  33.                 return;
  34.         }
  35.  
  36. -       avi_sound_samples_per_update = (wfx.nSamplesPerSec * frameskip) / framerate;
  37. +       avi_sound_samples_per_update = (double) (wfx.nSamplesPerSec * frameskip) / framerate;
  38.         avi_sound_bytes_per_sample = wfx.nBlockAlign;
  39. +       avi_sound_samples_error = 0;
  40.  
  41.         // init buffers
  42.         avi_buffer = new uint8[avi_image_size];
  43. -       avi_sound_buffer = new uint8[avi_sound_samples_per_update * avi_sound_bytes_per_sample];
  44. +       avi_sound_buffer = new uint8[(int) ceil(avi_sound_samples_per_update) * avi_sound_bytes_per_sample];
  45.  }
  46.  
  47.  void DoAVIClose(int reason)
  48. @@ -1520,9 +1523,13 @@ void DoAVIVideoFrame(SSurface* source_surface)
  49.         if(pwfex)
  50.         {
  51.                 const int stereo_multiplier = (Settings.Stereo) ? 2 : 1;
  52. -              
  53. -               S9xMixSamples(avi_sound_buffer, avi_sound_samples_per_update*stereo_multiplier);
  54.  
  55. -               AVIAddSoundSamples(avi_sound_buffer, avi_sound_samples_per_update, GUI.AVIOut);
  56. +               avi_sound_samples_error += avi_sound_samples_per_update;
  57. +               int samples = (int) avi_sound_samples_error;
  58. +               avi_sound_samples_error -= samples;
  59. +
  60. +               S9xMixSamples(avi_sound_buffer, samples*stereo_multiplier);
  61. +
  62. +               AVIAddSoundSamples(avi_sound_buffer, samples, GUI.AVIOut);
  63.         }
  64.  }
  65. --
  66. 1.7.3.1.msysgit.0
clone this paste RAW Paste Data