diff --git a/src/sound/snd_speaker.c b/src/sound/snd_speaker.c
index 9c40d5e89..799614fea 100644
--- a/src/sound/snd_speaker.c
+++ b/src/sound/snd_speaker.c
@@ -1,3 +1,21 @@
+/*
+ * 86Box A hypervisor and IBM PC system emulator that specializes in
+ * running old operating systems and software designed for IBM
+ * PC systems and compatibles from 1981 through fairly recent
+ * system designs based on the PCI bus.
+ *
+ * This file is part of the 86Box distribution.
+ *
+ * Emulation of the PC speaker.
+ *
+ * Version: @(#)snd_speaker.c 1.0.0 2019/11/11
+ *
+ * Authors: Sarah Walker,
+ * Miran Grca,
+ *
+ * Copyright 2008-2019 Sarah Walker.
+ * Copyright 2016-2019 Miran Grca.
+ */
#include
#include
#include
@@ -23,20 +41,31 @@ void
speaker_update(void)
{
int32_t val;
+ double timer2_count, amplitude;
+
+ timer2_count = pit.l[2] ? ((double) pit.l[2]) : 65536.0;
+ amplitude = ((timer2_count / 64.0) * 10240.0) - 5120.0;
+
+ if (amplitude > 5120.0)
+ amplitude = 5120.0;
if (speaker_pos >= sound_pos_global)
return;
for (; speaker_pos < sound_pos_global; speaker_pos++) {
if (speaker_gated && was_speaker_enable) {
- if (!pit.m[2] || pit.m[2]==4)
- val = speakval;
+ if ((pit.m[2] == 0) || (pit.m[2] == 4))
+ val = (int32_t) amplitude;
else if (pit.l[2] < 0x40)
val = 0xa00;
else
val = speakon ? 0x1400 : 0;
- } else
- val = was_speaker_enable ? 0x1400 : 0;
+ } else {
+ if (pit.m[2] == 1)
+ val = was_speaker_enable ? (int32_t) amplitude : 0;
+ else
+ val = was_speaker_enable ? 0x1400 : 0;
+ }
if (!speaker_enable)
was_speaker_enable = 0;