diff --git a/pkgs/applications/audio/musly/default.nix b/pkgs/applications/audio/musly/default.nix deleted file mode 100644 index 1f8e1a9f3aef1..0000000000000 --- a/pkgs/applications/audio/musly/default.nix +++ /dev/null @@ -1,34 +0,0 @@ -{ lib, stdenv, fetchFromGitHub, cmake, eigen, ffmpeg_4 }: -stdenv.mkDerivation { - pname = "musly"; - version = "unstable-2017-04-26"; - src = fetchFromGitHub { - owner = "dominikschnitzer"; - repo = "musly"; - rev = "f911eacbbe0b39ebe87cb37d0caef09632fa40d6"; - sha256 = "1q42wvdwy2pac7bhfraqqj2czw7w2m33ms3ifjl8phm7d87i8825"; - }; - nativeBuildInputs = [ cmake ]; - buildInputs = [ eigen ffmpeg_4 ]; - fixupPhase = lib.optionalString stdenv.isDarwin '' - install_name_tool -change libmusly.dylib $out/lib/libmusly.dylib $out/bin/musly - install_name_tool -change libmusly_resample.dylib $out/lib/libmusly_resample.dylib $out/bin/musly - install_name_tool -change libmusly_resample.dylib $out/lib/libmusly_resample.dylib $out/lib/libmusly.dylib - ''; - - meta = with lib; { - homepage = "https://www.musly.org"; - description = "Fast and high-quality audio music similarity library written in C/C++"; - longDescription = '' - Musly analyzes the the audio signal of music pieces to estimate their similarity. - No meta-data about the music piece is included in the similarity estimation. - To use Musly in your application, have a look at the library documentation - or try the command line application included in the package and start generating - some automatic music playlists right away. - ''; - license = licenses.mpl20; - maintainers = with maintainers; [ ggpeti ]; - platforms = with platforms; darwin ++ linux; - mainProgram = "musly"; - }; -} diff --git a/pkgs/by-name/ki/kissfft/fix-fftw-dependency-check.patch b/pkgs/by-name/ki/kissfft/fix-fftw-dependency-check.patch new file mode 100644 index 0000000000000..0e2cf0c9c452c --- /dev/null +++ b/pkgs/by-name/ki/kissfft/fix-fftw-dependency-check.patch @@ -0,0 +1,23 @@ +From a73134e594d85abc32e27a34a78ce75c5f006f92 Mon Sep 17 00:00:00 2001 +From: Emily +Date: Sat, 3 Aug 2024 17:49:57 +0100 +Subject: [PATCH] Fix FFTW dependency check + +`KISFFT_FLOAT` is not defined anywhere. +--- + test/CMakeLists.txt | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt +index 0a0e403..d7d8350 100644 +--- a/test/CMakeLists.txt ++++ b/test/CMakeLists.txt +@@ -24,7 +24,7 @@ add_kissfft_test_executable(bm_kiss benchkiss.c pstats.c) + # set_tests_properties(${NAME} PROPERTIES TIMEOUT 3600) + + include(FindPkgConfig) +-if(KISSFFT_FLOAT) ++if(KISSFFT_DATATYPE MATCHES "^float$") + set(fftw3_pkg fftw3f) + else() + set(fftw3_pkg fftw3) diff --git a/pkgs/by-name/ki/kissfft/package.nix b/pkgs/by-name/ki/kissfft/package.nix new file mode 100644 index 0000000000000..1480d73b537e4 --- /dev/null +++ b/pkgs/by-name/ki/kissfft/package.nix @@ -0,0 +1,86 @@ +{ + lib, + stdenv, + fetchFromGitHub, + cmake, + ninja, + pkg-config, + fftw, + fftwFloat, + python3, + datatype ? "double", + libpng, + enableStatic ? stdenv.hostPlatform.isStatic, + enableOpenmp ? false, + llvmPackages, +}: + +stdenv.mkDerivation (finalAttrs: { + pname = "kissfft-${datatype}${lib.optionalString enableOpenmp "-openmp"}"; + version = "131.1.0"; + + outputs = [ + "bin" + "dev" + "out" + ]; + + src = fetchFromGitHub { + owner = "mborgerding"; + repo = "kissfft"; + rev = finalAttrs.version; + hash = "sha256-ukikTVnmKomKXTo6zc+PhpZzEkzXN2imFwZOYlfR3Pk="; + }; + + patches = [ + # Fix FFTW dependency check + # https://github.com/mborgerding/kissfft/pull/95 + ./fix-fftw-dependency-check.patch + ]; + + nativeBuildInputs = [ + cmake + ninja + pkg-config + ]; + + buildInputs = + lib.optionals (datatype != "simd") [ libpng ] + # TODO: This may mismatch the LLVM version in the stdenv, see #79818. + ++ lib.optional (enableOpenmp && stdenv.cc.isClang) llvmPackages.openmp; + + nativeCheckInputs = [ (python3.withPackages (ps: [ ps.numpy ])) ]; + + checkInputs = [ (if datatype == "float" then fftwFloat else fftw) ]; + + cmakeFlags = [ + (lib.cmakeFeature "KISSFFT_DATATYPE" datatype) + (lib.cmakeBool "KISSFFT_STATIC" enableStatic) + # `test/testkiss.py` expects this… + (lib.cmakeFeature "KISSFFT_OPENMP" (if enableOpenmp then "ON" else "OFF")) + ]; + + # Required for `test/testcpp.c`. + env = { + NIX_CFLAGS_COMPILE = lib.optionalString stdenv.isDarwin "-D__MATH_LONG_DOUBLE_CONSTANTS=1"; + }; + + doCheck = true; + + # https://bugs.llvm.org/show_bug.cgi?id=45034 + postPatch = + lib.optionalString + (stdenv.hostPlatform.isLinux && stdenv.cc.isClang && lib.versionOlder stdenv.cc.version "10") + '' + substituteInPlace CMakeLists.txt \ + --replace "-ffast-math" "" + ''; + + meta = { + description = "Mixed-radix Fast Fourier Transform based up on the KISS principle"; + homepage = "https://github.com/mborgerding/kissfft"; + license = lib.licenses.bsd3; + maintainers = [ ]; + platforms = lib.platforms.all; + }; +}) diff --git a/pkgs/by-name/li/libresample/fix-test.patch b/pkgs/by-name/li/libresample/fix-test.patch new file mode 100644 index 0000000000000..eacb859dcca71 --- /dev/null +++ b/pkgs/by-name/li/libresample/fix-test.patch @@ -0,0 +1,108 @@ +From fb8e3c74d582038a358936d827f53c4c0c43d4e6 Mon Sep 17 00:00:00 2001 +From: Matt Harvey +Date: Mon, 27 Nov 2023 16:28:53 -0800 +Subject: [PATCH] Fix testresample.c output span; add exit code + +Prior to this chance, the "Resample with different factors" test only +passed for 60 of the 63 factors, with the 3 failing ones being the +largest. + +1. Since only 63 distinct factors were being considered, 100 random + samples was overkill. +2. To support noticing failure in continuous build systems, it's nice if + the test exit()s with nonzero when there are failures. +3. The root cause was a formula error when determining which indices in + the resampled output ought be compared. Details are explained in a + comment. +--- + tests/testresample.c | 32 ++++++++++++++++++++++++-------- + 1 file changed, 24 insertions(+), 8 deletions(-) + +diff --git a/tests/testresample.c b/tests/testresample.c +index aa83a46..640df5a 100644 +--- a/tests/testresample.c ++++ b/tests/testresample.c +@@ -19,6 +19,8 @@ + + #define MIN(A, B) (A) < (B)? (A) : (B) + ++int global_error; ++ + void runtest(int srclen, double freq, double factor, + int srcblocksize, int dstblocksize) + { +@@ -65,10 +67,12 @@ void runtest(int srclen, double freq, double factor, + + if (o < 0) { + printf("Error: resample_process returned an error: %d\n", o); ++ global_error = 1; + } + + if (out <= 0) { + printf("Error: resample_process returned %d samples\n", out); ++ global_error = 1; + free(src); + free(dst); + return; +@@ -79,15 +83,16 @@ void runtest(int srclen, double freq, double factor, + printf(" Expected ~%d, got %d samples out\n", + expectedlen, out); + } +- ++ + sum = 0.0; + sumsq = 0.0; + errcount = 0.0; + +- /* Don't compute statistics on all output values; the last few +- are guaranteed to be off because it's based on far less +- interpolation. */ +- statlen = out - fwidth; ++ /* Don't compute statistics on all output values; the last small fraction ++ are guaranteed to be off since they are interpolated based on far fewer ++ values. When upsampling, the length of the range where this concern ++ applies is in direct proportion to the upsampling factor. */ ++ statlen = out - ((int)round(fwidth * factor)); + + for(i=0; i +Date: Mon, 15 Jul 2024 00:41:04 +0100 +Subject: [PATCH 1/4] Fix build with FFmpeg 7 + +--- + libmusly/CMakeLists.txt | 5 -- + libmusly/decoders/libav.cpp | 136 +++++++++++------------------------- + 2 files changed, 42 insertions(+), 99 deletions(-) + +diff --git a/libmusly/CMakeLists.txt b/libmusly/CMakeLists.txt +index d6d3680..98151df 100644 +--- a/libmusly/CMakeLists.txt ++++ b/libmusly/CMakeLists.txt +@@ -16,11 +16,6 @@ if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/external") + PROPERTIES COMPILE_FLAGS "-DLIBMUSLY_EXTERNAL ${LIBMUSLY_EXTERNAL_FLAGS}") + endif() + +-if(EXISTS "${LIBAV_INCLUDE_DIRS}/libavutil/channel_layout.h") +- set_source_files_properties(decoders/libav.cpp +- PROPERTIES COMPILE_FLAGS "-DHAVE_AVUTIL_CHANNEL_LAYOUT") +-endif() +- + if(USE_OPENMP AND OPENMP_FOUND) + # disable OpenMP for kiss FFT, it slows things down terribly + set_source_files_properties(kissfft/kiss_fft.c +diff --git a/libmusly/decoders/libav.cpp b/libmusly/decoders/libav.cpp +index a78b904..90f93ae 100644 +--- a/libmusly/decoders/libav.cpp ++++ b/libmusly/decoders/libav.cpp +@@ -20,37 +20,13 @@ + extern "C" { + #include + #include +-#ifdef HAVE_AVUTIL_CHANNEL_LAYOUT + #include +-#endif + } + + #include "minilog.h" + #include "resampler.h" + #include "libav.h" + +-// We define some macros to be compatible to different libav versions +-// without spreading #if and #else all over the place. +-#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55, 45, 101) +-#define AV_FRAME_ALLOC avcodec_alloc_frame +-#define AV_FRAME_UNREF avcodec_get_frame_defaults +-#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(54, 28, 0) +-#define AV_FRAME_FREE(X) av_free(*(X)) +-#else +-#define AV_FRAME_FREE avcodec_free_frame +-#endif +-#else +-#define AV_FRAME_ALLOC av_frame_alloc +-#define AV_FRAME_UNREF av_frame_unref +-#define AV_FRAME_FREE av_frame_free +-#endif +- +-#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57, 7, 0) +-#define AV_PACKET_UNREF av_free_packet +-#else +-#define AV_PACKET_UNREF av_packet_unref +-#endif +- + namespace musly { + namespace decoders { + +@@ -58,12 +34,6 @@ MUSLY_DECODER_REGIMPL(libav, 0); + + libav::libav() + { +-#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(58, 9, 100) +- av_register_all(); +-#endif +-#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 9, 100) +- avcodec_register_all(); +-#endif + } + + int +@@ -177,13 +147,7 @@ libav::decodeto_22050hz_mono_float( + AVStream *st = fmtx->streams[audio_stream_idx]; + + // find a decoder for the stream +-#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57, 14, 0)) || ((LIBAVCODEC_VERSION_MICRO >= 100) && (LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57, 33, 100))) +- // old libav version (libavcodec < 57.14 for libav, < 57.33 for ffmpeg): +- // stream has a codec context we can use +- AVCodecContext *decx = st->codec; +- #define AVCODEC_FREE_CONTEXT(x) +-#else +- // new libav version: need to create codec context for stream ++ // need to create codec context for stream + AVCodecParameters *decp = st->codecpar; + AVCodecContext *decx = avcodec_alloc_context3(NULL); + if (!decx) { +@@ -200,71 +164,63 @@ libav::decodeto_22050hz_mono_float( + avformat_close_input(&fmtx); + return std::vector(0); + } +- #if LIBAVCODEC_VERSION_MICRO >= 100 +- #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58,3,102) +- // only available in ffmpeg, deprecated after 58 +- av_codec_set_pkt_timebase(decx, st->time_base); +- #endif +- #endif +- #define AVCODEC_FREE_CONTEXT(x) avcodec_free_context(x) +-#endif +- AVCodec *dec = avcodec_find_decoder(decx->codec_id); ++ const AVCodec *dec = avcodec_find_decoder(decx->codec_id); + if (!dec) { + MINILOG(logERROR) << "Could not find codec."; + +- AVCODEC_FREE_CONTEXT(&decx); ++ avcodec_free_context(&decx); + avformat_close_input(&fmtx); + return std::vector(0); + } + + // open the decoder + // (kindly ask for stereo downmix and floats, but not all decoders care) +- decx->request_channel_layout = AV_CH_LAYOUT_STEREO_DOWNMIX; + decx->request_sample_fmt = AV_SAMPLE_FMT_FLT; + #ifdef _OPENMP + #pragma omp critical + #endif + { +- avret = avcodec_open2(decx, dec, NULL); ++ AVDictionary *options = NULL; ++ av_dict_set(&options, "downmix", "stereo", 0); ++ avret = avcodec_open2(decx, dec, &options); + } + if (avret < 0) { + MINILOG(logERROR) << "Could not open codec."; + +- AVCODEC_FREE_CONTEXT(&decx); ++ avcodec_free_context(&decx); + avformat_close_input(&fmtx); + return std::vector(0); + } + + // Currently only mono and stereo files are supported. +- if ((decx->channels != 1) && (decx->channels != 2)) { ++ if ((decx->ch_layout.nb_channels != 1) && (decx->ch_layout.nb_channels != 2)) { + MINILOG(logWARNING) << "Unsupported number of channels: " +- << decx->channels; ++ << decx->ch_layout.nb_channels; + +- AVCODEC_FREE_CONTEXT(&decx); ++ avcodec_free_context(&decx); + avformat_close_input(&fmtx); + return std::vector(0); + } + + // allocate a frame +- AVFrame* frame = AV_FRAME_ALLOC(); ++ AVFrame* frame = av_frame_alloc(); + if (!frame) { + MINILOG(logWARNING) << "Could not allocate frame"; + +- AVCODEC_FREE_CONTEXT(&decx); ++ avcodec_free_context(&decx); + avformat_close_input(&fmtx); + return std::vector(0); + } + + // allocate and initialize a packet +- AVPacket pkt; +- av_init_packet(&pkt); +- pkt.data = NULL; +- pkt.size = 0; ++ AVPacket* pkt = av_packet_alloc(); ++ pkt->data = NULL; ++ pkt->size = 0; + int got_frame = 0; + + // configuration + const int input_stride = av_get_bytes_per_sample(decx->sample_fmt); +- const int num_planes = av_sample_fmt_is_planar(decx->sample_fmt) ? decx->channels : 1; ++ const int num_planes = av_sample_fmt_is_planar(decx->sample_fmt) ? decx->ch_layout.nb_channels : 1; + const int output_stride = sizeof(float) * num_planes; + int decode_samples; // how many samples to decode; zero to decode all + +@@ -296,7 +252,7 @@ libav::decodeto_22050hz_mono_float( + // fault when trying to access frame->data[i] for i > 0 further below) + if ((excerpt_start > 0) and (av_seek_frame(fmtx, audio_stream_idx, + excerpt_start * st->time_base.den / st->time_base.num, +- AVSEEK_FLAG_BACKWARD || AVSEEK_FLAG_ANY) >= 0)) { ++ AVSEEK_FLAG_BACKWARD | AVSEEK_FLAG_ANY) >= 0)) { + // skipping went fine: decode only what's needed + decode_samples = excerpt_length * decx->sample_rate; + excerpt_start = 0; +@@ -333,7 +289,7 @@ libav::decodeto_22050hz_mono_float( + // excerpt_start tells us up to how many seconds to cut from the beginning. + + // read packets +- const int channels = decx->channels; ++ const int channels = decx->ch_layout.nb_channels; + const int sample_rate = decx->sample_rate; + float* buffer = NULL; + int buffersize = 0; +@@ -344,35 +300,29 @@ libav::decodeto_22050hz_mono_float( + { + // skip all frames that are not part of the audio stream, and spurious + // frames possibly found after seeking (wrong channels / sample_rate) +- while (((avret = av_read_frame(fmtx, &pkt)) >= 0) +- && ((pkt.stream_index != audio_stream_idx) || +- (decx->channels != channels) || ++ while (((avret = av_read_frame(fmtx, pkt)) >= 0) ++ && ((pkt->stream_index != audio_stream_idx) || ++ (decx->ch_layout.nb_channels != channels) || + (decx->sample_rate != sample_rate))) + { +- AV_PACKET_UNREF(&pkt); ++ av_packet_unref(pkt); + MINILOG(logTRACE) << "Skipping frame..."; + } + if (avret < 0) { + // stop decoding if av_read_frame() failed +- AV_PACKET_UNREF(&pkt); ++ av_packet_unref(pkt); + break; + } + +- uint8_t* data = pkt.data; +- int size = pkt.size; +- while (pkt.size > 0) { ++ uint8_t* data = pkt->data; ++ int size = pkt->size; ++ while (pkt->size > 0) { + + // try to decode a frame +- AV_FRAME_UNREF(frame); ++ av_frame_unref(frame); + + int len = 0; + got_frame = 0; +-#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57, 48, 101) +- len = avcodec_decode_audio4(decx, frame, &got_frame, &pkt); +- if (len < 0) { +- avret = AVERROR(EINVAL); +- } +-#else + avret = avcodec_receive_frame(decx, frame); + if (avret == 0) { + got_frame = 1; +@@ -381,14 +331,13 @@ libav::decodeto_22050hz_mono_float( + avret = 0; + } + if (avret == 0) { +- avret = avcodec_send_packet(decx, &pkt); ++ avret = avcodec_send_packet(decx, pkt); + if (avret == 0) { +- len = pkt.size; ++ len = pkt->size; + } else if (avret == AVERROR(EAGAIN)) { + avret = 0; + } + } +-#endif + if (avret < 0) { + MINILOG(logWARNING) << "Error decoding an audio frame"; + +@@ -400,8 +349,8 @@ libav::decodeto_22050hz_mono_float( + + // if too many frames failed decoding, abort + MINILOG(logERROR) << "Too many errors, aborting."; +- AV_FRAME_FREE(&frame); +- AV_PACKET_UNREF(&pkt); ++ av_frame_free(&frame); ++ av_packet_unref(pkt); + avformat_close_input(&fmtx); + if (buffer) { + delete[] buffer; +@@ -414,7 +363,7 @@ libav::decodeto_22050hz_mono_float( + // if we got a frame + if (got_frame) { + // do we need to increase the buffer size? +- int input_samples = frame->nb_samples*decx->channels; ++ int input_samples = frame->nb_samples*decx->ch_layout.nb_channels; + if (input_samples > buffersize) { + if (buffer) { + delete[] buffer; +@@ -434,8 +383,8 @@ libav::decodeto_22050hz_mono_float( + input_samples / num_planes) < 0) { + MINILOG(logERROR) << "Strange sample format. Abort."; + +- AV_FRAME_FREE(&frame); +- AV_PACKET_UNREF(&pkt); ++ av_frame_free(&frame); ++ av_packet_unref(pkt); + avformat_close_input(&fmtx); + if (buffer) { + delete[] buffer; +@@ -445,7 +394,7 @@ libav::decodeto_22050hz_mono_float( + } + + // inplace downmix to mono, if required +- if (decx->channels == 2) { ++ if (decx->ch_layout.nb_channels == 2) { + for (int i = 0; i < frame->nb_samples; i++) { + buffer[i] = (buffer[i*2] + buffer[i*2+1]) / 2.0f; + } +@@ -457,13 +406,13 @@ libav::decodeto_22050hz_mono_float( + } + + // consume the packet +- pkt.data += len; +- pkt.size -= len; ++ pkt->data += len; ++ pkt->size -= len; + } +- pkt.data = data; +- pkt.size = size; ++ pkt->data = data; ++ pkt->size = size; + +- AV_PACKET_UNREF(&pkt); ++ av_packet_unref(pkt); + } + MINILOG(logTRACE) << "Decoding loop finished."; + +@@ -514,13 +463,12 @@ libav::decodeto_22050hz_mono_float( + if (buffer) { + delete[] buffer; + } +- AV_FRAME_FREE(&frame); ++ av_frame_free(&frame); + #ifdef _OPENMP + #pragma omp critical + #endif + { +- avcodec_close(decx); +- AVCODEC_FREE_CONTEXT(&decx); ++ avcodec_free_context(&decx); + avformat_close_input(&fmtx); + } + +-- +2.45.2 + diff --git a/pkgs/by-name/mu/musly/0002-Fix-build-with-C-17.patch b/pkgs/by-name/mu/musly/0002-Fix-build-with-C-17.patch new file mode 100644 index 0000000000000..f128bd4d0c02a --- /dev/null +++ b/pkgs/by-name/mu/musly/0002-Fix-build-with-C-17.patch @@ -0,0 +1,35 @@ +From 75efe27cbb03f2883e53e7a7f68386d93e2c1874 Mon Sep 17 00:00:00 2001 +From: Emily +Date: Sat, 3 Aug 2024 12:17:19 +0100 +Subject: [PATCH 2/4] Fix build with C++17 + +--- + musly/main.cpp | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +diff --git a/musly/main.cpp b/musly/main.cpp +index a9644f2..bb8b7ae 100644 +--- a/musly/main.cpp ++++ b/musly/main.cpp +@@ -14,6 +14,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -239,7 +240,9 @@ tracks_initialize( + else { + // use a random subset of 1000 tracks + std::vector tracks2(tracks); +- std::random_shuffle(tracks2.begin(), tracks2.end()); ++ std::random_device seeder; ++ std::default_random_engine rng(seeder()); ++ std::shuffle(tracks2.begin(), tracks2.end(), rng); + ret = musly_jukebox_setmusicstyle(mj, tracks2.data(), 1000); + } + if (ret != 0) { +-- +2.45.2 + diff --git a/pkgs/by-name/mu/musly/0003-Modernize-CMake-build-system.patch b/pkgs/by-name/mu/musly/0003-Modernize-CMake-build-system.patch new file mode 100644 index 0000000000000..3696fee9ba40a --- /dev/null +++ b/pkgs/by-name/mu/musly/0003-Modernize-CMake-build-system.patch @@ -0,0 +1,151 @@ +From 8abe6385e433b44c43134b4deef208c7498ab0d7 Mon Sep 17 00:00:00 2001 +From: Emily +Date: Sat, 3 Aug 2024 12:21:12 +0100 +Subject: [PATCH 3/4] Modernize CMake build system + +Use GNUInstallDirs, CTest, and FindPkgConfig. +--- + .travis.yml | 2 +- + CMakeLists.txt | 25 +++++++++++-------------- + libmusly/CMakeLists.txt | 11 +++-------- + musly/CMakeLists.txt | 6 +----- + 4 files changed, 16 insertions(+), 28 deletions(-) + +diff --git a/.travis.yml b/.travis.yml +index 8556b26..b051004 100644 +--- a/.travis.yml ++++ b/.travis.yml +@@ -19,7 +19,7 @@ matrix: + script: + - mkdir -p build + - cd build +- - cmake -DBUILD_TEST=ON .. ++ - cmake .. + - make -j + - ctest -V + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 4fab4ab..8d8bf0e 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -4,9 +4,11 @@ + # (c) 2013-2014, Dominik Schnitzer + # 2014, Jan Schlueter + +-cmake_minimum_required(VERSION 2.8) ++cmake_minimum_required(VERSION 3.17) + + project(musly) ++include(GNUInstallDirs) ++include(CTest) + set(MUSLY_VERSION "0.2") + add_definitions(-DMUSLY_VERSION="${MUSLY_VERSION}") + +@@ -36,8 +38,6 @@ else () + set(BUILD_SHARED_LIBS ON) + endif () + +-option(BUILD_TEST "Build selftest executable" OFF) +- + option(USE_OPENMP "Compile with OpenMP support (Parallelization)" OFF) + if (USE_OPENMP) + find_package(OpenMP) +@@ -54,26 +54,23 @@ if (USE_OPENMP) + endif() + endif () + +-set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) +- +-find_package(Eigen3 REQUIRED) +-find_package(LibAV 0.8 COMPONENTS avcodec avformat avutil REQUIRED) ++find_package(PkgConfig REQUIRED) ++pkg_check_modules(EIGEN3 REQUIRED IMPORTED_TARGET eigen3) ++pkg_check_modules(FFMPEG REQUIRED IMPORTED_TARGET ++ libavcodec ++ libavformat ++ libavutil) + + include_directories( +- "${PROJECT_BINARY_DIR}" + "${PROJECT_SOURCE_DIR}/include") + + add_subdirectory(libmusly) + add_subdirectory(musly) + add_subdirectory(include) +-if (BUILD_TEST) +- enable_testing() ++if (BUILD_TESTING) + add_subdirectory(test) + endif () + + # Documentation + set(musly_DOC_FILES AUTHORS COPYING README.md) +-set(musly_DOC_PATH "share/doc/musly") +-install(FILES ${musly_DOC_FILES} +- DESTINATION ${musly_DOC_PATH}) +- ++install(FILES ${musly_DOC_FILES} DESTINATION ${CMAKE_INSTALL_DOCDIR}) +diff --git a/libmusly/CMakeLists.txt b/libmusly/CMakeLists.txt +index 98151df..b9f6d11 100644 +--- a/libmusly/CMakeLists.txt ++++ b/libmusly/CMakeLists.txt +@@ -4,9 +4,6 @@ + # (c) 2013-2014, Dominik Schnitzer + # 2014-2016, Jan Schlueter + +-add_subdirectory( +- libresample) +- + if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/external") + add_subdirectory( + external) +@@ -24,8 +21,6 @@ endif() + + include_directories( + ${LIBMUSLY_INCLUDE} +- ${EIGEN3_INCLUDE_DIR} +- ${LIBAV_INCLUDE_DIRS} + ${CMAKE_CURRENT_SOURCE_DIR}) + + add_library(libmusly +@@ -60,7 +55,8 @@ set_target_properties(libmusly + + target_link_libraries(libmusly + ${LIBMUSLY_LIBS} +- ${LIBAV_LIBRARIES}) ++ PkgConfig::EIGEN3 ++ PkgConfig::FFMPEG) + if(WIN32 OR MINGW) + # link against winsock2 for ntohl() and htonl() + target_link_libraries(libmusly ws2_32) +@@ -69,5 +65,4 @@ endif() + set_target_properties(libmusly + PROPERTIES PREFIX "") + +-install(TARGETS libmusly +- DESTINATION lib) ++install(TARGETS libmusly) +diff --git a/musly/CMakeLists.txt b/musly/CMakeLists.txt +index 88d153b..846ed2c 100644 +--- a/musly/CMakeLists.txt ++++ b/musly/CMakeLists.txt +@@ -3,10 +3,6 @@ + + # (c) 2013, Dominik Schnitzer + +-include_directories( +- ${EIGEN3_INCLUDE_DIR}) +- +- + add_executable(musly + tools.cpp + fileiterator.cpp +@@ -17,4 +13,4 @@ add_executable(musly + target_link_libraries(musly + libmusly) + +-install(TARGETS musly DESTINATION bin) ++install(TARGETS musly) +-- +2.45.2 + diff --git a/pkgs/by-name/mu/musly/0004-Use-pkg-config-to-find-libresample-and-kissfft.patch b/pkgs/by-name/mu/musly/0004-Use-pkg-config-to-find-libresample-and-kissfft.patch new file mode 100644 index 0000000000000..c7f893a6a866b --- /dev/null +++ b/pkgs/by-name/mu/musly/0004-Use-pkg-config-to-find-libresample-and-kissfft.patch @@ -0,0 +1,110 @@ +From e4a0d0b48905bb949831c30c941e921da0b6f09c Mon Sep 17 00:00:00 2001 +From: Emily +Date: Sat, 3 Aug 2024 12:21:12 +0100 +Subject: [PATCH 4/4] Use pkg-config to find libresample and kissfft + +--- + .travis.yml | 2 ++ + CMakeLists.txt | 12 ++++++++++++ + libmusly/CMakeLists.txt | 12 +++--------- + libmusly/powerspectrum.h | 2 +- + libmusly/resampler.h | 2 +- + 5 files changed, 19 insertions(+), 11 deletions(-) + +diff --git a/.travis.yml b/.travis.yml +index b051004..b354641 100644 +--- a/.travis.yml ++++ b/.travis.yml +@@ -31,3 +31,5 @@ addons: + - libavcodec-dev + - libavformat-dev + - libavutil-dev ++ - libresample-dev ++ - libkissfft-dev +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 8d8bf0e..c5b0d2c 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -60,6 +60,18 @@ pkg_check_modules(FFMPEG REQUIRED IMPORTED_TARGET + libavcodec + libavformat + libavutil) ++pkg_check_modules(LIBRESAMPLE REQUIRED IMPORTED_TARGET libresample) ++pkg_search_module(KISSFFT REQUIRED IMPORTED_TARGET ++ kissfft-simd ++ kissfft-double ++ kissfft-float ++ kissfft-int32_t ++ kissfft-int16_t ++ kissfft-simd-openmp ++ kissfft-double-openmp ++ kissfft-float-openmp ++ kissfft-int32_t-openmp ++ kissfft-int16_t-openmp) + + include_directories( + "${PROJECT_SOURCE_DIR}/include") +diff --git a/libmusly/CMakeLists.txt b/libmusly/CMakeLists.txt +index b9f6d11..6f8c8e9 100644 +--- a/libmusly/CMakeLists.txt ++++ b/libmusly/CMakeLists.txt +@@ -13,19 +13,11 @@ if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/external") + PROPERTIES COMPILE_FLAGS "-DLIBMUSLY_EXTERNAL ${LIBMUSLY_EXTERNAL_FLAGS}") + endif() + +-if(USE_OPENMP AND OPENMP_FOUND) +- # disable OpenMP for kiss FFT, it slows things down terribly +- set_source_files_properties(kissfft/kiss_fft.c +- PROPERTIES COMPILE_FLAGS "-U_OPENMP") +-endif() +- + include_directories( + ${LIBMUSLY_INCLUDE} + ${CMAKE_CURRENT_SOURCE_DIR}) + + add_library(libmusly +- kissfft/kiss_fft.c +- kissfft/kiss_fftr.c + methods/mandelellis.cpp + methods/timbre.cpp + decoders/libav.cpp +@@ -56,7 +48,9 @@ set_target_properties(libmusly + target_link_libraries(libmusly + ${LIBMUSLY_LIBS} + PkgConfig::EIGEN3 +- PkgConfig::FFMPEG) ++ PkgConfig::FFMPEG ++ PkgConfig::LIBRESAMPLE ++ PkgConfig::KISSFFT) + if(WIN32 OR MINGW) + # link against winsock2 for ntohl() and htonl() + target_link_libraries(libmusly ws2_32) +diff --git a/libmusly/powerspectrum.h b/libmusly/powerspectrum.h +index 6957db4..096fc31 100644 +--- a/libmusly/powerspectrum.h ++++ b/libmusly/powerspectrum.h +@@ -14,7 +14,7 @@ + + #include + extern "C" { +- #include "kissfft/kiss_fftr.h" ++ #include + } + + +diff --git a/libmusly/resampler.h b/libmusly/resampler.h +index df8aaa4..f48e22a 100644 +--- a/libmusly/resampler.h ++++ b/libmusly/resampler.h +@@ -14,7 +14,7 @@ + + #include + extern "C" { +- #include "libresample/libresample.h" ++ #include + } + + namespace musly { +-- +2.45.2 + diff --git a/pkgs/by-name/mu/musly/package.nix b/pkgs/by-name/mu/musly/package.nix new file mode 100644 index 0000000000000..25938c2059fab --- /dev/null +++ b/pkgs/by-name/mu/musly/package.nix @@ -0,0 +1,72 @@ +{ + lib, + stdenv, + fetchFromGitHub, + cmake, + ninja, + pkg-config, + eigen, + ffmpeg_7, + libresample, + kissfft, +}: + +stdenv.mkDerivation { + pname = "musly"; + version = "0.1-unstable-2019-09-05"; + + outputs = [ + "bin" + "dev" + "out" + "doc" + ]; + + src = fetchFromGitHub { + owner = "dominikschnitzer"; + repo = "musly"; + rev = "7a0c6a9a2782e6fca84fb86fce5232a8c8a104ed"; + hash = "sha256-DOvGGx3pCcvPPsT97sQlINjT1sJy8ZWvxLsFGGZbgzE="; + }; + + patches = [ + # Fix build with FFmpeg 7, C++17, and external libresample and kissfft + # https://github.com/dominikschnitzer/musly/pull/53 + # Last commit omitted, as it is a large non‐functional removal + ./0001-Fix-build-with-FFmpeg-7.patch + ./0002-Fix-build-with-C-17.patch + ./0003-Modernize-CMake-build-system.patch + ./0004-Use-pkg-config-to-find-libresample-and-kissfft.patch + ]; + + nativeBuildInputs = [ + cmake + ninja + pkg-config + ]; + + buildInputs = [ + eigen + ffmpeg_7 + libresample + kissfft + ]; + + doCheck = true; + + meta = { + homepage = "https://www.musly.org"; + description = "Fast and high-quality audio music similarity library written in C/C++"; + longDescription = '' + Musly analyzes the the audio signal of music pieces to estimate their similarity. + No meta-data about the music piece is included in the similarity estimation. + To use Musly in your application, have a look at the library documentation + or try the command line application included in the package and start generating + some automatic music playlists right away. + ''; + license = lib.licenses.mpl20; + maintainers = with lib.maintainers; [ ggpeti ]; + platforms = lib.platforms.unix; + mainProgram = "musly"; + }; +} diff --git a/pkgs/development/libraries/audio/qm-dsp/default.nix b/pkgs/development/libraries/audio/qm-dsp/default.nix index 06b08b7e0c92b..2201f02c62e87 100644 --- a/pkgs/development/libraries/audio/qm-dsp/default.nix +++ b/pkgs/development/libraries/audio/qm-dsp/default.nix @@ -46,7 +46,7 @@ stdenv.mkDerivation rec { rmdir $out/include/qm-dsp ''; - env.NIX_CFLAGS_COMPILE = "-I${kissfft}/include/kissfft"; + env.NIX_CFLAGS_COMPILE = "-I${lib.getInclude kissfft}/include/kissfft"; meta = with lib; { description = "C++ library of functions for DSP and Music Informatics purposes"; diff --git a/pkgs/development/libraries/kissfft/0001-pkgconfig-darwin.patch b/pkgs/development/libraries/kissfft/0001-pkgconfig-darwin.patch deleted file mode 100644 index 534d46f0c8ba3..0000000000000 --- a/pkgs/development/libraries/kissfft/0001-pkgconfig-darwin.patch +++ /dev/null @@ -1,48 +0,0 @@ -From c0dc376be9154d143574a818417ceed23308b5f2 Mon Sep 17 00:00:00 2001 -From: OPNA2608 -Date: Sun, 18 Apr 2021 01:45:20 +0200 -Subject: [PATCH] pkgconfig darwin - ---- - Makefile | 4 ---- - 1 file changed, 4 deletions(-) - -diff --git a/Makefile b/Makefile -index 971c6d6..0f4be0c 100644 ---- a/Makefile -+++ b/Makefile -@@ -153,7 +153,6 @@ endif - # -DKISS_FFT_BUILD to TYPEFLAGS - # - --ifneq ($(shell uname -s),Darwin) - PKGCONFIG_KISSFFT_VERSION = $(KFVER_MAJOR).$(KFVER_MINOR).$(KFVER_PATCH) - PKGCONFIG_KISSFFT_OUTPUT_NAME = $(KISSFFTLIB_SHORTNAME) - PKGCONFIG_PKG_KISSFFT_DEFS = $(TYPEFLAGS) -@@ -170,7 +169,6 @@ ifneq ($(shell uname -s),Darwin) - PKGCONFIG_KISSFFT_LIBDIR = $(ABS_LIBDIR) - endif - PKGCONFIG_KISSFFT_PKGINCLUDEDIR = $${includedir}/kissfft --endif - - export TYPEFLAGS - -@@ -226,7 +224,6 @@ ifneq ($(KISSFFT_STATIC), 1) - ln -sf $(KISSFFTLIB_NAME) $(KISSFFTLIB_SODEVELNAME) - endif - endif --ifneq ($(shell uname -s),Darwin) - mkdir "$(ABS_LIBDIR)/pkgconfig" - sed \ - -e 's+@PKGCONFIG_KISSFFT_VERSION@+$(PKGCONFIG_KISSFFT_VERSION)+' \ -@@ -238,7 +235,6 @@ ifneq ($(shell uname -s),Darwin) - -e 's+@PKGCONFIG_KISSFFT_LIBDIR@+$(PKGCONFIG_KISSFFT_LIBDIR)+' \ - -e 's+@PKGCONFIG_KISSFFT_PKGINCLUDEDIR@+$(PKGCONFIG_KISSFFT_PKGINCLUDEDIR)+' \ - kissfft.pc.in 1>"$(ABS_LIBDIR)/pkgconfig/$(KISSFFT_PKGCONFIG)" --endif - ifneq ($(KISSFFT_TOOLS), 0) - make -C tools install - endif --- -2.29.3 - diff --git a/pkgs/development/libraries/kissfft/default.nix b/pkgs/development/libraries/kissfft/default.nix deleted file mode 100644 index 5156e1ccd8989..0000000000000 --- a/pkgs/development/libraries/kissfft/default.nix +++ /dev/null @@ -1,85 +0,0 @@ -{ lib -, stdenv -, fetchFromGitHub -, fftw -, fftwFloat -, python3 -, datatype ? "double" -, withTools ? false -, libpng -, enableStatic ? stdenv.hostPlatform.isStatic -, enableOpenmp ? false -, llvmPackages -}: -let - py = python3.withPackages (ps: with ps; [ numpy ]); - option = cond: if cond then "1" else "0"; -in -stdenv.mkDerivation rec { - pname = "kissfft-${datatype}${lib.optionalString enableOpenmp "-openmp"}"; - version = "131.1.0"; - - src = fetchFromGitHub { - owner = "mborgerding"; - repo = "kissfft"; - rev = version; - sha256 = "1yfws5bn4kh62yk6hdyp9h9775l6iz7wsfisbn58jap6b56s8j5s"; - }; - - patches = [ - ./0001-pkgconfig-darwin.patch - ]; - - # https://bugs.llvm.org/show_bug.cgi?id=45034 - postPatch = lib.optionalString (stdenv.hostPlatform.isLinux && stdenv.cc.isClang && lib.versionOlder stdenv.cc.version "10") '' - substituteInPlace test/Makefile \ - --replace "-ffast-math" "" - '' - + lib.optionalString (stdenv.hostPlatform.isDarwin) '' - substituteInPlace test/Makefile \ - --replace "LD_LIBRARY_PATH" "DYLD_LIBRARY_PATH" - # Don't know how to make math.h's double long constants available - substituteInPlace test/testcpp.cc \ - --replace "M_PIl" "M_PI" - ''; - - makeFlags = [ - "PREFIX=${placeholder "out"}" - "KISSFFT_DATATYPE=${datatype}" - "KISSFFT_TOOLS=${option withTools}" - "KISSFFT_STATIC=${option enableStatic}" - "KISSFFT_OPENMP=${option enableOpenmp}" - ]; - - buildInputs = lib.optionals (withTools && datatype != "simd") [ libpng ] - # TODO: This may mismatch the LLVM version in the stdenv, see #79818. - ++ lib.optional (enableOpenmp && stdenv.cc.isClang) llvmPackages.openmp; - - doCheck = true; - - nativeCheckInputs = [ - py - (if datatype == "float" then fftwFloat else fftw) - ]; - - checkFlags = [ "testsingle" ]; - - postInstall = '' - ln -s ${pname}.pc $out/lib/pkgconfig/kissfft.pc - ''; - - # Tools can't find kissfft libs on Darwin - postFixup = lib.optionalString (withTools && stdenv.hostPlatform.isDarwin) '' - for bin in $out/bin/*; do - install_name_tool -change lib${pname}.dylib $out/lib/lib${pname}.dylib $bin - done - ''; - - meta = with lib; { - description = "Mixed-radix Fast Fourier Transform based up on the KISS principle"; - homepage = "https://github.com/mborgerding/kissfft"; - license = licenses.bsd3; - maintainers = [ ]; - platforms = platforms.all; - }; -} diff --git a/pkgs/development/libraries/libresample/default.nix b/pkgs/development/libraries/libresample/default.nix deleted file mode 100644 index 6ca1d09ef202f..0000000000000 --- a/pkgs/development/libraries/libresample/default.nix +++ /dev/null @@ -1,29 +0,0 @@ -{lib, stdenv, fetchurl, cmake}: - -let - patch = fetchurl { - url = "mirror://debian/pool/main/libr/libresample/libresample_0.1.3-3.diff.gz"; - sha256 = "063w8rqxw87fc89gas47vk0ll7xl8cy7d8g70gm1l62bqkkajklx"; - }; -in -stdenv.mkDerivation rec { - pname = "libresample"; - version = "0.1.3"; - src = fetchurl { - url = "mirror://debian/pool/main/libr/libresample/libresample_${version}.orig.tar.gz"; - sha256 = "05a8mmh1bw5afqx0kfdqzmph4x2npcs4idx0p0v6q95lwf22l8i0"; - }; - patches = [ patch ]; - preConfigure = '' - cat debian/patches/1001_shlib-cmake.patch | patch -p1 - ''; - nativeBuildInputs = [ cmake ]; - - meta = { - description = "Real-time library for sampling rate conversion library"; - license = lib.licenses.lgpl2Plus; - homepage = "https://ccrma.stanford.edu/~jos/resample/Free_Resampling_Software.html"; - maintainers = [ lib.maintainers.sander ]; - platforms = lib.platforms.unix; - }; -} diff --git a/pkgs/development/libraries/libsamplerate/default.nix b/pkgs/development/libraries/libsamplerate/default.nix index bebe6c591ba43..45cd9d091dd0a 100644 --- a/pkgs/development/libraries/libsamplerate/default.nix +++ b/pkgs/development/libraries/libsamplerate/default.nix @@ -32,5 +32,7 @@ in stdenv.mkDerivation rec { license = licenses.bsd2; maintainers = with maintainers; [ lovek323 ]; platforms = platforms.all; + # Linker is unhappy with the `.def` file. + broken = stdenv.hostPlatform.isMinGW; }; } diff --git a/pkgs/development/libraries/libsndfile/default.nix b/pkgs/development/libraries/libsndfile/default.nix index 0e1dfb0bc08b0..a1ffdae6bb339 100644 --- a/pkgs/development/libraries/libsndfile/default.nix +++ b/pkgs/development/libraries/libsndfile/default.nix @@ -71,7 +71,7 @@ stdenv.mkDerivation rec { changelog = "https://github.com/libsndfile/libsndfile/releases/tag/${version}"; license = licenses.lgpl2Plus; maintainers = with maintainers; [ lovek323 ]; - platforms = platforms.unix; + platforms = platforms.all; longDescription = '' Libsndfile is a C library for reading and writing files containing diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index a529941abd264..8a3bec9f490eb 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -22031,8 +22031,6 @@ with pkgs; python = python3; }; - libresample = callPackage ../development/libraries/libresample { }; - librevenge = callPackage ../development/libraries/librevenge { }; librime = callPackage ../development/libraries/librime { }; @@ -23643,7 +23641,6 @@ with pkgs; rtrlib = callPackage ../development/libraries/rtrlib { }; - kissfft = callPackage ../development/libraries/kissfft { }; kissfftFloat = kissfft.override { datatype = "float"; }; @@ -38780,8 +38777,6 @@ with pkgs; museeks = callPackage ../applications/audio/museeks { }; - musly = callPackage ../applications/audio/musly { }; - mynewt-newt = callPackage ../tools/package-management/mynewt-newt { }; mynewt-newtmgr = callPackage ../tools/misc/mynewt-newtmgr { };