diff --git a/MiSTer.vcxproj b/MiSTer.vcxproj index cc5bd23..3738def 100644 --- a/MiSTer.vcxproj +++ b/MiSTer.vcxproj @@ -48,6 +48,7 @@ + @@ -98,6 +99,7 @@ + diff --git a/MiSTer.vcxproj.filters b/MiSTer.vcxproj.filters index eede0d6..c3abb9b 100644 --- a/MiSTer.vcxproj.filters +++ b/MiSTer.vcxproj.filters @@ -193,6 +193,9 @@ Source Files\support + + Source Files + @@ -363,5 +366,8 @@ Header Files\support + + Header Files + \ No newline at end of file diff --git a/audio.cpp b/audio.cpp new file mode 100644 index 0000000..4e90d6d --- /dev/null +++ b/audio.cpp @@ -0,0 +1,231 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "hardware.h" +#include "user_io.h" +#include "spi.h" +#include "cfg.h" +#include "file_io.h" +#include "menu.h" +#include "audio.h" + +static uint8_t vol_att = 0; +static uint8_t corevol_att = 0; +unsigned long vol_set_timeout = 0; +static int has_filter = 0; + +void send_volume() +{ + get_volume(); + get_core_volume(); + if (!(vol_att & 0x10) && vol_att + corevol_att > 7) vol_att = 7 - corevol_att; + spi_uio_cmd8(UIO_AUDVOL, vol_att + corevol_att); +} + +int get_volume() +{ + return vol_att & 0x17; +} + +int get_core_volume() +{ + corevol_att &= 7; + if (corevol_att > 6) corevol_att = 6; + return corevol_att; +} + +void set_volume(int cmd) +{ + vol_set_timeout = GetTimer(1000); + + vol_att &= 0x17; + if (!cmd) vol_att ^= 0x10; + else if (vol_att & 0x10) vol_att &= 0xF; + else if (cmd < 0 && vol_att < 7) vol_att += 1; + else if (cmd > 0 && vol_att > 0) vol_att -= 1; + + send_volume(); + + if (vol_att & 0x10) + { + Info("\x8d Mute", 1000); + } + else + { + char str[32]; + memset(str, 0, sizeof(str)); + + sprintf(str, "\x8d "); + char *bar = str + strlen(str); + + int vol = get_core_volume(); + memset(bar, 0x8C, 8 - vol); + memset(bar, 0x7f, 8 - vol - vol_att); + Info(str, 1000); + } +} + +void set_core_volume(int cmd) +{ + vol_set_timeout = GetTimer(1000); + + corevol_att &= 7; + if (cmd < 0 && corevol_att < 6) corevol_att += 1; + if (cmd > 0 && corevol_att > 0) corevol_att -= 1; + + send_volume(); +} + +void save_volume() +{ + if (vol_set_timeout && CheckTimer(vol_set_timeout)) + { + vol_set_timeout = 0; + FileSaveConfig("Volume.dat", &vol_att, 1); + + static char cfg_name[128]; + sprintf(cfg_name, "%s_volume.cfg", user_io_get_core_name_ex()); + FileSaveConfig(cfg_name, &corevol_att, 1); + } +} + +static char filter_cfg_path[1024] = {}; +static char filter_cfg[1024] = {}; + +static void setFilter() +{ + fileTYPE f = {}; + + has_filter = spi_uio_cmd(UIO_SET_AFILTER); + if (!has_filter || !filter_cfg[0]) return; + + sprintf(filter_cfg_path, AFILTER_DIR"/%s", filter_cfg + 1); + + if (filter_cfg[0] && FileOpen(&f, filter_cfg_path)) + { + char *buf = (char*)malloc(f.size + 1); + if (buf) + { + memset(buf, 0, f.size + 1); + int size; + if ((size = FileReadAdv(&f, buf, f.size))) + { + int line = 0; + spi_uio_cmd_cont(UIO_SET_AFILTER); + + char *end = buf + size; + char *pos = buf; + while (pos < end && line < 8) + { + char *st = pos; + while ((pos < end) && *pos && (*pos != 10)) pos++; + *pos = 0; + while (*st == ' ' || *st == '\t' || *st == 13) st++; + if (*st == '#' || *st == ';' || !*st) pos++; + else + { + if (line == 0 || line == 2 || line == 3 || line == 4) + { + int val = 0; + int n = sscanf(st, "%d", &val); + printf("got %d values: %d\n", n, val); + if (n == 1) + { + spi_w((uint16_t)val); + if (line == 0) spi_w((uint16_t)(val >> 16)); + line++; + } + } + else if (line == 1) + { + double val = 0; + int n = sscanf(st, "%lg", &val); + printf("got %d values: %g\n", n, val); + if (n == 1) + { + int64_t coeff = 0x8000000000 * val; + printf(" -> converted to: %lld\n", coeff); + spi_w((uint16_t)coeff); + spi_w((uint16_t)(coeff >> 16)); + spi_w((uint16_t)(coeff >> 32)); + line++; + } + } + else + { + double val = 0; + int n = sscanf(st, "%lg", &val); + printf("got %d values: %g\n", n, val); + if (n == 1) + { + int32_t coeff = 0x200000 * val; + printf(" -> converted to: %d\n", coeff); + spi_w((uint16_t)coeff); + spi_w((uint16_t)(coeff >> 16)); + line++; + } + } + } + } + DisableIO(); + } + free(buf); + } + } +} + +void load_volume() +{ + FileLoadConfig("Volume.dat", &vol_att, 1); + if (!is_menu()) + { + static char cfg_name[128]; + sprintf(cfg_name, "%s_volume.cfg", user_io_get_core_name_ex()); + FileLoadConfig(cfg_name, &corevol_att, 1); + } + send_volume(); + + sprintf(filter_cfg_path, "%s_afilter.cfg", user_io_get_core_name_ex()); + if (!FileLoadConfig(filter_cfg_path, &filter_cfg, sizeof(filter_cfg) - 1) || filter_cfg[0] > 1) + { + memset(filter_cfg, 0, sizeof(filter_cfg)); + } + setFilter(); +} + +int audio_filter_en() +{ + return has_filter ? filter_cfg[0] : -1; +} + +char* audio_get_filter() +{ + return filter_cfg + 1; +} + +void audio_set_filter(char *name) +{ + strcpy(filter_cfg + 1, name); + sprintf(filter_cfg_path, "%s_afilter.cfg", user_io_get_core_name_ex()); + FileSaveConfig(filter_cfg_path, &filter_cfg, sizeof(filter_cfg)); + setFilter(); +} + +void audio_set_filter_en(int n) +{ + filter_cfg[0] = n ? 1 : 0; + sprintf(filter_cfg_path, "%s_afilter.cfg", user_io_get_core_name_ex()); + FileSaveConfig(filter_cfg_path, &filter_cfg, sizeof(filter_cfg)); + setFilter(); +} diff --git a/audio.h b/audio.h new file mode 100644 index 0000000..11fc699 --- /dev/null +++ b/audio.h @@ -0,0 +1,17 @@ +#ifndef AUDIO_H +#define AUDIO_H + +void set_volume(int cmd); +int get_volume(); +int get_core_volume(); +void set_core_volume(int cmd); +void send_volume(); +void save_volume(); +void load_volume(); + +int audio_filter_en(); +char* audio_get_filter(); +void audio_set_filter(char *name); +void audio_set_filter_en(int n); + +#endif diff --git a/file_io.h b/file_io.h index 852249b..6124c1b 100644 --- a/file_io.h +++ b/file_io.h @@ -118,6 +118,7 @@ bool isMraName(char *path); #define COEFF_DIR "filters" #define GAMMA_DIR "gamma" +#define AFILTER_DIR "filters_audio" #define GAMES_DIR "games" #define CIFS_DIR "cifs" diff --git a/menu.cpp b/menu.cpp index 0a80b50..012fb2a 100644 --- a/menu.cpp +++ b/menu.cpp @@ -54,6 +54,7 @@ along with this program. If not, see . #include "battery.h" #include "cheats.h" #include "video.h" +#include "audio.h" #include "joymapping.h" #include "recent.h" #include "support.h" @@ -164,6 +165,7 @@ enum MENU MENU_8BIT_SYSTEM2, MENU_COEFF_FILE_SELECTED, MENU_GAMMA_FILE_SELECTED, + MENU_AFILTER_FILE_SELECTED, MENU_8BIT_INFO, MENU_8BIT_INFO2, MENU_8BIT_ABOUT1, @@ -199,6 +201,7 @@ const char *config_uart_msg[] = { " None", " PPP", " Console", " M const char *config_midilink_msg[] = { " MIDI Local", "MIDI Remote", " MFP UART", "" }; const char *config_uart_baud[] = { "110", "300", "600", "1200", "2400", "9600", "14400", "19200", "31250/MIDI", "38400", "57600", "115200"}; const char *config_scaler_msg[] = { "Internal","Custom" }; +const char *config_afilter_msg[] = { "Internal","Custom" }; const char *config_gamma_msg[] = { "Off","On" }; #define DPAD_NAMES 4 @@ -503,7 +506,7 @@ static uint32_t menu_key_get(void) else if (CheckTimer(repeat)) { repeat = GetTimer(REPEATRATE); - if (GetASCIIKey(c1) || ((menustate == MENU_8BIT_SYSTEM2) && (menusub == 11))) + if (GetASCIIKey(c1) || ((menustate == MENU_8BIT_SYSTEM2) && (menusub == 13))) { c = c1; hold_cnt++; @@ -1937,7 +1940,7 @@ void HandleUI(void) while(1) { n = 0; - menumask = 0x3e07; + menumask = 0xf807; if (!menusub) firstmenu = 0; adjvisible = 0; @@ -1998,24 +2001,42 @@ void HandleUI(void) MenuWrite(n++, s, menusub == 8, !video_get_gamma_en() || !S_ISDIR(getFileType(GAMMA_DIR))); } + if (audio_filter_en() >= 0) + { + MenuWrite(n++); + menumask |= 0x600; + sprintf(s, " Audio Filter - %s", config_afilter_msg[audio_filter_en() ? 1 : 0]); + MenuWrite(n++, s, menusub == 9); + + memset(s, 0, sizeof(s)); + s[0] = ' '; + if (strlen(audio_get_filter())) strncpy(s + 1, audio_get_filter(), 25); + else strcpy(s, " < none >"); + + while (strlen(s) < 26) strcat(s, " "); + strcat(s, " \x16 "); + + MenuWrite(n++, s, menusub == 10, !audio_filter_en() || !S_ISDIR(getFileType(AFILTER_DIR))); + } + if (is_minimig() || is_st()) { - menumask &= ~0x600; + menumask &= ~0x1800; } else { MenuWrite(n++); - MenuWrite(n++, " Reset settings", menusub == 9, is_archie()); - MenuWrite(n++, " Save settings", menusub == 10, 0); + MenuWrite(n++, " Reset settings", menusub == 11, is_archie()); + MenuWrite(n++, " Save settings", menusub == 12, 0); } MenuWrite(n++); cr = n; - MenuWrite(n++, " Reboot (hold \x16 cold reboot)", menusub == 11); - MenuWrite(n++, " About", menusub == 12); + MenuWrite(n++, " Reboot (hold \x16 cold reboot)", menusub == 13); + MenuWrite(n++, " About", menusub == 14); while(n < OsdGetSize() - 1) MenuWrite(n++); - MenuWrite(n++, STD_EXIT, menusub == 13, 0, OSD_ARROW_LEFT); + MenuWrite(n++, STD_EXIT, menusub == 15, 0, OSD_ARROW_LEFT); sysinfo_timer = 0; if (!adjvisible) break; @@ -2126,6 +2147,19 @@ void HandleUI(void) } break; case 9: + audio_set_filter_en(audio_filter_en() ? 0 : 1); + menustate = MENU_8BIT_SYSTEM1; + break; + + case 10: + if (audio_filter_en()) + { + snprintf(Selected_tmp, sizeof(Selected_tmp), AFILTER_DIR"/%s", audio_get_filter()); + if (!FileExists(Selected_tmp)) snprintf(Selected_tmp, sizeof(Selected_tmp), AFILTER_DIR); + SelectFile(Selected_tmp, 0, SCANO_DIR | SCANO_TXT, MENU_AFILTER_FILE_SELECTED, MENU_8BIT_SYSTEM1); + } + break; + case 11: if (!is_archie()) { menustate = MENU_RESET1; @@ -2138,7 +2172,7 @@ void HandleUI(void) } break; - case 10: + case 12: // Save settings menustate = MENU_8BIT_MAIN1; menusub = 0; @@ -2162,7 +2196,7 @@ void HandleUI(void) } break; - case 11: + case 13: { reboot_req = 1; @@ -2171,11 +2205,11 @@ void HandleUI(void) sprintf(s, " Cold Reboot"); p = s + 5 - off; - MenuWrite(cr, p, menusub == 11, 0); + MenuWrite(cr, p, 1, 0); } break; - case 12: + case 14: menustate = MENU_8BIT_ABOUT1; menusub = 0; break; @@ -2554,6 +2588,20 @@ void HandleUI(void) } break; + case MENU_AFILTER_FILE_SELECTED: + { + char *p = strcasestr(selPath, AFILTER_DIR"/"); + if (!p) audio_set_filter(selPath); + else + { + p += strlen(AFILTER_DIR); + while (*p == '/') p++; + audio_set_filter(p); + } + menustate = MENU_8BIT_SYSTEM1; + } + break; + case MENU_8BIT_INFO: OsdSetSize(16); helptext = 0; diff --git a/user_io.cpp b/user_io.cpp index 9435578..2f83322 100644 --- a/user_io.cpp +++ b/user_io.cpp @@ -32,16 +32,13 @@ #include "miniz.h" #include "cheats.h" #include "video.h" +#include "audio.h" #include "support.h" static char core_path[1024] = {}; static char rbf_path[1024] = {}; -static uint8_t vol_att = 0; -static uint8_t corevol_att = 0; -unsigned long vol_set_timeout = 0; - static fileTYPE sd_image[4] = {}; static uint64_t buffer_lba[4] = { ULLONG_MAX,ULLONG_MAX,ULLONG_MAX,ULLONG_MAX }; @@ -766,15 +763,7 @@ void user_io_init(const char *path, const char *xml) video_mode_load(); if(strlen(cfg.font)) LoadFont(cfg.font); - - FileLoadConfig("Volume.dat", &vol_att, 1); - if (!is_menu()) - { - static char cfg_name[128]; - sprintf(cfg_name, "%s_volume.cfg", user_io_get_core_name_ex()); - FileLoadConfig(cfg_name, &corevol_att, 1); - } - send_volume(); + load_volume(); user_io_send_buttons(1); @@ -2665,15 +2654,7 @@ void user_io_poll() reboot(1); } - if (vol_set_timeout && CheckTimer(vol_set_timeout)) - { - vol_set_timeout = 0; - FileSaveConfig("Volume.dat", &vol_att, 1); - - static char cfg_name[128]; - sprintf(cfg_name, "%s_volume.cfg", user_io_get_core_name_ex()); - FileSaveConfig(cfg_name, &corevol_att, 1); - } + save_volume(); if (diskled_is_on && CheckTimer(diskled_timer)) { @@ -2958,68 +2939,6 @@ void user_io_osd_key_enable(char on) input_switch(-1); } -void send_volume() -{ - get_volume(); - get_core_volume(); - if (!(vol_att & 0x10) && vol_att + corevol_att > 7) vol_att = 7 - corevol_att; - spi_uio_cmd8(UIO_AUDVOL, vol_att + corevol_att); -} - -int get_volume() -{ - return vol_att & 0x17; -} - -int get_core_volume() -{ - corevol_att &= 7; - if (corevol_att > 6) corevol_att = 6; - return corevol_att; -} - -void set_volume(int cmd) -{ - vol_set_timeout = GetTimer(1000); - - vol_att &= 0x17; - if(!cmd) vol_att ^= 0x10; - else if (vol_att & 0x10) vol_att &= 0xF; - else if (cmd < 0 && vol_att < 7) vol_att += 1; - else if (cmd > 0 && vol_att > 0) vol_att -= 1; - - send_volume(); - - if (vol_att & 0x10) - { - Info("\x8d Mute", 1000); - } - else - { - char str[32]; - memset(str, 0, sizeof(str)); - - sprintf(str, "\x8d "); - char *bar = str + strlen(str); - - int vol = get_core_volume(); - memset(bar, 0x8C, 8 - vol); - memset(bar, 0x7f, 8 - vol - vol_att); - Info(str, 1000); - } -} - -void set_core_volume(int cmd) -{ - vol_set_timeout = GetTimer(1000); - - corevol_att &= 7; - if (cmd < 0 && corevol_att < 6) corevol_att += 1; - if (cmd > 0 && corevol_att > 0) corevol_att -= 1; - - send_volume(); -} - void user_io_kbd(uint16_t key, int press) { if(is_menu()) spi_uio_cmd(UIO_KEYBOARD); //ping the Menu core to wakeup diff --git a/user_io.h b/user_io.h index b9a6c2d..70a8491 100644 --- a/user_io.h +++ b/user_io.h @@ -69,6 +69,7 @@ #define UIO_INFO_GET 0x36 #define UIO_SETWIDTH 0x37 // Set max scaled horizontal resolution #define UIO_SETSYNC 0x38 +#define UIO_SET_AFILTER 0x39 // codes as used by 8bit for file loading from OSD #define UIO_FILE_TX 0x53 @@ -247,12 +248,6 @@ void SetUARTMode(int mode); int GetMidiLinkMode(); void SetMidiLinkMode(int mode); -void set_volume(int cmd); -int get_volume(); -int get_core_volume(); -void set_core_volume(int cmd); -void send_volume(); - void user_io_store_filename(char *filename); int user_io_use_cheats();