Source: audiodevice.h


Annotated List
Files
Globals
Hierarchy
Index
// ##########################################################################
// ####                                                                  ####
// ####                      RTP Audio Server Project                    ####
// ####                    ============================                  ####
// ####                                                                  ####
// #### Audio Device                                                     ####
// ####                                                                  ####
// #### Version 1.00  --  February 23, 2001                              ####
// ####                                                                  ####
// #### Copyright (C) 1999  Thomas Dreibholz                             ####
// ####               2000  Universität Bonn, Abt. IV                    ####
// ####               2001  EMail: Dreibholz@bigfoot.com                 ####
// ####                     WWW:   http://www.bigfoot.com/~dreibholz     ####
// ####                                                                  ####
// ##########################################################################


#ifndef AUDIODEVICE_H
#define AUDIODEVICE_H


#include "system.h"
#include "audiowriterinterface.h"


namespace Coral {


/**
  * This class implements AudioWriterInterface for the audio device.
  *
  * @short   Audio Device
  * @author  Thomas Dreibholz (Dreibholz@bigfoot.com)
  * @version 1.0
  */
class AudioDevice : virtual public AudioWriterInterface
{
   // ====== Constructor/Destructor =========================================
   public:
   /**
     * Constructor.
     *
     * @param name Name of the audio device (normally "/dev/dsp").
     */
   AudioDevice(const char* name = "/dev/dsp");
   
   /**
     * Destructor.
     */
   ~AudioDevice();


   // ====== Status functions ===============================================
   /**
     * Get number of times, sync() has been called.
     *
     * @return Number of times, sync() has been called.
     *
     * @see AudioWriterInterface#sync
     */
   inline cardinal getSyncCount() const;
   
   /**
     * Reset number of times, sync() has been called.
     *
     * @see AudioWriterInterface#sync
     */   
   inline void resetSyncCount();

    
   // ====== AudioQualityInterface implementation ===========================
   /**
     * getSamplingRate() Implementation of AudioQualityInterface.
     *
     * @see AudioQualityInterface#getSamplingRate
     */
   card16 getSamplingRate() const;

   /**
     * getBits() Implementation of AudioQualityInterface.
     *
     * @see AudioQualityInterface#getBits
     */
   card8 getBits() const;

   /**
     * getChannels() Implementation of AudioQualityInterface.
     *
     * @see AudioQualityInterface#getChannels
     */
   card8 getChannels() const;


   /**
     * getByteOrder() Implementation of AudioQualityInterface.
     *
     * @see AudioQualityInterface#getByteOrder
     */
   card16 getByteOrder() const;


   /**
     * getBytesPerSecond() Implementation of AudioQualityInterface.
     *
     * @see AudioQualityInterface#getBytesPerSecond
     */
   cardinal getBytesPerSecond() const;

   /**
     * getBitsPerSample() Implementation of AudioQualityInterface.
     *
     * @see AudioQualityInterface#getBitsPerSample
     */
   cardinal getBitsPerSample() const;


   /**
     * setSamplingRate() Implementation of AdjustableAudioQualityInterface.
     *
     * @see AdjustableAudioQualityInterface#setSamplingRate
     */
   card16 setSamplingRate(const card16 samplingRate);

   /**
     * setBits() Implementation of AdjustableAudioQualityInterface.
     *
     * @see AdjustableAudioQualityInterface#setBits
     */
   card8 setBits(const card8 bits);
   
   /**
     * setChannels() Implementation of AdjustableAudioQualityInterface.
     *
     * @see AdjustableAudioQualityInterface#setChannels
     */
   card8 setChannels(const card8 channels);


   /**
     * setByteOrder() Implementation of AdjustableAudioQualityInterface.
     *
     * @see AdjustableAudioQualityInterface#setByteOrder
     */
   card16 setByteOrder(const card16 byteOrder);


   // ====== AudioInterface implementation ==================================
   /**
     * ready() implementation of AudioWriterInterface
     *
     * @see AudioWriterInterface#ready
     */
   bool ready() const;

   /**
     * sync() implementation of AudioWriterInterface
     *
     * @see AudioWriterInterface#sync
     */
   void sync();

   /**
     * write() implementation of AudioWriterInterface
     *
     * @see AudioWriterInterface#write
     */
   bool write(const void* data, const size_t length);


   // ====== Constants ======================================================
   /**
     * Buffer fill threshold to flush trigger buffer (in percent).
     */
   static const integer TriggerThresholdPercent = 20;

   /**
     * Buffer fill threshold to cut off one fragment of each written block
     * (in percent).
     */
   static const integer CutThresholdPercent = 75;


   // ====== Internal data ==================================================
   private:
   bool     IsReady;

   int      DeviceFD;           // Device and its properties.
   int      DeviceCapabilities;
   int      DeviceFormats;
   int      DeviceBlockSize;
   integer  DeviceFragmentSize;
   integer  DeviceOSpace;

   card16   DeviceSamplingRate; // Format of data written to real device.
   card8    DeviceBits;
   card8    DeviceChannels;
   card16   DeviceByteOrder;

   card16   AudioSamplingRate;  // Format of data written to AudioDevice.
   card8    AudioBits;
   card8    AudioChannels;
   card16   AudioByteOrder;

   integer  TriggerThreshold;   // Trigger and cut thresholds in bytes.
   integer  CutThreshold;

   cardinal SyncCount;          // Buffer management.
   card64   LastWriteTimeStamp;
   integer  Balance;
   char*    TriggerBuffer;
   cardinal TriggerPos;
   bool     Trigger;
};


}


#include "audiodevice.icc"


#endif

Generated by: viper@odin on Fri Feb 23 12:41:26 2001, using kdoc 2.0a36.