-- | Calculates the sample rate of a raw audio expression.
-- Any files referenced will be queried with @soxi@.
getSampleRate :: Rawdio -> IO Integer
getSampleRate raw = case raw of
  Silence r _ -> return r
  File f -> fmap read $ readProcess "soxi" ["-r", f] ""
  Pad    _ _ raw' -> getSampleRate raw'
  Trim   _ _ raw' -> getSampleRate raw'
  Cutoff _ _ raw' -> getSampleRate raw'
  Concatenate pairs -> getSampleRate $ snd $ head pairs
  Merge       pairs -> getSampleRate $ snd $ head pairs
  Mix         pairs -> getSampleRate $ snd $ head pairs
  Resample _ r -> return r

-- | Calculates the channel count of a raw audio expression.
-- Any files referenced will be queried with @soxi@.
getSampleRate :: Rawdio -> IO Integer
getSampleRate raw = case raw of
  Silence r _ -> return r
  File f -> fmap read $ readProcess "soxi" ["-r", f] ""
  Pad    _ _ raw' -> getSampleRate raw'
  Trim   _ _ raw' -> getSampleRate raw'
  Cutoff _ _ raw' -> getSampleRate raw'
  Concatenate pairs -> getSampleRate $ snd $ head pairs
  Merge       pairs -> getSampleRate $ snd $ head pairs
  Mix         pairs -> getSampleRate $ snd $ head pairs
  Resample _ r -> return r

-- | Calculates the channel count of a raw audio expression.
-- Any files referenced will be queried with @soxi@.
getSampleRate raw = case raw of
  Silence r _ -> return r
  File f -> fmap read $ readProcess "soxi" ["-r", f] ""
  Pad    _ _ raw' -> getSampleRate raw'
  Trim   _ _ raw' -> getSampleRate raw'
  Cutoff _ _ raw' -> getSampleRate raw'
  Concatenate pairs -> getSampleRate $ snd $ head pairs
  Merge       pairs -> getSampleRate $ snd $ head pairs
  Mix         pairs -> getSampleRate $ snd $ head pairs
  Resample _ r -> return r

-- | Calculates the channel count of a raw audio expression.
-- Any files referenced will be queried with @soxi@.