hunk ./src/PCMWriter.hs 31 - writeHeader - ,writeSamplerate - ,writeSamples + writeHeader + , writeSamplerate + , writeSamples + , writeNumSamples hunk ./src/PCMWriter.hs 71 -from16bit n = [chr . fromIntegral $ n .&. 0xff, +from16bit :: Word16 -> [Char] +from16bit n = [chr . fromIntegral $ n .&. 0xff, hunk ./src/PCMWriter.hs 74 + hunk ./src/PCMWriter.hs 80 -hWrite16 :: Handle -> Word16 -> IO () -hWrite16 handle n = do hPutStr handle $! from16bit n +hWrite16 :: Handle -> Word16 -> IO () +hWrite16 handle n = hPutStr handle $ from16bit n + hunk ./src/PCMWriter.hs 98 - let count1 = (num * 4) + let count1 = if even num then num else num-1 --(num * 4) hunk ./src/PCMWriter.hs 127 - do zipWithM_ writeInterleaved ch0 ch1 - cur <- hTell handle - let totalsamples = fromIntegral $ (cur - 44) `div` (2*2) - writeNumSamples handle $ fromIntegral $ (cur - 44) `div` (2*2) - --hFlush handle - where - writeInterleaved ch0sample ch1sample = - do hWrite16 handle (toPcmRepr ch0sample) - hWrite16 handle (toPcmRepr ch1sample) + do let samples = writeS ch0 ch1 + samples `seq` hPutStr handle samples + +-- is supposed to be lazy +writeS :: AudioSampleRepr a => [a] -> [a] -> String +writeS [] [] = [] +writeS (ch1:chs1) (ch2:chs2) + = let c1 = toPcmRepr ch1 + c2 = toPcmRepr ch2 + in ((chr . fromIntegral $ c1 .&. 0xff) : + (chr . fromIntegral $ c1 `shiftR` 8) : + (chr . fromIntegral $ c2 .&. 0xff) : + (chr . fromIntegral $ c2 `shiftR` 8) : + writeS chs1 chs2) hunk ./src/Test.hs 41 - PCM.writeSamplerate out 44100 -- we need to write this all the time... +-- PCM.writeSamplerate out 44100 -- we need to write this all the time... hunk ./src/Test.hs 43 + cur <- hTell out + PCM.writeNumSamples out $ fromIntegral $ (cur - 44) hunk ./src/Test.hs 46 - where --- extract :: ([Double], [Double]) -> (Double) - extract :: DChannel [Double] -> ([Double],[Double]) - extract chan = case chan of - Single _ _ _ (g0, g1) -> (fromChanData $ mp3Data g0, fromChanData $ mp3Data g1) - Dual _ _ _ (g0, g2) (g1, g3) -> - ( (fromChanData $ mp3Data g0) ++ (fromChanData $ mp3Data g2), - (fromChanData $ mp3Data g1) ++ (fromChanData $ mp3Data g3) ) - - fromChanData :: ChannelData [Double] -> [Double] - fromChanData (ChannelData _ as) = as