Skip to content

Commit

Permalink
workaround for libsndfile not handling utf8 file names on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrolcl committed Nov 3, 2024
1 parent b2a82e3 commit 8ed168b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
38 changes: 36 additions & 2 deletions src/bindings/fluid_filerenderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,43 @@ new_fluid_file_renderer(fluid_synth_t *synth)
FLUID_LOG(FLUID_ERR, "Invalid or unsupported audio file format settings");
goto error_recovery;
}


#ifdef _WIN32
if (0 == FLUID_STRCMP("-", filename))
{
dev->sndfile = sf_open(filename, SFM_WRITE, &info);
}
else
{
int u16_count;
LPWSTR wc_filename;
dev->sndfile = NULL;

// utf-8 filename to utf-16 wc_filename
if (1 > (u16_count = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, filename, -1, NULL, 0)))
{
FLUID_LOG(FLUID_ERR, "Failed to convert UTF8 string to wide char string");
}
else if (NULL == (wc_filename = (LPWSTR)FLUID_ARRAY(WCHAR, u16_count)))
{
FLUID_LOG(FLUID_ERR, "Out of memory");
}
else
{
if (u16_count != MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, filename, -1, wc_filename, u16_count))
{
FLUID_LOG(FLUID_ERR, "Failed to convert UTF8 string to wide char string");
}
else
{
dev->sndfile = sf_wchar_open(wc_filename, SFM_WRITE, &info);
}
FLUID_FREE(wc_filename);
}
}
#else
dev->sndfile = sf_open(filename, SFM_WRITE, &info);

#endif
if(!dev->sndfile)
{
FLUID_LOG(FLUID_ERR, "Failed to open audio file '%s' for writing", filename);
Expand Down
2 changes: 0 additions & 2 deletions test/test_fast_render.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,10 @@ int main(void)
delete_fluid_synth(synth);
delete_fluid_settings(settings);

#if 0
FILE *file;
file = FLUID_FOPEN(TEST_WAV_UTF8, "rb");
TEST_ASSERT(file != NULL);
TEST_ASSERT(FLUID_FCLOSE(file) == 0);
#endif

return EXIT_SUCCESS;
}

0 comments on commit 8ed168b

Please sign in to comment.