Skip to content

Commit

Permalink
New unit test to check libsndfile output file name (#1416)
Browse files Browse the repository at this point in the history
* new smf test file
* new unit test: fast rendering
* checking the output file from fast render fails in Windows
* workaround for libsndfile not handling utf8 file names on Windows
  • Loading branch information
pedrolcl authored Nov 3, 2024
1 parent d40a289 commit 0a86368
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Fluidsynth Windows

on:
workflow_dispatch:
pull_request:
push:
paths-ignore:
Expand Down
11 changes: 6 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ if ( NOT HAVE_LONG_LONG AND NOT MSVC)
message ( FATAL_ERROR "Your compiler does not support intrinsic type 'long long'. Unable to compile fluidsynth." )
endif ()

include ( CMakePrintHelpers ) # for cmake_print_properties() and cmake_print_variables()
include ( CMakePrintHelpers ) # for cmake_print_properties() and cmake_print_variables()
include ( TestInline )
include ( TestVLA )
include ( TestBigEndian )
Expand Down Expand Up @@ -441,9 +441,9 @@ if ( enable-profiling )
elseif ( CMAKE_C_COMPILER_ID STREQUAL "GNU" )
set ( OPT_FLAGS "" )
endif ( )

set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OPT_FLAGS}" )

find_program( CLANG_TIDY
NAMES "clang-tidy"
DOC "Path to clang-tidy executable" )
Expand Down Expand Up @@ -517,7 +517,7 @@ set ( ALSA_MINIMUM_VERSION 0.9.1 )
set ( DBUS_MINIMUM_VERSION 1.11.12 )
set ( GLIB2_MINUMUM_VERSION 2.6.5 )
set ( LIBINSTPATCH_MINIMUM_VERSION 1.1.0 )
set ( LIBSNDFILE_MINIMUM_VERSION 1.0.0 )
set ( LIBSNDFILE_MINIMUM_VERSION 1.2.1 )
set ( PIPEWIRE_MINIMUM_VERSION 0.3 )
set ( PORTAUDIO_MINIMUM_VERSION 2.19 )
set ( PULSEAUDIO_MINIMUM_VERSION 2.0 )
Expand Down Expand Up @@ -746,7 +746,8 @@ set(TEST_SOUNDFONT "${FluidSynth_SOURCE_DIR}/sf2/VintageDreamsWaves-v2.sf2")
set(TEST_SOUNDFONT_UTF8_1 "${FluidSynth_SOURCE_DIR}/sf2/\\xE2\\x96\\xA0VintageDreamsWaves-v2\\xE2\\x96\\xA0.sf2")
set(TEST_SOUNDFONT_UTF8_2 "${FluidSynth_SOURCE_DIR}/sf2/VìntàgèDrèàmsWàvès-v2.sf2")
set(TEST_SOUNDFONT_SF3 "${FluidSynth_SOURCE_DIR}/sf2/VintageDreamsWaves-v2.sf3")
set(TEST_MIDI_UTF8 "${FluidSynth_SOURCE_DIR}/test/èmpty.mid")
set(TEST_MIDI_UTF8 "${FluidSynth_SOURCE_DIR}/test/ⓉⒺⓈⓉ.mid")
set(TEST_WAV_UTF8 "${FluidSynth_BINARY_DIR}/test/ⓉⒺⓈⓉ.wav")

# Make sure to link against libm before checking for math functions below
set ( CMAKE_REQUIRED_LIBRARIES "${LIBFLUID_LIBS};${WINDOWS_LIBS}" )
Expand Down
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
5 changes: 3 additions & 2 deletions src/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@
#cmakedefine TEST_SOUNDFONT_UTF8_1 "@TEST_SOUNDFONT_UTF8_1@"
#cmakedefine TEST_SOUNDFONT_UTF8_2 "@TEST_SOUNDFONT_UTF8_2@"
#cmakedefine TEST_MIDI_UTF8 "@TEST_MIDI_UTF8@"
#cmakedefine TEST_WAV_UTF8 "@TEST_WAV_UTF8@"

/* SF3 Soundfont to load for unit testing */
#cmakedefine TEST_SOUNDFONT_SF3 "@TEST_SOUNDFONT_SF3@"
Expand All @@ -234,8 +235,8 @@
/* Define to use the readline library for line editing */
#cmakedefine READLINE_SUPPORT @READLINE_SUPPORT@

/* Define if the compiler supports VLA */
#cmakedefine SUPPORTS_VLA @SUPPORTS_VLA@
/* Define if the compiler supports VLA */
#cmakedefine SUPPORTS_VLA @SUPPORTS_VLA@

/* Define to 1 if your processor stores words with the most significant byte
first (like Motorola and SPARC, unlike Intel and VAX). */
Expand Down
4 changes: 4 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ ADD_FLUID_TEST(test_seq_event_queue_remove)
ADD_FLUID_TEST(test_jack_obtaining_synth)
ADD_FLUID_TEST(test_utf8_open)

if( LIBSNDFILE_SUPPORT )
ADD_FLUID_TEST(test_fast_render)
endif()

ADD_FLUID_TEST_UTIL(dump_sfont)

ADD_FLUID_SF_DUMP_TEST(VintageDreamsWaves-v2.sf2)
Expand Down
60 changes: 60 additions & 0 deletions test/test_fast_render.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

#include "test.h"
#include "fluidsynth.h"
#include "utils/fluid_sys.h"


// this tests fast file rendering and libsndfile output
int main(void)
{
int id;
fluid_settings_t *settings;
fluid_synth_t *synth;
fluid_player_t *player;
fluid_file_renderer_t *renderer;

settings = new_fluid_settings();
synth = new_fluid_synth(settings);

TEST_ASSERT(settings != NULL);
TEST_ASSERT(synth != NULL);

// no sfont loaded
TEST_ASSERT(fluid_synth_sfcount(synth) == 0);

TEST_ASSERT(fluid_is_soundfont(TEST_SOUNDFONT_UTF8_1) == TRUE);
TEST_SUCCESS(id = fluid_synth_sfload(synth, TEST_SOUNDFONT_UTF8_1, 1));

fluid_settings_setstr(settings, "audio.file.name", TEST_WAV_UTF8);

player = new_fluid_player(synth);
TEST_ASSERT(player != NULL);

TEST_ASSERT(fluid_is_midifile(TEST_MIDI_UTF8) == TRUE);
TEST_SUCCESS(fluid_player_add(player, TEST_MIDI_UTF8));

renderer = new_fluid_file_renderer(synth);
TEST_ASSERT(renderer != NULL);

TEST_SUCCESS(fluid_player_play(player));

while (fluid_player_get_status(player) == FLUID_PLAYER_PLAYING)
{
if (fluid_file_renderer_process_block(renderer) != FLUID_OK)
{
break;
}
}

delete_fluid_file_renderer(renderer);
delete_fluid_player(player);
delete_fluid_synth(synth);
delete_fluid_settings(settings);

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

return EXIT_SUCCESS;
}
Binary file added test/ⓉⒺⓈⓉ.mid
Binary file not shown.

0 comments on commit 0a86368

Please sign in to comment.