Last active
August 29, 2015 14:06
-
-
Save frms-/c0f387630e784234354c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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