standard audio pipeline

This commit is contained in:
2026-04-22 19:08:57 +02:00
parent ba263bd892
commit 4bbfa43501
2 changed files with 109 additions and 7 deletions
+90
View File
@@ -9,6 +9,7 @@
) )
;(define lib (ffi-lib "/home/hans/tmp/lib/libmpg123.so")) ;(get-lib '("libmpg123") '("0" #f)))
(define lib (get-lib '("libmpg123") '("0" #f))) (define lib (get-lib '("libmpg123") '("0" #f)))
(define-ffi-definer define-libmpg123 lib (define-ffi-definer define-libmpg123 lib
#:default-make-fail make-not-available) #:default-make-fail make-not-available)
@@ -95,6 +96,53 @@
) )
) )
(define _mpg123_param
(_enum '(force-mono = #x7
mono-left = #x1
mono-right = #x2
mono-mix = #x4
force-stereo = #x8
force-8bit = #x10
quiet = #x20
gapless = #x40
no-resync = #x80
seekbuffer = #x100
fuzzy = #x200
force-float = #x400
plain-id3text = #x800
ignore-streamlength = #x1000
skip-id3v2 = #x2000
ignore-infoframe = #x4000
auto-resample = #x8000
)
_int
)
)
#|
/** Flag bits for MPG123_FLAGS, use the usual binary or to combine. */
enum mpg123_param_flags
MPG123_FORCE_MONO = 0x7 /**< 0111 Force some mono mode: This is a test bitmask for seeing if any mono forcing is active. */
,MPG123_MONO_LEFT = 0x1 /**< 0001 Force playback of left channel only. */
,MPG123_MONO_RIGHT = 0x2 /**< 0010 Force playback of right channel only. */
,MPG123_MONO_MIX = 0x4 /**< 0100 Force playback of mixed mono. */
,MPG123_FORCE_STEREO = 0x8 /**< 1000 Force stereo output. */
,MPG123_FORCE_8BIT = 0x10 /**< 00010000 Force 8bit formats. */
,MPG123_QUIET = 0x20 /**< 00100000 Suppress any printouts (overrules verbose). */
,MPG123_GAPLESS = 0x40 /**< 01000000 Enable gapless decoding (default on if libmpg123 has support). */
,MPG123_NO_RESYNC = 0x80 /**< 10000000 Disable resync stream after error. */
,MPG123_SEEKBUFFER = 0x100 /**< 000100000000 Enable small buffer on non-seekable streams to allow some peek-ahead (for better MPEG sync). */
,MPG123_FUZZY = 0x200 /**< 001000000000 Enable fuzzy seeks (guessing byte offsets or using approximate seek points from Xing TOC) */
,MPG123_FORCE_FLOAT = 0x400 /**< 010000000000 Force floating point output (32 or 64 bits depends on mpg123 internal precision). */
,MPG123_PLAIN_ID3TEXT = 0x800 /**< 100000000000 Do not translate ID3 text data to UTF-8. ID3 strings will contain the raw text data, with the first byte containing the ID3 encoding code. */
,MPG123_IGNORE_STREAMLENGTH = 0x1000 /**< 1000000000000 Ignore any stream length information contained in the stream, which can be contained in a 'TLEN' frame of an ID3v2 tag or a Xing tag */
,MPG123_SKIP_ID3V2 = 0x2000 /**< 10 0000 0000 0000 Do not parse ID3v2 tags, just skip them. */
,MPG123_IGNORE_INFOFRAME = 0x4000 /**< 100 0000 0000 0000 Do not parse the LAME/Xing info frame, treat it as normal MPEG data. */
,MPG123_AUTO_RESAMPLE = 0x8000 /**< 1000 0000 0000 0000 Allow automatic internal resampling of any kind (default on if supported). Especially when going lowlevel with replacing output buffer, you might want to unset this flag. Setting MPG123_DOWNSAMPLE or MPG123_FORCE_RATE will override this. */
|#
(define _mpg123_handle _pointer) (define _mpg123_handle _pointer)
@@ -177,6 +225,28 @@
lib lib
(_fun _int -> _string*/utf-8))) (_fun _int -> _string*/utf-8)))
;MPG123_EXPORT int mpg123_getparam ( mpg123_handle * mh,;
; enum mpg123_parms type,
; long * value,
; double * fvalue
; )
(define-libmpg123 mpg123_getparam2
(_fun _mpg123_handle _mpg123_param
(value : (_ptr io _long ))
(fvalue : (_ptr io _double ))
-> (r : _MPG123_Result)
-> (values r value fvalue)))
;MPG123_EXPORT int mpg123_param2 ( mpg123_handle * mh,
; int type,
; long value,
; double fvalue
; )
(define-libmpg123 mpg123_param2
(_fun _mpg123_handle _mpg123_param
_long _double
-> _int))
#| #|
@@ -298,6 +368,24 @@ int main(int argc, char *argv[])
#t #t
) )
(define (params)
(for-each
(λ (p)
(let-values ([(r v fv) (mpg123_getparam2 mh p 0 0.0)])
(info-sound "~a: ~a - ~a - ~a" p r v fv)))
'(force-mono mono-left mono-right mono-mix
force-stereo force-8bit
quiet
gapless
no-resync seekbuffer fuzzy
force-float
plain-id3text ignore-streamlength skip-id3v2 ignore-infoframe
auto-resample
)))
(define (set-param p val)
(mpg123_param2 mh p val (exact->inexact val)))
(define (init file) (define (init file)
(let ((r (mpg123_open mh file))) (let ((r (mpg123_open mh file)))
(unless (eq? r 'MPG123_OK) (unless (eq? r 'MPG123_OK)
@@ -369,6 +457,8 @@ int main(int argc, char *argv[])
[(eq? cmd 'seek) (seek (car args))] [(eq? cmd 'seek) (seek (car args))]
[(eq? cmd 'tell) (tell)] [(eq? cmd 'tell) (tell)]
[(eq? cmd 'file) mp3-file] [(eq? cmd 'file) mp3-file]
[(eq? cmd 'params) (params)]
[(eq? cmd 'set-param) (set-param (car args) (cadr args))]
[else (error (format "Unknown command: ~a" cmd))] [else (error (format "Unknown command: ~a" cmd))]
) )
) )
+19 -7
View File
@@ -9,11 +9,14 @@
) )
(define test-file3 #f) (define test-file3 #f)
(define test-file4 #f)
(define test-file3-id 3) (define test-file3-id 3)
(define test-file4-id 4)
(let ((os (system-type 'os))) (let ((os (system-type 'os)))
(when (eq? os 'unix) (when (eq? os 'unix)
;(set! test-file3 "/muziek/Klassiek-Viool/Alina Ibragimova/Paganini_24 Caprices (2021)/24. 24 Caprices, Op 1 - No. 24 in A minor- Tema con variazioni. Quasi presto.flac") ;(set! test-file3 "/muziek/Klassiek-Viool/Alina Ibragimova/Paganini_24 Caprices (2021)/24. 24 Caprices, Op 1 - No. 24 in A minor- Tema con variazioni. Quasi presto.flac")
(set! test-file3 "/tmp/test.mp3") (set! test-file3 "/tmp/test.mp3")
(set! test-file4 "/tmp/test1.mp3")
) )
(when (eq? os 'windows) (when (eq? os 'windows)
(set! test-file3 "C:\\Muziek\\Klassiek-Strijkkwartet\\Quatuor Zaïde\\Franz\\01 Erlkönig, D. 328 (Arr. For String Quartet by Eric Mouret).flac") (set! test-file3 "C:\\Muziek\\Klassiek-Strijkkwartet\\Quatuor Zaïde\\Franz\\01 Erlkönig, D. 328 (Arr. For String Quartet by Eric Mouret).flac")
@@ -26,6 +29,8 @@
(define current-seconds 0) (define current-seconds 0)
(define ao-h #f) (define ao-h #f)
(define current-file-id -1)
(define current-audio-h #f)
(sl-log-to-display) (sl-log-to-display)
@@ -43,7 +48,7 @@
(when (eq? ao-h #f) (when (eq? ao-h #f)
(set! ao-h (ao-open-live bits-per-sample rate channels 'native-endian))) (set! ao-h (ao-open-live bits-per-sample rate channels 'native-endian)))
;(displayln 'ao-play) ;(displayln 'ao-play)
(ao-play ao-h test-file3-id second duration buffer buf-len ao-type) (ao-play ao-h current-file-id second duration buffer buf-len ao-type)
(set! duration (inexact->exact (round duration))) (set! duration (inexact->exact (round duration)))
;(displayln 'done) ;(displayln 'done)
(let ((second-printer (λ (buf-seconds) (let ((second-printer (λ (buf-seconds)
@@ -87,6 +92,9 @@
(ao-set-volume! ao-h 150)) (ao-set-volume! ao-h 150))
(when (= (round current-seconds) 40) (when (= (round current-seconds) 40)
(ao-set-volume! ao-h 100)) (ao-set-volume! ao-h 100))
(when (= (round current-seconds) 10)
(when (= current-file-id 3)
(audio-seek current-audio-h 97.0)))
(waiter))))) (waiter)))))
)) ))
(waiter)))) (waiter))))
@@ -102,13 +110,17 @@
(define (play) (define (play)
(set! ao-h #f) (set! ao-h #f)
(let ((audio-h (audio-open test-file3 audio-meta audio-play))) (let ((audio-h (audio-open test-file3 audio-meta audio-play)))
(set! current-file-id test-file3-id)
(set! current-audio-h audio-h)
(audio-read audio-h) (audio-read audio-h)
(ao-close ao-h) )
(set! ao-h #f))) (let ((audio-h (audio-open test-file4 audio-meta audio-play)))
;(sleep 1.0) (set! current-file-id test-file4-id)
;(play))) (set! current-audio-h audio-h)
(audio-read audio-h)
;(flac-read flac-h) )
(ao-close ao-h)
(set! ao-h #f))
(play) (play)