Subsections

Sound support - new (experimental) API

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:

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.

struct snd2_sample;

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.

struct snd2_stream;

A sound stream.

int snd2_channels(int channels);

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.

int snd2_samplerate(int rate);

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.

int snd2_sampleformat(int format);

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.

snd2_sample *snd2_makesample(int length);

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.

void snd2_allocatesample(snd2_sample *samp);

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.

void snd2_killsample (snd2_sample *samp);

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.

snd2_sample *snd2_readsample (char *file);

Reads a sample from the specified file and copies it to the sample structure.Returns a pointer to the sample that was created.

int snd2_writesample(snd2_sample *samp, char *file);

Writes the sample to the specified file.Returns the number of frames written.

int snd2_recordsample_blocking(snd2_sample *samp);

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.

void snd2_playsample_blocking(snd2_sample *samp);

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.

snd2_stream * snd2_recordsample(snd2_sample *samp);

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.

snd2_stream *snd2_playsample(snd2_sample *samp);

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.

int snd2_querysample(snd2_stream * stream)

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.

void snd2_stopsample(snd2_stream * stream);

Stops playing/recording a given stream.

float snd2_getstreamtime(snd2_stream * stream);

returns the time of a given stream in seconds.

__int64 snd2_getsampletime(snd2_sample * samp);

returns the time of a given sample in samples.

void snd2_tobuffer(snd2_sample * samp);

dumps the contents of a sample to disk.

void snd2_frombuffer(snd2_sample *samp);

reads the contents of a the disk buffer to a sample.


top
Persoonlijke pagina Universiteit GentTscope
Allegro | Cygwin | Gcc
© See license.html for copyright information