Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

AudioToFile Class Reference

Mixes each active channel and writes it to a file descriptor. More...

#include <AudioToFile.h>

Inheritance diagram for AudioToFile

Inheritance graph
[legend]
Collaboration diagram for AudioToFile:

Collaboration graph
[legend]
List of all members.

Public Methods

 AudioToFile (bool threaded = true)
virtual ~AudioToFile ()
virtual Result Play (Sample& sample)
 play the sample, without waiting for it to finish.

virtual Result PlayNoWait (Sample& sample, int& NewChanelID, int& NewVoice)
 Play the sample and return without waiting for it to finish.

virtual Result WaitForVoiceToFinish (int voice, int ChannelID)
 do as it says.

virtual int AllocateVoice (const Sample& sample, int voice = -1)
 Allocates a voice for a sound which will be mixed into the buffer. More...

virtual Result DeleteVoice (int voice)
 Remove the given voice from the Audio manager.

virtual ChannelAllocateChannel ()
 Create a new Channel.

virtual void DeleteChannel (Channel*& channel)
 Delete the given Channel.

virtual int VoicesAllocated () const
 Return the number of current voices allocated.

virtual Result SetLocation (int x, int y, int z, int channel)
virtual Result SetX (int x, int channel)
virtual Result SetY (int y, int channel)
virtual Result SetZ (int z, int channel)
virtual Result GetLocation (int& x, int& y, int& z, int channel)
virtual Result GetX (int& x, int channel)
virtual Result GetY (int& y, int channel)
virtual Result GetZ (int& z, int channel)
virtual Result SetVolume (Volume volume, int channel)
 volume.

virtual Volume GetVolume (int channel)
virtual Result SetVelocity (Velocity velocity, int channel)
 velocity -- how hard the key was pressed -- is this useful?

virtual Velocity GetVelocity (int channel)
virtual Result SetFrequency (Frequency frequency, int channel)
 frequency.

virtual Frequency GetFrequency (int channel)
virtual Result SetPosition (unsigned long position, int channel)
 position.

unsigned long GetPosition (int channel)
virtual Result SetVoice (int voice, int channel)
 Set the voice for the given channel.

virtual int GetVoice (int channel)
 get the voice that has been assigned to the channel.

virtual int NextChannel ()
 return the channel id for the next channel.

virtual void Start (int channel)
 Start the playback sample mixing thread if it hasn't already been started and enable the channel for mixing. We have two options for the mixer. Either fork a new process and communicate via a pipe or perhaps shared memory, or start a new thread for the mixer. Some libraries are not thread safe so it may be a good idea to fork a process for the mixer.

virtual void Stop (int channel)
 Stop the channel from making any noise.

virtual long GetPlaybackRate ()
virtual void SetTimeout (long milliseconds)
virtual void StartTimeout ()
virtual void StopTimeout ()
virtual void WaitForTimeout ()
virtual Result StreamBuffer (const unsigned char* buffer, unsigned long length, int bits = 16, int channels = 2)
 experimental and untested.

virtual Result StreamBuffer (const short* buffer, unsigned long length, int channels, Filters::SimpleFilter<short>& filter)
virtual bool IsStreamable () const

Protected Types

typedef ThreadV<class AudioToFile> MixerThreadV
typedef MapLikeContainer<Status, 128> ChannelContainer
typedef MapLikeContainer<const
Sample*, 128> 
VoiceContainer

Protected Methods

virtual void PrepareBuffer ()
 Prepare the buffer for mixing. More...

virtual void Output (int x)
 Write the samples to the output using the correct output function for the sample type.

virtual int WriteData (unsigned char* buffer, size_t length)
virtual void MixBuffer (Status& status, unsigned long length)
 
Parameters:
status   The Status of the channel that is being mixed.
length   The length of data to mix.


void MixerThread ()
 This thread mixes all the active channels together and writes the result to the audio device file.

bool Mix ()
 Enumate the channels, mix the samples in each channel, and write the result to the file descriptor using Output(). More...

void MixChannel ( Status& status )
 Mix a channel. More...

void MixLoopedChannel ( Status& status )
 
Parameters:
status.  


void MixOneShotChannel ( Status& status )
 
Parameters:
status   The Status of the channel being mixed.


void MixTinyLoop (Status& status, unsigned long& playlength)
bool KeepMixing ()
void Output32_16stereo (int x)
 Convert the audio buffer from 32 bit stereo to 16 bit stereo.

void Output32_16mono (int x)
 Convert the audio buffer from 32 stereo to 16 bit mono.

void Output32_8stereo (int x)
void Output32_8mono (int x)
bool TryToOutput (int x)
void Run ()

Protected Attributes

MixerThreadV* m_mixer_thread
Mutex m_mutex
bool m_use_threads
Timeoutm_timeout
ChannelContainer m_channels
VoiceContainer m_voices
long m_milliseconds
long m_mix_length
 number of samples to mix.

unsigned long m_buffer_size
 size in bytes.

unsigned char* m_audio_buffer [2]
bool m_dirty [2]
int m_current_mix_buffer
int m_current_output_buffer
int m_channels_enabled
int m_fd
int m_bits
int m_rate
bool m_stereo
bool m_mixer_started

Static Protected Methods

void StreamBufferCallback (Status* status, void* data)
void* thread_callback (void* me)
 This function is given to pthread_create as the callback. It must be static, otherwise the hidden "this" pointer will get corrupted. The argument given in me should be the "this" pointer so that we can get back inside the class again.


Static Protected Attributes

const int DEFAULT_BUFFER_SIZE = 8192

Friends

class  ThreadV< class AudioToFile >

Detailed Description

Mixes each active channel and writes it to a file descriptor.


Member Function Documentation

int AudioToFile::AllocateVoice ( const Sample & sample,
int voice = -1 ) [virtual]
 

Allocates a voice for a sound which will be mixed into the buffer.

It returns number corresponding to it's place in the array of samples (voices.)

this should make a copy of the sample structure or at least not rely on the reference to Sample given always being valid it will assign the voice to the number "voice" or if voice is -1 then it will get the next free voice number and return it.

Reimplemented from Audio.

bool AudioToFile::KeepMixing ( ) [inline, protected]
 

Returns:
True if there is still a channel enabled.

bool AudioToFile::Mix ( ) [inline, protected]
 

Enumate the channels, mix the samples in each channel, and write the result to the file descriptor using Output().

If the file was not yet ready to be written to then the samples will have been mixed but not output and false will be returned. The next time Mix() is called the samples that were mixed but not output will be written

void AudioToFile::MixChannel ( Status & status ) [protected]
 

Mix a channel.

Parameters:
status   The Status of the channel that is being mixed.

void AudioToFile::PrepareBuffer ( ) [inline, protected, virtual]
 

Prepare the buffer for mixing.

Simply zeros the buffer.

Reimplemented in DspMmapped.


The documentation for this class was generated from the following files:
Generated at Mon Nov 27 01:46:38 2000 for LibPenguinPlay by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000