diff options
| author | Torbjörn Andersson | 2004-10-19 08:47:10 +0000 | 
|---|---|---|
| committer | Torbjörn Andersson | 2004-10-19 08:47:10 +0000 | 
| commit | 61e438df2287d83dfe17e2497da0a41672e6df05 (patch) | |
| tree | 4d8ea47afb53c9c05a6450fa437602b02f9d413f | |
| parent | 4d3913d1b21d00692b0f761a8ade9d8b506cd7e0 (diff) | |
| download | scummvm-rg350-61e438df2287d83dfe17e2497da0a41672e6df05.tar.gz scummvm-rg350-61e438df2287d83dfe17e2497da0a41672e6df05.tar.bz2 scummvm-rg350-61e438df2287d83dfe17e2497da0a41672e6df05.zip  | |
Made the calculation of _samples_per_tick a bit less prone to arithmetic
overflow. It failed if the output rate was 44100 Hz. (It didn't use to, but
somewhere along the line an unsigned value was changed to a signed. This
seemed like a better fix, though.)
svn-id: r15610
| -rw-r--r-- | backends/midi/emumidi.h | 12 | 
1 files changed, 10 insertions, 2 deletions
diff --git a/backends/midi/emumidi.h b/backends/midi/emumidi.h index 787d8912f7..529662b7ee 100644 --- a/backends/midi/emumidi.h +++ b/backends/midi/emumidi.h @@ -54,7 +54,14 @@ public:  	int open() {  		_isOpen = true; -		_samples_per_tick = (getRate() << FIXP_SHIFT) / BASE_FREQ; + +		int d = getRate() / BASE_FREQ; +		int r = getRate() % BASE_FREQ; + +		// This is equivalent to (getRate() << FIXP_SHIFT) / BASE_FREQ +		// but less prone to arithmetic overflow. + +		_samples_per_tick = (d << FIXP_SHIFT) + (r << FIXP_SHIFT) / BASE_FREQ;  		return 0;  	} @@ -71,11 +78,12 @@ public:  		const int stereoFactor = isStereo() ? 2 : 1;  		int len = numSamples / stereoFactor;  		int step; -	 +  		do {  			step = len;  			if (step > (_next_tick >> FIXP_SHIFT))  				step = (_next_tick >> FIXP_SHIFT); +  			generate_samples(data, step);  			_next_tick -= step << FIXP_SHIFT;  | 
