CD-ROM and Iomega ZIP PIO request length is now reduced if it is bigger than the remaining amount of bytes to transfer;

Fixed CD-ROM sector reading from CUE/BIN images with 2048-byte sectors;
Fixed existing CD-ROM Mode 2 support and adding support for the remaining variants of Mode 2;
The Windows CD-ROM IOCTL code now correctly determines the track type, fixes CD Audio over IOCTL;
Applied all PCem sound-related commits;
Sound Blaster 16/AWE32 mixer effects now also apply to CD Audio when the Sound Blaster 16 or AWE32 is selected.
This commit is contained in:
OBattler
2018-02-15 23:14:44 +01:00
parent 07bc427839
commit 6cab207231
11 changed files with 514 additions and 169 deletions

View File

@@ -345,3 +345,33 @@ static inline float dac_iir(int i, float NewSample) {
return y[i][0];
}
#define SB16_NCoef 51
extern float low_fir_sb16_coef[SB16_NCoef];
static inline float low_fir_sb16(int i, float NewSample)
{
static float x[2][SB16_NCoef+1]; //input samples
static int pos = 0;
float out = 0.0;
int n;
/* Calculate the new output */
x[i][pos] = NewSample;
for (n = 0; n < ((SB16_NCoef+1)-pos) && n < SB16_NCoef; n++)
out += low_fir_sb16_coef[n] * x[i][n+pos];
for (; n < SB16_NCoef; n++)
out += low_fir_sb16_coef[n] * x[i][(n+pos) - (SB16_NCoef+1)];
if (i == 1)
{
pos++;
if (pos > SB16_NCoef)
pos = 0;
}
return out;
}

View File

@@ -8,7 +8,7 @@
*
* Sound Blaster emulation.
*
* Version: @(#)sound_sb.c 1.0.4 2017/11/04
* Version: @(#)sound_sb.c 1.0.5 2018/02/15
*
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
* Miran Grca, <mgrca8@gmail.com>
@@ -272,6 +272,41 @@ static void sb_get_buffer_sbpro(int32_t *buffer, int len, void *p)
sb->dsp.pos = 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->mixer_sb16;
int c;
for (c = 0; c < len * 2; c += 2)
{
int32_t out_l = 0, out_r = 0;
out_l = ((int32_t)(buffer[c] * mixer->cd_l) / 3) >> 15;
out_r = ((int32_t)(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);
}
}
static void sb_get_buffer_sb16(int32_t *buffer, int len, void *p)
{
sb_t *sb = (sb_t *)p;
@@ -296,10 +331,9 @@ static void sb_get_buffer_sb16(int32_t *buffer, int len, void *p)
in_l = (mixer->input_selector_left&INPUT_MIDI_L) ? out_l : 0 + (mixer->input_selector_left&INPUT_MIDI_R) ? out_r : 0;
in_r = (mixer->input_selector_right&INPUT_MIDI_L) ? out_l : 0 + (mixer->input_selector_right&INPUT_MIDI_R) ? out_r : 0;
/*TODO: CT1745 features dynamic filtering. https://www.vogons.org/viewtopic.php?f=62&t=51514 */
out_l += ((int32_t)(sb->dsp.buffer[c] * mixer->voice_l) / 3) >> 15;
out_r += ((int32_t)(sb->dsp.buffer[c + 1] * mixer->voice_r) / 3) >> 15;
out_l += ((int32_t)(low_fir_sb16(0, (float)sb->dsp.buffer[c]) * mixer->voice_l) / 3) >> 15;
out_r += ((int32_t)(low_fir_sb16(1, (float)sb->dsp.buffer[c + 1]) * mixer->voice_r) / 3) >> 15;
out_l = (out_l * mixer->master_l) >> 15;
out_r = (out_r * mixer->master_r) >> 15;
@@ -379,10 +413,8 @@ static void sb_get_buffer_emu8k(int32_t *buffer, int len, void *p)
in_l = (mixer->input_selector_left&INPUT_MIDI_L) ? out_l : 0 + (mixer->input_selector_left&INPUT_MIDI_R) ? out_r : 0;
in_r = (mixer->input_selector_right&INPUT_MIDI_L) ? out_l : 0 + (mixer->input_selector_right&INPUT_MIDI_R) ? out_r : 0;
/*TODO: CT1745 features dynamic filtering. https://www.vogons.org/viewtopic.php?f=62&t=51514 */
out_l += ((int32_t)(sb->dsp.buffer[c] * mixer->voice_l) / 3) >> 15;
out_r += ((int32_t)(sb->dsp.buffer[c + 1] * mixer->voice_r) / 3) >> 15;
out_l += ((int32_t)(low_fir_sb16(0, (float)sb->dsp.buffer[c]) * mixer->voice_l) / 3) >> 15;
out_r += ((int32_t)(low_fir_sb16(1, (float)sb->dsp.buffer[c + 1]) * mixer->voice_r) / 3) >> 15;
out_l = (out_l * mixer->master_l) >> 15;
out_r = (out_r * mixer->master_r) >> 15;
@@ -1217,6 +1249,7 @@ 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);
sound_add_process_handler(sb_process_buffer_sb16, sb);
mpu401_init(&sb->mpu, device_get_config_hex16("base401"), device_get_config_int("irq401"), device_get_config_int("mode401"));
sb_dsp_set_mpu(&sb->mpu);
@@ -1255,6 +1288,7 @@ 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);
sound_add_process_handler(sb_process_buffer_sb16, sb);
mpu401_init(&sb->mpu, device_get_config_hex16("base401"), device_get_config_int("irq401"), device_get_config_int("mode401"));
sb_dsp_set_mpu(&sb->mpu);
emu8k_init(&sb->emu8k, emu_addr, onboard_ram);

View File

@@ -4,6 +4,7 @@
486-50 - 32kHz
Pentium - 45kHz*/
#include <math.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
@@ -15,6 +16,7 @@
#include "../dma.h"
#include "../timer.h"
#include "../device.h"
#include "filters.h"
#include "sound.h"
#include "midi.h"
#include "snd_mpu401.h"
@@ -115,6 +117,41 @@ uint16_t sb_dsp_versions[] = {0, 0, 0x105, 0x200, 0x201, 0x300, 0x302, 0x405, 0x
252, 0, 252, 0
};
float low_fir_sb16_coef[SB16_NCoef];
static inline double sinc(double x)
{
return sin(M_PI * x) / (M_PI * x);
}
static void recalc_sb16_filter(int playback_freq)
{
/*Cutoff frequency = playback / 2*/
float fC = ((float)playback_freq / 2.0) / 48000.0;
float gain;
int n;
for (n = 0; n < SB16_NCoef; n++)
{
/*Blackman window*/
double w = 0.42 - (0.5 * cos((2.0*n*M_PI)/(double)(SB16_NCoef-1))) + (0.08 * cos((4.0*n*M_PI)/(double)(SB16_NCoef-1)));
/*Sinc filter*/
double h = sinc(2.0 * fC * ((double)n - ((double)(SB16_NCoef-1) / 2.0)));
/*Create windowed-sinc filter*/
low_fir_sb16_coef[n] = w * h;
}
low_fir_sb16_coef[(SB16_NCoef - 1) / 2] = 1.0;
gain = 0.0;
for (n = 0; n < SB16_NCoef; n++)
gain += low_fir_sb16_coef[n];
/*Normalise filter, to produce unity gain*/
for (n = 0; n < SB16_NCoef; n++)
low_fir_sb16_coef[n] /= gain;
}
void sb_irq(sb_dsp_t *dsp, int irq8)
@@ -423,6 +460,8 @@ void sb_exec_command(sb_dsp_t *dsp)
temp = 256 - dsp->sb_data[0];
temp = 1000000 / temp;
// pclog("Sample rate - %ihz (%i)\n",temp, dsp->sblatcho);
if (dsp->sb_freq != temp && dsp->sb_type >= SB16)
recalc_sb16_filter(temp);
dsp->sb_freq = temp;
break;
case 0x41: /*Set output sampling rate*/
@@ -430,10 +469,13 @@ void sb_exec_command(sb_dsp_t *dsp)
if (dsp->sb_type < SB16) break;
dsp->sblatcho = (int)(TIMER_USEC * (1000000.0f / (float)(dsp->sb_data[1] + (dsp->sb_data[0] << 8))));
// pclog("Sample rate - %ihz (%i)\n",dsp->sb_data[1]+(dsp->sb_data[0]<<8), dsp->sblatcho);
temp = dsp->sb_freq;
dsp->sb_freq = dsp->sb_data[1] + (dsp->sb_data[0] << 8);
dsp->sb_timeo = 256LL + dsp->sb_freq;
dsp->sblatchi = dsp->sblatcho;
dsp->sb_timei = dsp->sb_timeo;
if (dsp->sb_freq != temp && dsp->sb_type >= SB16)
recalc_sb16_filter(dsp->sb_freq);
break;
case 0x48: /*Set DSP block transfer size*/
dsp->sb_8_autolen = dsp->sb_data[0] + (dsp->sb_data[1] << 8);
@@ -773,6 +815,10 @@ void sb_dsp_init(sb_dsp_t *dsp, int type)
timer_add(pollsb, &dsp->sbcount, &dsp->sbenable, dsp);
timer_add(sb_poll_i, &dsp->sb_count_i, &dsp->sb_enable_i, dsp);
timer_add(sb_wb_clear, &dsp->wb_time, &dsp->wb_time, dsp);
/*Initialise SB16 filter to same cutoff as 8-bit SBs (3.2 kHz). This will be recalculated when
a set frequency command is sent.*/
recalc_sb16_filter(3200*2);
}
void sb_dsp_setaddr(sb_dsp_t *dsp, uint16_t addr)

View File

@@ -8,7 +8,7 @@
*
* Sound emulation core.
*
* Version: @(#)sound.c 1.0.12 2018/02/11
* Version: @(#)sound.c 1.0.13 2018/02/15
*
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
* Miran Grca, <mgrca8@gmail.com>
@@ -48,19 +48,23 @@ typedef struct {
device_t *device;
} SOUND_CARD;
typedef struct {
void (*get_buffer)(int32_t *buffer, int len, void *p);
void *priv;
} sound_handler_t;
int sound_card_current = 0;
int sound_pos_global = 0;
int soundon = 1;
volatile int soundon = 1;
int sound_gain = 0;
static int sound_card_last = 0;
static struct {
void (*get_buffer)(int32_t *buffer, int len, void *p);
void *priv;
} sound_handlers[8];
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];
@@ -162,17 +166,19 @@ static void sound_cd_thread(void *param)
float cd_buffer_temp[2] = {0.0, 0.0};
float cd_buffer_temp2[2] = {0.0, 0.0};
int32_t cd_buffer_temp4[2] = {0, 0};
int c, has_audio;
int d;
thread_set_event(sound_cd_start_event);
while (cdaudioon)
{
thread_wait_event(sound_cd_event, -1);
thread_reset_event(sound_cd_event);
if (!soundon || !cdaudioon)
{
return;
}
for (c = 0; c < CD_BUFLEN*2; c += 2)
{
if (sound_is_float)
@@ -189,11 +195,14 @@ static void sound_cd_thread(void *param)
for (i = 0; i < CDROM_NUM; i++)
{
has_audio = 0;
if (cdrom_drives[i].bus_type == CDROM_BUS_DISABLED)
continue;
if (cdrom_drives[i].handler->audio_callback)
{
cdrom_drives[i].handler->audio_callback(i, cd_buffer[i], CD_BUFLEN*2);
has_audio = (cdrom_drives[i].bus_type && cdrom_drives[i].sound_on);
}
} else
continue;
if (soundon && has_audio)
{
int32_t audio_vol_l = cdrom_mode_sense_get_volume(i, 0);
@@ -234,12 +243,26 @@ static void sound_cd_thread(void *param)
cd_buffer_temp2[1] += cd_buffer_temp[1];
}
/*Apply sound card CD volume*/
cd_buffer_temp2[0] *= (float) cd_vol_l;
cd_buffer_temp2[0] /= 65535.0;
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];
cd_buffer_temp2[1] *= (float) cd_vol_r;
cd_buffer_temp2[1] /= 65535.0;
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)
{
@@ -264,13 +287,9 @@ static void sound_cd_thread(void *param)
}
}
if (sound_is_float)
{
givealbuffer_cd(cd_out_buffer);
}
else
{
givealbuffer_cd(cd_out_buffer_int16);
}
}
}
@@ -327,14 +346,16 @@ void sound_init(void)
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);
cdaudioon = 1;
/* pclog("Waiting for CD start event...\n"); */
thread_wait_event(sound_cd_start_event, -1);
thread_reset_event(sound_cd_start_event);
/* pclog("Done!\n"); */
}
else
@@ -350,6 +371,13 @@ void sound_add_handler(void (*get_buffer)(int32_t *buffer, int len, void *p), vo
sound_handlers_num++;
}
void sound_add_process_handler(void (*get_buffer)(int32_t *buffer, int len, void *p), void *p)
{
sound_process_handlers[sound_process_handlers_num].get_buffer = get_buffer;
sound_process_handlers[sound_process_handlers_num].priv = p;
sound_process_handlers_num++;
}
void sound_poll(void *priv)
{
sound_poll_time += sound_poll_latch;
@@ -422,7 +450,8 @@ void sound_reset(void)
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);
for (i = 0; i < CDROM_NUM; i++)
@@ -473,13 +502,15 @@ void sound_cd_thread_reset(void)
if (available_cdrom_drives && !cd_thread_enable)
{
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);
cdaudioon = 1;
thread_wait_event(sound_cd_start_event, -1);
thread_reset_event(sound_cd_start_event);
}
else if (!available_cdrom_drives && cd_thread_enable)
{

View File

@@ -8,7 +8,7 @@
*
* Sound emulation core.
*
* Version: @(#)sound.h 1.0.4 2018/02/11
* Version: @(#)sound.h 1.0.5 2018/02/15
*
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
* Miran Grca, <mgrca8@gmail.com>
@@ -39,6 +39,8 @@ 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);