module Sound.SDIF where
import qualified Data.ByteString.Lazy as B
import Sound.SDIF.Byte.SDIF
import Sound.SDIF.Frame
import Sound.SDIF.Matrix
import Sound.SDIF.Type
data SDIF = SDIF { sdif_b :: B.ByteString
, sdif_frames :: Int
, sdif_frame_i :: [(Int, Int)]
, sdif_frame_c :: [Frame] }
deriving (Eq, Show)
decode_sdif :: B.ByteString -> SDIF
decode_sdif sdf =
let n = sdif_b_frames sdf
ix = sdif_b_frame_i sdf n
frm (i,j) = decode_frame (section' sdf i j)
s = SDIF { sdif_b = sdf
, sdif_frames = n
, sdif_frame_i = ix
, sdif_frame_c = map frm ix }
in if is_sdif_b sdf
then s
else error "decode_sdif" "illegal data"
sdif_read_file :: FilePath -> IO SDIF
sdif_read_file file_name = do
b <- B.readFile file_name
return (decode_sdif b)
sdif_frame_b :: SDIF -> Int -> B.ByteString
sdif_frame_b sdf n =
let (i,j) = sdif_frame_i sdf !! n
in (section' (sdif_b sdf) i j)
sdif_frame :: SDIF -> Int -> Frame
sdif_frame sdf n = sdif_frame_c sdf !! n
sdif_matrix :: SDIF -> Int -> Int -> Matrix
sdif_matrix sdf i = frame_matrix (sdif_frame sdf i)
sdif_matrix_v :: SDIF -> Int -> Int -> [Datum]
sdif_matrix_v sdf i = matrix_v . sdif_matrix sdf i