Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | Examples

Async::AudioIO Class Reference

A class for handling audio input/output to an audio device. More...

#include <AsyncAudioIO.h>

List of all members.

Public Types

Public Member Functions

Public Attributes

Friends


Detailed Description

A class for handling audio input/output to an audio device.

Author:
Tobias Blomberg
Date:
2003-03-23
This is a class for handling audio input and output to an audio device. For now, the AudioIO class only works with 16 bit mono samples at 8 Khz sampling rate. An example usage is shown below.

#include <math.h>

#include <iostream>
#include <AsyncCppApplication.h>
#include <AsyncAudioIO.h>

using namespace std;
using namespace Async;

class MyClass : public SigC::Object
{
  public:
    MyClass(void)
    {
      audio_io = new AudioIO("/dev/dsp");
      audio_io->open(AudioIO::MODE_RDWR);
      audio_io->audioRead.connect(slot(this, &MyClass::onAudioRead));
        /* Or just coonect the AudioIO object to itself... */
      //audio_io->audioRead.connect(slot(audio_io, &AudioIO::write));
      
      short samples[8000];
      for (int i=0; i<8000; ++i) // Put a sine wave into the buffer
      {
        samples[i] = static_cast<short int>(10000 * sin(2*M_PI*440*i/8000));
      }
      int samples_written = audio_io->write(samples, 8000);
      cout << "Wrote " << samples_written << " samples...\n";
    }
    
    ~MyClass(void)
    {
      delete audio_io;
    }

  private:
    AudioIO *audio_io;
    
    int onAudioRead(short *samples, int count)
    {
      //cout << count << " samples read...\n";
      return audio_io->write(samples, count);
    }
};

int main(int argc, char **argv)
{
  CppApplication app;
  MyClass my_class;
  app.exec();
}

Definition at line 130 of file AsyncAudioIO.h.


Member Enumeration Documentation

enum Async::AudioIO::Mode
 

The different modes to open a device in.

Enumerator:
MODE_NONE  No mode. The same as close.
MODE_RD  Read.
MODE_WR  Write.
MODE_RDWR  Both read and write.

Definition at line 136 of file AsyncAudioIO.h.


Constructor & Destructor Documentation

Async::AudioIO::AudioIO const std::string &  dev_name  ) 
 

Default constructor.

Async::AudioIO::~AudioIO void   ) 
 

Destructor.


Member Function Documentation

void Async::AudioIO::clearSamples void   ) 
 

void Async::AudioIO::close void   ) 
 

Close the adio device.

void Async::AudioIO::flushSamples void   ) 
 

bool Async::AudioIO::isFlushing void   )  const [inline]
 

Definition at line 218 of file AsyncAudioIO.h.

bool Async::AudioIO::isFullDuplexCapable void   ) 
 

Check if the audio device is capable of full duplex operation.

Returns:
Return true if the device is capable of full duplex or false if it is not

Mode Async::AudioIO::mode void   )  const [inline]
 

Definition at line 224 of file AsyncAudioIO.h.

bool Async::AudioIO::open Mode  mode  ) 
 

Open the audio device in the specified mode.

Parameters:
mode The mode to open the audio device in. See Async::AudioIO::Mode for more information
Returns:
Returns true on success or else false on failure

int Async::AudioIO::samplesToWrite void   )  const
 

Find out how many samples there are in the output buffer.

Returns:
Returns the number of samples in the output buffer on success or -1 on failure.
This function can be used to find out how many samples there are in the output buffer at the moment. This can for example be used to find out how long it will take before the output buffer has been flushed.

int Async::AudioIO::write short *  buf,
int  count
 

Write samples to the audio device.

Parameters:
buf The buffer that contains the samples to write
count The number of samples in the buffer
Returns:
Returns the number of samples written on success or else -1 on failure


Friends And Related Function Documentation

friend class AudioDevice [friend]
 

Definition at line 284 of file AsyncAudioIO.h.


Member Data Documentation

SigC::Signal0<void> Async::AudioIO::allSamplesFlushed
 

This signal is emitted when all samples in the buffer has been flushed.

When an application is done writing samples to the audio device it should call the flush-method. When all samples has been flushed from the audio device, this signal is emitted.

Definition at line 249 of file AsyncAudioIO.h.

SigC::Signal2<int, short *, int> Async::AudioIO::audioRead
 

A signal that is emitted when a block of audio has been received from the audio device.

Parameters:
buf A buffer containing the read samples
count The number of samples in the buffer

Definition at line 232 of file AsyncAudioIO.h.

SigC::Signal1<void, bool> Async::AudioIO::writeBufferFull
 

A signal that is emitted when the write buffer is full.

Parameters:
is_full Set to true if the buffer is full or false if the buffer full condition has been cleared

Definition at line 239 of file AsyncAudioIO.h.


The documentation for this class was generated from the following file:
Generated on Thu Dec 1 22:30:33 2005 for Async by  doxygen 1.4.4