1{ lib
2, stdenv
3, fetchFromGitHub
4, cmake
5, freedvSupport ? false
6, lpcnetfreedv
7, codec2
8}:
9
10stdenv.mkDerivation rec {
11 pname = "codec2";
12 version = "1.2.0";
13
14 src = fetchFromGitHub {
15 owner = "drowe67";
16 repo = "codec2";
17 rev = "${version}";
18 hash = "sha256-69Mp4o3MgV98Fqfai4txv5jQw2WpoPuoWcwHsNAFPQM=";
19 };
20
21 nativeBuildInputs = [ cmake ];
22
23 buildInputs = lib.optionals freedvSupport [
24 lpcnetfreedv
25 ];
26
27 postInstall = ''
28 install -Dm0755 src/{c2enc,c2sim,freedv_rx,freedv_tx,cohpsk_*,fdmdv_*,fsk_*,ldpc_*,ofdm_*} -t $out/bin/
29 '';
30
31 # Swap keyword order to satisfy SWIG parser
32 postFixup = ''
33 sed -r -i 's/(\<_Complex)(\s+)(float|double)/\3\2\1/' $out/include/$pname/freedv_api.h
34 '';
35
36 cmakeFlags = [
37 # RPATH of binary /nix/store/.../bin/freedv_rx contains a forbidden reference to /build/
38 "-DCMAKE_SKIP_BUILD_RPATH=ON"
39 ] ++ lib.optionals freedvSupport [
40 "-DLPCNET=ON"
41 ];
42
43 meta = with lib; {
44 description = "Speech codec designed for communications quality speech at low data rates";
45 homepage = "https://www.rowetel.com/codec2.html";
46 license = licenses.lgpl21Only;
47 platforms = platforms.unix;
48 maintainers = with maintainers; [ markuskowa ];
49 };
50}