2016-10-27 22:47:39 +02:00
|
|
|
namespace pxsim {
|
|
|
|
export class SpeakerState {
|
|
|
|
frequency: number;
|
|
|
|
ms: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
namespace pxsim.music {
|
|
|
|
|
2017-12-14 19:34:04 +01:00
|
|
|
export function speakerPlayTone(frequency: number, ms: number) {
|
2016-10-27 22:47:39 +02:00
|
|
|
const b = board();
|
|
|
|
b.speakerState.frequency = frequency;
|
|
|
|
b.speakerState.ms = ms;
|
|
|
|
|
|
|
|
runtime.queueDisplayUpdate();
|
|
|
|
let cb = getResume();
|
|
|
|
AudioContextManager.tone(frequency, 1);
|
|
|
|
if (ms <= 0) cb();
|
|
|
|
else {
|
|
|
|
setTimeout(() => {
|
|
|
|
AudioContextManager.stop();
|
|
|
|
b.speakerState.frequency = 0;
|
|
|
|
b.speakerState.ms = 0;
|
|
|
|
runtime.queueDisplayUpdate();
|
|
|
|
cb()
|
|
|
|
}, ms);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|