Skip to content

Instantly share code, notes, and snippets.

@frms-
Last active August 29, 2015 14:06
Show Gist options
  • Save frms-/c0f387630e784234354c to your computer and use it in GitHub Desktop.
Save frms-/c0f387630e784234354c to your computer and use it in GitHub Desktop.
module Silence (silence, silentStream, silentFile) where
import Data.ByteString.Builder
import Data.Int (Int64)
import Data.Monoid ((<>))
import qualified Data.ByteString.Lazy as BL
type Seconds = Int64
header :: Builder
header = word8 0xFF <>
word8 0xFB <>
word8 0x91 <>
word8 0x04
silent :: Builder
silent = lazyByteString $ BL.take 413 $ BL.repeat 0x0
frames :: Builder
frames = foldr1 (<>) (repeat frame)
where frame = header <> silent
silence :: Seconds -> BL.ByteString
silence nSec = BL.take (nSec * fps * fLen) silentStream
where fLen = 417
fps = 38
silentStream :: BL.ByteString
silentStream = toLazyByteString frames
silentFile :: FilePath -> Seconds -> IO ()
silentFile path seconds = BL.writeFile path $ silence seconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment