fromRawdio :: (KnownNat r, KnownNat c) => Rawdio -> IO (Either String (Audio r c))
fromRawdio raw = do
  r <- getSampleRate raw
  c <- getChannels raw
  let res = if r == sampleRate aud && c == channels aud
        then Right $ unsafeFromRawdio raw
        else Left $ unwords
          [ "Expected sample rate"
          , show $ sampleRate aud
          , "and channel count"
          , show $ channels aud
          , "but got"
          , show r
          , "and"
          , show c
          ]
      aud = (undefined :: Either a b -> b) res
  return res

-- | Checks that the sample rate and channel count of the file
-- match the type it is being cast to. If not, returns 'Nothing'.
fromRawdio :: (KnownNat r, KnownNat c) => Rawdio -> IO (Either String (Audio r c))
fromRawdio raw = do
  r <- getSampleRate raw
  c <- getChannels raw
  let res = if r == sampleRate aud && c == channels aud
        then Right $ unsafeFromRawdio raw
        else Left $ unwords
          [ "Expected sample rate"
          , show $ sampleRate aud
          , "and channel count"
          , show $ channels aud
          , "but got"
          , show r
          , "and"
          , show c
          ]
      aud = (undefined :: Either a b -> b) res
  return res

-- | Checks that the sample rate and channel count of the file
-- match the type it is being cast to. If not, returns 'Nothing'.
fromRawdio raw = do
  r <- getSampleRate raw
  c <- getChannels raw
  let res = if r == sampleRate aud && c == channels aud
        then Right $ unsafeFromRawdio raw
        else Left $ unwords
          [ "Expected sample rate"
          , show $ sampleRate aud
          , "and channel count"
          , show $ channels aud
          , "but got"
          , show r
          , "and"
          , show c
          ]
      aud = (undefined :: Either a b -> b) res
  return res

-- | Checks that the sample rate and channel count of the file
-- match the type it is being cast to. If not, returns 'Nothing'.