Files
86Box/src/sound/snd_speaker.c
waltje 7c67e867c8 Major commit, cleaning a lot of old stuff.
IBM.H is gone, video stuff re-organized. Keyboard stuff reorganized.
Machines that have their own video, mouse and/or keyboard now have all this in their machine file.
Fixed and other cleanups here and there.
2017-11-05 02:00:50 -05:00

69 lines
1.5 KiB
C

#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#include "../86box.h"
#include "../pit.h"
#include "sound.h"
#include "snd_speaker.h"
int speaker_mute = 0;
int speaker_gated = 0;
int speaker_enable = 0, was_speaker_enable = 0;
int gated,speakval,speakon;
static int16_t speaker_buffer[SOUNDBUFLEN];
static int speaker_pos = 0;
void speaker_update(void)
{
int16_t val;
for (; speaker_pos < sound_pos_global; speaker_pos++)
{
if (speaker_gated && was_speaker_enable)
{
if (!pit.m[2] || pit.m[2]==4)
val = speakval;
else if (pit.l[2] < 0x40)
val = 0xa00;
else
val = speakon ? 0x1400 : 0;
}
else
val = was_speaker_enable ? 0x1400 : 0;
if (!speaker_enable)
was_speaker_enable = 0;
speaker_buffer[speaker_pos] = val;
}
}
static void speaker_get_buffer(int32_t *buffer, int len, void *p)
{
int c;
speaker_update();
if (!speaker_mute)
{
for (c = 0; c < len * 2; c++)
buffer[c] += speaker_buffer[c >> 1];
}
speaker_pos = 0;
}
void speaker_init(void)
{
sound_add_handler(speaker_get_buffer, NULL);
speaker_mute = 0;
}