comparison 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
comparison
equal deleted inserted replaced
14946:806234e0a465 14947:2f4f347bd5e4
113 static LPDIRECTSOUNDBUFFER hdspribuf = NULL; ///primary direct sound buffer 113 static LPDIRECTSOUNDBUFFER hdspribuf = NULL; ///primary direct sound buffer
114 static LPDIRECTSOUNDBUFFER hdsbuf = NULL; ///secondary direct sound buffer (stream buffer) 114 static LPDIRECTSOUNDBUFFER hdsbuf = NULL; ///secondary direct sound buffer (stream buffer)
115 static int buffer_size = 0; ///size in bytes of the direct sound buffer 115 static int buffer_size = 0; ///size in bytes of the direct sound buffer
116 static int write_offset = 0; ///offset of the write cursor in the direct sound buffer 116 static int write_offset = 0; ///offset of the write cursor in the direct sound buffer
117 static int min_free_space = 0; ///if the free space is below this value get_space() will return 0 117 static int min_free_space = 0; ///if the free space is below this value get_space() will return 0
118 ///there will always be at least this amout of free space to prevent
119 ///get_space() from returning wrong values when buffer is 100% full.
120 ///will be replaced with nBlockAlign in init()
118 static int device_num = 0; ///wanted device number 121 static int device_num = 0; ///wanted device number
119 static GUID device; ///guid of the device 122 static GUID device; ///guid of the device
120 123
121 /***************************************************************************************/ 124 /***************************************************************************************/
122 125
480 483
481 dsbdesc.dwBufferBytes = ao_data.buffersize; 484 dsbdesc.dwBufferBytes = ao_data.buffersize;
482 dsbdesc.lpwfxFormat = (WAVEFORMATEX *)&wformat; 485 dsbdesc.lpwfxFormat = (WAVEFORMATEX *)&wformat;
483 buffer_size = dsbdesc.dwBufferBytes; 486 buffer_size = dsbdesc.dwBufferBytes;
484 write_offset = 0; 487 write_offset = 0;
488 min_free_space = wformat.Format.nBlockAlign;
485 ao_data.outburst = wformat.Format.nBlockAlign * 512; 489 ao_data.outburst = wformat.Format.nBlockAlign * 512;
486 490
487 // create primary buffer and set its format 491 // create primary buffer and set its format
488 492
489 res = IDirectSound_CreateSoundBuffer( hds, &dsbpridesc, &hdspribuf, NULL ); 493 res = IDirectSound_CreateSoundBuffer( hds, &dsbpridesc, &hdspribuf, NULL );
577 // play_cursor is the actual postion of the play cursor 581 // play_cursor is the actual postion of the play cursor
578 // write_cursor is the position after which it is assumed to be save to write data 582 // write_cursor is the position after which it is assumed to be save to write data
579 // write_offset is the postion where we actually write the data to 583 // write_offset is the postion where we actually write the data to
580 if(space > buffer_size)space -= buffer_size; // write_offset < play_offset 584 if(space > buffer_size)space -= buffer_size; // write_offset < play_offset
581 if(space < min_free_space)return 0; 585 if(space < min_free_space)return 0;
582 return space; 586 return space-min_free_space;
583 } 587 }
584 588
585 /** 589 /**
586 \brief play 'len' bytes of 'data' 590 \brief play 'len' bytes of 'data'
587 \param data pointer to the data to play 591 \param data pointer to the data to play