Copyright | (c) Ivan Perez 2017-2023 |
---|---|
License | BSD3 |
Maintainer | ivan.perez@keera.co.uk |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Streams and stream manipulation API.
The evaluation of Dunai MSFs, especially for testing purposes, needs the generation of suitable input streams.
While some streams can be generated randomly using QuickCheck, it is sometimes useful to be able to preprend or adapt an input stream. It is also useful to debug programs when you have recorded input streams using Haskell Titan.
This module defines types for input streams, as well as an API to create, examine and combine streams. It also provides evaluation functions that are needed to apply an MSF to a stream and obtain an output stream and a continuation MSF.
Synopsis
- type SignalSampleStream a = SampleStream (DTime, a)
- type SampleStream a = [a]
- type DTime = Double
- groupDeltas :: [a] -> [DTime] -> SignalSampleStream a
- samples :: SignalSampleStream a -> [a]
- firstSample :: SignalSampleStream a -> a
- lastSample :: SignalSampleStream a -> a
- sMerge :: (a -> a -> a) -> SignalSampleStream a -> SignalSampleStream a -> SignalSampleStream a
- sConcat :: SignalSampleStream a -> SignalSampleStream a -> SignalSampleStream a
- sRefine :: DTime -> a -> SignalSampleStream a -> SignalSampleStream a
- refineWith :: (a -> a -> a) -> DTime -> a -> SignalSampleStream a -> SignalSampleStream a
- sClipAfterFrame :: Int -> SignalSampleStream a -> SignalSampleStream a
- sClipAfterTime :: DTime -> SignalSampleStream a -> SignalSampleStream a
- sClipBeforeFrame :: Int -> SignalSampleStream a -> SignalSampleStream a
- sClipBeforeTime :: DTime -> SignalSampleStream a -> SignalSampleStream a
- evalSF :: Monad m => MSF (ReaderT DTime m) a b -> SignalSampleStream a -> m (SampleStream b, MSF (ReaderT DTime m) a b)
- evalMSF :: Monad m => MSF m a b -> SampleStream a -> m (SampleStream b, MSF m a b)
Types
type SignalSampleStream a = SampleStream (DTime, a) Source #
A stream of samples, with their sampling times.
type SampleStream a = [a] Source #
A stream of samples, with no sampling time.
DTime is the time type for lengths of sample intervals. Conceptually, DTime = R+ = { x in R | x > 0 }.
Creation
groupDeltas :: [a] -> [DTime] -> SignalSampleStream a Source #
Group a series of samples with a series of time deltas.
The first sample will have no delta. Unused samples and deltas will be dropped.
Obtain samples
samples :: SignalSampleStream a -> [a] Source #
Turn a stream with sampling times into a list of values.
firstSample :: SignalSampleStream a -> a Source #
Return the first sample in a signal sample stream.
lastSample :: SignalSampleStream a -> a Source #
Return the last sample in a signal sample stream.
Stream manipulation
Merging
sMerge :: (a -> a -> a) -> SignalSampleStream a -> SignalSampleStream a -> SignalSampleStream a Source #
Merge two streams, using an auxiliary function to merge samples that fall at the exact same sampling time.
Concatenating
sConcat :: SignalSampleStream a -> SignalSampleStream a -> SignalSampleStream a Source #
Concatenate two sample streams, separating them by a given time delta.
Refining
sRefine :: DTime -> a -> SignalSampleStream a -> SignalSampleStream a Source #
Refine a signal sample stream by establishing the maximum time delta.
If two samples are separated by a time delta bigger than the given max DT, the former is replicated as many times as necessary.
refineWith :: (a -> a -> a) -> DTime -> a -> SignalSampleStream a -> SignalSampleStream a Source #
Refine a stream by establishing the maximum time delta.
If two samples are separated by a time delta bigger than the given max DT, the auxiliary interpolation function is used to determine the intermediate sample.
Clipping (dropping samples)
sClipAfterFrame :: Int -> SignalSampleStream a -> SignalSampleStream a Source #
Clip a signal sample stream at a given number of samples.
sClipAfterTime :: DTime -> SignalSampleStream a -> SignalSampleStream a Source #
Clip a signal sample stream after a certain (non-zero) time.
sClipBeforeFrame :: Int -> SignalSampleStream a -> SignalSampleStream a Source #
Drop the first n samples of a signal sample stream. The time deltas are not re-calculated.
sClipBeforeTime :: DTime -> SignalSampleStream a -> SignalSampleStream a Source #
Drop the first samples of a signal sample stream up to a given time. The time deltas are not re-calculated to match the original stream.
evalSF :: Monad m => MSF (ReaderT DTime m) a b -> SignalSampleStream a -> m (SampleStream b, MSF (ReaderT DTime m) a b) Source #
Evaluate an SF with a SignalSampleStream
, obtaining an output stream and
a continuation.
You should never use this for actual execution in your applications, only for testing.
evalMSF :: Monad m => MSF m a b -> SampleStream a -> m (SampleStream b, MSF m a b) Source #
Evaluate an MSF with a SampleStream
, obtaining an output stream and a
continuation.
You should never use this for actual execution in your applications, only for testing.