Slight sound cleanups.
This commit is contained in:
@@ -43,7 +43,6 @@ enum fluid_interp {
|
||||
|
||||
extern void givealbuffer_midi(void *buf, uint32_t size);
|
||||
extern void al_set_midi(int freq, int buf_size);
|
||||
extern int soundon;
|
||||
|
||||
static void *fluidsynth_handle; /* handle to FluidSynth DLL */
|
||||
|
||||
@@ -152,8 +151,7 @@ static void fluidsynth_thread(void *param)
|
||||
buf_pos += buf_size;
|
||||
if (buf_pos >= data->buf_size)
|
||||
{
|
||||
if (soundon)
|
||||
givealbuffer_midi(data->buffer, data->buf_size / sizeof(float));
|
||||
givealbuffer_midi(data->buffer, data->buf_size / sizeof(float));
|
||||
buf_pos = 0;
|
||||
}
|
||||
}
|
||||
@@ -166,30 +164,10 @@ static void fluidsynth_thread(void *param)
|
||||
buf_pos += buf_size;
|
||||
if (buf_pos >= data->buf_size)
|
||||
{
|
||||
if (soundon)
|
||||
givealbuffer_midi(data->buffer_int16, data->buf_size / sizeof(int16_t));
|
||||
givealbuffer_midi(data->buffer_int16, data->buf_size / sizeof(int16_t));
|
||||
buf_pos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (sound_is_float)
|
||||
{
|
||||
memset(data->buffer, 0, data->buf_size * sizeof(float));
|
||||
if (data->synth)
|
||||
f_fluid_synth_write_float(data->synth, data->buf_size/2, data->buffer, 0, 2, data->buffer, 1, 2);
|
||||
if (soundon)
|
||||
givealbuffer_midi(data->buffer, data->buf_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
memset(data->buffer, 0, data->buf_size * sizeof(int16_t));
|
||||
if (data->synth)
|
||||
f_fluid_synth_write_s16(data->synth, data->buf_size/2, data->buffer_int16, 0, 2, data->buffer_int16, 1, 2);
|
||||
if (soundon)
|
||||
givealbuffer_midi(data->buffer_int16, data->buf_size);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -115,8 +115,6 @@ void mt32_poll()
|
||||
}
|
||||
}
|
||||
|
||||
extern int soundon;
|
||||
|
||||
static void mt32_thread(void *param)
|
||||
{
|
||||
int buf_pos = 0;
|
||||
@@ -139,8 +137,7 @@ static void mt32_thread(void *param)
|
||||
buf_pos += bsize;
|
||||
if (buf_pos >= buf_size)
|
||||
{
|
||||
if (soundon)
|
||||
givealbuffer_midi(buffer, buf_size / sizeof(float));
|
||||
givealbuffer_midi(buffer, buf_size / sizeof(float));
|
||||
buf_pos = 0;
|
||||
}
|
||||
}
|
||||
@@ -152,8 +149,7 @@ static void mt32_thread(void *param)
|
||||
buf_pos += bsize;
|
||||
if (buf_pos >= buf_size)
|
||||
{
|
||||
if (soundon)
|
||||
givealbuffer_midi(buffer_int16, buf_size / sizeof(int16_t));
|
||||
givealbuffer_midi(buffer_int16, buf_size / sizeof(int16_t));
|
||||
buf_pos = 0;
|
||||
}
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*
|
||||
* Sound Blaster emulation.
|
||||
*
|
||||
* Version: @(#)sound_sb.c 1.0.14 2018/10/18
|
||||
* Version: @(#)sound_sb.c 1.0.15 2018/10/26
|
||||
*
|
||||
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
|
||||
* Miran Grca, <mgrca8@gmail.com>
|
||||
@@ -136,9 +136,6 @@ typedef struct sb_t
|
||||
};
|
||||
mpu_t *mpu;
|
||||
emu8k_t emu8k;
|
||||
#if 0
|
||||
sb_ct1745_mixer_t temp_mixer_sb16;
|
||||
#endif
|
||||
|
||||
int pos;
|
||||
|
||||
@@ -298,44 +295,6 @@ static void sb_get_buffer_sbpro(int32_t *buffer, int len, void *p)
|
||||
sb->dsp.pos = 0;
|
||||
}
|
||||
|
||||
// FIXME: See why this causes weird audio glitches in some situations.
|
||||
#if 0
|
||||
static void sb_process_buffer_sb16(int32_t *buffer, int len, void *p)
|
||||
{
|
||||
sb_t *sb = (sb_t *)p;
|
||||
sb_ct1745_mixer_t *mixer = &sb->temp_mixer_sb16;
|
||||
|
||||
int c;
|
||||
|
||||
for (c = 0; c < len * 2; c += 2)
|
||||
{
|
||||
int32_t out_l = 0, out_r = 0;
|
||||
|
||||
out_l = ((int32_t)(low_fir_sb16(0, (float)buffer[c]) * mixer->cd_l) / 3) >> 15;
|
||||
out_r = ((int32_t)(low_fir_sb16(1, (float)buffer[c + 1]) * mixer->cd_r) / 3) >> 15;
|
||||
|
||||
out_l = (out_l * mixer->master_l) >> 15;
|
||||
out_r = (out_r * mixer->master_r) >> 15;
|
||||
|
||||
if (mixer->bass_l != 8 || mixer->bass_r != 8 || mixer->treble_l != 8 || mixer->treble_r != 8)
|
||||
{
|
||||
/* This is not exactly how one does bass/treble controls, but the end result is like it. A better implementation would reduce the cpu usage */
|
||||
if (mixer->bass_l>8) out_l += (int32_t)(low_iir(0, (float)out_l)*sb_bass_treble_4bits[mixer->bass_l]);
|
||||
if (mixer->bass_r>8) out_r += (int32_t)(low_iir(1, (float)out_r)*sb_bass_treble_4bits[mixer->bass_r]);
|
||||
if (mixer->treble_l>8) out_l += (int32_t)(high_iir(0, (float)out_l)*sb_bass_treble_4bits[mixer->treble_l]);
|
||||
if (mixer->treble_r>8) out_r += (int32_t)(high_iir(1, (float)out_r)*sb_bass_treble_4bits[mixer->treble_r]);
|
||||
if (mixer->bass_l<8) out_l = (int32_t)((out_l )*sb_bass_treble_4bits[mixer->bass_l] + low_cut_iir(0, (float)out_l)*(1.f-sb_bass_treble_4bits[mixer->bass_l]));
|
||||
if (mixer->bass_r<8) out_r = (int32_t)((out_r )*sb_bass_treble_4bits[mixer->bass_r] + low_cut_iir(1, (float)out_r)*(1.f-sb_bass_treble_4bits[mixer->bass_r]));
|
||||
if (mixer->treble_l<8) out_l = (int32_t)((out_l )*sb_bass_treble_4bits[mixer->treble_l] + high_cut_iir(0, (float)out_l)*(1.f-sb_bass_treble_4bits[mixer->treble_l]));
|
||||
if (mixer->treble_r<8) out_r = (int32_t)((out_r )*sb_bass_treble_4bits[mixer->treble_r] + high_cut_iir(1, (float)out_r)*(1.f-sb_bass_treble_4bits[mixer->treble_r]));
|
||||
}
|
||||
|
||||
buffer[c] = (out_l << mixer->output_gain_L);
|
||||
buffer[c + 1] = (out_r << mixer->output_gain_R);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void sb_get_buffer_sb16(int32_t *buffer, int len, void *p)
|
||||
{
|
||||
sb_t *sb = (sb_t *)p;
|
||||
@@ -407,9 +366,6 @@ static void sb_get_buffer_sb16(int32_t *buffer, int len, void *p)
|
||||
sb->pos = 0;
|
||||
sb->opl.pos = 0;
|
||||
sb->dsp.pos = 0;
|
||||
#if 0
|
||||
memcpy(&sb->temp_mixer_sb16, &sb->mixer_sb16, sizeof(sb_ct1745_mixer_t));
|
||||
#endif
|
||||
}
|
||||
#ifdef SB_DSP_RECORD_DEBUG
|
||||
int old_dsp_rec_pos=0;
|
||||
@@ -520,9 +476,6 @@ static void sb_get_buffer_emu8k(int32_t *buffer, int len, void *p)
|
||||
sb->opl.pos = 0;
|
||||
sb->dsp.pos = 0;
|
||||
sb->emu8k.pos = 0;
|
||||
#if 0
|
||||
memcpy(&sb->temp_mixer_sb16, &sb->mixer_sb16, sizeof(sb_ct1745_mixer_t));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -1292,9 +1245,6 @@ void *sb_16_init()
|
||||
}
|
||||
io_sethandler(addr+4, 0x0002, sb_ct1745_mixer_read, NULL, NULL, sb_ct1745_mixer_write, NULL, NULL, sb);
|
||||
sound_add_handler(sb_get_buffer_sb16, sb);
|
||||
#if 0
|
||||
sound_add_process_handler(sb_process_buffer_sb16, sb);
|
||||
#endif
|
||||
if (mpu_addr) {
|
||||
sb->mpu = (mpu_t *) malloc(sizeof(mpu_t));
|
||||
memset(sb->mpu, 0, sizeof(mpu_t));
|
||||
@@ -1302,9 +1252,6 @@ void *sb_16_init()
|
||||
sb_dsp_set_mpu(sb->mpu);
|
||||
} else
|
||||
sb->mpu = NULL;
|
||||
#if 0
|
||||
memcpy(&sb->temp_mixer_sb16, &sb->mixer_sb16, sizeof(sb_ct1745_mixer_t));
|
||||
#endif
|
||||
|
||||
return sb;
|
||||
}
|
||||
@@ -1341,9 +1288,6 @@ void *sb_awe32_init()
|
||||
}
|
||||
io_sethandler(addr+4, 0x0002, sb_ct1745_mixer_read, NULL, NULL, sb_ct1745_mixer_write, NULL, NULL, sb);
|
||||
sound_add_handler(sb_get_buffer_emu8k, sb);
|
||||
#if 0
|
||||
sound_add_process_handler(sb_process_buffer_sb16, sb);
|
||||
#endif
|
||||
if (mpu_addr) {
|
||||
sb->mpu = (mpu_t *) malloc(sizeof(mpu_t));
|
||||
memset(sb->mpu, 0, sizeof(mpu_t));
|
||||
@@ -1352,9 +1296,6 @@ void *sb_awe32_init()
|
||||
} else
|
||||
sb->mpu = NULL;
|
||||
emu8k_init(&sb->emu8k, emu_addr, onboard_ram);
|
||||
#if 0
|
||||
memcpy(&sb->temp_mixer_sb16, &sb->mixer_sb16, sizeof(sb_ct1745_mixer_t));
|
||||
#endif
|
||||
|
||||
return sb;
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*
|
||||
* Sound emulation core.
|
||||
*
|
||||
* Version: @(#)sound.c 1.0.22 2018/10/17
|
||||
* Version: @(#)sound.c 1.0.23 2018/10/26
|
||||
*
|
||||
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
|
||||
* Miran Grca, <mgrca8@gmail.com>
|
||||
@@ -61,25 +61,27 @@ typedef struct {
|
||||
|
||||
int sound_card_current = 0;
|
||||
int sound_pos_global = 0;
|
||||
volatile int soundon = 1;
|
||||
int sound_gain = 0;
|
||||
|
||||
|
||||
static int sound_card_last = 0;
|
||||
static sound_handler_t sound_handlers[8];
|
||||
static sound_handler_t sound_process_handlers[8];
|
||||
static int sound_handlers_num;
|
||||
static int sound_process_handlers_num;
|
||||
static int64_t sound_poll_time = 0LL, sound_poll_latch;
|
||||
static int16_t cd_buffer[CDROM_NUM][CD_BUFLEN * 2];
|
||||
static float cd_out_buffer[CD_BUFLEN * 2];
|
||||
static int16_t cd_out_buffer_int16[CD_BUFLEN * 2];
|
||||
|
||||
static thread_t *sound_cd_thread_h;
|
||||
static event_t *sound_cd_event;
|
||||
static event_t *sound_cd_start_event;
|
||||
static int32_t *outbuffer;
|
||||
static float *outbuffer_ex;
|
||||
static int16_t *outbuffer_ex_int16;
|
||||
static int sound_handlers_num;
|
||||
static int64_t sound_poll_time = 0LL, sound_poll_latch;
|
||||
|
||||
static int16_t cd_buffer[CDROM_NUM][CD_BUFLEN * 2];
|
||||
static float cd_out_buffer[CD_BUFLEN * 2];
|
||||
static int16_t cd_out_buffer_int16[CD_BUFLEN * 2];
|
||||
static unsigned int cd_vol_l, cd_vol_r;
|
||||
static int cd_buf_update = CD_BUFLEN / SOUNDBUFLEN;
|
||||
static volatile int cdaudioon = 0;
|
||||
static int cd_thread_enable = 0;
|
||||
|
||||
|
||||
static const SOUND_CARD sound_cards[] =
|
||||
@@ -128,364 +130,310 @@ sound_log(const char *fmt, ...)
|
||||
#endif
|
||||
|
||||
|
||||
int sound_card_available(int card)
|
||||
int
|
||||
sound_card_available(int card)
|
||||
{
|
||||
if (sound_cards[card].device)
|
||||
return device_available(sound_cards[card].device);
|
||||
if (sound_cards[card].device)
|
||||
return device_available(sound_cards[card].device);
|
||||
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *sound_card_getname(int card)
|
||||
|
||||
char *
|
||||
sound_card_getname(int card)
|
||||
{
|
||||
return (char *) sound_cards[card].name;
|
||||
return (char *) sound_cards[card].name;
|
||||
}
|
||||
|
||||
const device_t *sound_card_getdevice(int card)
|
||||
|
||||
const device_t *
|
||||
sound_card_getdevice(int card)
|
||||
{
|
||||
return sound_cards[card].device;
|
||||
return sound_cards[card].device;
|
||||
}
|
||||
|
||||
int sound_card_has_config(int card)
|
||||
{
|
||||
if (!sound_cards[card].device)
|
||||
return 0;
|
||||
return sound_cards[card].device->config ? 1 : 0;
|
||||
}
|
||||
|
||||
char *sound_card_get_internal_name(int card)
|
||||
int
|
||||
sound_card_has_config(int card)
|
||||
{
|
||||
return (char *) sound_cards[card].internal_name;
|
||||
}
|
||||
|
||||
int sound_card_get_from_internal_name(char *s)
|
||||
{
|
||||
int c = 0;
|
||||
|
||||
while (strlen((char *) sound_cards[c].internal_name))
|
||||
{
|
||||
if (!strcmp((char *) sound_cards[c].internal_name, s))
|
||||
return c;
|
||||
c++;
|
||||
}
|
||||
|
||||
if (!sound_cards[card].device)
|
||||
return 0;
|
||||
return sound_cards[card].device->config ? 1 : 0;
|
||||
}
|
||||
|
||||
void sound_card_init(void)
|
||||
|
||||
char *
|
||||
sound_card_get_internal_name(int card)
|
||||
{
|
||||
if (sound_cards[sound_card_current].device)
|
||||
device_add(sound_cards[sound_card_current].device);
|
||||
sound_card_last = sound_card_current;
|
||||
return (char *) sound_cards[card].internal_name;
|
||||
}
|
||||
|
||||
void sound_set_cd_volume(unsigned int vol_l, unsigned int vol_r)
|
||||
|
||||
int
|
||||
sound_card_get_from_internal_name(char *s)
|
||||
{
|
||||
cd_vol_l = vol_l;
|
||||
cd_vol_r = vol_r;
|
||||
int c = 0;
|
||||
|
||||
while (strlen((char *) sound_cards[c].internal_name)) {
|
||||
if (!strcmp((char *) sound_cards[c].internal_name, s))
|
||||
return c;
|
||||
c++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void sound_cd_thread(void *param)
|
||||
|
||||
void
|
||||
sound_card_init(void)
|
||||
{
|
||||
int c, has_audio, d, r, i = 0;
|
||||
int32_t audio_vol_l, audio_vol_r;
|
||||
if (sound_cards[sound_card_current].device)
|
||||
device_add(sound_cards[sound_card_current].device);
|
||||
}
|
||||
|
||||
int channel_select[2];
|
||||
|
||||
float cd_buffer_temp[2] = {0.0, 0.0};
|
||||
float cd_buffer_temp2[2] = {0.0, 0.0};
|
||||
void
|
||||
sound_set_cd_volume(unsigned int vol_l, unsigned int vol_r)
|
||||
{
|
||||
cd_vol_l = vol_l;
|
||||
cd_vol_r = vol_r;
|
||||
}
|
||||
|
||||
int32_t cd_buffer_temp4[2] = {0, 0};
|
||||
|
||||
thread_set_event(sound_cd_start_event);
|
||||
static void
|
||||
sound_cd_clean_buffers(void)
|
||||
{
|
||||
if (sound_is_float)
|
||||
memset(cd_out_buffer, 0, 2 * sizeof(float));
|
||||
else
|
||||
memset(cd_out_buffer_int16, 0, 2 * sizeof(int16_t));
|
||||
}
|
||||
|
||||
while (cdaudioon) {
|
||||
thread_wait_event(sound_cd_event, -1);
|
||||
thread_reset_event(sound_cd_event);
|
||||
|
||||
if (!soundon || !cdaudioon)
|
||||
return;
|
||||
static void
|
||||
sound_cd_thread(void *param)
|
||||
{
|
||||
int c, r, i, channel_select[2];
|
||||
float audio_vol_l, audio_vol_r;
|
||||
float cd_buffer_temp[2] = {0.0, 0.0};
|
||||
|
||||
thread_set_event(sound_cd_start_event);
|
||||
|
||||
while (cdaudioon) {
|
||||
thread_wait_event(sound_cd_event, -1);
|
||||
thread_reset_event(sound_cd_event);
|
||||
|
||||
if (!cdaudioon)
|
||||
return;
|
||||
|
||||
sound_cd_clean_buffers();
|
||||
|
||||
for (i = 0; i < CDROM_NUM; i++) {
|
||||
if ((cdrom[i].bus_type == CDROM_BUS_DISABLED) || !cdrom[i].ops)
|
||||
continue;
|
||||
if (cdrom[i].ops->audio_callback) {
|
||||
r = cdrom[i].ops->audio_callback(&(cdrom[i]), cd_buffer[i], CD_BUFLEN * 2);
|
||||
if (!cdrom[i].bus_type || !cdrom[i].sound_on || !r)
|
||||
continue;
|
||||
} else
|
||||
continue;
|
||||
|
||||
if (cdrom[i].get_volume) {
|
||||
audio_vol_l = (float) (cdrom[i].get_volume(cdrom[i].p, 0));
|
||||
audio_vol_r = (float) (cdrom[i].get_volume(cdrom[i].p, 1));
|
||||
} else {
|
||||
audio_vol_l = 255.0;
|
||||
audio_vol_r = 255.0;
|
||||
}
|
||||
|
||||
audio_vol_l /= 511.0;
|
||||
audio_vol_r /= 511.0;
|
||||
|
||||
if (cdrom[i].get_channel) {
|
||||
channel_select[0] = cdrom[i].get_channel(cdrom[i].p, 0);
|
||||
channel_select[1] = cdrom[i].get_channel(cdrom[i].p, 1);
|
||||
} else {
|
||||
channel_select[0] = 1;
|
||||
channel_select[1] = 2;
|
||||
}
|
||||
|
||||
for (c = 0; c < CD_BUFLEN*2; c += 2) {
|
||||
/*Apply ATAPI channel select*/
|
||||
cd_buffer_temp[0] = cd_buffer_temp[1] = 0.0;
|
||||
|
||||
if (channel_select[0] & 1)
|
||||
cd_buffer_temp[0] += ((float) cd_buffer[i][c]) * audio_vol_l;
|
||||
if (channel_select[0] & 2)
|
||||
cd_buffer_temp[1] += ((float) cd_buffer[i][c]) * audio_vol_l;
|
||||
if (channel_select[1] & 1)
|
||||
cd_buffer_temp[0] += ((float) cd_buffer[i][c + 1]) * audio_vol_r;
|
||||
if (channel_select[1] & 2)
|
||||
cd_buffer_temp[1] += ((float) cd_buffer[i][c + 1]) * audio_vol_r;
|
||||
|
||||
/*Apply sound card CD volume*/
|
||||
cd_buffer_temp[0] *= ((float) cd_vol_l) / 65535.0;
|
||||
cd_buffer_temp[1] *= ((float) cd_vol_r) / 65535.0;
|
||||
|
||||
if (sound_is_float) {
|
||||
cd_out_buffer[c] = 0.0;
|
||||
cd_out_buffer[c+1] = 0.0;
|
||||
cd_out_buffer[c] += (cd_buffer_temp[0] / 32768.0);
|
||||
cd_out_buffer[c+1] += (cd_buffer_temp[1] / 32768.0);
|
||||
} else {
|
||||
cd_out_buffer_int16[c] = 0;
|
||||
cd_out_buffer_int16[c+1] = 0;
|
||||
if (cd_buffer_temp[0] > 32767)
|
||||
cd_buffer_temp[0] = 32767;
|
||||
if (cd_buffer_temp[0] < -32768)
|
||||
cd_buffer_temp[0] = -32768;
|
||||
if (cd_buffer_temp[1] > 32767)
|
||||
cd_buffer_temp[1] = 32767;
|
||||
if (cd_buffer_temp[1] < -32768)
|
||||
cd_buffer_temp[1] = -32768;
|
||||
|
||||
cd_out_buffer_int16[c] += cd_buffer_temp[0];
|
||||
cd_out_buffer_int16[c+1] += cd_buffer_temp[1];
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < CDROM_NUM; i++) {
|
||||
has_audio = 0;
|
||||
if ((cdrom[i].bus_type == CDROM_BUS_DISABLED) || !cdrom[i].ops)
|
||||
continue;
|
||||
if (cdrom[i].ops->audio_callback)
|
||||
{
|
||||
r = cdrom[i].ops->audio_callback(&(cdrom[i]), cd_buffer[i], CD_BUFLEN*2);
|
||||
has_audio = (cdrom[i].bus_type && cdrom[i].sound_on/* && r*/);
|
||||
} else
|
||||
continue;
|
||||
|
||||
if (soundon && has_audio) {
|
||||
if (cdrom[i].get_volume) {
|
||||
audio_vol_l = cdrom[i].get_volume(cdrom[i].p, 0);
|
||||
audio_vol_r = cdrom[i].get_volume(cdrom[i].p, 1);
|
||||
} else {
|
||||
audio_vol_l = 255;
|
||||
audio_vol_r = 255;
|
||||
}
|
||||
|
||||
if (cdrom[i].get_channel) {
|
||||
channel_select[0] = cdrom[i].get_channel(cdrom[i].p, 0);
|
||||
channel_select[1] = cdrom[i].get_channel(cdrom[i].p, 1);
|
||||
} else {
|
||||
channel_select[0] = 1;
|
||||
channel_select[1] = 2;
|
||||
}
|
||||
|
||||
if (!r) {
|
||||
for (c = 0; c < CD_BUFLEN*2; c += 2) {
|
||||
if (sound_is_float) {
|
||||
cd_out_buffer[c] += 0.0;
|
||||
cd_out_buffer[c+1] += 0.0;
|
||||
} else {
|
||||
cd_out_buffer_int16[c] += 0;
|
||||
cd_out_buffer_int16[c+1] += 0;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
for (c = 0; c < CD_BUFLEN*2; c += 2) {
|
||||
/* First, transfer the CD audio data to the temporary buffer. */
|
||||
cd_buffer_temp[0] = (float) cd_buffer[i][c];
|
||||
cd_buffer_temp[1] = (float) cd_buffer[i][c+1];
|
||||
|
||||
/* Then, adjust input from drive according to ATAPI/SCSI volume. */
|
||||
cd_buffer_temp[0] *= (float) audio_vol_l;
|
||||
cd_buffer_temp[0] /= 511.0;
|
||||
cd_buffer_temp[1] *= (float) audio_vol_r;
|
||||
cd_buffer_temp[1] /= 511.0;
|
||||
|
||||
/*Apply ATAPI channel select*/
|
||||
cd_buffer_temp2[0] = cd_buffer_temp2[1] = 0.0;
|
||||
|
||||
if (channel_select[0] & 1)
|
||||
cd_buffer_temp2[0] += cd_buffer_temp[0];
|
||||
if (channel_select[0] & 2)
|
||||
cd_buffer_temp2[1] += cd_buffer_temp[0];
|
||||
if (channel_select[1] & 1)
|
||||
cd_buffer_temp2[0] += cd_buffer_temp[1];
|
||||
if (channel_select[1] & 2)
|
||||
cd_buffer_temp2[1] += cd_buffer_temp[1];
|
||||
|
||||
if (sound_process_handlers_num) {
|
||||
cd_buffer_temp4[0] = (int32_t) cd_buffer_temp2[0];
|
||||
cd_buffer_temp4[1] = (int32_t) cd_buffer_temp2[1];
|
||||
|
||||
for (d = 0; d < sound_process_handlers_num; d++)
|
||||
sound_process_handlers[d].get_buffer(cd_buffer_temp4, 1, sound_process_handlers[d].priv);
|
||||
|
||||
cd_buffer_temp2[0] = (float) cd_buffer_temp4[0];
|
||||
cd_buffer_temp2[1] = (float) cd_buffer_temp4[1];
|
||||
} else {
|
||||
/*Apply sound card CD volume*/
|
||||
cd_buffer_temp2[0] *= (float) cd_vol_l;
|
||||
cd_buffer_temp2[0] /= 65535.0;
|
||||
|
||||
cd_buffer_temp2[1] *= (float) cd_vol_r;
|
||||
cd_buffer_temp2[1] /= 65535.0;
|
||||
}
|
||||
|
||||
if (sound_is_float) {
|
||||
cd_out_buffer[c] += (cd_buffer_temp2[0] / 32768.0);
|
||||
cd_out_buffer[c+1] += (cd_buffer_temp2[1] / 32768.0);
|
||||
} else {
|
||||
if (cd_buffer_temp2[0] > 32767)
|
||||
cd_buffer_temp2[0] = 32767;
|
||||
if (cd_buffer_temp2[0] < -32768)
|
||||
cd_buffer_temp2[0] = -32768;
|
||||
if (cd_buffer_temp2[1] > 32767)
|
||||
cd_buffer_temp2[1] = 32767;
|
||||
if (cd_buffer_temp2[1] < -32768)
|
||||
cd_buffer_temp2[1] = -32768;
|
||||
|
||||
cd_out_buffer_int16[c] += cd_buffer_temp2[0];
|
||||
cd_out_buffer_int16[c+1] += cd_buffer_temp2[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sound_is_float)
|
||||
givealbuffer_cd(cd_out_buffer);
|
||||
else
|
||||
givealbuffer_cd(cd_out_buffer_int16);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t *outbuffer;
|
||||
static float *outbuffer_ex;
|
||||
static int16_t *outbuffer_ex_int16;
|
||||
|
||||
static int cd_thread_enable = 0;
|
||||
|
||||
static void sound_realloc_buffers(void)
|
||||
{
|
||||
if (outbuffer_ex != NULL)
|
||||
{
|
||||
free(outbuffer_ex);
|
||||
}
|
||||
|
||||
if (outbuffer_ex_int16 != NULL)
|
||||
{
|
||||
free(outbuffer_ex_int16);
|
||||
}
|
||||
|
||||
if (sound_is_float)
|
||||
{
|
||||
outbuffer_ex = malloc(SOUNDBUFLEN * 2 * sizeof(float));
|
||||
}
|
||||
givealbuffer_cd(cd_out_buffer);
|
||||
else
|
||||
{
|
||||
outbuffer_ex_int16 = malloc(SOUNDBUFLEN * 2 * sizeof(int16_t));
|
||||
}
|
||||
givealbuffer_cd(cd_out_buffer_int16);
|
||||
}
|
||||
}
|
||||
|
||||
void sound_init(void)
|
||||
|
||||
static void
|
||||
sound_realloc_buffers(void)
|
||||
{
|
||||
int i = 0;
|
||||
int available_cdrom_drives = 0;
|
||||
if (outbuffer_ex != NULL)
|
||||
free(outbuffer_ex);
|
||||
|
||||
outbuffer_ex = NULL;
|
||||
outbuffer_ex_int16 = NULL;
|
||||
if (outbuffer_ex_int16 != NULL)
|
||||
free(outbuffer_ex_int16);
|
||||
|
||||
outbuffer = malloc(SOUNDBUFLEN * 2 * sizeof(int32_t));
|
||||
if (sound_is_float)
|
||||
outbuffer_ex = malloc(SOUNDBUFLEN * 2 * sizeof(float));
|
||||
else
|
||||
outbuffer_ex_int16 = malloc(SOUNDBUFLEN * 2 * sizeof(int16_t));
|
||||
}
|
||||
|
||||
for (i = 0; i < CDROM_NUM; i++)
|
||||
{
|
||||
if (cdrom[i].bus_type != CDROM_BUS_DISABLED)
|
||||
{
|
||||
available_cdrom_drives++;
|
||||
|
||||
void
|
||||
sound_init(void)
|
||||
{
|
||||
int i = 0;
|
||||
int available_cdrom_drives = 0;
|
||||
|
||||
outbuffer_ex = NULL;
|
||||
outbuffer_ex_int16 = NULL;
|
||||
|
||||
outbuffer = malloc(SOUNDBUFLEN * 2 * sizeof(int32_t));
|
||||
|
||||
for (i = 0; i < CDROM_NUM; i++) {
|
||||
if (cdrom[i].bus_type != CDROM_BUS_DISABLED)
|
||||
available_cdrom_drives++;
|
||||
}
|
||||
|
||||
if (available_cdrom_drives) {
|
||||
cdaudioon = 1;
|
||||
|
||||
sound_cd_start_event = thread_create_event();
|
||||
|
||||
sound_cd_event = thread_create_event();
|
||||
sound_cd_thread_h = thread_create(sound_cd_thread, NULL);
|
||||
|
||||
sound_log("Waiting for CD start event...\n");
|
||||
thread_wait_event(sound_cd_start_event, -1);
|
||||
thread_reset_event(sound_cd_start_event);
|
||||
sound_log("Done!\n");
|
||||
} else
|
||||
cdaudioon = 0;
|
||||
|
||||
cd_thread_enable = available_cdrom_drives ? 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
sound_add_handler(void (*get_buffer)(int32_t *buffer, int len, void *p), void *p)
|
||||
{
|
||||
sound_handlers[sound_handlers_num].get_buffer = get_buffer;
|
||||
sound_handlers[sound_handlers_num].priv = p;
|
||||
sound_handlers_num++;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
sound_poll(void *priv)
|
||||
{
|
||||
sound_poll_time += sound_poll_latch;
|
||||
|
||||
midi_poll();
|
||||
|
||||
sound_pos_global++;
|
||||
if (sound_pos_global == SOUNDBUFLEN) {
|
||||
int c;
|
||||
|
||||
memset(outbuffer, 0, SOUNDBUFLEN * 2 * sizeof(int32_t));
|
||||
|
||||
for (c = 0; c < sound_handlers_num; c++)
|
||||
sound_handlers[c].get_buffer(outbuffer, SOUNDBUFLEN, sound_handlers[c].priv);
|
||||
|
||||
for (c = 0; c < SOUNDBUFLEN * 2; c++) {
|
||||
if (sound_is_float)
|
||||
outbuffer_ex[c] = ((float) outbuffer[c]) / 32768.0;
|
||||
else {
|
||||
if (outbuffer[c] > 32767)
|
||||
outbuffer[c] = 32767;
|
||||
if (outbuffer[c] < -32768)
|
||||
outbuffer[c] = -32768;
|
||||
|
||||
outbuffer_ex_int16[c] = outbuffer[c];
|
||||
}
|
||||
}
|
||||
|
||||
if (available_cdrom_drives)
|
||||
{
|
||||
cdaudioon = 1;
|
||||
|
||||
sound_cd_start_event = thread_create_event();
|
||||
|
||||
sound_cd_event = thread_create_event();
|
||||
sound_cd_thread_h = thread_create(sound_cd_thread, NULL);
|
||||
|
||||
sound_log("Waiting for CD start event...\n");
|
||||
thread_wait_event(sound_cd_start_event, -1);
|
||||
thread_reset_event(sound_cd_start_event);
|
||||
sound_log("Done!\n");
|
||||
}
|
||||
|
||||
if (sound_is_float)
|
||||
givealbuffer(outbuffer_ex);
|
||||
else
|
||||
cdaudioon = 0;
|
||||
givealbuffer(outbuffer_ex_int16);
|
||||
|
||||
cd_thread_enable = available_cdrom_drives ? 1 : 0;
|
||||
if (cd_thread_enable) {
|
||||
cd_buf_update--;
|
||||
if (!cd_buf_update) {
|
||||
cd_buf_update = (48000 / SOUNDBUFLEN) / (CD_FREQ / CD_BUFLEN);
|
||||
thread_set_event(sound_cd_event);
|
||||
}
|
||||
}
|
||||
|
||||
sound_pos_global = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void sound_add_handler(void (*get_buffer)(int32_t *buffer, int len, void *p), void *p)
|
||||
|
||||
void
|
||||
sound_speed_changed(void)
|
||||
{
|
||||
sound_handlers[sound_handlers_num].get_buffer = get_buffer;
|
||||
sound_handlers[sound_handlers_num].priv = p;
|
||||
sound_handlers_num++;
|
||||
sound_poll_latch = (int64_t)((double)TIMER_USEC * (1000000.0 / 48000.0));
|
||||
}
|
||||
|
||||
void sound_add_process_handler(void (*get_buffer)(int32_t *buffer, int len, void *p), void *p)
|
||||
|
||||
void
|
||||
sound_reset(void)
|
||||
{
|
||||
sound_process_handlers[sound_process_handlers_num].get_buffer = get_buffer;
|
||||
sound_process_handlers[sound_process_handlers_num].priv = p;
|
||||
sound_process_handlers_num++;
|
||||
sound_realloc_buffers();
|
||||
|
||||
midi_device_init();
|
||||
inital();
|
||||
|
||||
timer_add(sound_poll, &sound_poll_time, TIMER_ALWAYS_ENABLED, NULL);
|
||||
|
||||
sound_handlers_num = 0;
|
||||
|
||||
sound_set_cd_volume(65535, 65535);
|
||||
}
|
||||
|
||||
void sound_poll(void *priv)
|
||||
{
|
||||
sound_poll_time += sound_poll_latch;
|
||||
|
||||
midi_poll();
|
||||
|
||||
sound_pos_global++;
|
||||
if (sound_pos_global == SOUNDBUFLEN)
|
||||
{
|
||||
int c;
|
||||
|
||||
memset(outbuffer, 0, SOUNDBUFLEN * 2 * sizeof(int32_t));
|
||||
|
||||
for (c = 0; c < sound_handlers_num; c++)
|
||||
sound_handlers[c].get_buffer(outbuffer, SOUNDBUFLEN, sound_handlers[c].priv);
|
||||
|
||||
|
||||
for (c = 0; c < SOUNDBUFLEN * 2; c++)
|
||||
{
|
||||
if (sound_is_float)
|
||||
{
|
||||
outbuffer_ex[c] = ((float) outbuffer[c]) / 32768.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (outbuffer[c] > 32767)
|
||||
outbuffer[c] = 32767;
|
||||
if (outbuffer[c] < -32768)
|
||||
outbuffer[c] = -32768;
|
||||
|
||||
outbuffer_ex_int16[c] = outbuffer[c];
|
||||
}
|
||||
}
|
||||
|
||||
if (soundon)
|
||||
{
|
||||
if (sound_is_float)
|
||||
{
|
||||
givealbuffer(outbuffer_ex);
|
||||
}
|
||||
else
|
||||
{
|
||||
givealbuffer(outbuffer_ex_int16);
|
||||
}
|
||||
}
|
||||
|
||||
if (cd_thread_enable)
|
||||
{
|
||||
cd_buf_update--;
|
||||
if (!cd_buf_update)
|
||||
{
|
||||
cd_buf_update = (48000 / SOUNDBUFLEN) / (CD_FREQ / CD_BUFLEN);
|
||||
thread_set_event(sound_cd_event);
|
||||
}
|
||||
}
|
||||
|
||||
sound_pos_global = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void sound_speed_changed(void)
|
||||
{
|
||||
sound_poll_latch = (int64_t)((double)TIMER_USEC * (1000000.0 / 48000.0));
|
||||
}
|
||||
|
||||
void sound_reset(void)
|
||||
{
|
||||
sound_realloc_buffers();
|
||||
|
||||
midi_device_init();
|
||||
inital();
|
||||
|
||||
timer_add(sound_poll, &sound_poll_time, TIMER_ALWAYS_ENABLED, NULL);
|
||||
|
||||
sound_handlers_num = 0;
|
||||
sound_process_handlers_num = 0;
|
||||
|
||||
sound_set_cd_volume(65535, 65535);
|
||||
}
|
||||
|
||||
void sound_card_reset(void)
|
||||
void
|
||||
sound_card_reset(void)
|
||||
{
|
||||
sound_card_init();
|
||||
if (mpu401_standalone_enable)
|
||||
@@ -498,56 +446,59 @@ void sound_card_reset(void)
|
||||
device_add(&ssi2001_device);
|
||||
}
|
||||
|
||||
void sound_cd_thread_end(void)
|
||||
|
||||
void
|
||||
sound_cd_thread_end(void)
|
||||
{
|
||||
if (cdaudioon) {
|
||||
cdaudioon = 0;
|
||||
if (cdaudioon) {
|
||||
cdaudioon = 0;
|
||||
|
||||
sound_log("Waiting for CD Audio thread to terminate...\n");
|
||||
thread_set_event(sound_cd_event);
|
||||
thread_wait(sound_cd_thread_h, -1);
|
||||
sound_log("CD Audio thread terminated...\n");
|
||||
sound_log("Waiting for CD Audio thread to terminate...\n");
|
||||
thread_set_event(sound_cd_event);
|
||||
thread_wait(sound_cd_thread_h, -1);
|
||||
sound_log("CD Audio thread terminated...\n");
|
||||
|
||||
if (sound_cd_event) {
|
||||
thread_destroy_event(sound_cd_event);
|
||||
sound_cd_event = NULL;
|
||||
}
|
||||
|
||||
sound_cd_thread_h = NULL;
|
||||
|
||||
if (sound_cd_start_event) {
|
||||
thread_destroy_event(sound_cd_start_event);
|
||||
sound_cd_event = NULL;
|
||||
}
|
||||
if (sound_cd_event) {
|
||||
thread_destroy_event(sound_cd_event);
|
||||
sound_cd_event = NULL;
|
||||
}
|
||||
|
||||
sound_cd_thread_h = NULL;
|
||||
|
||||
if (sound_cd_start_event) {
|
||||
thread_destroy_event(sound_cd_start_event);
|
||||
sound_cd_event = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void sound_cd_thread_reset(void)
|
||||
|
||||
void
|
||||
sound_cd_thread_reset(void)
|
||||
{
|
||||
int i = 0;
|
||||
int available_cdrom_drives = 0;
|
||||
int i = 0;
|
||||
int available_cdrom_drives = 0;
|
||||
|
||||
for (i = 0; i < CDROM_NUM; i++) {
|
||||
if (cdrom[i].ops && cdrom[i].ops->audio_stop)
|
||||
cdrom[i].ops->audio_stop(&(cdrom[i]));
|
||||
for (i = 0; i < CDROM_NUM; i++) {
|
||||
if (cdrom[i].ops && cdrom[i].ops->audio_stop)
|
||||
cdrom[i].ops->audio_stop(&(cdrom[i]));
|
||||
|
||||
if (cdrom[i].bus_type != CDROM_BUS_DISABLED)
|
||||
available_cdrom_drives++;
|
||||
}
|
||||
if (cdrom[i].bus_type != CDROM_BUS_DISABLED)
|
||||
available_cdrom_drives++;
|
||||
}
|
||||
|
||||
if (available_cdrom_drives && !cd_thread_enable) {
|
||||
cdaudioon = 1;
|
||||
if (available_cdrom_drives && !cd_thread_enable) {
|
||||
cdaudioon = 1;
|
||||
|
||||
sound_cd_start_event = thread_create_event();
|
||||
sound_cd_start_event = thread_create_event();
|
||||
|
||||
sound_cd_event = thread_create_event();
|
||||
sound_cd_thread_h = thread_create(sound_cd_thread, NULL);
|
||||
sound_cd_event = thread_create_event();
|
||||
sound_cd_thread_h = thread_create(sound_cd_thread, NULL);
|
||||
|
||||
thread_wait_event(sound_cd_start_event, -1);
|
||||
thread_reset_event(sound_cd_start_event);
|
||||
} else if (!available_cdrom_drives && cd_thread_enable) {
|
||||
sound_cd_thread_end();
|
||||
}
|
||||
thread_wait_event(sound_cd_start_event, -1);
|
||||
thread_reset_event(sound_cd_start_event);
|
||||
} else if (!available_cdrom_drives && cd_thread_enable)
|
||||
sound_cd_thread_end();
|
||||
|
||||
cd_thread_enable = available_cdrom_drives ? 1 : 0;
|
||||
cd_thread_enable = available_cdrom_drives ? 1 : 0;
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*
|
||||
* Sound emulation core.
|
||||
*
|
||||
* Version: @(#)sound.h 1.0.7 2018/04/23
|
||||
* Version: @(#)sound.h 1.0.8 2018/10/26
|
||||
*
|
||||
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
|
||||
* Miran Grca, <mgrca8@gmail.com>
|
||||
@@ -39,8 +39,6 @@ extern int sound_card_current;
|
||||
|
||||
extern void sound_add_handler(void (*get_buffer)(int32_t *buffer, \
|
||||
int len, void *p), void *p);
|
||||
extern void sound_add_process_handler(void (*get_buffer)(int32_t *buffer, \
|
||||
int len, void *p), void *p);
|
||||
|
||||
extern int sound_card_available(int card);
|
||||
extern char *sound_card_getname(int card);
|
||||
|
Reference in New Issue
Block a user