--RUN WITH OPTIONS
-- +RTS -N2 -s -qg2 -A1024k
main = do
    --bs holds our BufferS
    (info, Just (bs :: B.Buffer Double)) <- Snd.readFile "./shpongle.ogg"
    --Convert to an unboxed array
    let b = sterilize bs

    --Grab all of the sound file
    let ct = (truncate $ (fromIntegral $ Snd.frames info)/2048.0)-2
    let i = StreamInfo 1024 44100 2
    let b' = sampleRawPCM 0 ct (i, b)
    let s = pcmStream b'
    
    let (i, freqs) = freqStream s
    let fluxes = onsetStream 12 ( fluxStream (i, freqs) 32)
     
    let bins = [86, 172..]
    let freqBins = [43, 86..]
    

    --let sPlot = streamPlot $ zip bins (F.toList fluxes)
    
    let onsetL = fmap (S.length) (bands fluxes)
    print $ "Onsets: "++(show onsetL)
    print $ "total Onsets: "++ (show $ sumS onsetL)
    --plot X11 $ Data2D [Color Magenta, Style Lines] [Step 43] (sPlot) 
    plot X11 $ Data2D [Color DarkGreen, Style Impulses] [Step 1] (toPlot (bands fluxes) 0)
    print $ show "done"

--plot a single frame of onsets
main = do
    --bs holds our BufferS
    (info, Just (bs :: B.Buffer Double)) <- Snd.readFile "./shpongle.ogg"
    --Convert to an unboxed array
    let b = sterilize bs

    --Grab all of the sound file
    let ct = (truncate $ (fromIntegral $ Snd.frames info)/2048.0)-2
    let i = StreamInfo 1024 44100 2
    let b' = sampleRawPCM 0 ct (i, b)
    let s = pcmStream b'
    
    let (i, freqs) = freqStream s
    let fluxes = onsetStream 12 ( fluxStream (i, freqs) 32)
     
    let bins = [86, 172..]
    let freqBins = [43, 86..]
    

    --let sPlot = streamPlot $ zip bins (F.toList fluxes)
    
    let onsetL = fmap (S.length) (bands fluxes)
    print $ "Onsets: "++(show onsetL)
    print $ "total Onsets: "++ (show $ sumS onsetL)
    --plot X11 $ Data2D [Color Magenta, Style Lines] [Step 43] (sPlot) 
    plot X11 $ Data2D [Color DarkGreen, Style Impulses] [Step 1] (toPlot (bands fluxes) 0)
    print $ show "done"

--plot a single frame of onsets
main = do
    --bs holds our BufferS
    (info, Just (bs :: B.Buffer Double)) <- Snd.readFile "./shpongle.ogg"
    --Convert to an unboxed array
    let b = sterilize bs

    --Grab all of the sound file
    let ct = (truncate $ (fromIntegral $ Snd.frames info)/2048.0)-2
    let i = StreamInfo 1024 44100 2
    let b' = sampleRawPCM 0 ct (i, b)
    let s = pcmStream b'
    
    let (i, freqs) = freqStream s
    let fluxes = onsetStream 12 ( fluxStream (i, freqs) 32)
     
    let bins = [86, 172..]
    let freqBins = [43, 86..]
    

    --let sPlot = streamPlot $ zip bins (F.toList fluxes)
    
    let onsetL = fmap (S.length) (bands fluxes)
    print $ "Onsets: "++(show onsetL)
    print $ "total Onsets: "++ (show $ sumS onsetL)
    --plot X11 $ Data2D [Color Magenta, Style Lines] [Step 43] (sPlot) 
    plot X11 $ Data2D [Color DarkGreen, Style Impulses] [Step 1] (toPlot (bands fluxes) 0)
    print $ show "done"

--plot a single frame of onsets