diff libao2/ao_dsound.c @ 14947:2f4f347bd5e4

get_space fix by Florian Dietrich <flodt8 at yahoo.de>
author faust3
date Tue, 15 Mar 2005 16:29:18 +0000
parents 6fb9eca97d41
children 6a1eaca0e6c1
line wrap: on
line diff
--- a/libao2/ao_dsound.c	Tue Mar 15 10:57:00 2005 +0000
+++ b/libao2/ao_dsound.c	Tue Mar 15 16:29:18 2005 +0000
@@ -115,6 +115,9 @@
 static int buffer_size = 0;               ///size in bytes of the direct sound buffer   
 static int write_offset = 0;              ///offset of the write cursor in the direct sound buffer
 static int min_free_space = 0;            ///if the free space is below this value get_space() will return 0
+                                          ///there will always be at least this amout of free space to prevent
+                                          ///get_space() from returning wrong values when buffer is 100% full.
+                                          ///will be replaced with nBlockAlign in init()
 static int device_num = 0;                ///wanted device number
 static GUID device;                       ///guid of the device 
 
@@ -482,6 +485,7 @@
 	dsbdesc.lpwfxFormat = (WAVEFORMATEX *)&wformat;
 	buffer_size = dsbdesc.dwBufferBytes;
 	write_offset = 0;
+	min_free_space = wformat.Format.nBlockAlign;
 	ao_data.outburst = wformat.Format.nBlockAlign * 512;
 
 	// create primary buffer and set its format
@@ -579,7 +583,7 @@
 	// write_offset is the postion where we actually write the data to
 	if(space > buffer_size)space -= buffer_size; // write_offset < play_offset
 	if(space < min_free_space)return 0;
-	return space;
+	return space-min_free_space;
 }
 
 /**