|
Synthesizer.Physical.Signal | Portability | requires multi-parameter type classes
This module equips a list of values
with a sampling rate and an amplitude.
Since sampling rate and amplitude need not to be of the same type
and need not to be of the type of the values
one can choose physical quantities for sampling rate and amplitude
but low level types like Double and Float for the values.
The only thing we need is the conversion to scalar types
provided by the 'Algebra.OccasionallyScalar.C' type class.
This conversion may fail in which case we encountered a unit error.
We can also use this module with plain number types.
Then toScalar cannot fail.
The conversion to scalars is very general
and might support applications I can currently not imagine. | Stability | provisional | Maintainer | synthesizer@henning-thielemann.de |
|
|
|
|
|
Description |
|
|
Synopsis |
|
data T t t' y y' yv = Cons {} | | cons :: t' -> y' -> [yv] -> T t t' y y' yv | | sampleRate :: T t t' y y' yv -> t' | | amplitude :: T t t' y y' yv -> y' | | samples :: T t t' y y' yv -> [yv] | | replaceParameters :: t1' -> y1' -> T t t0' y y0' yv -> T t t1' y y1' yv | | replaceSampleRate :: t1' -> T t t0' y y' yv -> T t t1' y y' yv | | replaceAmplitude :: y1' -> T t t' y y0' yv -> T t t' y y1' yv | | replaceSamples :: [yv1] -> T t t' y y' yv0 -> T t t' y y' yv1 | | assert :: String -> Bool -> T t t' y y' yv -> T t t' y y' yv | | assertAmplitude :: Eq y' => y' -> T t t' y y' yv -> T t t' y y' yv | | assertSampleRate :: Eq t' => t' -> T t t' y y' yv -> T t t' y y' yv | | asTypeOfTime :: t -> T t t' y y' yv -> t | | asTypeOfAmplitude :: y -> T t t' y y' yv -> y | | toTimeScalar :: (C t', C t t') => T t t' y y' yv -> t' -> t | | toFrequencyScalar :: (C t', C t t') => T t t' y y' yv -> t' -> t | | toAmplitudeScalar :: (C y', C y y') => T t t' y y' yv -> y' -> y | | commonSampleRate :: Eq t' => T t t' y0 y'0 yv0 -> T t t' y1 y'1 yv1 -> t' | | commonSampleRate' :: Eq a => a -> a -> a | | pureData :: (C t', C t t', C y', C y y', C y yv) => t' -> y' -> T t t' y y' yv -> (t, [yv]) | | runPlain :: t' -> (T t t' -> T y y' yv) -> T t t' y y' yv | | addPlainSampleRate :: t' -> T y y' yv -> T t t' y y' yv | | run :: T t t' -> (T t t' -> T y y' yv) -> T t t' y y' yv | | addSampleRate :: T t t' -> T y y' yv -> T t t' y y' yv | | splitSampleRate :: T t t' y y' yv -> (T t t', T y y' yv) | | checkSampleRate :: Eq t' => String -> T t t' -> T t t' y y' yv -> T y y' yv | | splitSampleRateList :: Eq t' => [T t t' y y' yv] -> (T t t', [T y y' yv]) | | apply :: (T t t' -> T y0 y'0 y0v -> T y1 y'1 y1v) -> T t t' y0 y'0 y0v -> T t t' y1 y'1 y1v | | lift0 :: (T t t' -> T y y' yv) -> t' -> T t t' y y' yv | | lift1 :: (T t t' -> T y0 y0' yv0 -> T y1 y1' yv1) -> T t t' y0 y0' yv0 -> T t t' y1 y1' yv1 | | lift2 :: Eq t' => (T t t' -> T y0 y'0 yv0 -> T y1 y'1 yv1 -> T y2 y'2 yv2) -> T t t' y0 y'0 yv0 -> T t t' y1 y'1 yv1 -> T t t' y2 y'2 yv2 | | lift3 :: Eq t' => (T t t' -> T y0 y'0 yv0 -> T y1 y'1 yv1 -> T y2 y'2 yv2 -> T y3 y'3 yv3) -> T t t' y0 y'0 yv0 -> T t t' y1 y'1 yv1 -> T t t' y2 y'2 yv2 -> T t t' y3 y'3 yv3 | | liftList :: Eq t' => (T t t' -> [T y1 y'1 yv1] -> T y y' yv) -> [T t t' y1 y'1 yv1] -> T t t' y y' yv | | liftR2 :: (T t t' -> T y y' yv -> (T y0 y'0 yv0, T y1 y'1 yv1)) -> T t t' y y' yv -> (T t t' y0 y'0 yv0, T t t' y1 y'1 yv1) | | liftR3 :: (T t t' -> T y y' yv -> (T y0 y'0 yv0, T y1 y'1 yv1, T y2 y'2 yv2)) -> T t t' y y' yv -> (T t t' y0 y'0 yv0, T t t' y1 y'1 yv1, T t t' y2 y'2 yv2) |
|
|
Documentation |
|
|
t and y are plain number types,
t' and y' may be physical quantities.
yv may be a vector type.
It should hold:
(OccScalar.C t t',
OccScalar.C y y',
Module.C y yv)
There are no values of type t and type y in T
but they are essential to computation of intermediate results.
| Constructors | Cons | | fullSampleRate :: T t t' | how many values per unit are stored
| content :: T y y' yv | the signal with a unit-equipped volume
|
|
| Instances | |
|
|
|
:: | | => t' | sampling rate, must be positive (unchecked)
| -> y' | amplitude, must be positive (unchecked)
| -> [yv] | samples, values should be between -1 and 1 (unchecked)
| -> T t t' y y' yv | | Construct a signal.
|
|
|
sampleRate :: T t t' y y' yv -> t' | Source |
|
|
amplitude :: T t t' y y' yv -> y' | Source |
|
|
samples :: T t t' y y' yv -> [yv] | Source |
|
|
replaceParameters :: t1' -> y1' -> T t t0' y y0' yv -> T t t1' y y1' yv | Source |
|
Replace sample rate and amplitude
with different representations of their values.
This is needed for internal purposes,
especially for preserving the phantom types.
Do not use it for arbitrary changes of sample rate or amplitude!
|
|
replaceSampleRate :: t1' -> T t t0' y y' yv -> T t t1' y y' yv | Source |
|
|
replaceAmplitude :: y1' -> T t t' y y0' yv -> T t t' y y1' yv | Source |
|
|
replaceSamples :: [yv1] -> T t t' y y' yv0 -> T t t' y y' yv1 | Source |
|
|
|
Assert a condition before shipping the first sample.
|
|
assertAmplitude :: Eq y' => y' -> T t t' y y' yv -> T t t' y y' yv | Source |
|
Assert that the amplitude of the signal matches the given one.
Otherwise give an error when the first sample is fetched.
|
|
assertSampleRate :: Eq t' => t' -> T t t' y y' yv -> T t t' y y' yv | Source |
|
Assert that the sample rate of the signal matches the given one.
|
|
|
:: | | => t | time value, of with a type to be fixed
| -> T t t' y y' yv | signal, whose time type shall be matched
| -> t | the time value, again
| Fix the type of a value to the scalar time type of a signal.
|
|
|
asTypeOfAmplitude :: y -> T t t' y y' yv -> y | Source |
|
Fix the type of a value to the scalar amplitude type of a signal.
|
|
toTimeScalar :: (C t', C t t') => T t t' y y' yv -> t' -> t | Source |
|
Express a time value as a multiple of the sampling period.
The multiplicity is returned.
It is a checked error,
if the units of time value and sampling period mismatch.
|
|
toFrequencyScalar :: (C t', C t t') => T t t' y y' yv -> t' -> t | Source |
|
Express a frequency value as a multiple of the sampling frequency.
The multiplicity is returned.
In many applications the multiplicity is below 1.
It is a checked error,
if the units of frequency value and sampling frequency mismatch.
|
|
toAmplitudeScalar :: (C y', C y y') => T t t' y y' yv -> y' -> y | Source |
|
Express an amplitude value as a multiple of the signal amplitude.
The multiplicity is returned.
It is a checked error,
if the units of amplitude value and signal amplitude mismatch.
|
|
commonSampleRate :: Eq t' => T t t' y0 y'0 yv0 -> T t t' y1 y'1 yv1 -> t' | Source |
|
If all signals share the same sampleRate, then return it,
otherwise raise an error.
|
|
commonSampleRate' :: Eq a => a -> a -> a | Source |
|
|
|
:: (C t', C t t', C y', C y y', C y yv) | | => t' | The unit of the sampling frequency, say Number.SI.hertz
| -> y' | The maximum expected value.
The data is normalized to this value,
in order to preserve that all output samples
are at most 1 in magnitude.
| -> T t t' y y' yv | The input signal.
| -> (t, [yv]) | The sampling frequency without unit and
the list of normalized samples.
This information should suffice for playback
or writing the signal to a file.
| Extract data for further processing that is not aware of physical units,
such as playing and creating files.
|
|
|
Conversion from and to signals with sample rate context
|
|
runPlain :: t' -> (T t t' -> T y y' yv) -> T t t' y y' yv | Source |
|
|
addPlainSampleRate :: t' -> T y y' yv -> T t t' y y' yv | Source |
|
|
run :: T t t' -> (T t t' -> T y y' yv) -> T t t' y y' yv | Source |
|
|
addSampleRate :: T t t' -> T y y' yv -> T t t' y y' yv | Source |
|
|
splitSampleRate :: T t t' y y' yv -> (T t t', T y y' yv) | Source |
|
|
|
If the given sample rate matches the one of the signal,
then return the core signal, otherwise undefined.
|
|
splitSampleRateList :: Eq t' => [T t t' y y' yv] -> (T t t', [T y y' yv]) | Source |
|
|
apply :: (T t t' -> T y0 y'0 y0v -> T y1 y'1 y1v) -> T t t' y0 y'0 y0v -> T t t' y1 y'1 y1v | Source |
|
|
lift0 :: (T t t' -> T y y' yv) -> t' -> T t t' y y' yv | Source |
|
|
lift1 :: (T t t' -> T y0 y0' yv0 -> T y1 y1' yv1) -> T t t' y0 y0' yv0 -> T t t' y1 y1' yv1 | Source |
|
|
lift2 :: Eq t' => (T t t' -> T y0 y'0 yv0 -> T y1 y'1 yv1 -> T y2 y'2 yv2) -> T t t' y0 y'0 yv0 -> T t t' y1 y'1 yv1 -> T t t' y2 y'2 yv2 | Source |
|
|
lift3 :: Eq t' => (T t t' -> T y0 y'0 yv0 -> T y1 y'1 yv1 -> T y2 y'2 yv2 -> T y3 y'3 yv3) -> T t t' y0 y'0 yv0 -> T t t' y1 y'1 yv1 -> T t t' y2 y'2 yv2 -> T t t' y3 y'3 yv3 | Source |
|
|
liftList :: Eq t' => (T t t' -> [T y1 y'1 yv1] -> T y y' yv) -> [T t t' y1 y'1 yv1] -> T t t' y y' yv | Source |
|
|
liftR2 :: (T t t' -> T y y' yv -> (T y0 y'0 yv0, T y1 y'1 yv1)) -> T t t' y y' yv -> (T t t' y0 y'0 yv0, T t t' y1 y'1 yv1) | Source |
|
|
liftR3 :: (T t t' -> T y y' yv -> (T y0 y'0 yv0, T y1 y'1 yv1, T y2 y'2 yv2)) -> T t t' y y' yv -> (T t t' y0 y'0 yv0, T t t' y1 y'1 yv1, T t t' y2 y'2 yv2) | Source |
|
|
Produced by Haddock version 2.4.2 |