From 7cba7ddee053198ee3dc344470139f858cd913df Mon Sep 17 00:00:00 2001 From: Giles Atkinson <“gatk555@gmail.com”> Date: Wed, 6 May 2026 17:55:52 +0100 Subject: [PATCH] Allow building without soundfile libraries. --- src/frontend/commands.c | 36 +++++++++++++++++------------- src/frontend/dotcards.c | 2 ++ src/frontend/postcoms.c | 2 ++ src/frontend/sndprint.c | 4 +++- src/spicelib/devices/vsrc/vsjack.c | 16 ++++++++++++- 5 files changed, 42 insertions(+), 18 deletions(-) diff --git a/src/frontend/commands.c b/src/frontend/commands.c index c4e592246..027b9a0d9 100644 --- a/src/frontend/commands.c +++ b/src/frontend/commands.c @@ -248,14 +248,16 @@ struct comm spcp_coms[] = { { 040000, 040000, 040000, 040000 }, E_BEGINNING, 1, LOTS, arg_print, "[col] expr ... : Print vector values." } , - { "sndprint", com_sndprint, FALSE, FALSE, - { 040000, 040000, 040000, 040000 }, E_BEGINNING, 1, LOTS, - arg_print, - "[col] expr ... : Print vector values." }, - { "sndparam", com_sndparam, FALSE, FALSE, - { 1, 1, 1, 1 }, E_BEGINNING | E_NOPLOTS, 1, LOTS, - arg_load, - "file samplerate : set sndprint parameters." }, +#if defined(HAVE_LIBSNDFILE) && defined(HAVE_LIBSAMPLERATE) + { "sndprint", com_sndprint, FALSE, FALSE, + { 040000, 040000, 040000, 040000 }, E_BEGINNING, 1, LOTS, + arg_print, + "[col] expr ... : Print vector values." }, + { "sndparam", com_sndparam, FALSE, FALSE, + { 1, 1, 1, 1 }, E_BEGINNING | E_NOPLOTS, 1, LOTS, + arg_load, + "file samplerate : set sndprint parameters." }, +#endif #ifdef XSPICE { "esave", EVTsave, FALSE, TRUE, { 040000, 040000, 040000, 040000 }, E_BEGINNING, 1, LOTS, @@ -793,14 +795,16 @@ struct comm nutcp_coms[] = { { 040000, 040000, 040000, 040000 }, E_BEGINNING, 1, LOTS, arg_print, "[col] expr ... : Print vector values." } , - { "sndprint", com_sndprint, FALSE, FALSE, - { 040000, 040000, 040000, 040000 }, E_BEGINNING, 1, LOTS, - arg_print, - "[col] expr ... : Print vector values." }, - { "sndparam", com_sndparam, FALSE, FALSE, - { 1, 1, 1, 1 }, E_BEGINNING | E_NOPLOTS, 1, LOTS, - arg_load, - "file samplerate : set sndprint parameters." }, +#if defined(HAVE_LIBSNDFILE) && defined(HAVE_LIBSAMPLERATE) + { "sndprint", com_sndprint, FALSE, FALSE, + { 040000, 040000, 040000, 040000 }, E_BEGINNING, 1, LOTS, + arg_print, + "[col] expr ... : Print vector values." }, + { "sndparam", com_sndparam, FALSE, FALSE, + { 1, 1, 1, 1 }, E_BEGINNING | E_NOPLOTS, 1, LOTS, + arg_load, + "file samplerate : set sndprint parameters." }, +#endif { "load", com_load, FALSE, TRUE, { 1, 1, 1, 1 }, E_BEGINNING | E_NOPLOTS, 1, LOTS, arg_load, diff --git a/src/frontend/dotcards.c b/src/frontend/dotcards.c index 6dc2bc034..60a3e1ac6 100644 --- a/src/frontend/dotcards.c +++ b/src/frontend/dotcards.c @@ -355,6 +355,7 @@ ft_cktcoms(bool terse) fprintf(cp_err, "Error: .plot: no %s analysis found.\n", plottype); } +#if defined(HAVE_LIBSNDFILE) && defined(HAVE_LIBSAMPLERATE) } else if (eq(command->wl_word, ".sndparam")) { if (terse) { fprintf(cp_out, ".sndparam line ignored since rawfile was produced.\n"); @@ -390,6 +391,7 @@ ft_cktcoms(bool terse) if (!found) fprintf(cp_err, "Error: .sndprint: no %s analysis found.\n", plottype); } +#endif // Sound file support } else if (ciprefix(".four", command->wl_word)) { if (terse) { fprintf(cp_out, diff --git a/src/frontend/postcoms.c b/src/frontend/postcoms.c index 248aa5a99..425587071 100644 --- a/src/frontend/postcoms.c +++ b/src/frontend/postcoms.c @@ -430,6 +430,7 @@ done: tfree(buf2); } +#if defined(HAVE_LIBSNDFILE) && defined(HAVE_LIBSAMPLERATE) /* tweaked version of print - write sound-files */ @@ -558,6 +559,7 @@ com_sndparam(wordlist* wl) snd_configure(file, srate, fmt, mult, off, oversampling); return; } +#endif // HAVE_LIBSNDFILE /* Write out some data into a ngspice raw file with 'write filename expr'. diff --git a/src/frontend/sndprint.c b/src/frontend/sndprint.c index e35b2dec5..9174a7c3b 100644 --- a/src/frontend/sndprint.c +++ b/src/frontend/sndprint.c @@ -1,12 +1,13 @@ #include #include -#include #include #include #include #include "sndprint.h" #include "ngspice/ngspice.h" +#if defined(HAVE_LIBSNDFILE) && defined(HAVE_LIBSAMPLERATE) +#include static int o_samplerate = 48000; static int o_sndfmt = (SF_FORMAT_WAV | SF_FORMAT_PCM_24); @@ -323,3 +324,4 @@ double snd_get_samplerate(void) { /* vi:set ts=8 sts=2 sw=2: */ +#endif // HAVE_LIBSNDFILE diff --git a/src/spicelib/devices/vsrc/vsjack.c b/src/spicelib/devices/vsrc/vsjack.c index 06bf3b45a..9988fc695 100644 --- a/src/spicelib/devices/vsrc/vsjack.c +++ b/src/spicelib/devices/vsrc/vsjack.c @@ -2,6 +2,9 @@ #include #include +#include "ngspice/ngspice.h" + +#if defined(HAVE_LIBSNDFILE) && defined(HAVE_LIBSAMPLERATE) /////// SNDFILE /////// #include #include @@ -12,7 +15,6 @@ // the whole audio file, do it in smaller chunks #define VS_RESAMPLING_CHUNK 1024 -#include "ngspice/ngspice.h" #include "vsjack.h" extern char* inp_pathresolve(const char* name); @@ -229,3 +231,15 @@ int vsjack_open(int d, char *file, int channel, double oversampling) { } /* vi:set ts=8 sts=4 sw=4: */ +#else // not HAVE_LIBSNDFILE + +double vsjack_get_value(int d, double time, double time_offset) { + return 0; +} + +int vsjack_open(int d, char *file, int channel, double oversampling) { + fprintf(stderr, "Error: Ngspice built without soundfile support.\n"); + controlled_exit(1); + return -1; +} +#endif