Popularity
6.8
Stable
Activity
0.0
Stable
11
2
7
Monthly Downloads: 132
Programming language: Haskell
License: BSD 3-clause "New" or "Revised" License
Tags:
Codec
HCodecs alternatives and similar packages
Based on the "Codec" category.
Alternatively, view HCodecs alternatives based on common mentions on social networks and blogs.
Get performance insights in less than 4 minutes
Scout APM uses tracing logic that ties bottlenecks to source code so you know the exact line of code causing performance issues and can get back to building a great product faster.
Sponsored
scoutapm.com
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest. Visit our partner's website for more details.
Do you think we are missing an alternative of HCodecs or a related project?
README
HCodecs - A library to read, write and manipulate MIDI, WAVE, and SoundFont2 files.
Code example
This programs generates a short WAV file "sample.wav", then reads it and prints each sample.
import Codec.Wav ( exportFile, importFile )
import Data.Audio ( Audio(Audio) )
import Data.Array.Unboxed ( listArray, elems )
import Data.Int ( Int32 )
import Data.Maybe ( fromMaybe )
import System.IO (FilePath)
filename = "sample.wav"
sinewave :: [Float]
sinewave = map (\x -> sin ((fromInteger x) / 10.0)) [1..10000]
outMain :: FilePath -> IO ()
outMain path = do
let fs :: [Float]
fs = sinewave
l = 1000
rate = 44100
-- Float is 32bit, so i use Int32 for each sample in the output.
let maxInt32 :: Float
maxInt32 = fromIntegral (maxBound::Int32)
-- actual transformation function
rounder :: Float -> Int32
rounder = round . (*maxInt32)
exportFile path ( Audio rate 1 -- 1 channel
$ listArray (0,l)
$ map rounder
$ fs)
inMain :: FilePath -> IO ()
inMain path = do
maybeAudio <- importFile path
case maybeAudio :: Either String (Audio Int32) of
Left s -> putStrLn $ "wav decoding error: " ++ s
Right (Audio rate channels samples) -> do
putStrLn $ "rate = " ++ show rate
putStrLn $ "channels: " ++ show channels
print $ elems samples
main = do
putStrLn $ "* Outputting the sound to "++filename
outMain filename
putStrLn $ "* Printing the content of "++filename
inMain filename
-- Original by hexagoxel @ freenode/#haskell
-- Modified by Vitaly "_Vi" Shukela