play -package:apecs-gloss
Play a game in a window. Like simulate, but you manage your
own input events.
Play a round of the game, making the solver guess the secret number
42. Note that you can generate a random-number and make the solver
guess it too! We have:
>>> play
Current bounds: (0,1000)
Current bounds: (21,1000)
Current bounds: (31,1000)
Current bounds: (36,1000)
Current bounds: (39,1000)
Current bounds: (40,1000)
Current bounds: (41,1000)
Current bounds: (42,1000)
Solved in: 8 guesses:
8 21 31 36 39 40 41 42
First, we define a play routine for lazy storable vectors. Storable
lazy vectors are lazy lists of low-level arrays. They are both
efficient in time and memory consumption, but the blocks disallow
feedback by small delays. Elements of a storable vector must be of
type class Storable. This means that elements must have fixed size and
advanced data types like functions cannot be used.
For the following examples we will stick to monophonic sounds played
at 44100 Hz. Thus we define a function for convenience.
play applied to an
Initial source will promote the
source to
Playing, thus the data found in the buffer will be
fed into the processing, starting at the beginning.
play
applied to a
Playing source will restart the source from the
beginning. It will not affect the configuration, and will leave the
source in
Playing state, but reset the sampling offset to the
beginning.
play applied to a
Paused source will resume
processing using the source state as preserved at the
pause
operation.
play applied to a
Stopped source will
propagate it to
Initial then to
Playing immediately.
Begin playback (optionally at a specific position).
Play audio signals via ALSA. The module could also be called
Output, because with a file sink, data can also be
written to disk.
Play a game in a window, using IO actions to build the pictures.
The next signal type we want to consider is the stateful signal
generator. It is not a common data structure, where the sample values
are materialized. Instead it is a description of how to generate
sample values iteratively. This is almost identical to the
Data.Stream module from the stream-fusion package.
With respect to laziness and restrictions of the sample type (namely
none), this signal representation is equivalent to lists. You can
convert one into the other in a lossless way. That is, function as
sample type is possible. Combination of such signal generators is
easily possible and does not require temporary storage, because this
signal representation needs no sample value storage at all. However at
the end of such processes, the signal must be materialized. Here we
write the result into a lazy storable vector and play that. What the
compiler actually does is to create a single loop, that generates the
storable vector to be played in one go.