Skip to content

Commit fb12ebf

Browse files
committed
MEGA65: mixer refinements #272
[DEPLOYMENT]
1 parent f3dcc99 commit fb12ebf

File tree

5 files changed

+55
-9
lines changed

5 files changed

+55
-9
lines changed

targets/mega65/audio65.c

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ static void recalulate_scalers ( void )
351351
scalers_right[8] = scalers_right[9] = GETMIXFL(0x3C) * master_right;
352352
if (XEMU_UNLIKELY(mono_downmix))
353353
for (int c = 0; c < MIXED_CHANNELS; c++)
354-
scalers_left[c] = scalers_right[c] = (scalers_left[c] + scalers_right[c]) / 2;
354+
scalers_left[c] = scalers_right[c] = (scalers_left[c] + scalers_right[c]) / 2.0;
355355
}
356356

357357

@@ -423,9 +423,10 @@ static void default_mixer_helper ( const int basereg, const Uint16 value_l, cons
423423
}
424424

425425

426-
static void print_audio_info ( void )
426+
static void print_audio_info ( const char *msg )
427427
{
428-
DEBUGPRINT("AUDIO: emu-volume = %d%%, mono-downmix = %s, output-reg-shift = $%02X" NL,
428+
DEBUGPRINT("AUDIO: emu-setup [%s] event; emu-volume = %d%%, mono-downmix = %s, output-reg-shift = $%02X" NL,
429+
msg ? msg : "-",
429430
xemu_volume_int,
430431
mono_downmix ? "ON" : "off",
431432
output_selection
@@ -445,6 +446,7 @@ void audio65_reset_mixer ( void )
445446
default_mixer_helper(0x1C, 0xBEBE, 0xBEBE); // OPL FM! On MEGA65 OPL channel is maybe muted by default, btw ...
446447
default_mixer_helper(0x1E, 0xFFFF, 0xFFFF); // master volume
447448
recalulate_scalers();
449+
print_audio_info("reset-mixer");
448450
}
449451

450452

@@ -461,7 +463,7 @@ void audio65_set_volume ( int vol )
461463
{
462464
set_volume(vol);
463465
recalulate_scalers();
464-
print_audio_info();
466+
print_audio_info("set-volume");
465467
}
466468

467469

@@ -475,7 +477,7 @@ void audio65_set_mono_downmix ( const bool status )
475477
{
476478
mono_downmix = status;
477479
recalulate_scalers();
478-
print_audio_info();
480+
print_audio_info("mono-downmix");
479481
}
480482

481483

@@ -489,7 +491,7 @@ void audio65_set_output ( const int val )
489491
{
490492
output_selection = val;
491493
recalulate_scalers();
492-
print_audio_info();
494+
print_audio_info("set-output");
493495
}
494496

495497

@@ -499,6 +501,38 @@ int audio65_get_output ( void )
499501
}
500502

501503

504+
#define GETMIXPCNT(n) (int)(mixer_floats[((n) + output_selection) >> 1] * 100.0)
505+
506+
507+
size_t audio65_get_description ( char *buffer, const size_t buffer_size )
508+
{
509+
const char *output_name;
510+
switch (output_selection) {
511+
case AUDIO_OUTPUT_SPEAKERS:
512+
output_name = "HDMI/speakers";
513+
break;
514+
case AUDIO_OUTPUT_HEADPHONES:
515+
output_name = "heaphones";
516+
break;
517+
default:
518+
output_name = "UNKNOWN";
519+
break;
520+
}
521+
return snprintf(
522+
buffer, buffer_size,
523+
"Sampling: %dHz, emulation volume: %d%%, emulated output: %s\n"
524+
"SIDL L=%03d%% R=%03d%% SIDR L=%03d%% R=%03d%%\n"
525+
"DIGL L=%03d%% R=%03d%% DIGR L=%03d%% R=%03d%%\n"
526+
"OPLFM L=%03d%% R=%03d%% MASTER L=%03d%% R=%03d%%"
527+
,
528+
system_sound_mix_freq, xemu_volume_int, output_name,
529+
GETMIXPCNT(0x00), GETMIXPCNT(0x20), GETMIXPCNT(0x02), GETMIXPCNT(0x22),
530+
GETMIXPCNT(0x10), GETMIXPCNT(0x30), GETMIXPCNT(0x12), GETMIXPCNT(0x32),
531+
GETMIXPCNT(0x1C), GETMIXPCNT(0x3C), GETMIXPCNT(0x1E), GETMIXPCNT(0x3E)
532+
);
533+
}
534+
535+
502536
void audio65_init ( int sid_cycles_per_sec, int sound_mix_freq, int volume, unsigned int buffer_size )
503537
{
504538
static volatile int initialized = 0;
@@ -512,7 +546,6 @@ void audio65_init ( int sid_cycles_per_sec, int sound_mix_freq, int volume, unsi
512546
mono_downmix = false;
513547
set_volume(volume);
514548
audio65_reset_mixer();
515-
print_audio_info();
516549
for (int i = 0; i < NUMBER_OF_SIDS; i++)
517550
UNLOCK_SID("INIT", i);
518551
UNLOCK_OPL("INIT");

targets/mega65/audio65.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,6 @@ extern void audio65_set_mono_downmix ( const bool status );
5656
extern bool audio65_get_mono_downmix ( void );
5757
extern void audio65_set_output ( const int val );
5858
extern int audio65_get_output ( void );
59+
extern size_t audio65_get_description ( char *buffer, const size_t buffer_size );
5960

6061
#endif

targets/mega65/hypervisor.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
3030
#include "rom.h"
3131
#define XEMU_MEGA65_HDOS_H_ALLOWED
3232
#include "hdos.h"
33+
#include "audio65.h"
3334

3435
#include <sys/types.h>
3536
#include <fcntl.h>
@@ -306,6 +307,7 @@ static inline void first_leave ( void )
306307
hdos_notify_system_start_end();
307308
xemu_sleepless_temporary_mode(0); // turn off temporary sleepless mode which may have been enabled before
308309
vic_frame_counter_since_boot = 0;
310+
audio65_reset_mixer();
309311
//memory_reset_unwritten_debug_stat(); // FIXME/TODO: commented out since it generates a **tons** of warnings then with the "unwritten mem read" debug mode (-ramcheckread emu option)
310312
DEBUGPRINT("HYPERVISOR: first return after RESET, end of processing workarounds." NL);
311313
}

targets/mega65/matrix_mode.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
2828
#include "mega65.h"
2929
#include "io_mapper.h"
3030
#include "memory_mapper.h"
31+
#include "audio65.h"
3132

3233
#include <ctype.h>
3334
#include <string.h>
@@ -583,6 +584,14 @@ static void cmd_shade ( char *p )
583584
}
584585

585586

587+
static void cmd_audio ( char * p )
588+
{
589+
char buffer[4096];
590+
audio65_get_description(buffer, sizeof buffer);
591+
MATRIX("%s", buffer);
592+
}
593+
594+
586595
static void cmd_help ( char *p );
587596

588597

@@ -605,6 +614,7 @@ static const struct command_tab_st {
605614
{ "write", cmd_write, "w" },
606615
{ "map", cmd_map, "m" },
607616
{ "shade", cmd_shade, NULL },
617+
{ "audio", cmd_audio, NULL },
608618
{ .cmdname = NULL },
609619
};
610620

targets/mega65/ui.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,10 +1072,10 @@ static const struct menu_st menu_audio[] = {
10721072
XEMUGUI_MENUFLAG_QUERYBACK, xemugui_cb_toggle_int_inverted, (void*)&configdb.nosound },
10731073
{ "Force mono downmix", XEMUGUI_MENUID_CALLABLE |
10741074
XEMUGUI_MENUFLAG_QUERYBACK, ui_cb_mono_downmix, NULL },
1075+
{ "Restore mixer to default", XEMUGUI_MENUID_CALLABLE, xemugui_cb_call_user_data, audio65_reset_mixer },
1076+
{ "Clear audio registers", XEMUGUI_MENUID_CALLABLE, xemugui_cb_call_user_data, audio65_clear_regs },
10751077
{ "OPL3 emulation", XEMUGUI_MENUID_CALLABLE |
10761078
XEMUGUI_MENUFLAG_QUERYBACK, xemugui_cb_toggle_int_inverted, (void*)&configdb.noopl3 },
1077-
{ "Clear audio registers", XEMUGUI_MENUID_CALLABLE, xemugui_cb_call_user_data, audio65_clear_regs },
1078-
{ "Restore mixer to default", XEMUGUI_MENUID_CALLABLE, xemugui_cb_call_user_data, audio65_reset_mixer },
10791079
{ "Emulated SIDs", XEMUGUI_MENUID_SUBMENU, NULL, menu_audio_sids },
10801080
{ "Emulator volume level", XEMUGUI_MENUID_SUBMENU, NULL, menu_audio_volume },
10811081
{ "Emulated audio output", XEMUGUI_MENUID_SUBMENU, NULL, menu_audio_output },

0 commit comments

Comments
 (0)