mirror of
https://github.com/Yonokid/PyTaiko.git
synced 2026-02-04 11:40:13 +01:00
Merge pull request #156 from Yonokid/audio_fix
Fix confirmed to work for non japanese locale at least
This commit is contained in:
@@ -141,12 +141,16 @@ def main():
|
|||||||
force_dedicated_gpu()
|
force_dedicated_gpu()
|
||||||
global_data.config = get_config()
|
global_data.config = get_config()
|
||||||
log_level = global_data.config["general"]["log_level"]
|
log_level = global_data.config["general"]["log_level"]
|
||||||
|
if sys.platform == 'win32':
|
||||||
|
import io
|
||||||
|
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
|
||||||
|
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8', errors='replace')
|
||||||
colored_formatter = ColoredFormatter('[%(levelname)s] %(name)s: %(message)s')
|
colored_formatter = ColoredFormatter('[%(levelname)s] %(name)s: %(message)s')
|
||||||
plain_formatter = logging.Formatter('[%(levelname)s] %(name)s: %(message)s')
|
plain_formatter = logging.Formatter('[%(levelname)s] %(name)s: %(message)s')
|
||||||
console_handler = logging.StreamHandler()
|
console_handler = logging.StreamHandler()
|
||||||
console_handler.setFormatter(colored_formatter)
|
console_handler.setFormatter(colored_formatter)
|
||||||
|
|
||||||
file_handler = logging.FileHandler("latest.log")
|
file_handler = logging.FileHandler("latest.log", encoding='utf-8')
|
||||||
file_handler.setFormatter(plain_formatter)
|
file_handler.setFormatter(plain_formatter)
|
||||||
file_handler = DedupHandler(file_handler)
|
file_handler = DedupHandler(file_handler)
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include "portaudio.h"
|
#include "portaudio.h"
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include "pa_asio.h"
|
#include "pa_asio.h"
|
||||||
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
@@ -647,7 +648,26 @@ wave load_wave(const char* filename) {
|
|||||||
SF_INFO sf_info;
|
SF_INFO sf_info;
|
||||||
memset(&sf_info, 0, sizeof(sf_info));
|
memset(&sf_info, 0, sizeof(sf_info));
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
// Convert UTF-8 filename to wide string for Windows
|
||||||
|
int wlen = MultiByteToWideChar(CP_UTF8, 0, filename, -1, NULL, 0);
|
||||||
|
if (wlen == 0) {
|
||||||
|
TRACELOG(LOG_ERROR, "Failed to convert filename to wide string: '%s'\n", filename);
|
||||||
|
return wave;
|
||||||
|
}
|
||||||
|
|
||||||
|
wchar_t *wfilename = malloc(wlen * sizeof(wchar_t));
|
||||||
|
if (wfilename == NULL) {
|
||||||
|
TRACELOG(LOG_ERROR, "Failed to allocate memory for wide filename");
|
||||||
|
return wave;
|
||||||
|
}
|
||||||
|
|
||||||
|
MultiByteToWideChar(CP_UTF8, 0, filename, -1, wfilename, wlen);
|
||||||
|
snd_file = sf_wchar_open(wfilename, SFM_READ, &sf_info);
|
||||||
|
free(wfilename);
|
||||||
|
#else
|
||||||
snd_file = sf_open(filename, SFM_READ, &sf_info);
|
snd_file = sf_open(filename, SFM_READ, &sf_info);
|
||||||
|
#endif
|
||||||
if (snd_file == NULL) {
|
if (snd_file == NULL) {
|
||||||
TRACELOG(LOG_ERROR, "Failed to open file '%s'\n", filename);
|
TRACELOG(LOG_ERROR, "Failed to open file '%s'\n", filename);
|
||||||
return wave;
|
return wave;
|
||||||
@@ -921,9 +941,30 @@ void update_audio_stream(audio_stream stream, const void *data, int frame_count)
|
|||||||
music load_music_stream(const char* filename) {
|
music load_music_stream(const char* filename) {
|
||||||
music music = { 0 };
|
music music = { 0 };
|
||||||
bool music_loaded = false;
|
bool music_loaded = false;
|
||||||
|
|
||||||
SF_INFO sf_info = { 0 };
|
SF_INFO sf_info = { 0 };
|
||||||
SNDFILE *snd_file = sf_open(filename, SFM_READ, &sf_info);
|
SNDFILE *snd_file;
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
// Convert UTF-8 filename to wide string for Windows
|
||||||
|
int wlen = MultiByteToWideChar(CP_UTF8, 0, filename, -1, NULL, 0);
|
||||||
|
if (wlen == 0) {
|
||||||
|
TRACELOG(LOG_WARNING, "FILEIO: [%s] Failed to convert filename to wide string", filename);
|
||||||
|
return music;
|
||||||
|
}
|
||||||
|
|
||||||
|
wchar_t *wfilename = malloc(wlen * sizeof(wchar_t));
|
||||||
|
if (wfilename == NULL) {
|
||||||
|
TRACELOG(LOG_WARNING, "FILEIO: Failed to allocate memory for wide filename");
|
||||||
|
return music;
|
||||||
|
}
|
||||||
|
|
||||||
|
MultiByteToWideChar(CP_UTF8, 0, filename, -1, wfilename, wlen);
|
||||||
|
snd_file = sf_wchar_open(wfilename, SFM_READ, &sf_info);
|
||||||
|
free(wfilename);
|
||||||
|
#else
|
||||||
|
snd_file = sf_open(filename, SFM_READ, &sf_info);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (snd_file != NULL) {
|
if (snd_file != NULL) {
|
||||||
music_ctx *ctx = calloc(1, sizeof(music_ctx));
|
music_ctx *ctx = calloc(1, sizeof(music_ctx));
|
||||||
if (ctx == NULL) {
|
if (ctx == NULL) {
|
||||||
@@ -932,7 +973,6 @@ music load_music_stream(const char* filename) {
|
|||||||
return music;
|
return music;
|
||||||
}
|
}
|
||||||
ctx->snd_file = snd_file;
|
ctx->snd_file = snd_file;
|
||||||
|
|
||||||
if (sf_info.samplerate != AUDIO.System.sampleRate) {
|
if (sf_info.samplerate != AUDIO.System.sampleRate) {
|
||||||
TRACELOG(LOG_INFO, "Resampling music from %d Hz to %f Hz", sf_info.samplerate, AUDIO.System.sampleRate);
|
TRACELOG(LOG_INFO, "Resampling music from %d Hz to %f Hz", sf_info.samplerate, AUDIO.System.sampleRate);
|
||||||
int error;
|
int error;
|
||||||
@@ -948,7 +988,6 @@ music load_music_stream(const char* filename) {
|
|||||||
ctx->resampler = NULL;
|
ctx->resampler = NULL;
|
||||||
ctx->src_ratio = 1.0;
|
ctx->src_ratio = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
music.ctxData = ctx;
|
music.ctxData = ctx;
|
||||||
int sample_size = 32;
|
int sample_size = 32;
|
||||||
music.stream = load_audio_stream(AUDIO.System.sampleRate, sample_size, sf_info.channels);
|
music.stream = load_audio_stream(AUDIO.System.sampleRate, sample_size, sf_info.channels);
|
||||||
|
|||||||
@@ -378,6 +378,7 @@ class TJAParser:
|
|||||||
elif item.startswith('WAVE'):
|
elif item.startswith('WAVE'):
|
||||||
data = item.split(':')[1]
|
data = item.split(':')[1]
|
||||||
if not Path(self.file_path.parent / data.strip()).exists():
|
if not Path(self.file_path.parent / data.strip()).exists():
|
||||||
|
logger.error(f'{data}, {self.file_path}')
|
||||||
logger.warning(f"Invalid WAVE value: {data} in TJA file {self.file_path}")
|
logger.warning(f"Invalid WAVE value: {data} in TJA file {self.file_path}")
|
||||||
self.metadata.wave = Path()
|
self.metadata.wave = Path()
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user