From 7b974605643638a688ce3401bc99cca61c266106 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Fri, 29 Jul 2022 04:19:22 +0200 Subject: [PATCH] Fix libsndfile build and add CI --- .github/workflows/build.yml | 43 ++++++++++ .../st_audiofile/src/st_audiofile_sndfile.c | 84 +++++++++++++++++++ src/sfizz/AudioReader.cpp | 4 +- 3 files changed, 129 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 30d20a431..7b828605c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -102,6 +102,49 @@ jobs: name: Linux tarball path: ${{runner.workspace}}/build/${{env.install_name}}.tar.gz + build_with_libsndfile: + runs-on: ubuntu-18.04 + steps: + - name: Set install name + run: | + echo "install_ref=${GITHUB_REF##*/}" >> "$GITHUB_ENV" + echo "install_name=sfizz-${GITHUB_REF##*/}-linux" >> "$GITHUB_ENV" + - uses: actions/checkout@v2 + with: + submodules: recursive + - name: Set up dependencies + run: | + sudo apt-get update && \ + sudo apt-get install \ + ninja-build \ + libsndfile1-dev + - name: Create Build Environment + shell: bash + working-directory: ${{runner.workspace}} + run: cmake -E make_directory build + - name: Configure CMake + shell: bash + working-directory: ${{runner.workspace}}/build + run: | + cmake "$GITHUB_WORKSPACE" -G Ninja \ + -DCMAKE_BUILD_TYPE="$BUILD_TYPE" \ + -DSFIZZ_JACK=OFF \ + -DSFIZZ_VST=OFF \ + -DSFIZZ_LV2_UI=OFF \ + -DSFIZZ_PUREDATA=OFF \ + -DSFIZZ_USE_SNDFILE=ON \ + -DSFIZZ_TESTS=ON \ + -DSFIZZ_SHARED=OFF \ + -DSFIZZ_STATIC_DEPENDENCIES=OFF \ + -DSFIZZ_LV2=OFF + - name: Build tests + shell: bash + working-directory: ${{runner.workspace}}/build + run: cmake --build . --config "$BUILD_TYPE" -j 2 --target sfizz_tests + - name: Run tests + shell: bash + run: ${{runner.workspace}}/build/tests/sfizz_tests + build_for_macos: runs-on: macos-11 steps: diff --git a/external/st_audiofile/src/st_audiofile_sndfile.c b/external/st_audiofile/src/st_audiofile_sndfile.c index 31cc115d6..3a9a15feb 100644 --- a/external/st_audiofile/src/st_audiofile_sndfile.c +++ b/external/st_audiofile/src/st_audiofile_sndfile.c @@ -17,8 +17,92 @@ struct st_audio_file { SNDFILE* snd; SF_INFO info; + // Virtual IO data + const void* data; + sf_count_t offset; + sf_count_t size; }; +static sf_count_t sndfile_vio_get_filelen(void *user_data) +{ + const struct st_audio_file* af = user_data; + return af->size; +} + +static sf_count_t sndfile_vio_seek(sf_count_t offset, int whence, void *user_data) +{ + struct st_audio_file* af = user_data; + + sf_count_t new_offset = af->offset; + switch(whence) { + case SEEK_SET: + new_offset = offset; + break; + case SEEK_CUR: + new_offset += offset; + break; + case SEEK_END: + new_offset = af->size + offset; + break; + } + + if( ( new_offset >= 0 ) && ( new_offset < af->size ) ) { + af->offset = new_offset; + } else { + return 1; + } + + return 0; +} + +static sf_count_t sndfile_vio_read(void *ptr, sf_count_t count, void *user_data) +{ + struct st_audio_file* af = user_data; + sf_count_t remaining = af->size - af->offset; + sf_count_t to_read = remaining > count ? count : remaining; + memcpy(ptr, af->data + af->offset, to_read); + af->offset += to_read; + return to_read; +} + +static sf_count_t sndfile_vio_write(const void *ptr, sf_count_t count, void *user_data) +{ + (void)ptr; + (void)count; + (void)user_data; + return -1; +} + +static sf_count_t sndfile_vio_tell(void *user_data) +{ + const struct st_audio_file* af = user_data; + return af->offset; +} + + +st_audio_file* st_open_memory(const void* memory, size_t length) +{ + st_audio_file* af = (st_audio_file*)malloc(sizeof(st_audio_file)); + if (!af) + return NULL; + + memset(&af->info, 0, sizeof(SF_INFO)); + af->data = memory; + af->size = length; + af->offset = 0; + + SF_VIRTUAL_IO virtual_io = { + .get_filelen = sndfile_vio_get_filelen, + .seek = sndfile_vio_seek, + .read = sndfile_vio_read, + .write = sndfile_vio_write, + .tell = sndfile_vio_tell + }; + + af->snd = sf_open_virtual(&virtual_io, SFM_READ, &af->info, af); + return af; +} + st_audio_file* st_open_file(const char* filename) { st_audio_file* af = (st_audio_file*)malloc(sizeof(st_audio_file)); diff --git a/src/sfizz/AudioReader.cpp b/src/sfizz/AudioReader.cpp index eecf7d771..86a8c000e 100644 --- a/src/sfizz/AudioReader.cpp +++ b/src/sfizz/AudioReader.cpp @@ -68,9 +68,9 @@ bool BasicSndfileReader::getWavetableInfo(WavetableInfo& wt) bool BasicSndfileReader::getInstrumentInfo(InstrumentInfo& instrument) { -#if defined(SFIZZ_USE_SNDFILE) +#if 0 // Our metadata reader is more general, e.g. for FLAC SNDFILE* sndfile = reinterpret_cast(handle_.get_sndfile_handle()); - SF_INSTRUMENT* sfins = instrument; + SF_INSTRUMENT* sfins = &instrument; if (sf_command(sndfile, SFC_GET_INSTRUMENT, sfins, sizeof(SF_INSTRUMENT)) == SF_TRUE) return true; #else