trying to overcome gapless problems with mpg123 (very small tick left) and facilitate output to wav
This commit is contained in:
+24
-16
@@ -329,6 +329,7 @@ int main(int argc, char *argv[])
|
||||
(define pcm-length -1)
|
||||
(define encoding -1)
|
||||
(define mp3-file "")
|
||||
(define current-pcm-pos 0)
|
||||
|
||||
(define (new)
|
||||
(if (eq? mh #f)
|
||||
@@ -386,11 +387,8 @@ int main(int argc, char *argv[])
|
||||
(define (set-param p val)
|
||||
(mpg123_param2 mh p val (exact->inexact val)))
|
||||
|
||||
(define (init file)
|
||||
(let ((r (mpg123_open mh file)))
|
||||
(unless (eq? r 'MPG123_OK)
|
||||
(error (format "mpg123_open: ~a" (mpg123_plain_strerror r))))
|
||||
)
|
||||
(define (do-format)
|
||||
(dbg-sound "do-format called, got an MPG123_NEW_FORMAT message")
|
||||
(let-values ([(fr rate* channels* encoding*) (mpg123_getformat mh)])
|
||||
(unless (eq? fr 'MPG123_OK)
|
||||
(error (format "mpg123_format: ~a" (mpg123_plain_strerror fr))))
|
||||
@@ -404,11 +402,19 @@ int main(int argc, char *argv[])
|
||||
(unless (eq? sr 'MPG123_OK)
|
||||
(error (format "mpg123_scan: ~a" (mpg123_plain_strerror sr))))
|
||||
(set! pcm-length (mpg123_length64 mh)))
|
||||
)
|
||||
|
||||
(define (init file)
|
||||
(let ((r (mpg123_open mh file)))
|
||||
(unless (eq? r 'MPG123_OK)
|
||||
(error (format "mpg123_open: ~a" (mpg123_plain_strerror r))))
|
||||
)
|
||||
(set! mp3-file (format "~a" file))
|
||||
(set! current-pcm-pos 0)
|
||||
#t)
|
||||
|
||||
(define (mp3-format cb)
|
||||
(cb rate channels sample-bits sample-bytes pcm-length))
|
||||
(cb current-pcm-pos rate channels sample-bits sample-bytes pcm-length))
|
||||
|
||||
(define (close)
|
||||
(let ((r (mpg123_close mh)))
|
||||
@@ -423,16 +429,18 @@ int main(int argc, char *argv[])
|
||||
(set! mp3-file "")
|
||||
#t))
|
||||
|
||||
(define (read cb)
|
||||
(define (read cb format-cb)
|
||||
(let-values ([(r done) (mpg123_read mh buffer buf-size)])
|
||||
(if (eq? r 'MPG123_DONE)
|
||||
(cb 'done -1 buffer done)
|
||||
(if (eq? r 'MPG123_OK)
|
||||
(let ((pcm-pos (mpg123_tell64 mh)))
|
||||
(cb 'data pcm-pos buffer done))
|
||||
(error (format "mpg123_read: ~a" (mpg123_plain_strerror r)))
|
||||
)
|
||||
)
|
||||
(cond
|
||||
((eq? r 'MPG123_DONE) (cb 'done -1 buffer done))
|
||||
((eq? r 'MPG123_NEW_FORMAT) (do-format)
|
||||
(mp3-format format-cb)
|
||||
(read cb format-cb))
|
||||
((eq? r 'MPG123_OK) (let ((pcm-pos (mpg123_tell64 mh)))
|
||||
(set! current-pcm-pos pcm-pos)
|
||||
(cb 'data pcm-pos buffer done)))
|
||||
(else (error (format "mpg123_read: ~a" (mpg123_plain_strerror r))))
|
||||
)
|
||||
)
|
||||
#t)
|
||||
|
||||
@@ -453,7 +461,7 @@ int main(int argc, char *argv[])
|
||||
[(eq? cmd 'close) (close)]
|
||||
[(eq? cmd 'format) (mp3-format (car args))]
|
||||
[(eq? cmd 'info) (info)]
|
||||
[(eq? cmd 'read) (read (car args))]
|
||||
[(eq? cmd 'read) (read (car args) (cadr args))]
|
||||
[(eq? cmd 'seek) (seek (car args))]
|
||||
[(eq? cmd 'tell) (tell)]
|
||||
[(eq? cmd 'file) mp3-file]
|
||||
|
||||
Reference in New Issue
Block a user