forked from Shirakumo/harmony
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrain.lisp
More file actions
55 lines (45 loc) · 1.89 KB
/
drain.lisp
File metadata and controls
55 lines (45 loc) · 1.89 KB
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
#|
This file is a part of harmony
(c) 2017 Shirakumo http://tymoon.eu (shinmera@tymoon.eu)
Author: Nicolas Hafner <shinmera@tymoon.eu>
|#
(in-package #:org.shirakumo.fraf.harmony)
(defclass drain (segment)
())
(defmethod initialize-instance :after ((drain drain) &key)
(setf (cl-mixed-cffi:direct-segment-mix (handle drain)) (cffi:callback drain-mix)))
(cffi:defcallback drain-mix :int ((samples cl-mixed-cffi:size_t) (segment :pointer))
(let ((drain (pointer->object segment)))
(when drain
(process drain samples)))
1)
(defclass pack-drain (drain)
((remix-factor :initform 0 :accessor remix-factor)
(packed-audio :initform NIL :accessor packed-audio)
(pack-mix-function :initform NIL :accessor pack-mix-function)))
(defmethod initialize-instance ((drain pack-drain) &key)
(call-next-method)
(setf (packed-audio drain) (initialize-packed-audio drain))
(setf (remix-factor drain) (coerce (/ (samplerate (packed-audio drain))
(samplerate (context drain)))
'single-float))
(cl-mixed::with-error-on-failure ()
(cl-mixed-cffi:make-segment-packer (handle (packed-audio drain)) (samplerate (context drain)) (handle drain)))
(setf (pack-mix-function drain) (cl-mixed-cffi:direct-segment-mix (handle drain))))
(defmethod process :around ((drain pack-drain) samples)
(let ((endpoint-samples (floor (* samples (remix-factor drain)))))
;; Pack
(cffi:foreign-funcall-pointer
(pack-mix-function drain) ()
cl-mixed-cffi:size_t samples
:pointer (handle drain))
;; Encode
(call-next-method drain endpoint-samples)))
(defmethod pause ((drain drain))
(setf (paused-p drain) T)
drain)
(defmethod resume ((drain drain))
(setf (paused-p drain) NIL)
drain)
(cl-mixed::define-field-accessor volume pack-drain :float :volume)
(cl-mixed::define-field-accessor bypass pack-drain :bool :bypass)