Sound buffer size now configurable.

This commit is contained in:
SarahW 2017-06-10 21:00:23 +01:00
commit 6e51e8975e
22 changed files with 92 additions and 26 deletions

View file

@ -1,5 +1,6 @@
#include "ibm.h"
#include "dac.h"
#include "sound.h"
uint8_t dac,dac2;
uint8_t dacctrl;
@ -43,7 +44,7 @@ void pollss()
}
}
int16_t dacbuffer[SOUNDBUFLEN+20];
int16_t dacbuffer[MAXSOUNDBUFLEN+20];
int dacbufferpos=0;
void getdacsamp()
{

View file

@ -485,8 +485,6 @@ float VGACONST1,VGACONST2;
float RTCCONST;
int gated,speakval,speakon;
#define SOUNDBUFLEN (48000/20)
/*Sound Blaster*/
#define SADLIB 1 /*No DSP*/

View file

@ -36,6 +36,7 @@
#include "serial.h"
#include "sound.h"
#include "sound_cms.h"
#include "sound_dbopl.h"
#include "sound_opl.h"
#include "sound_sb.h"
#include "sound_speaker.h"
@ -430,6 +431,8 @@ void resetpchard()
ioctl_reset();
}
}
sound_update_buf_length();
}
char romsets[17][40]={"IBM PC","IBM XT","Generic Turbo XT","Euro PC","Tandy 1000","Amstrad PC1512","Sinclair PC200","Amstrad PC1640","IBM AT","AMI 286 clone","Dell System 200","Misc 286","IBM AT 386","Misc 386","386 clone","486 clone","486 clone 2"};
@ -632,6 +635,8 @@ void loadconfig(char *fn)
window_y = config_get_int(CFG_GLOBAL, NULL, "window_y", 0);
window_remember = config_get_int(CFG_GLOBAL, NULL, "window_remember", 0);
sound_buf_len = config_get_int(CFG_GLOBAL, NULL, "sound_buf_len", 200);
GAMEBLASTER = config_get_int(CFG_MACHINE, NULL, "gameblaster", 0);
GUS = config_get_int(CFG_MACHINE, NULL, "gus", 0);
SSI2001 = config_get_int(CFG_MACHINE, NULL, "ssi2001", 0);
@ -782,6 +787,8 @@ void saveconfig(char *fn)
config_set_int(CFG_GLOBAL, NULL, "window_y", window_y);
config_set_int(CFG_GLOBAL, NULL, "window_remember", window_remember);
config_set_int(CFG_GLOBAL, NULL, "sound_buf_len", sound_buf_len);
config_set_int(CFG_MACHINE, NULL, "gameblaster", GAMEBLASTER);
config_set_int(CFG_MACHINE, NULL, "gus", GUS);
config_set_int(CFG_MACHINE, NULL, "ssi2001", SSI2001);

View file

@ -53,6 +53,15 @@ BEGIN
MENUITEM SEPARATOR
MENUITEM "Disc activity indicator", IDM_VID_DISC
END
POPUP "&Sound"
BEGIN
POPUP "&Buffer length"
BEGIN
MENUITEM "&100ms", IDM_BUF_100MS
MENUITEM "&200ms", IDM_BUF_200MS
MENUITEM "&400ms", IDM_BUF_400MS
END
END
END
POPUP "&Misc"
BEGIN

View file

@ -21,6 +21,9 @@
#define IDM_VID_FS_43 40072
#define IDM_VID_FS_SQ 40073
#define IDM_VID_FS_INT 40074
#define IDM_BUF_100MS 40080
#define IDM_BUF_200MS 40081
#define IDM_BUF_400MS 40082
#define IDM_CDROM_EMPTY 40100
#define IDM_CDROM_REAL 40100
#define IDM_CDROM_DISABLED 40200

View file

@ -120,7 +120,18 @@ static int16_t cd_buffer[CD_BUFLEN * 2];
static thread_t *sound_cd_thread_h;
static event_t *sound_cd_event;
static unsigned int cd_vol_l, cd_vol_r;
static int cd_buf_update = CD_BUFLEN / SOUNDBUFLEN;
int sound_buf_len = 48000 / 10;
void sound_update_buf_length()
{
int new_buf_len = (48000 / (1000 / sound_buf_len)) / 4;
if (new_buf_len > MAXSOUNDBUFLEN)
new_buf_len = MAXSOUNDBUFLEN;
SOUNDBUFLEN = new_buf_len;
}
void sound_set_cd_volume(unsigned int vol_l, unsigned int vol_r)
{
@ -194,7 +205,7 @@ void sound_init()
initalmain(0,NULL);
inital();
outbuffer = malloc(SOUNDBUFLEN * 2 * sizeof(int32_t));
outbuffer = malloc(MAXSOUNDBUFLEN * 2 * sizeof(int32_t));
sound_cd_event = thread_create_event();
sound_cd_thread_h = thread_create(sound_cd_thread, NULL);
@ -207,10 +218,18 @@ void sound_add_handler(void (*get_buffer)(int32_t *buffer, int len, void *p), vo
sound_handlers_num++;
}
static int cd_pos = 0;
void sound_poll(void *priv)
{
sound_poll_time += sound_poll_latch;
cd_pos++;
if (cd_pos == (CD_BUFLEN * 48000) / CD_FREQ)
{
cd_pos = 0;
thread_set_event(sound_cd_event);
}
sound_pos_global++;
if (sound_pos_global == SOUNDBUFLEN)
{
@ -238,14 +257,8 @@ void sound_poll(void *priv)
if (soundon) givealbuffer(outbuffer);
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;
sound_update_buf_length();
}
}

View file

@ -27,3 +27,9 @@ void inital();
void givealbuffer(int32_t *buf);
void givealbuffer_cd(int16_t *buf);
extern int sound_buf_len;
void sound_update_buf_length();
extern int SOUNDBUFLEN;
#define MAXSOUNDBUFLEN (48000 / 10)

View file

@ -21,7 +21,7 @@ typedef struct ad1848_t
int timer_count, timer_latch;
int16_t buffer[SOUNDBUFLEN * 2];
int16_t buffer[MAXSOUNDBUFLEN * 2];
int pos;
} ad1848_t;

View file

@ -55,8 +55,8 @@ typedef struct adgold_t
int vol_l, vol_r;
int treble, bass;
int16_t opl_buffer[SOUNDBUFLEN * 2];
int16_t mma_buffer[2][SOUNDBUFLEN];
int16_t opl_buffer[MAXSOUNDBUFLEN * 2];
int16_t mma_buffer[2][MAXSOUNDBUFLEN];
int pos;

View file

@ -23,7 +23,7 @@ typedef struct cms_t
int noisecount[2][2];
int noisetype[2][2];
int16_t buffer[SOUNDBUFLEN * 2];
int16_t buffer[MAXSOUNDBUFLEN * 2];
int pos;
} cms_t;

View file

@ -81,7 +81,7 @@ typedef struct emu8k_t
int16_t out_l, out_r;
int pos;
int32_t buffer[SOUNDBUFLEN * 2];
int32_t buffer[MAXSOUNDBUFLEN * 2];
} emu8k_t;
void emu8k_init(emu8k_t *emu8k, int onboard_ram);

View file

@ -39,7 +39,7 @@ typedef struct gus_t
int32_t out_l, out_r;
int16_t buffer[2][SOUNDBUFLEN];
int16_t buffer[2][MAXSOUNDBUFLEN];
int pos;
int samp_timer, samp_latch;

View file

@ -1,3 +1,5 @@
#include "sound.h"
typedef struct opl_t
{
int chip_nr[2];
@ -7,7 +9,7 @@ typedef struct opl_t
int16_t filtbuf[2];
int16_t buffer[SOUNDBUFLEN * 2];
int16_t buffer[MAXSOUNDBUFLEN * 2];
int pos;
} opl_t;

View file

@ -132,7 +132,7 @@ typedef struct pas16_t
opl_t opl;
sb_dsp_t dsp;
int16_t pcm_buffer[2][SOUNDBUFLEN];
int16_t pcm_buffer[2][MAXSOUNDBUFLEN];
int pos;
} pas16_t;

View file

@ -21,7 +21,7 @@ typedef struct ps1_audio_t
uint8_t dac_val;
int16_t buffer[SOUNDBUFLEN];
int16_t buffer[MAXSOUNDBUFLEN];
int pos;
} ps1_audio_t;

View file

@ -27,7 +27,7 @@ typedef struct pssj_t
int wave_pos;
int pulse_width;
int16_t buffer[SOUNDBUFLEN];
int16_t buffer[MAXSOUNDBUFLEN];
int pos;
} pssj_t;

View file

@ -57,7 +57,7 @@ typedef struct sb_dsp_t
int wb_time, wb_full;
int16_t buffer[SOUNDBUFLEN * 2];
int16_t buffer[MAXSOUNDBUFLEN * 2];
int pos;
} sb_dsp_t;

View file

@ -1,3 +1,5 @@
#include "sound.h"
enum
{
SN76496,
@ -23,7 +25,7 @@ typedef struct sn76489_t
int type;
int extra_divide;
int16_t buffer[SOUNDBUFLEN];
int16_t buffer[MAXSOUNDBUFLEN];
int pos;
double psgconst;

View file

@ -4,7 +4,7 @@
int speaker_mute = 0;
static int16_t speaker_buffer[SOUNDBUFLEN];
static int16_t speaker_buffer[MAXSOUNDBUFLEN];
static int speaker_pos = 0;

View file

@ -10,7 +10,7 @@
typedef struct ssi2001_t
{
void *psid;
int16_t buffer[SOUNDBUFLEN * 2];
int16_t buffer[MAXSOUNDBUFLEN * 2];
int pos;
} ssi2001_t;

View file

@ -16,6 +16,9 @@ ALuint buffers_cd[4]; // front and back buffers
static ALuint source[2]; // audio source
#endif
#define FREQ 48000
int SOUNDBUFLEN = 48000/20;
#define BUFLEN SOUNDBUFLEN
void closeal();

View file

@ -646,6 +646,9 @@ int WINAPI WinMain (HINSTANCE hThisInstance,
CheckMenuItem(menu, IDM_VID_REMEMBER, window_remember ? MF_CHECKED : MF_UNCHECKED);
CheckMenuItem(menu, IDM_BPB_DISABLE, bpb_disable ? MF_CHECKED : MF_UNCHECKED);
CheckMenuItem(menu, IDM_VID_DISC, vid_disc_indicator ? MF_CHECKED : MF_UNCHECKED);
CheckMenuItem(menu, IDM_BUF_100MS, (sound_buf_len == 100) ? MF_CHECKED : MF_UNCHECKED);
CheckMenuItem(menu, IDM_BUF_200MS, (sound_buf_len == 200) ? MF_CHECKED : MF_UNCHECKED);
CheckMenuItem(menu, IDM_BUF_400MS, (sound_buf_len == 400) ? MF_CHECKED : MF_UNCHECKED);
if (!loadbios())
{
@ -1051,6 +1054,25 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
saveconfig(NULL);
break;
case IDM_BUF_100MS: case IDM_BUF_200MS: case IDM_BUF_400MS:
switch (LOWORD(wParam))
{
case IDM_BUF_100MS:
sound_buf_len = 100;
break;
case IDM_BUF_200MS:
sound_buf_len = 200;
break;
case IDM_BUF_400MS:
sound_buf_len = 400;
break;
}
CheckMenuItem(hmenu, IDM_BUF_100MS, (sound_buf_len == 100) ? MF_CHECKED : MF_UNCHECKED);
CheckMenuItem(hmenu, IDM_BUF_200MS, (sound_buf_len == 200) ? MF_CHECKED : MF_UNCHECKED);
CheckMenuItem(hmenu, IDM_BUF_400MS, (sound_buf_len == 400) ? MF_CHECKED : MF_UNCHECKED);
saveconfig(NULL);
break;
case IDM_CDROM_DISABLED:
if (cdrom_enabled)
{