How well would the storablevector package (Data.StorableVector) work for storing audio data? One of the major issues I'm still working over is that I want to maintain something similar to a [[a]] format (since the underlying PortAudio library and hardware could support hundreds of interleaved channels) but I would like to be able to build in some typechecking to the functions to make sure the number of channels matches the nubmer expected in the functions. I've considered doing the following:

> data SingleChannel
> data DualChannel
> data TriChannel
> type Frames = [[a]]

> data AudioData a = AudioData Frames

> adata = [[x] | x <- [...]] :: AudioData SingleChannel

I'd like to have a better way of:
1) packing the audio data in something other than a list
2) representing more information about the data parameters (such as sample rate and number of channels) without relying as heavily upon runtime checks/errors (which HCodecs Data.Audio format seems to rely on).

The ideal format would be [(a,a,..a)], but this seems cumbersome (since each tuple would have to be defined individually),

I'm pretty sure that a runtime check on both sample rate, and number of channels will be necessary, but I just want to ask a little more before continuing down that path.

I also noticed that Data.Audio uses a DiffUArray. In this circumstance, would a StorableVector be better, or a DiffUArray?


On Sun, Aug 24, 2008 at 1:06 PM, Eric Kidd <haskell@randomhacks.net> wrote:
On Sun, Aug 24, 2008 at 12:41 PM, John Van Enk <vanenkj@gmail.com> wrote:
> It implements the Haskell bindings to the PortAudio library. This is the
> library behind Audacious. I *have not* implemented the callback model yet,
> but I plan to do that.
>
> Perhaps this will be something which is useful to you?

Looks like a great binding! We actually use portaudio in callback mode
at work, with reasonable success (from C++).

One question: I notice that your writeStream function represents audio
using '[[a]]'.

 writeStream :: (Storable a) => PaStream a -- ^ The output stream
             -> [[a]]                    -- ^ The samples to be played
             -> Int                      -- ^ Number of frames
             -> IO (Either String ErrorCode) -- ^ The return status
of the write

In my experiments, I've been somewhat unsatisfied with the performance
of '[[a]]' as an audio format. Would you be interested in also
supporting an array-based format for audio data?

I'm currently converting my program to use HCodec's Data.Audio
representation, which looks pretty promising. I don't know how it
performs yet, but I'll let you know.

Thank you for the pointer to your library! It will make an excellent
addition to the available Haskell sound libraries.

Cheers,
Eric



--
/jve