Last active
October 30, 2015 08:31
-
-
Save lucamolteni/44f6083584ff3f4d6d76 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Main where | |
| import Data.WAVE | |
| import Control.Monad | |
| import Data.List | |
| main :: IO () | |
| main = do | |
| f <- getWAVEFile "example.wav" | |
| let samples = waveSamples f | |
| let flatten = flatSamples samples | |
| let toConsole = map (toString . consoleAmplitude) flatten | |
| forM_ toConsole putStrLn | |
| return () | |
| numChannel :: WAVE -> Int | |
| numChannel f = waveNumChannels (waveHeader f) | |
| flatSamples :: WAVESamples -> [Double] | |
| flatSamples f = map average $ splitEvery 10 (map avgSample f) | |
| average xs = realToFrac (sum xs) / genericLength xs | |
| avgSample :: [WAVESample] -> Double | |
| avgSample = average | |
| splitEvery :: Int -> [a] -> [[a]] | |
| splitEvery _ [] = [] | |
| splitEvery n xs = as : splitEvery n bs | |
| where (as,bs) = splitAt n xs | |
| toString :: Int -> String | |
| toString n = map (const 'X') [1..n] | |
| consoleAmplitude :: Double -> Int | |
| consoleAmplitude x = floor x `mod` 120 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment