ahefner / mixalot

Loosely-coupled collection of audio libraries in Common Lisp

Home Page:http://vintage-digital.com/hefner/software/mixalot/mixalot.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can I store raw chunks of mp3, flac, ... in wav format to a file using streamer class?

ks opened this issue · comments

commented

Hi,
I would like to make a simple program which can convert mp3, ogg or flac to a constant rate stereo mp3 (my car audio doesn't like vbr mp3).
I was wondering how to use various streamer classes, and especially if that what comes in chunks in the buffer to the streamer closure is a raw audio, which I can continuously save to a file resulting with file in wav format.

Also if that's a valid way to get to the wav file, how do I force Mixalot to call streamer's closure without waiting until the chunk in buffer is "played" completely?

Thank you for your work!

Karol Skocik

The buffer filled by the streamer-write-into functions is raw audio, yes.
The format is an array of stereo pairs of samples, each packed into one
(unsigned-byte 32) value. Depending on the format you're converting to, you
might be able to use that form, otherwise you can split it apart using the
stereo-left/stereo-right functions.

The design of Mixalot isn't quite right for you want to do; I've been
meaning to fix that. It isn't quite a clean stream-style abstraction - I
didn't think about consuming audio for uses other than playback through the
mixer, but it can be made to work. I just hacked the Git version slightly
to enable the following:

(defclass stream-monitor ()
((eof-flag :accessor eof-flag :initform nil))
(:documentation "Used to detect end of stream. Ugly hack."))

(defmethod mixalot:mixer-remove-streamer ((mixer stream-monitor) stream)
(setf (eof-flag mixer) t))

(defun drain-streamer (streamer)
(loop
with monitor = (make-instance 'stream-monitor)
with buffer-size = 16384
with buffer = (make-array buffer-size :element-type
'mixalot:stereo-sample)
for time upfrom 0 by buffer-size
do
(fill buffer 0)
(mixalot:streamer-write-into streamer monitor buffer 0 buffer-size 0)
;; Do something with the audio buffer here..
(print buffer)
until (eof-flag monitor)
finally (mixalot:streamer-cleanup streamer monitor)))

What I should do is add a streamer-eof-p function, remove the mixer
argument from the rest of the functions, and change how streams end (the
way they presently remove themselves from the mixer, instead of just
indicating EOF, is silly). Minor interface changes; I'd have done it ages
ago, but for the trouble of updating the documentation.

On Fri, Aug 31, 2012 at 10:47 AM, Karol Skocik notifications@github.comwrote:

Hi,
I would like to make a simple program which can convert mp3, ogg or flac
to a constant rate stereo mp3 (my car audio doesn't like vbr mp3).
I was wondering how to use various streamer classes, and especially if
that what comes in chunks in the buffer to the streamer closure is a raw
audio, which I can continuously save to a file resulting with file in wav
format.

Also if that's a valid way to get to the wav file, how do I force Mixalot
to call streamer's closure without waiting until the chunk in buffer is
"played" completely?

Thank you for your work!

Karol Skocik


Reply to this email directly or view it on GitHubhttps://github.com//issues/1.

commented

Thanks a lot!
I took your code and put it into https://github.com/ks/audio-conv with some modifications.
The exported raw PCM plays in Audacity nicely!
Now only the dir-walking and encoding part remains...

Have a nice day!

Karol Skocik