Fix libsndfile build and add CI

This commit is contained in:
Paul Fd 2022-07-29 04:19:22 +02:00
parent b6aea989d3
commit 7b97460564
3 changed files with 129 additions and 2 deletions

View file

@ -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:

View file

@ -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));

View file

@ -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