;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2013 Andreas Enge ;;; Copyright © 2014, 2015, 2017, 2020, 2021 Ludovic Courtès ;;; Copyright © 2015 Mark H Weaver ;;; Copyright © 2016, 2021 Efraim Flashner ;;; Copyright © 2017 Thomas Danckaert ;;; Copyright © 2017, 2019, 2020 Pierre Langlois ;;; Copyright © 2018–2021 Tobias Geerinckx-Rice ;;; Copyright © 2019 Ricardo Wurmus ;;; Copyright © 2020 Michael Rohleder ;;; Copyright © 2021 Simon Streit ;;; Copyright © 2021 Guillaume Le Vaillant ;;; Copyright © 2022 John Kehayias ;;; Copyright © 2022 Joeke de Graaf ;;; ;;; This file is part of GNU Guix. ;;; ;;; GNU Guix is free software; you can redistribute it and/or modify it ;;; under the terms of the GNU General Public License as published by ;;; the Free Software
aboutsummaryrefslogtreecommitdiff
blob: 22c1a992507782c7053d129e3cf33f49e396b7e3 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2023 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (gnu home services sound)
  #:use-module (gnu home services)
  #:use-module (gnu home services shepherd)
  #:use-module (guix records)
  #:use-module (guix gexp)
  #:use-module (srfi srfi-1)
  #:use-module (ice-9 match)
  #:export (home-pulseaudio-rtp-sink-service-type
            home-pulseaudio-rtp-source-service-type
            %pulseaudio-rtp-multicast-address))


;;;
;;; PulseAudio support.
;;;

(define (with-pulseaudio-connection sock exp)
  ;; Wrap EXP in an expression where SOCK is bound to a socket connected to
  ;; the user's PulseAudio command-line interface socket.
  #~(let* ((#$sock (socket AF_UNIX SOCK_STREAM 0))
           (pulse-user-file
            (lambda (name)
              (string-append "/run/user/" (number->string (getuid))
                             "/pulse/" name)))
           (file (pulse-user-file "cli")))
      (let loop ((tries 0))
        (catch #t
          (lambda ()
            (connect #$sock AF_UNIX file)
            (let ((result #$exp))
              (close-port #$sock)
              result))
          (lambda (key . args)
            (if (and (eq? key 'system-error)
                     (= ENOENT (system-error-errno (cons key args)))
                     (< tries 3))
                ;; The CLI socket doesn't exist yet, so send pulseaudio
                ;; SIGUSR2 so that it creates it and listens to it.
                (let ((pid (call-with-input-file (pulse-user-file "pid")
                             read)))
                  (when (and (integer? pid) (> pid 1))
                    (kill pid SIGUSR2))
                  ((@ (fibers) sleep) 1)
                  (loop (+ tries 1)))
                (begin
                  (close-port #$sock)
                  (apply throw key args))))))))

(define %pulseaudio-rtp-multicast-address
  ;; Default address used by 'module-rtp-sink' and 'module-rtp-recv'.  This is
  ;; a multicast address, for the Session Announcement Protocol (SAP) and the
  ;; Session Description Protocol (SDP).
  "224.0.0.56")

(define (pulseaudio-rtp-sink-shepherd-services destination-ip)
  (list (shepherd-service
         (provision '(pulseaudio-rtp-sink))
         (start
          #~(lambda* (#:optional (destination-ip #$destination-ip))
              #$(with-pulseaudio-connection
                 #~sock
                 #~(begin
                     (display "\
load-module module-null-sink \
sink_name=rtp sink_properties=\"device.description='RTP network output'\"\n"
                              sock)
                     (display (string-append "\
load-module module-rtp-send source=rtp.monitor"
                                             (if destination-ip
                                                 (string-append
                                                  " destination_ip="
                                                  destination-ip)
                                                 "")
                                             "\n")
                              sock)
                     #t))))
         (stop
          #~(lambda (_)
              #$(with-pulseaudio-connection
                 #~sock
                 #~(begin
                     (display "unload-module module-rtp-send\n"
                              sock)
                     (display "unload-module module-null-sink\n"
                              sock)
                     #f))))
         (auto-start? #f))))

(define home-pulseaudio-rtp-sink-service-type
  (service-type
   (name 'pulseaudio-rtp-sink)
   (extensions
    (list (service-extension home-shepherd-service-type
                             pulseaudio-rtp-sink-shepherd-services)))
   (description
    "Define a PulseAudio sink to broadcast audio output over RTP, which can
then by played by another PulseAudio instance.")

   ;; By default, send to the SAP multicast address, 224.0.0.56, which can be
   ;; network-intensive.
   (default-value %pulseaudio-rtp-multicast-address)))

(define (pulseaudio-rtp-source-shepherd-services source-ip)
  (list (shepherd-service
         (provision '(pulseaudio-rtp-source))
         (start
          #~(lambda* (#:optional (source-ip #$source-ip))
              #$(with-pulseaudio-connection
                 #~sock
                 #~(begin
                     (format sock "\
load-module module-rtp-recv sap_address=~a\n" source-ip)
                     #t))))
         (stop
          #~(lambda (_)
              #$(with-pulseaudio-connection
                 #~sock
                 #~(begin
                     (display "unload-module module-rtp-recv\n"
                              sock)
                     #f))))
         (auto-start? #f))))

(define home-pulseaudio-rtp-source-service-type
  (service-type
   (name 'pulseaudio-rtp-source)
   (extensions
    (list (service-extension home-shepherd-service-type
                             pulseaudio-rtp-source-shepherd-services)))
   (description
    "Define a PulseAudio source to receive audio broadcasted over RTP by
another PulseAudio instance.")
   (default-value %pulseaudio-rtp-multicast-address)))
(assoc-ref outputs "gui"))) (mkdir-p (string-append gui "/bin")) (rename-file (string-append out "/bin/gmp3info") (string-append gui "/bin/gmp3info"))) #t))) #:tests? #f)) (native-inputs (list pkg-config)) (inputs (list gtk+-2 ncurses)) (home-page "https://www.ibiblio.org/mp3info/") (synopsis "MP3 technical info viewer and ID3 1.x tag editor") (description "MP3Info is a little utility used to read and modify the ID3 tags of MP3 files. MP3Info can also display various technical aspects of an MP3 file including playing time, bit-rate, sampling frequency and other attributes in a pre-defined or user-specifiable output format.") (license license:gpl2+))) (define-public libmp3splt (package (name "libmp3splt") (version "0.9.2") (source (origin (method url-fetch) (uri (string-append "mirror://sourceforge/mp3splt/libmp3splt/" version "/libmp3splt-" version ".tar.gz")) (sha256 (base32 "1p1mn2hsmj5cp40fnc8g1yfvk72p8pjxi866gjdkgjsqrr7xdvih")))) (build-system gnu-build-system) (inputs (list flac libid3tag libmad libogg libltdl libvorbis pcre)) (native-inputs (list pkg-config)) (synopsis "Library for splitting mp3 and ogg vorbis files") (description "Mp3splt is a utility to split mp3 and ogg vorbis files selecting a begin and an end time position, without decoding. For splitting an album, one may select split points and file names manually or obtain them automatically from CDDB (internet or a local file) or from .cue files. The tool also supports automatic silence split, that can be used also to adjust cddb/cue splitpoints. This package contains the library.") (license license:gpl2+) (home-page "https://mp3splt.sourceforge.net/mp3splt_page/home.php"))) (define-public mp3splt (package (name "mp3splt") (version "2.6.2") (source (origin (method url-fetch) (uri (string-append "mirror://sourceforge/mp3splt/mp3splt/" version "/mp3splt-" version ".tar.gz")) (sha256 (base32 "1aiv20gypb6r84qabz8gblk8vi42cg3x333vk2pi3fyqvl82phry")))) (build-system gnu-build-system) (native-inputs (list pkg-config)) (inputs (list libmp3splt)) (synopsis "Utility for splitting mp3 and ogg vorbis files") (description "Mp3splt is a utility to split mp3 and ogg vorbis files selecting a begin and an end time position, without decoding. For splitting an album, one may select split points and file names manually or obtain them automatically from CDDB (internet or a local file) or from .cue files. The tool also supports automatic silence split, that can be used also to adjust cddb/cue splitpoints. This package contains the binary.") (license license:gpl2+) (home-page "https://mp3splt.sourceforge.net/mp3splt_page/home.php"))) (define-public mpg123 (package (name "mpg123") (version "1.31.2") (source (origin (method url-fetch) (uri (list (string-append "mirror://sourceforge/mpg123/mpg123/" version "/mpg123-" version ".tar.bz2") (string-append "https://www.mpg123.org/download/mpg123-" version ".tar.bz2"))) (sha256 (base32 "1pn777l9m7qbsx4v93gnav8bf6yi3skzdz8x81mkpx1ibs824zxi")))) (build-system gnu-build-system) (arguments '(#:configure-flags '("--with-default-audio=pulse"))) (native-inputs (list pkg-config)) (inputs (list alsa-lib pulseaudio)) (home-page "https://www.mpg123.org/") (synopsis "Console MP3 player and decoder library") (description "Mpg123 is a real time MPEG 1.0/2.0/2.5 audio player/decoder for layers 1,2 and 3 (MPEG 1.0 layer 3 aka MP3 most commonly tested). It comes with a command-line tool as well as a C library, libmpg123.") (license license:lgpl2.1))) (define-public mpg321 (package (name "mpg321") (version "0.3.2") (source (origin (method url-fetch) (uri (string-append "mirror://sourceforge/mpg321/mpg321/" version "/mpg321_" version ".orig.tar.gz")) (file-name (string-append "mpg321-" version ".tar.gz")) (sha256 (base32 "0ki8mh76bbmdh77qsiw682dvi8y468yhbdabqwg05igmwc1wqvq5")) (patches (search-patches "mpg321-CVE-2019-14247.patch" "mpg321-gcc-10.patch")))) (build-system gnu-build-system) (arguments '(#:configure-flags '("--disable-alsa"))) (inputs `(("zlib" ,zlib) ("libmad" ,libmad) ("libid3tag" ,libid3tag) ("libao" ,ao))) (home-page "https://mpg321.sourceforge.net/") (synopsis "Command-line MP3 player") (description "Mpg321 is a command-line mp3 player. mpg321 is used for frontends, as an mp3 player and as an mp3 to wave file decoder (primarily for use with CD-recording software).") (license license:gpl2))) (define-public lame (package (name "lame") (version "3.100") (source (origin (method url-fetch) (uri (string-append "mirror://sourceforge/lame/lame/" (version-major+minor version) "/lame-" version ".tar.gz")) (sha256 (base32 "07nsn5sy3a8xbmw1bidxnsj5fj6kg9ai04icmqw40ybkp353dznx")))) (build-system gnu-build-system) (arguments `(#:phases (modify-phases %standard-phases (add-after 'install 'install-pkg-config (lambda* (#:key outputs #:allow-other-keys) (let* ((out (assoc-ref outputs "out")) (pkg-config-dir (string-append out "/lib/pkgconfig"))) (mkdir-p pkg-config-dir) (with-output-to-file (string-append pkg-config-dir "/lame.pc") (lambda _ (format #t "prefix=~@*~a~@ libdir=${prefix}/lib~@ includedir=${prefix}/include~@ Name: lame~@ Description:~@ Version: ~a~@ Libs: -L${libdir} -lmp3lame~@ Cflags: -I${includedir}~%" out ,version))))))))) (home-page "https://lame.sourceforge.net/") (synopsis "MPEG Audio Layer III (MP3) encoder") (description "LAME is a high quality MPEG Audio Layer III (MP3) encoder.") (license license:lgpl2.0))) (define-public ripperx (package (name "ripperx") (version "2.8.0") (source (origin (method url-fetch) (uri (string-append "mirror://sourceforge/ripperx/ripperx/" version "/ripperx-" version ".tar.bz2")) (sha256 (base32 "1ss3c1a5hx6c99q1cryxg0jhbnbdj6ga9xyz0dzlz9qhzg5qswfs")) (patches (search-patches "ripperx-missing-file.patch")))) (build-system gnu-build-system) (propagated-inputs (list font-ghostscript cdparanoia flac lame vorbis-tools)) (inputs (list glib gtk+-2 id3lib taglib)) (native-inputs (list pkg-config)) (synopsis "GTK program to rip and encode CD audio tracks") (description "RipperX is a GTK program to rip CD audio tracks and encode them to the Ogg, MP3, or FLAC formats. Its goal is to be easy to use, requiring only a few mouse clicks to convert an entire album. It supports CDDB lookups for album and track information.") (license license:gpl2) (home-page "https://sourceforge.net/projects/ripperx/"))) (define-public libmpcdec (package (name "libmpcdec") (version "1.2.6") (source (origin (method url-fetch) (uri (string-append "https://files.musepack.net/source/libmpcdec-" version ".tar.bz2")) (sha256 (base32 "1a0jdyga1zfi4wgkg3905y6inghy3s4xfs5m4x7pal08m0llkmab")))) (build-system gnu-build-system) (synopsis "Decoding library for the Musepack audio format") (description "This library supports decoding of the Musepack (MPC) audio compression format.") (license license:bsd-3) (home-page "https://musepack.net"))) (define-public mpc123 (package (name "mpc123") (version "0.2.4") (source (origin (method url-fetch) (uri (list (string-append "mirror://sourceforge/mpc123/version%20" version "/mpc123-" version ".tar.gz") (string-append "mirror://debian/pool/main/m/" name "/" name "_" version ".orig.tar.gz"))) (sha256 (base32 "0sf4pns0245009z6mbxpx7kqy4kwl69bc95wz9v23wgappsvxgy1")) (patches (search-patches "mpc123-initialize-ao.patch")))) (build-system gnu-build-system) (arguments '(#:phases (modify-phases %standard-phases (replace 'configure (lambda _ (substitute* "Makefile" (("CC[[:blank:]]*:=.*") "CC := gcc\n")) (setenv "CFLAGS" "-fcommon -g"))) ;allow compilation with GCC 10 (replace 'install (lambda* (#:key outputs #:allow-other-keys) (let* ((out (assoc-ref outputs "out")) (bin (string-append out "/bin"))) (install-file "mpc123" bin))))) #:tests? #f)) (native-inputs `(("gettext" ,gettext-minimal))) (inputs `(("libao" ,ao) ("libmpcdec" ,libmpcdec))) (home-page "https://github.com/bucciarati/mpc123") (synopsis "Audio player for Musepack-formatted files") (description "Mpc123 is a command-line player for files in the Musepack audio compression format (.mpc files).") (license license:gpl2+))) (define-public eyed3 (package (name "eyed3") (version "0.9.6") (source (origin (method url-fetch) (uri (pypi-uri "eyeD3" version)) (sha256 (base32 "063mpg5bks9dgggjyag8968z5r7z4x50s0m0rja956dk1zn68l2b")))) (build-system python-build-system) (arguments `(#:tests? #f)) ; the required test data contains copyrighted material (propagated-inputs (list python-deprecation python-filetype python-grako python-magic python-pathlib python-six)) (synopsis "MP3 tag ID3 metadata editor") (description "eyeD3 is a Python tool for working with audio files, specifically mp3 files containing ID3 metadata (i.e. song info). It provides a command-line tool (eyeD3) and a Python library (import eyed3) that can be used to write your own applications or plugins that are callable from the command-line tool.") (home-page "https://eyed3.readthedocs.io/en/latest/") (license license:gpl2+))) (define-public chromaprint (package (name "chromaprint") (version "1.5.1") (source (origin (method url-fetch) (uri (string-append "https://github.com/acoustid/chromaprint/releases/download/v" version "/chromaprint-" version ".tar.gz")) (sha256 (base32 "072y6c7ijkm6r674f6z089rbdazrmxzpdcsm6y6vf64b7gxdiam1")))) (build-system cmake-build-system) (arguments `(#:tests? #f ; tests require googletest *sources* ;;#:configure-flags '("-DBUILD_TESTS=ON") ; for building the tests #:configure-flags '("-DBUILD_TOOLS=ON") ; for fpcalc #:test-target "check")) (inputs ;; requires one of FFmpeg (prefered), FFTW3 or vDSP ;; use the same ffmpeg version as for acoustid-fingerprinter (list ffmpeg-4 boost)) (home-page "https://acoustid.org/chromaprint") (synopsis "Audio fingerprinting library") (description "Chromaprint is a library for calculating audio fingerprints which are used by the Acoustid service. Its main purpose is to provide an accurate identifier for record tracks.") (license license:lgpl2.1+))) (define-public python-audioread (package (name "python-audioread") (version "2.1.9") (source (origin (method url-fetch) (uri (pypi-uri "audioread" version)) (sha256 (base32 "129hab8x9sb3plff2bkq4xnzc3i8k9rgcm1a36l813kc0m10wj53")))) (build-system python-build-system) (arguments `(#:tests? #f)) ; there is no "audiofile" fixture (native-inputs (list python-pytest python-pytest-runner)) (home-page "https://github.com/sampsyo/audioread") (synopsis "Decode audio files using whichever backend is available") (description "This package provides a Python library for audo decoding. It uses whatever audio backend is available, such as GStreamer, Core Audio, MAD, FFmpeg, etc.") (license license:expat))) (define-public python-pyacoustid (package (name "python-pyacoustid") (version "1.2.2") (source (origin (method url-fetch) (uri (pypi-uri "pyacoustid" version)) (sha256 (base32 "0ha15m41r8ckmanc4k9nrlb9hprvhdjxndzw40a1yj3z1b1xjyf2")))) (build-system python-build-system) (arguments `(#:phases (modify-phases %standard-phases (add-after 'unpack 'chromaprint-path (lambda* (#:key inputs #:allow-other-keys) (substitute* "chromaprint.py" (("libchromaprint.so.1") (string-append (assoc-ref inputs "chromaprint") "/lib/libchromaprint.so.1"))) (substitute* "acoustid.py" (("'fpcalc'") (string-append "'" (assoc-ref inputs "chromaprint") "/bin/fpcalc'"))) #t))))) (inputs (list chromaprint)) (propagated-inputs (list python-audioread python-requests)) (home-page "https://github.com/beetbox/pyacoustid") (synopsis "Bindings for Chromaprint acoustic fingerprinting") (description "This package provides bindings for the Chromaprint acoustic fingerprinting library and the Acoustid API.") (license license:expat))) (define-public python-pytaglib (package (name "python-pytaglib") (version "1.4.6") (source (origin (method url-fetch) (uri (pypi-uri "pytaglib" version)) (sha256 (base32 "0li970qslfymz4vk1wrij2nfqw3l15cpc3fjjci48mpvg17gbnhn")) ;; Delete file generated by Cython. (modules '((guix build utils))) (snippet '(begin (delete-file "src/taglib.cpp"))))) (build-system python-build-system) (arguments '(#:phases (modify-phases %standard-phases ;; Ensure that the Cython file is regenerated. (add-after 'unpack 'setup-environment (lambda _ (setenv "PYTAGLIB_CYTHONIZE" "1")))))) (native-inputs (list python-cython python-pytest)) (inputs (list taglib)) (home-page "https://github.com/supermihi/pytaglib") (synopsis "Python bindings for taglib") (description "This package is a Python audio tagging library. It is cross-platform, works with all Python versions, and is very simple to use yet fully featured.") (license license:gpl3))) (define-public wavbreaker (package (name "wavbreaker") (version "0.15") (source (origin (method git-fetch) (uri (git-reference (url "https://github.com/thp/wavbreaker/") (commit version))) (file-name (git-file-name name version)) (sha256 (base32 "16h0sfcb8av6a368giizzwv9m0lq5c3bnf4b9vyyh9nkbbsc7c3j")))) (build-system meson-build-system) (arguments '(#:modules ((guix build utils) (guix build meson-build-system)) #:phases (modify-phases %standard-phases (add-after 'install 'wrap-program ;; This wrapping is necessary to make wavbreaker find things it ;; needs in pure environments. (lambda* (#:key inputs outputs #:allow-other-keys) (let ((out (assoc-ref outputs "out")) (adwaita-icons (assoc-ref inputs "adwaita-icon-theme")) (hicolor-icons (assoc-ref inputs "hicolor-icon-theme")) (shared-mime (assoc-ref inputs "shared-mime-info"))) (wrap-program (string-append out "/bin/wavbreaker") ;; Needed in order for wavbreakere to find the icons it needs `("XDG_DATA_DIRS" ":" prefix ,(map (lambda (package) (string-append package "/share")) `(,out ;for wavbreaker's icon ,adwaita-icons ,hicolor-icons ,shared-mime))) ;; This is necessary to load some pixbufs like Adwaita's ;; check-symbolic.svg and wavbreaker's own logo in the ;; 'about' section. `("GDK_PIXBUF_MODULE_FILE" = (,(getenv "GDK_PIXBUF_MODULE_FILE"))) ;; Needed for GTK's file chooser to not crash. `("GSETTINGS_SCHEMA_DIR" = (,(string-append (assoc-ref inputs "gtk+") "/share/glib-2.0/schemas")))))))))) (native-inputs (list pkg-config cmake)) (inputs (list glib gtk+ ao bash-minimal adwaita-icon-theme shared-mime-info hicolor-icon-theme gsettings-desktop-schemas)) (home-page "https://wavbreaker.sourceforge.io/") (synopsis "WAV and MP3 file splitter with a GUI") (description "Wavbreaker is a WAV and MP3 file splitter. It can be used to break up a WAV or MP3 audio file into multiple WAV files. Wavbreaker contains a helpful waveform display of the audio file being edited, to help the user in splitting the file at the right point. Wavbreaker also supports splitting MP3 files without re-encoding them, to preserve their original audio quality.") (license license:gpl2+)))