summaryrefslogtreecommitdiff
path: root/sdl2
diff options
context:
space:
mode:
Diffstat (limited to 'sdl2')
-rw-r--r--sdl2/audio.scm48
-rw-r--r--sdl2/bindings.scm14
2 files changed, 62 insertions, 0 deletions
diff --git a/sdl2/audio.scm b/sdl2/audio.scm
new file mode 100644
index 0000000..0e35d4e
--- /dev/null
+++ b/sdl2/audio.scm
@@ -0,0 +1,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))))
diff --git a/sdl2/bindings.scm b/sdl2/bindings.scm
index 02988ad..cb8dd97 100644
--- a/sdl2/bindings.scm
+++ b/sdl2/bindings.scm
@@ -1240,6 +1240,20 @@ RETURN-TYPE and accept arguments of ARG-TYPES."
(define-public AUDIO_F32MSB #x9120)
(define-public AUDIO_F32 AUDIO_F32LSB)
+(define-public SDL_AUDIO_ALLOW_FREQUENCY_CHANGE 1)
+(define-public SDL_AUDIO_ALLOW_FORMAT_CHANGE 2)
+(define-public SDL_AUDIO_ALLOW_CHANNELS_CHANGE 4)
+(define-public SDL_AUDIO_ALLOW_SAMPLES_CHANGE 8)
+
+(define-foreign sdl-get-num-audio-devices
+ int "SDL_GetNumAudioDevices" (list int))
+
+(define-foreign sdl-get-audio-device-name
+ '* "SDL_GetAudioDeviceName" (list int int))
+
+(define-foreign sdl-open-audio-device
+ int "SDL_OpenAudioDevice" (list '* int '* '* int))
+
;;;
;;; Joystick