Merge pull request #6147 from jriwanek-forks/miscclean

Some misc cleanups and code formatting
This commit is contained in:
Miran Grča
2025-09-10 02:23:17 +02:00
committed by GitHub
15 changed files with 379 additions and 302 deletions

View File

@@ -103,8 +103,29 @@ if(INSTRUMENT)
add_compile_definitions(USE_INSTRUMENT)
endif()
target_link_libraries(86Box cpu chipset mch dev mem fdd game cdrom rdisk mo hdd
net print scsi sio snd utils vid voodoo plat ui)
target_link_libraries(86Box
cpu
chipset
mch
dev
mem
fdd
game
cdrom
rdisk
mo
hdd
net
print
scsi
sio
snd
utils
vid
voodoo
plat
ui
)
if(HAIKU)
target_link_libraries(86Box be)

View File

@@ -92,8 +92,8 @@ cart_image_close(int drive)
static void
cart_image_load(int drive, char *fn)
{
FILE *fp;
uint32_t size;
FILE *fp = NULL;
uint32_t size = 0;
uint32_t base = 0x00000000;
cart_image_close(drive);
@@ -137,7 +137,7 @@ cart_image_load(int drive, char *fn)
static void
cart_load_common(int drive, char *fn, uint8_t hard_reset)
{
FILE *fp;
FILE *fp = NULL;
cartridge_log("Cartridge: loading drive %d with '%s'\n", drive, fn);

View File

@@ -105,39 +105,39 @@ static const struct
void (*close)(int drive);
int size;
} loaders[] = {
{ "001", img_load, img_close, -1},
{ "002", img_load, img_close, -1},
{ "003", img_load, img_close, -1},
{ "004", img_load, img_close, -1},
{ "005", img_load, img_close, -1},
{ "006", img_load, img_close, -1},
{ "007", img_load, img_close, -1},
{ "008", img_load, img_close, -1},
{ "009", img_load, img_close, -1},
{ "010", img_load, img_close, -1},
{ "12", img_load, img_close, -1},
{ "144", img_load, img_close, -1},
{ "360", img_load, img_close, -1},
{ "720", img_load, img_close, -1},
{ "86F", d86f_load, d86f_close, -1},
{ "BIN", img_load, img_close, -1},
{ "CQ", img_load, img_close, -1},
{ "CQM", img_load, img_close, -1},
{ "DDI", img_load, img_close, -1},
{ "DSK", img_load, img_close, -1},
{ "FDI", fdi_load, fdi_close, -1},
{ "FDF", img_load, img_close, -1},
{ "FLP", img_load, img_close, -1},
{ "HDM", img_load, img_close, -1},
{ "IMA", img_load, img_close, -1},
{ "IMD", imd_load, imd_close, -1},
{ "IMG", img_load, img_close, -1},
{ "JSON", pcjs_load, pcjs_close, -1},
{ "MFM", mfm_load, mfm_close, -1},
{ "TD0", td0_load, td0_close, -1},
{ "VFD", img_load, img_close, -1},
{ "XDF", img_load, img_close, -1},
{ 0, 0, 0, 0 }
{ "001", img_load, img_close, -1 },
{ "002", img_load, img_close, -1 },
{ "003", img_load, img_close, -1 },
{ "004", img_load, img_close, -1 },
{ "005", img_load, img_close, -1 },
{ "006", img_load, img_close, -1 },
{ "007", img_load, img_close, -1 },
{ "008", img_load, img_close, -1 },
{ "009", img_load, img_close, -1 },
{ "010", img_load, img_close, -1 },
{ "12", img_load, img_close, -1 },
{ "144", img_load, img_close, -1 },
{ "360", img_load, img_close, -1 },
{ "720", img_load, img_close, -1 },
{ "86F", d86f_load, d86f_close, -1 },
{ "BIN", img_load, img_close, -1 },
{ "CQ", img_load, img_close, -1 },
{ "CQM", img_load, img_close, -1 },
{ "DDI", img_load, img_close, -1 },
{ "DSK", img_load, img_close, -1 },
{ "FDI", fdi_load, fdi_close, -1 },
{ "FDF", img_load, img_close, -1 },
{ "FLP", img_load, img_close, -1 },
{ "HDM", img_load, img_close, -1 },
{ "IMA", img_load, img_close, -1 },
{ "IMD", imd_load, imd_close, -1 },
{ "IMG", img_load, img_close, -1 },
{ "JSON", pcjs_load, pcjs_close, -1 },
{ "MFM", mfm_load, mfm_close, -1 },
{ "TD0", td0_load, td0_close, -1 },
{ "VFD", img_load, img_close, -1 },
{ "XDF", img_load, img_close, -1 },
{ 0, 0, 0, 0 }
};
static const struct {
@@ -211,7 +211,7 @@ fdd_get_internal_name(int type)
int
fdd_get_from_internal_name(char *s)
{
int c = 0;
int c = 0;
while (strlen(drive_types[c].internal_name)) {
if (!strcmp((char *) drive_types[c].internal_name, s))
@@ -466,7 +466,7 @@ fdd_load(int drive, char *fn)
if (!fn)
return;
if (strstr(fn, "wp://") == fn) {
offs = 5;
offs = 5;
ui_writeprot[drive] = 1;
}
fn += offs;

View File

@@ -1,3 +1,4 @@
extern char *path_get_basename(const char *path);
extern void path_get_dirname(char *dest, const char *path);
extern char *path_get_filename(char *s);
extern char *path_get_extension(char *s);
@@ -5,4 +6,4 @@ extern void path_append_filename(char *dest, const char *s1, const char *s2);
extern void path_slash(char *path);
extern const char *path_get_slash(char *path);
extern void path_normalize(char *path);
extern int path_abs(char *path);
extern int path_abs(char *path);

View File

@@ -199,8 +199,8 @@ typedef struct emu8k_voice_t {
* something, similarly to targets and current, but... of what?
* what is curious is that if they are already zero, they are not written to, so it really
* looks like they are information about the status of the channel. (lfo position maybe?) */
uint32_t unknown_data0_4;
uint32_t unknown_data0_5;
uint32_t z2;
uint32_t z1;
union {
uint32_t psst;
struct {
@@ -229,7 +229,7 @@ typedef struct emu8k_voice_t {
};
#define CCCA_FILTQ_GET(ccca) (ccca >> 28)
#define CCCA_FILTQ_SET(ccca, q) ccca = (ccca & 0x0FFFFFFF) | (q << 28)
/* Bit 27 should always be zero */
/* Bit 27 should always be zero on EMU8000 */
#define CCCA_DMA_ACTIVE(ccca) (ccca & 0x04000000)
#define CCCA_DMA_WRITE_MODE(ccca) (ccca & 0x02000000)
#define CCCA_DMA_WRITE_RIGHT(ccca) (ccca & 0x01000000)
@@ -316,7 +316,9 @@ typedef struct emu8k_voice_t {
int env_engine_on;
emu8k_mem_internal_t addr, loop_start, loop_end;
emu8k_mem_internal_t addr;
emu8k_mem_internal_t loop_start;
emu8k_mem_internal_t loop_end;
int32_t initial_att;
int32_t initial_filter;

View File

@@ -774,14 +774,14 @@ pit_irq0_timer_pcjr(int new_out, int old_out, UNUSED(void *priv))
static const device_config_t pcjr_config[] = {
// clang-format off
{
.name = "display_type",
.description = "Display type",
.type = CONFIG_SELECTION,
.default_string = "",
.default_int = PCJR_RGB,
.file_filter = "",
.spinner = { 0 },
.selection = {
.name = "display_type",
.description = "Display type",
.type = CONFIG_SELECTION,
.default_string = NULL,
.default_int = PCJR_RGB,
.file_filter = NULL,
.spinner = { 0 },
.selection = {
{ .description = "RGB", .value = PCJR_RGB },
{ .description = "Composite", .value = PCJR_COMPOSITE },
{ .description = "RGB (no brown)", .value = PCJR_RGB_NO_BROWN },
@@ -807,11 +807,11 @@ static const device_config_t pcjr_config[] = {
.bios = { { 0 } }
},
{
.name = "apply_hd",
.description = "Apply overscan deltas",
.type = CONFIG_BINARY,
.default_string = "",
.default_int = 1
.name = "apply_hd",
.description = "Apply overscan deltas",
.type = CONFIG_BINARY,
.default_string = NULL,
.default_int = 1
},
{ .name = "", .description = "", .type = CONFIG_END }
// clang-format on

View File

@@ -267,6 +267,13 @@ plat_getcwd(char *bufp, int max)
return 0;
}
char *
path_get_basename(const char *path)
{
QFileInfo fi(path);
return fi.fileName().toUtf8().data();
}
void
path_get_dirname(char *dest, const char *path)
{

View File

@@ -50,9 +50,13 @@ joystick_init(void)
SDL_SetHint(SDL_HINT_JOYSTICK_THREAD, "1");
#endif
if (SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) != 0) {
#ifdef __APPLE__
if (SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) != 0)
#else
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) != 0)
#endif
return;
}
joysticks_present = SDL_NumJoysticks();
memset(sdl_joy, 0, sizeof(sdl_joy));

View File

@@ -34,128 +34,146 @@
#endif
#define I_NORMAL 0
#define I_MUSIC 1
#define I_WT 2
#define I_CD 3
#define I_MIDI 4
#define I_MUSIC 1
#define I_WT 2
#define I_CD 3
#define I_MIDI 4
static int audio[5] = {-1, -1, -1, -1, -1};
static int audio[5] = { -1, -1, -1, -1, -1 };
#ifdef USE_NEW_API
static struct audio_swpar info[5];
#else
static audio_info_t info[5];
#endif
static int freqs[5] = {SOUND_FREQ, MUSIC_FREQ, WT_FREQ, CD_FREQ, 0};
static int freqs[5] = { SOUND_FREQ, MUSIC_FREQ, WT_FREQ, CD_FREQ, 0 };
void closeal(void){
int i;
for(i = 0; i < sizeof(audio) / sizeof(audio[0]); i++){
if(audio[i] != -1){
close(audio[i]);
}
audio[i] = -1;
}
void
closeal(void)
{
for (int i = 0; i < sizeof(audio) / sizeof(audio[0]); i++) {
if (audio[i] != -1)
close(audio[i]);
audio[i] = -1;
}
}
void inital(void){
int i;
for(i = 0; i < sizeof(audio) / sizeof(audio[0]); i++){
audio[i] = open("/dev/audio", O_WRONLY);
if(audio[i] == -1) audio[i] = open("/dev/audio0", O_WRONLY);
if(audio[i] != -1){
void
inital(void)
{
for (int i = 0; i < sizeof(audio) / sizeof(audio[0]); i++) {
audio[i] = open("/dev/audio", O_WRONLY);
if (audio[i] == -1)
audio[i] = open("/dev/audio0", O_WRONLY);
if (audio[i] != -1) {
#ifdef USE_NEW_API
AUDIO_INITPAR(&info[i]);
ioctl(audio[i], AUDIO_GETPAR, &info[i]);
info[i].sig = 1;
info[i].bits = 16;
info[i].pchan = 2;
info[i].bps = 2;
ioctl(audio[i], AUDIO_SETPAR, &info[i]);
AUDIO_INITPAR(&info[i]);
ioctl(audio[i], AUDIO_GETPAR, &info[i]);
info[i].sig = 1;
info[i].bits = 16;
info[i].pchan = 2;
info[i].bps = 2;
ioctl(audio[i], AUDIO_SETPAR, &info[i]);
#else
AUDIO_INITINFO(&info[i]);
AUDIO_INITINFO(&info[i]);
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 900000000)
ioctl(audio[i], AUDIO_GETFORMAT, &info[i]);
ioctl(audio[i], AUDIO_GETFORMAT, &info[i]);
#else
ioctl(audio[i], AUDIO_GETINFO, &info[i]);
ioctl(audio[i], AUDIO_GETINFO, &info[i]);
#endif
info[i].play.channels = 2;
info[i].play.precision = 16;
info[i].play.encoding = AUDIO_ENCODING_SLINEAR;
info[i].hiwat = 5;
info[i].lowat = 3;
ioctl(audio[i], AUDIO_SETINFO, &info[i]);
info[i].play.channels = 2;
info[i].play.precision = 16;
info[i].play.encoding = AUDIO_ENCODING_SLINEAR;
info[i].hiwat = 5;
info[i].lowat = 3;
ioctl(audio[i], AUDIO_SETINFO, &info[i]);
#endif
}
}
}
}
}
void givealbuffer_common(const void *buf, const uint8_t src, const int size){
const int freq = freqs[src];
int16_t* output;
int output_size;
int16_t* conv;
int conv_size;
int i;
double gain;
int target_rate;
if(audio[src] == -1) return;
void
givealbuffer_common(const void *buf, const uint8_t src, const int size)
{
const int freq = freqs[src];
int16_t* output;
int output_size;
int16_t* conv;
int conv_size;
double gain;
int target_rate;
gain = sound_muted ? 0.0 : pow(10.0, (double) sound_gain / 20.0);
if(audio[src] == -1)
return;
if(sound_is_float){
float* input = (float*)buf;
conv_size = sizeof(int16_t) * size;
conv = malloc(conv_size);
for(i = 0; i < conv_size / sizeof(int16_t); i++){
conv[i] = 32767 * input[i];
}
}else{
conv_size = size * sizeof(int16_t);
conv = malloc(conv_size);
memcpy(conv, buf, conv_size);
}
gain = sound_muted ? 0.0 : pow(10.0, (double) sound_gain / 20.0);
if (sound_is_float) {
float* input = (float*)buf;
conv_size = sizeof(int16_t) * size;
conv = malloc(conv_size);
for (int i = 0; i < conv_size / sizeof(int16_t); i++)
conv[i] = 32767 * input[i];
} else {
conv_size = size * sizeof(int16_t);
conv = malloc(conv_size);
memcpy(conv, buf, conv_size);
}
#ifdef USE_NEW_API
target_rate = info[src].rate;
target_rate = info[src].rate;
#else
target_rate = info[src].play.sample_rate;
target_rate = info[src].play.sample_rate;
#endif
output_size = (double)conv_size * target_rate / freq;
output_size -= output_size % 4;
output = malloc(output_size);
for(i = 0; i < output_size / sizeof(int16_t) / 2; i++){
int ind = i * freq / target_rate * 2;
output[i * 2 + 0] = conv[ind + 0] * gain;
output[i * 2 + 1] = conv[ind + 1] * gain;
}
output_size = (double) conv_size * target_rate / freq;
output_size -= output_size % 4;
output = malloc(output_size);
for (int i = 0; i < output_size / sizeof(int16_t) / 2; i++) {
int ind = i * freq / target_rate * 2;
output[i * 2 + 0] = conv[ind + 0] * gain;
output[i * 2 + 1] = conv[ind + 1] * gain;
}
write(audio[src], output, output_size);
write(audio[src], output, output_size);
free(conv);
free(output);
free(conv);
free(output);
}
void givealbuffer(const void *buf){
givealbuffer_common(buf, I_NORMAL, SOUNDBUFLEN << 1);
void
givealbuffer(const void *buf)
{
givealbuffer_common(buf, I_NORMAL, SOUNDBUFLEN << 1);
}
void givealbuffer_music(const void *buf){
givealbuffer_common(buf, I_MUSIC, MUSICBUFLEN << 1);
void
givealbuffer_music(const void *buf)
{
givealbuffer_common(buf, I_MUSIC, MUSICBUFLEN << 1);
}
void givealbuffer_wt(const void *buf){
givealbuffer_common(buf, I_WT, WTBUFLEN << 1);
void
givealbuffer_wt(const void *buf)
{
givealbuffer_common(buf, I_WT, WTBUFLEN << 1);
}
void givealbuffer_cd(const void *buf){
givealbuffer_common(buf, I_CD, CD_BUFLEN << 1);
void
givealbuffer_cd(const void *buf)
{
givealbuffer_common(buf, I_CD, CD_BUFLEN << 1);
}
void givealbuffer_midi(const void *buf, const uint32_t size){
givealbuffer_common(buf, I_MIDI, (int) size);
void
givealbuffer_midi(const void *buf, const uint32_t size)
{
givealbuffer_common(buf, I_MIDI, (int) size);
}
void al_set_midi(const int freq, UNUSED(const int buf_size)){
freqs[I_MIDI] = freq;
void
al_set_midi(const int freq, UNUSED(const int buf_size))
{
freqs[I_MIDI] = freq;
}

View File

@@ -37,6 +37,12 @@
#define FREQ SOUND_FREQ
#define BUFLEN SOUNDBUFLEN
#define I_NORMAL 0
#define I_MUSIC 1
#define I_WT 2
#define I_CD 3
#define I_MIDI 4
ALuint buffers[4]; /* front and back buffers */
ALuint buffers_music[4]; /* front and back buffers */
ALuint buffers_wt[4]; /* front and back buffers */
@@ -124,7 +130,7 @@ inital(void)
int16_t *cd_buf_int16 = NULL;
int16_t *midi_buf_int16 = NULL;
int init_midi = 0;
int init_midi = 0;
if (initialized)
return;
@@ -166,32 +172,36 @@ inital(void)
else
alGenSources(4, source);
alSource3f(source[0], AL_POSITION, 0.0f, 0.0f, 0.0f);
alSource3f(source[0], AL_VELOCITY, 0.0f, 0.0f, 0.0f);
alSource3f(source[0], AL_DIRECTION, 0.0f, 0.0f, 0.0f);
alSourcef(source[0], AL_ROLLOFF_FACTOR, 0.0f);
alSourcei(source[0], AL_SOURCE_RELATIVE, AL_TRUE);
alSource3f(source[1], AL_POSITION, 0.0f, 0.0f, 0.0f);
alSource3f(source[1], AL_VELOCITY, 0.0f, 0.0f, 0.0f);
alSource3f(source[1], AL_DIRECTION, 0.0f, 0.0f, 0.0f);
alSourcef(source[1], AL_ROLLOFF_FACTOR, 0.0f);
alSourcei(source[1], AL_SOURCE_RELATIVE, AL_TRUE);
alSource3f(source[2], AL_POSITION, 0.0f, 0.0f, 0.0f);
alSource3f(source[2], AL_VELOCITY, 0.0f, 0.0f, 0.0f);
alSource3f(source[2], AL_DIRECTION, 0.0f, 0.0f, 0.0f);
alSourcef(source[2], AL_ROLLOFF_FACTOR, 0.0f);
alSourcei(source[2], AL_SOURCE_RELATIVE, AL_TRUE);
alSource3f(source[3], AL_POSITION, 0.0f, 0.0f, 0.0f);
alSource3f(source[3], AL_VELOCITY, 0.0f, 0.0f, 0.0f);
alSource3f(source[3], AL_DIRECTION, 0.0f, 0.0f, 0.0f);
alSourcef(source[3], AL_ROLLOFF_FACTOR, 0.0f);
alSourcei(source[3], AL_SOURCE_RELATIVE, AL_TRUE);
alSource3f(source[I_NORMAL], AL_POSITION, 0.0f, 0.0f, 0.0f);
alSource3f(source[I_NORMAL], AL_VELOCITY, 0.0f, 0.0f, 0.0f);
alSource3f(source[I_NORMAL], AL_DIRECTION, 0.0f, 0.0f, 0.0f);
alSourcef(source[I_NORMAL], AL_ROLLOFF_FACTOR, 0.0f);
alSourcei(source[I_NORMAL], AL_SOURCE_RELATIVE, AL_TRUE);
alSource3f(source[I_MUSIC], AL_POSITION, 0.0f, 0.0f, 0.0f);
alSource3f(source[I_MUSIC], AL_VELOCITY, 0.0f, 0.0f, 0.0f);
alSource3f(source[I_MUSIC], AL_DIRECTION, 0.0f, 0.0f, 0.0f);
alSourcef(source[I_MUSIC], AL_ROLLOFF_FACTOR, 0.0f);
alSourcei(source[I_MUSIC], AL_SOURCE_RELATIVE, AL_TRUE);
alSource3f(source[I_WT], AL_POSITION, 0.0f, 0.0f, 0.0f);
alSource3f(source[I_WT], AL_VELOCITY, 0.0f, 0.0f, 0.0f);
alSource3f(source[I_WT], AL_DIRECTION, 0.0f, 0.0f, 0.0f);
alSourcef(source[I_WT], AL_ROLLOFF_FACTOR, 0.0f);
alSourcei(source[I_WT], AL_SOURCE_RELATIVE, AL_TRUE);
alSource3f(source[I_CD], AL_POSITION, 0.0f, 0.0f, 0.0f);
alSource3f(source[I_CD], AL_VELOCITY, 0.0f, 0.0f, 0.0f);
alSource3f(source[I_CD], AL_DIRECTION, 0.0f, 0.0f, 0.0f);
alSourcef(source[I_CD], AL_ROLLOFF_FACTOR, 0.0f);
alSourcei(source[I_CD], AL_SOURCE_RELATIVE, AL_TRUE);
if (init_midi) {
alSource3f(source[4], AL_POSITION, 0.0f, 0.0f, 0.0f);
alSource3f(source[4], AL_VELOCITY, 0.0f, 0.0f, 0.0f);
alSource3f(source[4], AL_DIRECTION, 0.0f, 0.0f, 0.0f);
alSourcef(source[4], AL_ROLLOFF_FACTOR, 0.0f);
alSourcei(source[4], AL_SOURCE_RELATIVE, AL_TRUE);
alSource3f(source[I_MIDI], AL_POSITION, 0.0f, 0.0f, 0.0f);
alSource3f(source[I_MIDI], AL_VELOCITY, 0.0f, 0.0f, 0.0f);
alSource3f(source[I_MIDI], AL_DIRECTION, 0.0f, 0.0f, 0.0f);
alSourcef(source[I_MIDI], AL_ROLLOFF_FACTOR, 0.0f);
alSourcei(source[I_MIDI], AL_SOURCE_RELATIVE, AL_TRUE);
}
if (sound_is_float) {
@@ -228,18 +238,18 @@ inital(void)
}
}
alSourceQueueBuffers(source[0], 4, buffers);
alSourceQueueBuffers(source[1], 4, buffers_music);
alSourceQueueBuffers(source[2], 4, buffers_wt);
alSourceQueueBuffers(source[3], 4, buffers_cd);
alSourceQueueBuffers(source[I_NORMAL], 4, buffers);
alSourceQueueBuffers(source[I_MUSIC], 4, buffers_music);
alSourceQueueBuffers(source[I_WT], 4, buffers_wt);
alSourceQueueBuffers(source[I_CD], 4, buffers_cd);
if (init_midi)
alSourceQueueBuffers(source[4], 4, buffers_midi);
alSourcePlay(source[0]);
alSourcePlay(source[1]);
alSourcePlay(source[2]);
alSourcePlay(source[3]);
alSourceQueueBuffers(source[I_MIDI], 4, buffers_midi);
alSourcePlay(source[I_NORMAL]);
alSourcePlay(source[I_MUSIC]);
alSourcePlay(source[I_WT]);
alSourcePlay(source[I_CD]);
if (init_midi)
alSourcePlay(source[4]);
alSourcePlay(source[I_MIDI]);
if (sound_is_float) {
if (init_midi)

View File

@@ -556,11 +556,11 @@ emu8k_inw(uint16_t addr, void *priv)
return ret;
case 4:
READ16(addr, emu8k->voice[emu8k->cur_voice].unknown_data0_4);
READ16(addr, emu8k->voice[emu8k->cur_voice].z2);
return ret;
case 5:
READ16(addr, emu8k->voice[emu8k->cur_voice].unknown_data0_5);
READ16(addr, emu8k->voice[emu8k->cur_voice].z1);
return ret;
case 6:
@@ -888,11 +888,11 @@ emu8k_outw(uint16_t addr, uint16_t val, void *priv)
return;
case 4:
WRITE16(addr, emu8k->voice[emu8k->cur_voice].unknown_data0_4, val);
WRITE16(addr, emu8k->voice[emu8k->cur_voice].z2, val);
return;
case 5:
WRITE16(addr, emu8k->voice[emu8k->cur_voice].unknown_data0_5, val);
WRITE16(addr, emu8k->voice[emu8k->cur_voice].z1, val);
return;
case 6:
@@ -1006,7 +1006,7 @@ emu8k_outw(uint16_t addr, uint16_t val, void *priv)
case 0x9:
emu8k->reverb_engine.reflections[0].feedback = (val & 0xF) / 15.0;
break;
case 0xB:
case 0xB:
#if 0
emu8k->reverb_engine.reflections[0].feedback_r = (val&0xF)/15.0;
#endif
@@ -1050,7 +1050,7 @@ emu8k_outw(uint16_t addr, uint16_t val, void *priv)
case 1:
emu8k->reverb_engine.refl_in_amp = val & 0xFF;
break;
case 3:
case 3:
#if 0
emu8k->reverb_engine.refl_in_amp_r = val&0xFF;
#endif
@@ -1811,11 +1811,10 @@ emu8k_update(emu8k_t *emu8k)
emu_voice->filt_buffer[1] += (emu_voice->filt_buffer[0] * coef0) >> 24;
emu_voice->filt_buffer[0] += (vhp * coef0) >> 24;
dat = (int32_t) (emu_voice->filt_buffer[1] >> 8);
if (dat > 32767) {
if (dat > 32767)
dat = 32767;
} else if (dat < -32768) {
else if (dat < -32768)
dat = -32768;
}
#elif defined FILTER_MOOG
@@ -1823,15 +1822,15 @@ emu8k_update(emu8k_t *emu8k)
dat <<= 8;
dat -= (coef2 * emu_voice->filt_buffer[4]) >> 24; /*feedback*/
int64_t t1 = emu_voice->filt_buffer[1];
int64_t t1 = emu_voice->filt_buffer[1];
emu_voice->filt_buffer[1] = ((dat + emu_voice->filt_buffer[0]) * coef0 - emu_voice->filt_buffer[1] * coef1) >> 24;
emu_voice->filt_buffer[1] = ClipBuffer(emu_voice->filt_buffer[1]);
int64_t t2 = emu_voice->filt_buffer[2];
int64_t t2 = emu_voice->filt_buffer[2];
emu_voice->filt_buffer[2] = ((emu_voice->filt_buffer[1] + t1) * coef0 - emu_voice->filt_buffer[2] * coef1) >> 24;
emu_voice->filt_buffer[2] = ClipBuffer(emu_voice->filt_buffer[2]);
int64_t t3 = emu_voice->filt_buffer[3];
int64_t t3 = emu_voice->filt_buffer[3];
emu_voice->filt_buffer[3] = ((emu_voice->filt_buffer[2] + t2) * coef0 - emu_voice->filt_buffer[3] * coef1) >> 24;
emu_voice->filt_buffer[3] = ClipBuffer(emu_voice->filt_buffer[3]);
@@ -1841,11 +1840,10 @@ emu8k_update(emu8k_t *emu8k)
emu_voice->filt_buffer[0] = ClipBuffer(dat);
dat = (int32_t) (emu_voice->filt_buffer[4] >> 8);
if (dat > 32767) {
if (dat > 32767)
dat = 32767;
} else if (dat < -32768) {
else if (dat < -32768)
dat = -32768;
}
#elif defined FILTER_CONSTANT
@@ -1864,11 +1862,10 @@ emu8k_update(emu8k_t *emu8k)
emu_voice->filt_buffer[1] = ClipBuffer(emu_voice->filt_buffer[1]);
dat = (int32_t) (emu_voice->filt_buffer[1] >> 8);
if (dat > 32767) {
if (dat > 32767)
dat = 32767;
} else if (dat < -32768) {
else if (dat < -32768)
dat = -32768;
}
#endif
}
@@ -2372,6 +2369,8 @@ emu8k_init(emu8k_t *emu8k, uint16_t emu_addr, int onboard_ram)
void
emu8k_close(emu8k_t *emu8k)
{
free(emu8k->rom);
free(emu8k->ram);
if (emu8k->rom)
free(emu8k->rom);
if (emu8k->ram)
free(emu8k->ram);
}

View File

@@ -32,109 +32,125 @@
#define I_CD 3
#define I_MIDI 4
static struct sio_hdl* audio[5] = {NULL, NULL, NULL, NULL, NULL};
static struct sio_hdl* audio[5] = { NULL, NULL, NULL, NULL, NULL };
static struct sio_par info[5];
static int freqs[5] = {SOUND_FREQ, MUSIC_FREQ, WT_FREQ, CD_FREQ, 0};
static int freqs[5] = { SOUND_FREQ, MUSIC_FREQ, WT_FREQ, CD_FREQ, 0 };
void closeal(void){
int i;
for(i = 0; i < sizeof(audio) / sizeof(audio[0]); i++){
if(audio[i] != NULL){
sio_close(audio[i]);
}
audio[i] = NULL;
}
void
closeal(void)
{
for (int i = 0; i < sizeof(audio) / sizeof(audio[0]); i++) {
if (audio[i] != NULL)
sio_close(audio[i]);
audio[i] = NULL;
}
}
void inital(void){
int i;
for(i = 0; i < sizeof(audio) / sizeof(audio[0]); i++){
audio[i] = sio_open(SIO_DEVANY, SIO_PLAY, 0);
if(audio[i] != NULL){
int rate;
int max_frames;
sio_getpar(audio[i], &info[i]);
rate = info[i].rate;
max_frames = info[i].bufsz;
sio_initpar(&info[i]);
info[i].sig = 1;
info[i].bits = 16;
info[i].pchan = 2;
info[i].rate = rate;
info[i].appbufsz = max_frames;
sio_setpar(audio[i], &info[i]);
sio_getpar(audio[i], &info[i]);
if(!sio_start(audio[i])){
sio_close(audio[i]);
audio[i] = NULL;
}
}
}
void
inital(void)
{
for (int i = 0; i < sizeof(audio) / sizeof(audio[0]); i++) {
audio[i] = sio_open(SIO_DEVANY, SIO_PLAY, 0);
if (audio[i] != NULL) {
int rate;
int max_frames;
sio_getpar(audio[i], &info[i]);
rate = info[i].rate;
max_frames = info[i].bufsz;
sio_initpar(&info[i]);
info[i].sig = 1;
info[i].bits = 16;
info[i].pchan = 2;
info[i].rate = rate;
info[i].appbufsz = max_frames;
sio_setpar(audio[i], &info[i]);
sio_getpar(audio[i], &info[i]);
if (!sio_start(audio[i])) {
sio_close(audio[i]);
audio[i] = NULL;
}
}
}
}
void givealbuffer_common(const void *buf, const uint8_t src, const int size){
const int freq = freqs[src];
int16_t* output;
int output_size;
int16_t* conv;
int conv_size;
int i;
double gain;
int target_rate;
if(audio[src] == NULL) return;
void
givealbuffer_common(const void *buf, const uint8_t src, const int size)
{
const int freq = freqs[src];
int16_t* output;
int output_size;
int16_t* conv;
int conv_size;
double gain;
int target_rate;
if (audio[src] == NULL)
return;
gain = sound_muted ? 0.0 : pow(10.0, (double) sound_gain / 20.0);
gain = sound_muted ? 0.0 : pow(10.0, (double) sound_gain / 20.0);
if(sound_is_float){
float* input = (float*)buf;
conv_size = sizeof(int16_t) * size;
conv = malloc(conv_size);
for(i = 0; i < conv_size / sizeof(int16_t); i++){
conv[i] = 32767 * input[i];
}
}else{
conv_size = size * sizeof(int16_t);
conv = malloc(conv_size);
memcpy(conv, buf, conv_size);
}
if (sound_is_float) {
float* input = (float*) buf;
conv_size = sizeof(int16_t) * size;
conv = malloc(conv_size);
for (int i = 0; i < conv_size / sizeof(int16_t); i++)
conv[i] = 32767 * input[i];
} else {
conv_size = size * sizeof(int16_t);
conv = malloc(conv_size);
memcpy(conv, buf, conv_size);
}
target_rate = info[src].rate;
target_rate = info[src].rate;
output_size = (double)conv_size * target_rate / freq;
output_size -= output_size % 4;
output = malloc(output_size);
for(i = 0; i < output_size / sizeof(int16_t) / 2; i++){
int ind = i * freq / target_rate * 2;
output[i * 2 + 0] = conv[ind + 0] * gain;
output[i * 2 + 1] = conv[ind + 1] * gain;
}
output_size = (double) conv_size * target_rate / freq;
output_size -= output_size % 4;
output = malloc(output_size);
for (int i = 0; i < output_size / sizeof(int16_t) / 2; i++) {
int ind = i * freq / target_rate * 2;
output[i * 2 + 0] = conv[ind + 0] * gain;
output[i * 2 + 1] = conv[ind + 1] * gain;
}
sio_write(audio[src], output, output_size);
sio_write(audio[src], output, output_size);
free(conv);
free(output);
free(conv);
free(output);
}
void givealbuffer(const void *buf){
givealbuffer_common(buf, I_NORMAL, SOUNDBUFLEN << 1);
void
givealbuffer(const void *buf)
{
givealbuffer_common(buf, I_NORMAL, SOUNDBUFLEN << 1);
}
void givealbuffer_music(const void *buf){
givealbuffer_common(buf, I_MUSIC, MUSICBUFLEN << 1);
void
givealbuffer_music(const void *buf)
{
givealbuffer_common(buf, I_MUSIC, MUSICBUFLEN << 1);
}
void givealbuffer_wt(const void *buf){
givealbuffer_common(buf, I_WT, WTBUFLEN << 1);
void
givealbuffer_wt(const void *buf)
{
givealbuffer_common(buf, I_WT, WTBUFLEN << 1);
}
void givealbuffer_cd(const void *buf){
givealbuffer_common(buf, I_CD, CD_BUFLEN << 1);
void
givealbuffer_cd(const void *buf)
{
givealbuffer_common(buf, I_CD, CD_BUFLEN << 1);
}
void givealbuffer_midi(const void *buf, const uint32_t size){
givealbuffer_common(buf, I_MIDI, (int) size);
void
givealbuffer_midi(const void *buf, const uint32_t size)
{
givealbuffer_common(buf, I_MIDI, (int) size);
}
void al_set_midi(const int freq, UNUSED(const int buf_size)){
freqs[I_MIDI] = freq;
void
al_set_midi(const int freq, UNUSED(const int buf_size))
{
freqs[I_MIDI] = freq;
}

View File

@@ -55,7 +55,6 @@ int wavetable_pos_global = 0;
int sound_gain = 0;
static sound_handler_t sound_handlers[8];
static sound_handler_t music_handlers[8];
static sound_handler_t wavetable_handlers[8];

View File

@@ -39,8 +39,8 @@
static void *xaudio2_handle = NULL;
static HRESULT(WINAPI *pXAudio2Create)(IXAudio2 **ppXAudio2, uint32_t Flags, XAUDIO2_PROCESSOR XAudio2Processor);
static dllimp_t xaudio2_imports[] = {
{"XAudio2Create", &pXAudio2Create},
{ NULL, NULL },
{"XAudio2Create", &pXAudio2Create },
{ NULL, NULL },
};
# define XAudio2Create pXAudio2Create
#endif
@@ -119,22 +119,18 @@ void
inital(void)
{
#if defined(_WIN32) && !defined(USE_FAUDIO)
if (xaudio2_handle == NULL) {
if (xaudio2_handle == NULL)
xaudio2_handle = dynld_module("xaudio2_9.dll", xaudio2_imports);
}
if (xaudio2_handle == NULL) {
if (xaudio2_handle == NULL)
xaudio2_handle = dynld_module("xaudio2_9redist.dll", xaudio2_imports);
}
if (xaudio2_handle == NULL) {
if (xaudio2_handle == NULL)
return;
}
#endif
if (XAudio2Create(&xaudio2, 0, XAUDIO2_DEFAULT_PROCESSOR)) {
if (XAudio2Create(&xaudio2, 0, XAUDIO2_DEFAULT_PROCESSOR))
return;
}
if (IXAudio2_CreateMasteringVoice(xaudio2, &mastervoice, 2, FREQ, 0, 0, NULL, 0)) {
IXAudio2_Release(xaudio2);
@@ -209,6 +205,7 @@ closeal(void)
{
if (!initialized)
return;
initialized = 0;
(void) IXAudio2SourceVoice_Stop(srcvoice, 0, XAUDIO2_COMMIT_NOW);
(void) IXAudio2SourceVoice_FlushSourceBuffers(srcvoice);
@@ -229,9 +226,11 @@ closeal(void)
IXAudio2SourceVoice_DestroyVoice(srcvoice);
IXAudio2MasteringVoice_DestroyVoice(mastervoice);
IXAudio2_Release(xaudio2);
srcvoice = srcvoicecd = srcvoicemidi = NULL;
mastervoice = NULL;
xaudio2 = NULL;
srcvoice = NULL;
srcvoicecd = NULL;
srcvoicemidi = NULL;
mastervoice = NULL;
xaudio2 = NULL;
#if defined(_WIN32) && !defined(USE_FAUDIO)
dynld_close(xaudio2_handle);

View File

@@ -351,7 +351,7 @@ plat_put_backslash(char *s)
/* Return the last element of a pathname. */
char *
plat_get_basename(const char *path)
path_get_basename(const char *path)
{
int c = (int) strlen(path);
@@ -1420,6 +1420,7 @@ main(int argc, char **argv)
f_rl_callback_handler_remove();
return 0;
}
char *
plat_vidapi_name(UNUSED(int i))
{