Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix libsndfile build and add CI #1112

Merged
merged 1 commit into from
Jul 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
84 changes: 84 additions & 0 deletions external/st_audiofile/src/st_audiofile_sndfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions src/sfizz/AudioReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<SNDFILE*>(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
Expand Down