1
+ import $ from "jquery" ;
1
2
import _ from "underscore" ;
2
3
import { Cpu6502 } from "jsbeeb/6502" ;
3
4
import * as canvasLib from "jsbeeb/canvas" ;
4
5
import { Video } from "jsbeeb/video" ;
5
6
import { Debugger } from "jsbeeb/web/debug" ;
6
- import { FakeSoundChip } from "jsbeeb/soundchip" ;
7
- import { FakeDdNoise } from "jsbeeb/ddnoise" ;
7
+ import { AudioHandler } from "jsbeeb/web/audio-handler" ;
8
8
import * as models from "jsbeeb/models" ;
9
9
import { Cmos } from "jsbeeb/cmos" ;
10
10
import * as utils from "jsbeeb/utils" ;
@@ -98,8 +98,14 @@ export class Emulator {
98
98
99
99
this . video = new Video ( Model . isMaster , this . canvas . fb32 , _ . bind ( this . paint , this ) ) ;
100
100
101
- this . soundChip = new FakeSoundChip ( ) ;
102
- this . ddNoise = new FakeDdNoise ( ) ;
101
+ const audioFilterFreq = 7000 ;
102
+ const audioFilterQ = 5 ;
103
+ const noSeek = false ;
104
+ this . audioHandler = new AudioHandler ( $ ( "#audio-warning" ) , audioFilterFreq , audioFilterQ , noSeek ) ;
105
+ // Firefox will report that audio is suspended even when it will
106
+ // start playing without user interaction, so we need to delay a
107
+ // little to get a reliable indication.
108
+ window . setTimeout ( ( ) => this . audioHandler . checkStatus ( ) , 1000 ) ;
103
109
104
110
this . dbgr = new Debugger ( this . video ) ;
105
111
const cmos = new Cmos ( {
@@ -118,8 +124,8 @@ export class Emulator {
118
124
Model ,
119
125
this . dbgr ,
120
126
this . video ,
121
- this . soundChip ,
122
- this . ddNoise ,
127
+ this . audioHandler . soundChip ,
128
+ this . audioHandler . ddNoise ,
123
129
cmos ,
124
130
config ,
125
131
) ;
@@ -138,7 +144,7 @@ export class Emulator {
138
144
}
139
145
140
146
async initialise ( ) {
141
- await Promise . all ( [ this . cpu . initialise ( ) , this . ddNoise . initialise ( ) ] ) ;
147
+ await Promise . all ( [ this . audioHandler . initialise ( ) , this . cpu . initialise ( ) ] ) ;
142
148
this . ready = true ;
143
149
}
144
150
@@ -157,11 +163,13 @@ export class Emulator {
157
163
158
164
start ( ) {
159
165
if ( this . running ) return ;
166
+ this . audioHandler . unmute ( ) ;
160
167
this . running = true ;
161
168
requestAnimationFrame ( this . onAnimFrame ) ;
162
169
}
163
170
164
171
pause ( ) {
172
+ this . audioHandler . mute ( ) ;
165
173
this . running = false ;
166
174
}
167
175
@@ -293,6 +301,7 @@ export class Emulator {
293
301
294
302
keyDown ( event ) {
295
303
if ( ! this . running ) return ;
304
+ this . audioHandler . tryResume ( ) ;
296
305
297
306
const code = this . keyCode ( event ) ;
298
307
const processor = this . cpu ;
@@ -317,6 +326,7 @@ export class Emulator {
317
326
}
318
327
319
328
mouseMove ( event ) {
329
+ this . audioHandler . tryResume ( ) ;
320
330
this . showCoords = true ;
321
331
const processor = this . cpu ;
322
332
const screen = this . root . find ( ".screen" ) ;
0 commit comments