Commit 80f7037

Nick committed on
Fixed sound bug, outputs 44.1khz 32-bit audio now
commit 80f703728142374c44ac9a0383fd9351f2099d9b parent 0d394f1
3 changed files +21−24
ModifiedCpu/z80cpu.pas +1−1
@@ -18,7 +18,7 @@ implementation
18 18
19 uses vars, machine; 19 uses vars, machine;
20 20
21 // temporäre Variablen 21 // temporary variables
22 var 22 var
23 b: Pair; 23 b: Pair;
24 cycle: byte; 24 cycle: byte;
ModifiedGBEmu.lpi +1−1
@@ -26,7 +26,7 @@
26 <RunParams> 26 <RunParams>
27 <local> 27 <local>
28 <FormatVersion Value="1"/> 28 <FormatVersion Value="1"/>
29 <CommandLineParams Value="C:\Projects\GB-Stuff\gb-test-roms-master\gb-test-roms-master\cpu_instrs\cpu_instrs.gb"/> 29 <CommandLineParams Value="C:\Projects\GB-Stuff\sml.gb"/>
30 </local> 30 </local>
31 </RunParams> 31 </RunParams>
32 <RequiredPackages Count="2"> 32 <RequiredPackages Count="2">
ModifiedSound/sound.pas +19−22
@@ -155,16 +155,15 @@ implementation
155 uses vars, bass; 155 uses vars, bass;
156 156
157 const 157 const
158 sampleCycles: longint = (8192 * 1024) div 22050; 158 VolumeDecreaseCoeff = 6; // It's really loud otherwise...
159 TooFullThreshold: DWORD = 5120; // (0.2s) 159 playbackFrequency = 44100;
160 sampleCycles: longint = (8192 * 1024) div playbackFrequency;
161 TooFullThreshold: DWORD = (playbackFrequency div 10)*sizeof(single); //0.1s
160 162
161 var 163 var
162 playStream: HStream; 164 playStream: HStream;
163 bufPos, bufCycles, bufLVal, bufRVal: integer; 165 bufCycles, bufLVal, bufRVal: integer;
164 buf: array[0..2047] of byte;
165 166
166 // HACK: This is kind of a hack. We should probably figure out a way to
167 // tie playback rate to the emulation function instead of this, but it works.
168 function SoundBufferTooFull: Boolean; 167 function SoundBufferTooFull: Boolean;
169 begin 168 begin
170 Result := BASS_ChannelGetData(PlayStream, nil, BASS_DATA_AVAILABLE) > TooFullThreshold; 169 Result := BASS_ChannelGetData(PlayStream, nil, BASS_DATA_AVAILABLE) > TooFullThreshold;
@@ -175,11 +174,11 @@ begin
175 if soundEnable then 174 if soundEnable then
176 exit; 175 exit;
177 176
178 BASS_Init(-1, 22050, 0, 0, nil); 177 BASS_Init(-1, playbackFrequency, 0, 0, nil);
179 PlayStream := BASS_StreamCreate( 178 PlayStream := BASS_StreamCreate(
180 22050, 179 playbackFrequency,
181 2, 180 2,
182 BASS_SAMPLE_8BITS, 181 BASS_SAMPLE_FLOAT,
183 StreamProc(STREAMPROC_PUSH), 182 StreamProc(STREAMPROC_PUSH),
184 nil); 183 nil);
185 BASS_ChannelPlay(PlayStream, True); 184 BASS_ChannelPlay(PlayStream, True);
@@ -200,28 +199,25 @@ begin
200 soundEnable := False; 199 soundEnable := False;
201 end; 200 end;
202 201
203 procedure SoundDoOut(l, r: byte; cycles: integer); 202 procedure SoundDoOut(l, r: Integer; cycles: integer);
203 var
204 buf: array[0..1] of Single;
204 begin 205 begin
205 Inc(bufLVal, l * cycles); 206 Inc(bufLVal, l * cycles);
206 Inc(bufRVal, r * cycles); 207 Inc(bufRVal, r * cycles);
207 Inc(bufCycles, cycles); 208 Inc(bufCycles, cycles);
208 if bufCycles >= sampleCycles then 209 if bufCycles >= sampleCycles then
209 begin 210 begin
210 buf[bufPos] := bufRVal div sampleCycles; 211 buf[0] := ((bufRVal div sampleCycles) / 512.0)/VolumeDecreaseCoeff;
211 buf[bufPos + 1] := bufLVal div sampleCycles; 212 buf[1] := ((bufLVal div sampleCycles) / 512.0)/VolumeDecreaseCoeff;
212 bufCycles := 0; 213 bufCycles := 0;
213 Inc(bufPos, 2);
214 bufLVal := 0; 214 bufLVal := 0;
215 bufRVal := 0; 215 bufRVal := 0;
216 if bufPos >= 2048 then 216 BASS_StreamPutData(PlayStream, @buf, 8 {2 32-bit float samples});
217 begin
218 BASS_StreamPutData(PlayStream, @buf, 2048);
219 bufPos := 0;
220 end;
221 end; 217 end;
222 end; 218 end;
223 219
224 procedure SoundOutBits(l, r: byte; cycles: integer); 220 procedure SoundOutBits(l, r: Integer; cycles: integer);
225 var 221 var
226 left: integer; 222 left: integer;
227 begin 223 begin
@@ -555,9 +551,10 @@ begin
555 Dec(r, vol[snd[4].Vol]); 551 Dec(r, vol[snd[4].Vol]);
556 end; 552 end;
557 553
558 l := shortint(l shr 2) + 128; 554 SoundOutBits(l, r, cycles);
559 r := shortint(r shr 2) + 128; 555
560 SoundOutBits(l, r, cycles) 556 l := 0;
557 r := 0
561 end; 558 end;
562 559
563 procedure SoundSetCycles(n: integer); 560 procedure SoundSetCycles(n: integer);