summaryrefslogtreecommitdiff
path: root/sdl2/audio.scm
blob: 0e35d4e5836b90a35d4ec54a4d5a591df0647ee0 (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
;;; guile-sdl2 --- FFI bindings for SDL2
;;; Copyright © 2022 David Thompson <davet@gnu.org>
;;;
;;; This file is part of guile-sdl2.
;;;
;;; Guile-sdl2 is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU Lesser General Public License as
;;; published by the Free Software Foundation; either version 3 of the
;;; License, or (at your option) any later version.
;;;
;;; Guile-sdl2 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 Lesser General Public
;;; License along with guile-sdl2.  If not, see
;;; <http://www.gnu.org/licenses/>.

;;; Commentary:
;;
;; Platform-independent audio API.
;;
;;; Code:

(define-module (sdl2 audio)
  #:use-module (sdl2)
  #:use-module ((sdl2 bindings) #:prefix ffi:)
  #:use-module (system foreign)
  #:export (audio-device-name
            num-audio-devices))

(define* (num-audio-devices #:optional capture?)
  "Return the number of recording or playback audio devices available.
  If CAPTURE is not given or #f, the number of playback devices is
returned.  If CAPTURE? is #t, the number of recording devices is
returned."
  (ffi:sdl-get-num-audio-devices (if capture? 1 0)))

(define* (audio-device-name index #:optional capture?)
  "Return the name of the audio device at INDEX.  If CAPTURE? is not
given or #f, the name of the playback device for INDEX is returned.
If CAPTURE? is #t, the name of the recording device for INDEX is
returned."
  (let ((ptr (ffi:sdl-get-audio-device-name index (if capture? 0 1))))
    (if (null-pointer? ptr)
        #f
        (pointer->string ptr))))