Defined in sound2.h and sound2.c
The old sound functions work fine for playing sounds, but recording sound does not work with
the underlying allegro library. Therefore a new set of sound functions are being implemented
based on the libsndfile and portaudio libraries.
The functions are still experimental. This has some implications:
- currently the new sound functions start with snd2_ instead of the usual ts_. This will
change once all features are implemented and all (or most) bugs are found.
- the set of functions is not complete yet. Expect additions.
- the behavior and interface of the functions may change.
- there may be bugs.
The old sound functions still work, but you can not mix systems in one program. Tscope will
exit (at runtime) when you try to do that.
Bitmap memory structure used by Tscope. It is defined as follows:
typedef struct {
int channels;
int samplerate;
sf_count_t frames;
sf_count_t current_frame;
float *data;
} snd2_sample;
channels and samplerate contain the number of channels and the sample rate of the
sample.
frames and current_frame contain the total number of frames of the sample and the frame that
is currently being processed (for internal use).
data points to the contents of the sample.
A sound stream.
Sets the number of channels the recording and stream functions. Possible values are 1 (MONO)
or 2 (STEREO). Default is 1.
Has no influence on samples that are read from disk - for disk files the number of channels
is set by the file's header.
Returns the previous number of channels.
Sets the number of samples per second for the recording and stream functions. The samplerate
influences the sound quality (higher is better). Supported values are 44100 (cd quality), 22050
or 11025. Default is 22050. This is good enough for recording voices.
Has no influence on samples that are read from disk - for disk files the sample rate is set
by the file's header.
Returns the previous samplerate.
Sets the sample format in which samples are written to disk. Possible values are 16-bit
integer (SAMPLE_INTEGER) and 32-bit floating point (SAMPLE_FLOAT). Default is
SAMPLE_INTEGER.
Internally (i.e. in RAM memory) samples are always represented as 32-bit floats.
Returns the previous sample format.
Creates a sample that is large enough to hold
'length' milliseconds of sample data and sets the samplerate and number of channels
according to the values set by snd2_samplerate and snd2_channels. The sample data is
initialized to 0 and the current frame set to 0.Returns a pointer to the sample that was
created.
Internal function. Allocates memory for the
data element of the snd2_sample stucture and initializes the data to 0. The amout of memory is
set according to the frames element of the snd2_sample structure.
Removes the specified sample out of memory. You
should do this at the end of your program for all samples generated with snd2_makesample or
snd2_readsample.
Reads a sample from the specified file and copies it to
the sample structure.Returns a pointer to the sample that was created.
Writes the sample to the specified
file.Returns the number of frames written.
Records the sample samp using the
blocking api. The function does not return until the samples data element is full, i.e. until
the number of frames specified in the frames element of the sample structure have been
recorded.
Plays the sample samp using the blocking
api. The function does not return until the sample is finished, i.e. until the number of frames
specified in the frames element of the sample structure have been played.
Starts recording the sample samp using the
non-blocking api. The function returns immediately and the sample is recorded until its data
element is full or until snd2_stopsample is called.Returns a pointer to the stream that was
started.
Starts playing the sample samp using the
non-blocking api. The function returns immediately and the sample is played until it is
finished or until snd2_stopsample is called.Returns a pointer to the stream that was started.
Checks whether a given stream has finished
playing/recording or not. Returns 1 when the stream is still active and 0 when the stream has
finished.
Stops playing/recording a given stream.
returns the time of a given stream in
seconds.
returns the time of a given sample in samples.
dumps the contents of a sample to disk.
reads the contents of a the disk buffer to a
sample.