forked from Shirakumo/harmony
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmp3.lisp
More file actions
45 lines (38 loc) · 1.51 KB
/
mp3.lisp
File metadata and controls
45 lines (38 loc) · 1.51 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
#|
This file is a part of harmony
(c) 2017 Shirakumo http://tymoon.eu (shinmera@tymoon.eu)
Author: Nicolas Hafner <shinmera@tymoon.eu>
|#
(in-package #:cl-user)
(defpackage #:harmony-mp3
(:nicknames #:org.shirakumo.fraf.harmony.sources.mp3)
(:use #:cl #:harmony)
(:export
#:mp3-source))
(in-package #:org.shirakumo.fraf.harmony.sources.mp3)
(define-source-type "mp3" mp3-source)
(defclass mp3-source (unpack-source file-source)
((mp3-file :initform NIL :accessor mp3-file)
(channels :initarg :channels :accessor channels))
(:default-initargs :channels 2))
(defmethod initialize-packed-audio ((source mp3-source))
(let ((file (cl-mpg123:make-file (file source)
:accepted-format (list (samplerate (context source))
(channels source)
:float))))
(cl-mpg123:connect file)
(setf (mp3-file source) file)
(multiple-value-bind (rate channels encoding) (cl-mpg123:file-format file)
(cl-mixed:make-packed-audio
NIL
0
encoding
channels
:alternating
rate))))
(defmethod seek-to-sample ((source mp3-source) position)
(cl-mpg123:seek (mp3-file source) position :mode :absolute :by :sample))
(defmethod sample-count ((source mp3-source))
(cl-mpg123:sample-count (mp3-file source)))
(defmethod process ((source mp3-source) samples)
(fill-for-unpack-source source samples #'cl-mpg123:read-directly (mp3-file source)))