-- | Encode audio data.
module Sound.File.Encode (interleave,encode) where

import qualified Data.ByteString.Lazy as B
import Data.List
import Sound.OpenSoundControl.Coding.Byte
import Sound.File.Encoding

-- | Interleave channel data, ie. 'concat' '.' 'transpose'.
--
-- > interleave [[0,2..8],[1,3..9]] == [0,1,2,3,4,5,6,7,8,9]
interleave :: [[a]] -> [a]
interleave = concat . transpose

encodef32 :: [[Double]] -> B.ByteString
encodef32 = B.concat . map encode_f32 . interleave

-- | Given 'Encoding' and a set of channels, 'interleave' and encode
-- as 'B.ByteString'.
encode :: Encoding -> [[Double]] -> B.ByteString
encode enc d =
    case enc of
      Float -> encodef32 d
      _ -> undefined