diff --git a/src/audio/audiodevice.cpp b/src/audio/audiodevice.cpp index 765fc6be9b1ab3f995370420552a1a48e108aca7..a4672da846bd13b1b2e369824ae9d007fc73690a 100644 --- a/src/audio/audiodevice.cpp +++ b/src/audio/audiodevice.cpp @@ -22,8 +22,8 @@ const double AudioDevice::DEFAULT_RATE = 8000.0; -AudioDevice::AudioDevice(int id, const std::string& apiName, const std::string& name) : - _id(id), _apiName(apiName), _name(name) +AudioDevice::AudioDevice(int id, const std::string& name) : + _id(id), _name(name) { _rate = DEFAULT_RATE; } diff --git a/src/audio/audiodevice.h b/src/audio/audiodevice.h index acdfee46368c8f9d187a6d82556600ad4ef8dabb..64c884be9a133748cb9155b251449a076937ba02 100644 --- a/src/audio/audiodevice.h +++ b/src/audio/audiodevice.h @@ -20,36 +20,62 @@ #ifndef _AUDIO_DEVICE_H #define _AUDIO_DEVICE_H - #include <string> #define AUDIODEVICERATE 8000 /** - * @file audiodevice.c + * @file audiodevice.h * @brief Container device for attribute storage * Have almost only get/set method */ class AudioDevice { public: - AudioDevice(int id, const std::string& apiName, const std::string& name); + /** + * Constructor + * @param id + * @param + * @param + */ + AudioDevice(int id, const std::string& name); + + /** + * Destructor + */ ~AudioDevice(); + /** Default sample rate */ const static double DEFAULT_RATE; + /** + * Read accessor to the ID + * @return int The ID of the audiodevice + */ int getId() { return _id; } - const std::string& getApiName() {return _apiName; } + + /** + * Read accessor to the name + * @return std::string& A string description + */ const std::string& getName() {return _name; } + /** + * Write accessor to the sample rate + * @param rate The sample rate + */ void setRate(double rate) { _rate = rate;} + + /** + * Read accessor to the sample rate + * @return double The sample rate + */ double getRate() { return _rate; } private: /** Integer id of the device, can not be 0 */ int _id; - /** Host API Name, ex: OSS, ALSA */ - std::string _apiName; + /** Name of the device */ std::string _name; diff --git a/src/audio/audiofile.h b/src/audio/audiofile.h index d615e358f42477eaaebd1675a323ecc913811dc7..1de076de13f992ee77ebf2112a51fa5b0a3548be 100644 --- a/src/audio/audiofile.h +++ b/src/audio/audiofile.h @@ -28,22 +28,57 @@ #include "codecDescriptor.h" /** - @author Yan Morin <yan.morin@savoirfairelinux.com> -*/ + * @file audiofile.h + * @brief A class to manage sound files + */ + class AudioFile : public AudioLoop { public: + /** + * Constructor + */ AudioFile(); + + /** + * Destructor + */ ~AudioFile(); - bool loadFile(const std::string& filename, AudioCodec *codec , unsigned int sampleRate/*=8000*/); + /** + * Load a sound file in memory + * @param filename The absolute path to the file + * @param codec The codec to decode and encode it + * @param sampleRate The sample rate to read it + * @return bool True on success + */ + bool loadFile(const std::string& filename, AudioCodec *codec , unsigned int sampleRate); + + /** + * Start the sound file + */ void start() { _start = true; } + + /** + * Stop the sound file + */ void stop() { _start = false; } + + /** + * Tells whether or not the file is playing + * @return bool True if yes + * false otherwise + */ bool isStarted() { return _start; } private: + /** The absolute path to the sound file */ std::string _filename; + + /** Your preferred codec */ AudioCodec* _codec; + + /** Start or not */ bool _start; }; diff --git a/src/audio/audiolayer.cpp b/src/audio/audiolayer.cpp index ff13e4f9c566082804bbfee7751873cd63f8c4fc..183f8231e26709b4687f12d9d5e0eb29284ebaad 100644 --- a/src/audio/audiolayer.cpp +++ b/src/audio/audiolayer.cpp @@ -1,9 +1,8 @@ /* - * Copyright (C) 2005 Savoir-Faire Linux inc. + * Copyright (C) 2008 Savoir-Faire Linux inc. * Author: Yan Morin <yan.morin@savoirfairelinux.com> * Author: Jerome Oufella <jerome.oufella@savoirfairelinux.com> * Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> - * Author: Guillaume Carmel-Archambault <guillaume.carmel-archambault@savoirfairelinux.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,7 +36,6 @@ AudioLayer::AudioLayer(ManagerImpl* manager) : _defaultVolume(100) - , _errorMessage(-1) , _manager(manager) , _PlaybackHandle( NULL ) , _CaptureHandle( NULL ) @@ -123,13 +121,6 @@ AudioLayer::stopStream(void) _urgentBuffer.flush(); } - int -AudioLayer::getDeviceCount() -{ - // TODO: everything - return 1; -} - void AudioLayer::AlsaCallBack( snd_async_handler_t* pcm_callback ) { ( ( AudioLayer *)snd_async_handler_get_callback_private( pcm_callback )) -> playTones(); @@ -326,8 +317,6 @@ AudioLayer::open_device(std::string pcm_p, std::string pcm_c, int flag) if( err = snd_pcm_hw_params_set_format( _CaptureHandle, hwParams, SND_PCM_FORMAT_S16_LE) < 0) _debugAlsa(" Cannot set sample format (%s)\n", snd_strerror(err)); if( err = snd_pcm_hw_params_set_rate_near( _CaptureHandle, hwParams, &rate_in, &dir) < 0) _debugAlsa(" Cannot set sample rate (%s)\n", snd_strerror(err)); if( err = snd_pcm_hw_params_set_channels( _CaptureHandle, hwParams, 1) < 0) _debugAlsa(" Cannot set channel count (%s)\n", snd_strerror(err)); - //if( err = snd_pcm_hw_params_set_period_size_near( _CaptureHandle, hwParams, &period_size_in , &dir) < 0) _debugAlsa(" Cannot set period size (%s)\n", snd_strerror(err)); - //if( err = snd_pcm_hw_params_set_buffer_size_near( _CaptureHandle, hwParams, &buffer_size_in ) < 0) _debugAlsa(" Cannot set buffer size (%s)\n", snd_strerror(err)); if( err = snd_pcm_hw_params_set_period_time_near( _CaptureHandle, hwParams, &period_time , &dir) < 0) _debugAlsa(" Cannot set period time (%s)\n", snd_strerror(err)); if( err = snd_pcm_hw_params_set_buffer_time_near( _CaptureHandle, hwParams, &buffer_time , &dir) < 0) _debugAlsa(" Cannot set buffer time (%s)\n", snd_strerror(err)); if( err = snd_pcm_hw_params_get_period_size( hwParams, &period_size_in , &dir) < 0) _debugAlsa(" Cannot get period size (%s)\n", snd_strerror(err)); diff --git a/src/audio/audiolayer.h b/src/audio/audiolayer.h index 18426aa57af21daf3008ee15b9f0bea541fdc8b6..e56f5ad7a48bf13f2c3adfc3b75d4e5ced95da58 100644 --- a/src/audio/audiolayer.h +++ b/src/audio/audiolayer.h @@ -1,9 +1,8 @@ /* - * Copyright (C) 2004-2005 Savoir-Faire Linux inc. + * Copyright (C) 2004-2008 Savoir-Faire Linux inc. * Author: Yan Morin <yan.morin@savoirfairelinux.com> * Author: Jerome Oufella <jerome.oufella@savoirfairelinux.com> * Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> - * Author: Guillaume Carmel-Archambault <guillaume.carmel-archambault@savoirfairelinux.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,29 +22,40 @@ #ifndef _AUDIO_LAYER_H #define _AUDIO_LAYER_H -#include <cc++/thread.h> // for ost::Mutex - #include "../global.h" #include "audiodevice.h" #include "ringbuffer.h" +#include <cc++/thread.h> // for ost::Mutex #include <vector> #include <alsa/asoundlib.h> #include <iostream> -#include <fstream> #include <istream> #include <sstream> #define FRAME_PER_BUFFER 160 - class RingBuffer; class ManagerImpl; +/** Associate a sound card index to its string description */ typedef std::pair<int , std::string> HwIDPair; +/** + * @file audiolayer.h + * @brief Main sound class. Manages the data transfers between the application and the hardware. + */ + class AudioLayer { public: + /** + * Constructor + * @param manager An instance of managerimpl + */ AudioLayer(ManagerImpl* manager); + + /** + * Destructor + */ ~AudioLayer(void); /** @@ -61,7 +71,7 @@ class AudioLayer { * SFL_PCM_BOTH * @param plugin The alsa plugin ( dmix , default , front , surround , ...) */ - bool openDevice(int, int, int, int, int, std::string); + bool openDevice(int indexIn, int indexOut, int sampleRate, int frameSize, int stream, std::string plugin); /** * Start the capture stream and prepare the playback stream. @@ -107,8 +117,9 @@ class AudioLayer { /** * Send samples to the audio device. - * @params buffer The buffer containing the data to be played ( voice and DTMF ) - * @params toCopy The number of samples, in bytes + * @param buffer The buffer containing the data to be played ( voice and DTMF ) + * @param toCopy The number of samples, in bytes + * @param isTalking If whether or not the conversation is running * @return int The number of bytes played */ int playSamples(void* buffer, int toCopy, bool isTalking); @@ -154,22 +165,50 @@ class AudioLayer { * @return std::vector<std::string> The vector containing the string description of the card */ std::vector<std::string> getSoundCardsInfo( int stream ); + + /** + * Check if the given index corresponds to an existing sound card and supports the specified streaming mode + * @param card An index + * @param stream The stream mode + * SFL_PCM_CAPTURE + * SFL_PCM_PLAYBACK + * SFL_PCM_BOTH + * @return bool True if it exists and supports the mode + * false otherwise + */ bool soundCardIndexExist( int card , int stream ); + + /** + * An index is associated with its string description + * @param description The string description + * @return int Its index + */ int soundCardGetIndex( std::string description ); + /** + * Write accessor to the error state + * @param error The error code + * Could be: ALSA_PLAYBACK_DEVICE + * ALSA_CAPTURE_DEVICE + */ void setErrorMessage(const int& error) { _errorMessage = error; } + + /** + * Read accessor to the error state + * @return int The error code + */ int getErrorMessage() { return _errorMessage; } /** * Get the index of the audio card for capture - * @return _indexIn The index of the card used for capture + * @return int The index of the card used for capture * 0 for the first available card on the system, 1 ... */ int getIndexIn() { return _indexIn; } /** * Get the index of the audio card for playback - * @return _indexOut The index of the card used for playback + * @return int The index of the card used for playback * 0 for the first available card on the system, 1 ... */ int getIndexOut() { return _indexOut; } @@ -193,7 +232,6 @@ class AudioLayer { * @return std::string The name of the audio plugin */ std::string getAudioPlugin( void ) { return _audioPlugin; } - std::ofstream _fstream; /** * Get the current state. Conversation or not * @return bool true if playSamples has been called @@ -201,14 +239,11 @@ class AudioLayer { */ bool getCurrentState( void ) { return _talk; } - int getDeviceCount(); - /** * Toggle echo testing on/off */ void toggleEchoTesting(); - private: /** @@ -231,8 +266,9 @@ class AudioLayer { /** * Callback used for asynchronous playback. * Called when a certain amount of data is written ot the device + * @param pcm_callback The callback pointer */ - static void AlsaCallBack( snd_async_handler_t* ); + static void AlsaCallBack( snd_async_handler_t* pcm_callback); /** * Callback used for asynchronous playback. @@ -244,8 +280,8 @@ class AudioLayer { * Open the specified device. * ALSA Library API * @param pcm_p The string name for the playback device - * pcm_c The string name for the capture device - * flag To indicate which kind of stream you want to open + * @param pcm_c The string name for the capture device + * @param flag To indicate which kind of stream you want to open * SFL_PCM_CAPTURE * SFL_PCM_PLAYBACK * SFL_PCM_BOTH @@ -258,7 +294,7 @@ class AudioLayer { * Copy a data buffer in the internal ring buffer * ALSA Library API * @param buffer The data to be copied - * length The size of the buffer + * @param length The size of the buffer * @return int The number of frames actually copied */ int write( void* buffer, int length); @@ -267,7 +303,7 @@ class AudioLayer { * Read data from the internal ring buffer * ALSA Library API * @param buffer The buffer to stock the read data - * toCopy The number of bytes to get + * @param toCopy The number of bytes to get * @return int The number of frames actually read */ int read( void* buffer, int toCopy); @@ -277,16 +313,31 @@ class AudioLayer { * ALSA Library API */ void handle_xrun_capture( void ); - void handle_xrun_playback( void ); - ManagerImpl* _manager; // augment coupling, reduce indirect access + /** + * Recover from XRUN state for playback + * ALSA Library API + */ + void handle_xrun_playback( void ); + + /** Augment coupling, reduce indirect access */ + ManagerImpl* _manager; /** - * Handles to manipulate capture and playback streams + * Handles to manipulate playback stream * ALSA Library API */ snd_pcm_t* _PlaybackHandle; + + /** + * Handles to manipulate capture stream + * ALSA Library API + */ snd_pcm_t* _CaptureHandle; + + /** + * Alsa parameter - Size of a period in the hardware ring buffer + */ snd_pcm_uframes_t _periodSize; /** @@ -299,6 +350,12 @@ class AudioLayer { */ RingBuffer _urgentBuffer; + /** + * Volume is controlled by the application. Data buffer are modified here to adjust to the right volume selected by the user on the main interface + * @param buffer The buffer to adjust + * @param len The number of bytes + * @param stream The stream mode ( PLAYBACK - CAPTURE ) + */ void * adjustVolume( void * , int , int); /** @@ -316,9 +373,13 @@ class AudioLayer { bool deviceClosed; /** - * Number of audio cards on which stream has been opened + * Number of audio cards on which capture stream has been opened */ int _indexIn; + + /** + * Number of audio cards on which playback stream has been opened + */ int _indexOut; /** @@ -341,12 +402,12 @@ class AudioLayer { /** * Input channel (mic) should be 1 mono */ - unsigned int _inChannel; // mic + unsigned int _inChannel; /** * Output channel (stereo) should be 1 mono */ - unsigned int _outChannel; // speaker + unsigned int _outChannel; /** * Default volume for incoming RTP and Urgent sounds. @@ -358,12 +419,13 @@ class AudioLayer { */ bool _echoTesting; + /** Vector to manage all soundcard index - description association of the system */ std::vector<HwIDPair> IDSoundCards; + /** Contains the current error code */ int _errorMessage; - ost::Mutex _mutex; + ost::Mutex _mutex; }; #endif // _AUDIO_LAYER_H_ - diff --git a/src/audio/audioloop.h b/src/audio/audioloop.h index 647455edf7dc54a1c006e8564bda9ecaf7a4eadf..1e950c2ac75a0e0a7fe3ee0b41a428cd700accbc 100644 --- a/src/audio/audioloop.h +++ b/src/audio/audioloop.h @@ -26,33 +26,58 @@ #include "../global.h" // for int16 declaration /** - * @author Yan Morin <yan.morin@savoirfairelinux.com> + * @file audioloop.h + * @brief Loop on a sound file */ + class AudioLoop { public: + /** + * Constructor + */ AudioLoop(); + + /** + * Virtual destructor + */ virtual ~AudioLoop(); /** - * get the next fragment of the tone + * Get the next fragment of the tone * the function change the intern position, and will loop + * @param output The data buffer * @param nb of int16 to send + * @param volume The volume * @return the number of int16 sent (nb*2) */ int getNext(SFLDataFormat* output, int nb, short volume=100); + + /** + * Reset the pointer position + */ void reset() { _pos = 0; } - unsigned int getMonoSize() { return _size; } + + /** + * Accessor to the size of the buffer + * @return unsigned int The size + */ unsigned int getSize() { return _size; } protected: + /** The data buffer */ SFLDataFormat* _buffer; - int _size; // number of int16 inside the buffer, not the delay - int _pos; // current position, set to 0, when initialize - int _sampleRate; // last samplerate -}; + /** Number of int16 inside the buffer, not the delay */ + int _size; + + /** current position, set to 0, when initialize */ + int _pos; + + /** Sample rate */ + int _sampleRate; +}; #endif // __AUDIOLOOP_H__ diff --git a/src/audio/audiortp.cpp b/src/audio/audiortp.cpp index 01f4729704b3095ac603758289e2f466b42ff9da..e98458bdc36af9fdd2098d8ffe81bb465eb94dcf 100644 --- a/src/audio/audiortp.cpp +++ b/src/audio/audiortp.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (C) 2004-2007 Savoir-Faire Linux inc. + * Copyright (C) 2004-2008 Savoir-Faire Linux inc. * Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> * Author: Alexandre Bourget <alexandre.bourget@savoirfairelinux.com> * Author: Yan Morin <yan.morin@savoirfairelinux.com> @@ -97,7 +97,6 @@ AudioRtp::closeRtpSession () { // AudioRtpRTX Class // //////////////////////////////////////////////////////////////////////////////// AudioRtpRTX::AudioRtpRTX (SIPCall *sipcall, bool sym) - : _fstream("/tmp/audio.gsm", std::ofstream::binary|std::ios::out|std::ios::app) { setCancel(cancelDeferred); time = new ost::Time(); diff --git a/src/audio/audiortp.h b/src/audio/audiortp.h index 0947543ed07596a6be47f45a4c810d2281dcea35..0b735ac890414ed4a27b7556432d18111b0779d1 100644 --- a/src/audio/audiortp.h +++ b/src/audio/audiortp.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2007 Savoir-Faire Linux inc. + * Copyright (C) 2004-2008 Savoir-Faire Linux inc. * Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> * Author: Alexandre Bourget <alexandre.bourget@savoirfairelinux.com> * Author: Yan Morin <yan.morin@savoirfairelinux.com> @@ -24,19 +24,20 @@ #include <cstdio> #include <cstdlib> -#include <fstream> // fstream + iostream for _fstream debugging... #include <iostream> - #include <ccrtp/rtp.h> #include <cc++/numbers.h> #include <samplerate.h> - #include "../global.h" #define UP_SAMPLING 0 #define DOWN_SAMPLING 1 +/** + * @file audiortp.h + * @brief Manage the real-time data transport in a SIP call + */ class SIPCall; @@ -44,101 +45,170 @@ class SIPCall; // Two pair of sockets /////////////////////////////////////////////////////////////////////////////// class AudioRtpRTX : public ost::Thread, public ost::TimerPort { - public: - AudioRtpRTX (SIPCall *, bool); - ~AudioRtpRTX(); - - ost::Time *time; // For incoming call notification - virtual void run (); - - private: - SIPCall* _ca; - ost::RTPSession *_sessionSend; - ost::RTPSession *_sessionRecv; - ost::SymmetricRTPSession *_session; - ost::Semaphore _start; - bool _sym; - - /** When we receive data, we decode it inside this buffer */ - int16* _receiveDataDecoded; - /** Buffers used for send data from the mic */ - unsigned char* _sendDataEncoded; - int16* _intBufferDown; - - /** After that we send the data inside this buffer if there is a format conversion or rate conversion */ - /** Also use for getting mic-ringbuffer data */ - SFLDataFormat* _dataAudioLayer; - - /** Buffers used for sample rate conversion */ - float32* _floatBufferDown; - float32* _floatBufferUp; - - /** Debugging output file */ - std::ofstream _fstream; - FILE* fd; - - /** libsamplerate converter for incoming voice */ - SRC_STATE* _src_state_spkr; - /** libsamplerate converter for outgoing voice */ - SRC_STATE* _src_state_mic; - /** libsamplerate error */ - int _src_err; - - // Variables to process audio stream - int _layerSampleRate; // sample rate for playing sound (typically 44100HZ) - int _codecSampleRate; // sample rate of the codec we use to encode and decode (most of time 8000HZ) - int _layerFrameSize; // length of the sound frame we capture in ms(typically 20ms) - - void initAudioRtpSession(void); - /** - * Get the data from the mic, encode it and send it through the RTP session - */ - void sendSessionFromMic(int); - /** - * Get the data from the RTP packets, decode it and send it to the sound card - */ - void receiveSessionForSpkr(int&); - /** - * Init the buffers used for processing sound data - */ - void initBuffers(void); - /** - * Call the appropriate function, up or downsampling - */ - int reSampleData(int, int ,int); - /** - * Upsample the data from the clock rate of the codec to the sample rate of the layer - * @param int The clock rate of the codec - * @param int The number of samples we have in the buffer - * @return int The number of samples after the operation - */ - int upSampleData(int, int); - /** - * Downsample the data from the sample rate of the layer to the clock rate of the codec - * @param int The clock rate of the codec - * @param int The number of samples we have in the buffer - * @return int The number of samples after the operation - */ - int downSampleData(int, int); - - AudioCodec* _audiocodec; + public: + /** + * Constructor + * @param sipcall The pointer on the SIP call + * @param sym Tells whether or not the voip links are symmetric + */ + AudioRtpRTX (SIPCall* sipcall, bool sym); + + /** + * Destructor + */ + ~AudioRtpRTX(); + + /** For incoming call notification */ + ost::Time *time; + + /** Thread associated method */ + virtual void run (); + + private: + /** A SIP call */ + SIPCall* _ca; + + /** RTP session to send data */ + ost::RTPSession *_sessionSend; + + /** RTP session to receive data */ + ost::RTPSession *_sessionRecv; + + /** RTP symmetric session ( receive and send data in the same session ) */ + ost::SymmetricRTPSession *_session; + + /** Semaphore */ + ost::Semaphore _start; + + /** Is the session symmetric or not */ + bool _sym; + + /** When we receive data, we decode it inside this buffer */ + int16* _receiveDataDecoded; + + /** Buffers used for send data from the mic */ + unsigned char* _sendDataEncoded; + + /** Downsampled int16 buffer */ + int16* _intBufferDown; + + /** After that we send the data inside this buffer if there is a format conversion or rate conversion */ + /** Also use for getting mic-ringbuffer data */ + SFLDataFormat* _dataAudioLayer; + + /** Downsampled float buffer */ + float32* _floatBufferDown; + + /** Upsampled float buffer */ + float32* _floatBufferUp; + + /** libsamplerate converter for incoming voice */ + SRC_STATE* _src_state_spkr; + + /** libsamplerate converter for outgoing voice */ + SRC_STATE* _src_state_mic; + + /** libsamplerate error */ + int _src_err; + + /** Variables to process audio stream: sample rate for playing sound (typically 44100HZ) */ + int _layerSampleRate; + + /** Sample rate of the codec we use to encode and decode (most of time 8000HZ) */ + int _codecSampleRate; + + /** Length of the sound frame we capture in ms(typically 20ms) */ + int _layerFrameSize; + + /** + * Init the RTP session. Create either symmetric or double sessions to manage data transport + * Set the payloads according to the manager preferences + */ + void initAudioRtpSession(void); + + /** + * Get the data from the mic, encode it and send it through the RTP session + * @param timestamp To manage time and synchronizing + */ + void sendSessionFromMic(int timestamp); + + /** + * Get the data from the RTP packets, decode it and send it to the sound card + * @param countTime To manage time and synchronizing + */ + void receiveSessionForSpkr(int& countTime); + + /** + * Init the buffers used for processing sound data + */ + void initBuffers(void); + + /** + * Call the appropriate function, up or downsampling + * @param sampleRate_codec The sample rate of the codec selected to encode/decode the data + * @param nbSamples Number of samples to process + * @param status Type of resampling + * UPSAMPLING + * DOWNSAMPLING + * @return int The number of samples after process + */ + int reSampleData(int sampleRate_codec, int nbSamples, int status); + + /** + * Upsample the data from the clock rate of the codec to the sample rate of the layer + * @param sampleRate_codec The sample rate of the codec selected to encode/decode the data + * @param nbSamples Number of samples to process + * @return int The number of samples after process + */ + int upSampleData(int sampleRate_codec, int nbSamples); + + /** + * Downsample the data from the sample rate of the layer to the clock rate of the codec + * @param sampleRate_codec The sample rate of the codec selected to encode/decode the data + * @param nbSamples Number of samples to process + * @return int The number of samples after process + */ + int downSampleData(int sampleRate_codec, int nbSamples); + + /** The audio codec used during the session */ + AudioCodec* _audiocodec; }; /////////////////////////////////////////////////////////////////////////////// // Main class rtp /////////////////////////////////////////////////////////////////////////////// class AudioRtp { - public: - AudioRtp(); - ~AudioRtp(); - - int createNewSession (SIPCall *); - void closeRtpSession (); - - private: - AudioRtpRTX* _RTXThread; - bool _symmetric; - ost::Mutex _threadMutex; + public: + /** + * Constructor + */ + AudioRtp(); + + /** + * Destructor + */ + ~AudioRtp(); + + /** + * Create a brand new RTP session by calling the AudioRtpRTX constructor + * @param ca A pointer on a SIP call + */ + int createNewSession (SIPCall *ca); + + /** + * Close a RTP session and kills the remaining threads + */ + void closeRtpSession( void ); + + private: + /** The RTP thread */ + AudioRtpRTX* _RTXThread; + + /** Symmetric session or not */ + bool _symmetric; + + /** Mutex */ + ost::Mutex _threadMutex; }; #endif // __AUDIO_RTP_H__ diff --git a/src/audio/codecDescriptor.cpp b/src/audio/codecDescriptor.cpp index 6ff16d5c86680cd639a2c879db8cebebaf879d32..ba6ca1e681b1219f2f61895335ac53766cb76a7a 100644 --- a/src/audio/codecDescriptor.cpp +++ b/src/audio/codecDescriptor.cpp @@ -26,10 +26,6 @@ CodecDescriptor::CodecDescriptor() { - //init(); - //#ifdef HAVE_SPEEX - //_codecMap[PAYLOAD_CODEC_SPEEX] = new CodecSpeex(PAYLOAD_CODEC_SPEEX); // TODO: this is a variable payload! - //#endif } CodecDescriptor::~CodecDescriptor() @@ -54,7 +50,6 @@ CodecDescriptor::init() _nbCodecs = CodecDynamicList.size(); if( _nbCodecs <= 0 ){ _debug(" Error - No codecs available in directory %s\n" , CODECS_DIR); - //exit(0); } int i; diff --git a/src/audio/codecDescriptor.h b/src/audio/codecDescriptor.h index fd5775fa8d52fb7392b60ca5753b4bfa2a9d009a..92093cd32ee33034df0870e43476233f8d463ea6 100644 --- a/src/audio/codecDescriptor.h +++ b/src/audio/codecDescriptor.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2005 Savoir-Faire Linux inc. + * Copyright (C) 2004-2008 Savoir-Faire Linux inc. * Author: Yan Morin <yan.morin@savoirfairelinux.com> * Author: Laurielle Lea <laurielle.lea@savoirfairelinux.com> * Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> @@ -19,37 +19,36 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - #ifndef __CODEC_DESCRIPTOR_H__ #define __CODEC_DESCRIPTOR_H__ #include <string> #include <map> #include <vector> -// To read directories content #include <dirent.h> #include "../global.h" #include "../user_cfg.h" #include "codecs/audiocodec.h" +/** Enumeration that contains known audio payloads */ typedef enum { -// http://www.iana.org/assignments/rtp-parameters -// http://www.gnu.org/software/ccrtp/doc/refman/html/formats_8h.html#a0 -// 0 PCMU A 8000 1 [RFC3551] + // http://www.iana.org/assignments/rtp-parameters + // http://www.gnu.org/software/ccrtp/doc/refman/html/formats_8h.html#a0 + // 0 PCMU A 8000 1 [RFC3551] PAYLOAD_CODEC_ULAW = 0, -// 3 GSM A 8000 1 [RFC3551] + // 3 GSM A 8000 1 [RFC3551] PAYLOAD_CODEC_GSM = 3, -// 8 PCMA A 8000 1 [RFC3551] + // 8 PCMA A 8000 1 [RFC3551] PAYLOAD_CODEC_ALAW = 8, -// http://www.ietf.org/rfc/rfc3952.txt -// 97 iLBC/8000 + // http://www.ietf.org/rfc/rfc3952.txt + // 97 iLBC/8000 PAYLOAD_CODEC_ILBC_20 = 97, PAYLOAD_CODEC_ILBC_30 = 98, -// http://www.speex.org/drafts/draft-herlein-speex-rtp-profile-00.txt -// 97 speex/8000 -// http://support.xten.com/viewtopic.php?p=8684&sid=3367a83d01fdcad16c7459a79859b08e -// 100 speex/16000 + // http://www.speex.org/drafts/draft-herlein-speex-rtp-profile-00.txt + // 97 speex/8000 + // http://support.xten.com/viewtopic.php?p=8684&sid=3367a83d01fdcad16c7459a79859b08e + // 100 speex/16000 PAYLOAD_CODEC_SPEEX_8000 = 110, PAYLOAD_CODEC_SPEEX_16000 = 111, PAYLOAD_CODEC_SPEEX_32000 = 112 @@ -61,200 +60,212 @@ typedef enum { typedef std::map<AudioCodecType, std::string> CodecMap; /** The struct to reflect the order the user wants to use the codecs */ typedef std::vector<AudioCodecType> CodecOrder; - +/** Enable us to keep the handle pointer on the codec dynamicaly loaded so that we could destroy when we dont need it anymore */ typedef std::pair<AudioCodec* , void*> CodecHandlePointer; +/** Maps a pointer on an audiocodec object to a payload */ typedef std::map<AudioCodecType , AudioCodec*> CodecsMap; -class CodecDescriptor { -public: - /** - * Initialize all codec - */ - CodecDescriptor(); - ~CodecDescriptor(); - - /** - * Accessor to data structures - */ - CodecsMap& getCodecsMap() { return _CodecsMap; } - CodecOrder& getActiveCodecs() { return _codecOrder; } - - /** - * Get codec name by its payload - * @param payload the payload looked for - * same as getPayload() - * @return the name of the codec - */ - std::string getCodecName(AudioCodecType payload); - - /** - * Get the codec object associated with the payload - * @param payload The payload looked for - * @return AudioCodec* A pointer on a AudioCodec object - */ - AudioCodec* getCodec( AudioCodecType payload ); - - /** - * Initialiaze the map with all the supported codecs, even those inactive - */ - void init(); - - /** - * Set the default codecs order - */ - void setDefaultOrder(); - - /** - * Check in the map codec if the specified codec is supported - * @param payload unique identifier of a codec (RFC) - * @return true if the codec specified is supported - * false otherwise - */ - bool isActive(AudioCodecType payload); - - /** - * Remove the codec with payload payload from the list - * @param payload the codec to erase - */ - void removeCodec(AudioCodecType payload); - - /** - * Add a codec in the list. - * @param payload the codec to add - */ - void addCodec(AudioCodecType payload); - - /** - * Get the bit rate of the specified codec. - * @param payload The payload of the codec - * @return double The bit rate - */ - double getBitRate(AudioCodecType payload); - - /** - * Get the bandwidth for one call with the specified codec. - * The value has been calculated with the further information: - * RTp communication, SIP protocol (the value with IAX2 is very close), no RTCP, one simultaneous call, for one channel (the incoming one). - * @param payload The payload of the codec - * @return double The bandwidth - */ - double getBandwidthPerCall(AudioCodecType payload); - - - /** - * Get the clock rate of the specified codec - * @param payload The payload of the codec - * @return int The clock rate of the specified codec - */ - int getSampleRate(AudioCodecType payload); - - /** - * Get the number of channels - * @param payload The payload of the codec - * @return int Number of channels - */ - int getChannel(AudioCodecType payload); - -/** - * Set the order of codecs by their payload - * @param list The ordered list sent by DBus +/* + * @file codecdescriptor.h + * @brief Handle audio codecs, load them in memory */ - void saveActiveCodecs(const std::vector<std::string>& list); - - - std::string getDescription( std::string ); - /** - * Get the number of codecs loaded in dynamic memory - */ - int getCodecsNumber( void ) { return _nbCodecs; } - - /** - * Unreferences the codecs loaded in memory - */ - void deleteHandlePointer( void ); - - /** - * Get the first element of the CodecsMap struct. - * i.e the one with the lowest payload - * @return AudioCodec The pointer on the codec object - */ - AudioCodec* getFirstCodecAvailable( void ); - -private: - - /** - * Scan the installation directory ( --prefix configure option ) - * And load the dynamic library - * @return std::vector<AudioCodec*> The list of the codec object successfully loaded in memory - */ - std::vector<AudioCodec *> scanCodecDirectory( void ); - - /** - * Load a codec - * @param std::string The path of the shared ( dynamic ) library. - * @return AudioCodec* the pointer of the object loaded. - */ - AudioCodec* loadCodec( std::string ); - - /** - * Unload a codec - * @param CodecHandlePointer The map containing the pointer on the object and the pointer on the handle function - */ - void unloadCodec( CodecHandlePointer ); - - /** - * Check if the files found in searched directories seems valid - * @param std::string The name of the file - * @return true if the file name begins with libcodec_ and ends with .so - * false otherwise - */ - bool seemsValid( std::string ); - - /** - * Check if the codecs shared library has already been scanned during the session - * Useful not to load twice the same codec saved in the different directory - * @param std::string The complete name of the shared directory ( without the path ) - * @return true if the codecs has been scanned - * false otherwise - */ - bool alreadyInCache( std::string ); - - /** - * Check if the audiocodec object has been successfully created - * @param payload The payload of the codec - * @return true if the audiocodec has been created - * false otherwise - */ - bool isCodecLoaded( int payload ); - - /** - * Map the payload of a codec and the object associated ( AudioCodec * ) - */ - CodecsMap _CodecsMap; - - /** - * Vector containing the order of the codecs - */ - CodecOrder _codecOrder; - - /** - * Vector containing the complete name of the codec shared library scanned - */ - std::vector<std::string> _Cache; - - /** - * Number of codecs loaded - */ - int _nbCodecs; - - /** - * Vector containing pairs - * Pair between pointer on function handle and pointer on audiocodec object - */ - std::vector< CodecHandlePointer > _CodecInMemory; +class CodecDescriptor { + public: + /** + * Constructor + */ + CodecDescriptor(); + + /** + * Destructor + */ + ~CodecDescriptor(); + + /** + * Accessor to data structures + * @return CodecsMap& The available codec + */ + CodecsMap& getCodecsMap() { return _CodecsMap; } + + /** + * Accessor to data structures + * @return CodecOrder& The list that reflects the user's choice + */ + CodecOrder& getActiveCodecs() { return _codecOrder; } + + /** + * Get codec name by its payload + * @param payload the payload looked for + * same as getPayload() + * @return std::string The name of the codec + */ + std::string getCodecName(AudioCodecType payload); + + /** + * Get the codec object associated with the payload + * @param payload The payload looked for + * @return AudioCodec* A pointer on a AudioCodec object + */ + AudioCodec* getCodec( AudioCodecType payload ); + + /** + * Initialiaze the map with all the supported codecs, even those inactive + */ + void init(); + + /** + * Set the default codecs order + */ + void setDefaultOrder(); + + /** + * Check in the map codec if the specified codec is supported + * @param payload unique identifier of a codec (RFC) + * @return bool True if the codec specified is supported + * false otherwise + */ + bool isActive(AudioCodecType payload); + + /** + * Remove the codec with payload payload from the list + * @param payload the codec to erase + */ + void removeCodec(AudioCodecType payload); + + /** + * Add a codec in the list. + * @param payload the codec to add + */ + void addCodec(AudioCodecType payload); + + /** + * Get the bit rate of the specified codec. + * @param payload The payload of the codec + * @return double The bit rate + */ + double getBitRate(AudioCodecType payload); + + /** + * Get the bandwidth for one call with the specified codec. + * The value has been calculated with the further information: + * RTp communication, SIP protocol (the value with IAX2 is very close), no RTCP, one simultaneous call, for one channel (the incoming one). + * @param payload The payload of the codec + * @return double The bandwidth + */ + double getBandwidthPerCall(AudioCodecType payload); -}; + /** + * Get the clock rate of the specified codec + * @param payload The payload of the codec + * @return int The clock rate of the specified codec + */ + int getSampleRate(AudioCodecType payload); + + /** + * Get the number of channels + * @param payload The payload of the codec + * @return int Number of channels + */ + int getChannel(AudioCodecType payload); + + /** + * Set the order of codecs by their payload + * @param list The ordered list sent by DBus + */ + void saveActiveCodecs(const std::vector<std::string>& list); + + /** + * Get the number of codecs loaded in dynamic memory + * @return int The number + */ + int getCodecsNumber( void ) { return _nbCodecs; } + + /** + * Unreferences the codecs loaded in memory + */ + void deleteHandlePointer( void ); + + /** + * Get the first element of the CodecsMap struct. + * i.e the one with the lowest payload + * @return AudioCodec The pointer on the codec object + */ + AudioCodec* getFirstCodecAvailable( void ); + + private: + + /** + * Scan the installation directory ( --prefix configure option ) + * And load the dynamic library + * @return std::vector<AudioCodec*> The list of the codec object successfully loaded in memory + */ + std::vector<AudioCodec *> scanCodecDirectory( void ); + + /** + * Load a codec + * @param std::string The path of the shared ( dynamic ) library. + * @return AudioCodec* the pointer of the object loaded. + */ + AudioCodec* loadCodec( std::string ); + + /** + * Unload a codec + * @param CodecHandlePointer The map containing the pointer on the object and the pointer on the handle function + */ + void unloadCodec( CodecHandlePointer ); + + /** + * Check if the files found in searched directories seems valid + * @param std::string The name of the file + * @return bool True if the file name begins with libcodec_ and ends with .so + * false otherwise + */ + bool seemsValid( std::string ); + + /** + * Check if the codecs shared library has already been scanned during the session + * Useful not to load twice the same codec saved in the different directory + * @param std::string The complete name of the shared directory ( without the path ) + * @return bool True if the codecs has been scanned + * false otherwise + */ + bool alreadyInCache( std::string ); + + /** + * Check if the audiocodec object has been successfully created + * @param payload The payload of the codec + * @return bool True if the audiocodec has been created + * false otherwise + */ + bool isCodecLoaded( int payload ); + + /** + * Map the payload of a codec and the object associated ( AudioCodec * ) + */ + CodecsMap _CodecsMap; + + /** + * Vector containing the order of the codecs + */ + CodecOrder _codecOrder; + + /** + * Vector containing the complete name of the codec shared library scanned + */ + std::vector<std::string> _Cache; + + /** + * Number of codecs loaded + */ + int _nbCodecs; + + /** + * Vector containing pairs + * Pair between pointer on function handle and pointer on audiocodec object + */ + std::vector< CodecHandlePointer > _CodecInMemory; +}; #endif // __CODEC_DESCRIPTOR_H__ diff --git a/src/audio/common.h b/src/audio/common.h index fb2cb85c834069230c1f350bb2ed82047d00146e..5be3d28e17ef2af2cf2548cc4d4d037e0436f953 100644 --- a/src/audio/common.h +++ b/src/audio/common.h @@ -41,12 +41,10 @@ typedef signed short int16; /**< An 16 bit signed integer (2s complement) */ typedef signed int int32; /**< An 32 bit signed integer (2s complement) */ typedef unsigned int uint; /**< An unsigned integer or at least 32 bits */ - #ifndef NULL #define NULL 0 /**< Used to represent a null pointer type */ #endif - #ifdef _MSC_VER // Compiling for Microsoft Visual C++ #define DEBUGGER { _asm int 3 } /**< Invoke debugger */ @@ -59,17 +57,13 @@ typedef unsigned int uint; /**< An unsigned integer or at least 32 bits */ #define DEBUGGER /**< Invoke debugger */ #define IMPORT /**< Mark a function which is to be imported from a DLL */ #define EXPORT /**< Mark a function to be exported from a DLL */ -//#define ASSERT(c) /**< Assert that expression 'c' is true */ #endif - #ifdef DEBUG #define ASSERT_DEBUG(c) ASSERT(c) /**< Assert that expression 'c' is true (when compiled for debugging)*/ #else #define ASSERT_DEBUG(c) #endif - #endif - diff --git a/src/audio/dtmf.h b/src/audio/dtmf.h index b3713eadd050fbd404c279779ed55dc377a1a61c..9041514d48feaa2c70ce9a043f2b21b77b823108 100644 --- a/src/audio/dtmf.h +++ b/src/audio/dtmf.h @@ -28,29 +28,39 @@ #include "dtmfgenerator.h" /** - * DMTF library to generate a dtmf sample + * @file dtmf.h + * @brief DMTF library to generate a dtmf sample */ class DTMF { -public: - /** - * Create a new DTMF. - * @param samplingRate frequency of the sample (ex: 8000 hz) - */ - DTMF (unsigned int sampleRate); - ~DTMF (void); - - void startTone (char); - /** - * Copy the sound inside the sampling* buffer - * @param buffer : a SFLDataFormat* buffer - * @param n : - */ - bool generateDTMF (SFLDataFormat* buffer, size_t n); + public: + /** + * Create a new DTMF. + * @param samplingRate frequency of the sample (ex: 8000 hz) + */ + DTMF (unsigned int sampleRate); + + /** + * Destructor + */ + ~DTMF (void); - char currentTone; - char newTone; + /** + * Start the done for th given dtmf + * @param code The DTMF code + */ + void startTone(char code); + + /** + * Copy the sound inside the sampling* buffer + * @param buffer : a SFLDataFormat* buffer + * @param n : The size to generate + */ + bool generateDTMF (SFLDataFormat* buffer, size_t n); - DTMFGenerator dtmfgenerator; + char currentTone; + char newTone; + + DTMFGenerator dtmfgenerator; }; #endif // __KEY_DTMF_H_ diff --git a/src/audio/dtmfgenerator.h b/src/audio/dtmfgenerator.h index 71b25852e513112f270142914b908f185e8df009..376d31ce82b6b93ec974127b4f1c2edb87f7c4e2 100644 --- a/src/audio/dtmfgenerator.h +++ b/src/audio/dtmfgenerator.h @@ -28,85 +28,108 @@ #include <exception> #include <string.h> -//#include "tonegenerator.h" #include "tone.h" #define NUM_TONES 16 /* - * DMTF Generator Exception + * @file dtmfgenerator.h + * @brief DMTF Generator Exception */ class DTMFException : public std::exception { -private: - const char* reason; -public: - DTMFException(const char* _reason) throw(); - virtual ~DTMFException() throw(); - virtual const char* what() const throw(); + private: + /** Message */ + const char* reason; + public: + /** + * Constructor + * @param _reason An error message + */ + DTMFException(const char* _reason) throw(); + + /** + * Destructor + */ + virtual ~DTMFException() throw(); + + /** + * @return const char* The error + */ + virtual const char* what() const throw(); }; - /* - * DTMF Tone Generator + * @file dtmfgenerator.h + * @brief DTMF Tone Generator */ class DTMFGenerator { -private: - struct DTMFTone { - unsigned char code; // Code of the tone - int lower; // Lower frequency - int higher; // Higher frequency - }; - -/* - * State of the DTMF generator - */ - struct DTMFState { - unsigned int offset; // Offset in the sample currently being played - SFLDataFormat* sample; // Currently generated code - }; - - DTMFState state; - static const DTMFTone tones[NUM_TONES]; - - SFLDataFormat* samples[NUM_TONES]; // Generated samples - - /** - * Sampling rate of generated dtmf - */ - int _sampleRate; - Tone tone; - -public: - /** - * DTMF Generator contains frequency of each keys - * and can build one DTMF. - * @param sampleRate frequency of the sample (ex: 8000 hz) - */ - DTMFGenerator(unsigned int sampleRate); - ~DTMFGenerator(); - -/* - * Get n samples of the signal of code code - * @param buffer a SFLDataFormat pointer to an allocated buffer - * @param n number of sampling to get, should be lower or equal to buffer size - * @parma code dtmf code to get sound - */ - void getSamples(SFLDataFormat* buffer, size_t n, unsigned char code) throw (DTMFException); - -/* - * Get next n samples (continues where previous call to - * genSample or genNextSamples stopped - * @param buffer a SFLDataFormat pointer to an allocated buffer - * @param n number of sampling to get, should be lower or equal to buffer size - */ - void getNextSamples(SFLDataFormat* buffer, size_t n) throw (DTMFException); - -private: - SFLDataFormat* generateSample(unsigned char code) throw (DTMFException); - + private: + /** Struct to handle a DTMF */ + struct DTMFTone { + unsigned char code; /** Code of the tone */ + int lower; /** Lower frequency */ + int higher; /** Higher frequency */ + }; + + /** State of the DTMF generator */ + struct DTMFState { + unsigned int offset; /** Offset in the sample currently being played */ + SFLDataFormat* sample; /** Currently generated code */ + }; + + /** State of the DTMF generator */ + DTMFState state; + + /** The different kind of tones */ + static const DTMFTone tones[NUM_TONES]; + + /** Generated samples */ + SFLDataFormat* samples[NUM_TONES]; + + /** Sampling rate of generated dtmf */ + int _sampleRate; + + /** A tone object */ + Tone tone; + + public: + /** + * DTMF Generator contains frequency of each keys + * and can build one DTMF. + * @param sampleRate frequency of the sample (ex: 8000 hz) + */ + DTMFGenerator(unsigned int sampleRate); + + /** + * Destructor + */ + ~DTMFGenerator(); + + /* + * Get n samples of the signal of code code + * @param buffer a SFLDataFormat pointer to an allocated buffer + * @param n number of sampling to get, should be lower or equal to buffer size + * @param code dtmf code to get sound + */ + void getSamples(SFLDataFormat* buffer, size_t n, unsigned char code) throw (DTMFException); + + /* + * Get next n samples (continues where previous call to + * genSample or genNextSamples stopped + * @param buffer a SFLDataFormat pointer to an allocated buffer + * @param n number of sampling to get, should be lower or equal to buffer size + */ + void getNextSamples(SFLDataFormat* buffer, size_t n) throw (DTMFException); + + private: + /** + * Generate samples for a specific dtmf code + * @param code The code + * @return SFLDataFormat* The generated data + */ + SFLDataFormat* generateSample(unsigned char code) throw (DTMFException); }; - #endif // DTMFGENERATOR_H diff --git a/src/audio/ringbuffer.h b/src/audio/ringbuffer.h index 1a06c8e723b849af13784ed60e59a8efd60efc5e..b6ae54473a8e3db2d8f44f83bb1fba48c4fba3a0 100644 --- a/src/audio/ringbuffer.h +++ b/src/audio/ringbuffer.h @@ -26,40 +26,81 @@ typedef unsigned char* samplePtr; class RingBuffer { - public: - RingBuffer(int size); - ~RingBuffer(); + public: + /** + * Constructor + * @param size Size of the buffer to create + */ + RingBuffer(int size); - // To set counters to 0 - void flush (void); - - // - // For the writer only: - // - int AvailForPut (void) const; - int Put (void*, int, unsigned short volume = 100); + /** + * Destructor + */ + ~RingBuffer(); - // - // For the reader only: - // - int AvailForGet (void) const; - int Get (void *, int, unsigned short volume = 100); - int Discard(int); + /** + * Reset the counters to 0 + */ + void flush (void); - int Len() const; - /** - * Debug function print mEnd, mStart, mBufferSize - */ - void debug(); - - private: + /** + * To get how much space is available in the buffer to write in + * @return int The available size + */ + int AvailForPut (void) const; - int mStart; - int mEnd; - int mBufferSize; - samplePtr mBuffer; -}; + /** + * Write data in the ring buffer + * @param buffer Data to copied + * @param toCopy Number of bytes to copy + * @param volume The volume + * @return int Number of bytes copied + */ + int Put (void* buffer, int toCopy, unsigned short volume = 100); -#endif /* __RING_BUFFER__ */ + /** + * To get how much space is available in the buffer to read in + * @return int The available size + */ + int AvailForGet (void) const; + + /** + * Get data in the ring buffer + * @param buffer Data to copied + * @param toCopy Number of bytes to copy + * @param volume The volume + * @return int Number of bytes copied + */ + int Get (void* buffer, int toCopy, unsigned short volume = 100); + + /** + * Discard data from the buffer + * @param toDiscard Number of bytes to discard + * @return int Number of bytes discarded + */ + int Discard(int toDiscard); + /** + * Total length of the ring buffer + * @return int + */ + int Len() const; + + /** + * Debug function print mEnd, mStart, mBufferSize + */ + void debug(); + private: + + /** Pointer on the first data */ + int mStart; + /** Pointer on the last data */ + int mEnd; + /** Buffer size */ + int mBufferSize; + /** Data */ + samplePtr mBuffer; +}; + +#endif /* __RING_BUFFER__ */ diff --git a/src/audio/tone.h b/src/audio/tone.h index a9de7a3d34fd351edab86ce735cd3c34e97582c3..e75a865e7d2fd45287514e892c144f3565fe0181 100644 --- a/src/audio/tone.h +++ b/src/audio/tone.h @@ -29,17 +29,24 @@ #define TONE_NBCOUNTRY 7 /** - * Tone sample (dial, busy, ring, congestion) - * @author Yan Morin <yan.morin@savoirfairelinux.com> + * @file tone.h + * @brief Tone sample (dial, busy, ring, congestion) */ class Tone : public AudioLoop { public: /** + * Constructor * @param definition String that contain frequency/time of the tone * @param sampleRate SampleRating of audio tone */ Tone(const std::string& definition, unsigned int sampleRate); + + /** + * Destructor + */ ~Tone(); + + /** The different kind of tones */ enum TONEID { TONE_DIALTONE = 0, TONE_BUSY, @@ -47,8 +54,12 @@ public: TONE_CONGESTION, TONE_NULL }; + /** - * add a simple or double sin to the buffer, it double the sin in stereo + * Add a simple or double sin to the buffer, it double the sin in stereo + * @param buffer The data + * @param frequency1 The first frequency + * @param frequency2 The second frequency * @param nb are the number of int16 (mono) to generate * by example nb=5 generate 10 int16, 5 for the left, 5 for the right */ @@ -58,9 +69,11 @@ private: /** * allocate the memory with the definition + * @param definition String that contain frequency/time of the tone. */ void genBuffer(const std::string& definition); + /** Sample rate */ unsigned int _sampleRate; }; diff --git a/src/audio/tonegenerator.cpp b/src/audio/tonegenerator.cpp index 2ef0ac0b276bcce60700e3c3a3fdda5d6f2ceb53..37cfd1eaaab1def74be072e130876ce41b129873 100644 --- a/src/audio/tonegenerator.cpp +++ b/src/audio/tonegenerator.cpp @@ -41,9 +41,6 @@ ToneGenerator::~ToneGenerator (void) { /** * Calculate superposition of 2 sinus * - * @param lower frequency - * @param higher frequency - * @param ptr for result buffer */ void ToneGenerator::generateSin (int lowerfreq, int higherfreq, int16* ptr, int len) const { diff --git a/src/audio/tonegenerator.h b/src/audio/tonegenerator.h index b649398378e4d31b6d33b51e8872ead688e45c7b..062caebd518387c129a363a70702ce454331e764 100644 --- a/src/audio/tonegenerator.h +++ b/src/audio/tonegenerator.h @@ -27,35 +27,49 @@ #include "../global.h" /** - * Sine generator to create tone with string definition + * @file tonegenerator.h + * @brief Sine generator to create tone with string definition */ + class ToneGenerator { -public: - ToneGenerator (unsigned int sampleRate); - ~ToneGenerator (void); - - /** - * Calculate sinus with superposition of 2 frequencies - */ - void generateSin (int, int, int16 *, int len) const; - - - /////////////////////////// - // Public members variable - ////////////////////////// - int16 *sample; - int freq1, freq2; - int time; - int totalbytes; - -private: - /* - * Initialisation of the supported tones according to the countries. - */ - void initTone (void); - - int16 _buf[SIZEBUF]; - int _sampleRate; + public: + /** + * Constructor + * @param sampleRate The sample rate of the generated samples + */ + ToneGenerator (unsigned int sampleRate); + + /** + * Destructor + */ + ~ToneGenerator (void); + + /** + * Calculate sinus with superposition of 2 frequencies + * @param lowerfreq Lower frequency + * @param higherfreq Higher frequency + * @param ptr For result buffer + * @param len The length of the data to be generated + */ + void generateSin (int, int, int16 *, int len) const; + + + /////////////////////////// + // Public members variable + ////////////////////////// + int16 *sample; + int freq1, freq2; + int time; + int totalbytes; + + private: + /* + * Initialisation of the supported tones according to the countries. + */ + void initTone (void); + + int16 _buf[SIZEBUF]; + int _sampleRate; }; #endif // __TONE_GENRATOR_H__ diff --git a/src/audio/tonelist.h b/src/audio/tonelist.h index 20d681ccac17a4f4b59f8dc2bd6d3103a2151ce1..a381193c025b9d4cad54a4a527bbdc84c34397ed 100644 --- a/src/audio/tonelist.h +++ b/src/audio/tonelist.h @@ -25,13 +25,22 @@ #include "tone.h" /** - * @author Yan Morin <yan.morin@savoirfairelinux.com> + * @file tonelist.h + * @brief Manages the different kind of tones according to the country */ class ToneList { public: + /** + * Constructor + */ ToneList(); + + /** + * Destructor + */ ~ToneList(); + /** Countries */ enum COUNTRYID { ZID_NORTH_AMERICA = 0, ZID_FRANCE, @@ -43,22 +52,26 @@ public: }; /** - * get the string definition of a tone + * Get the string definition of a tone * return the default country or default tone if id are invalid - * @param country the country Id, see ToneList constructor for the list - * @param toneId toneId - * @return a string definition of the tone + * @param countryId The country Id, see ToneList constructor for the list + * @param toneId The toneId + * @return std::string A string definition of the tone */ std::string getDefinition(COUNTRYID countryId, Tone::TONEID toneId); + /** - * get the country id associate to a country name + * Get the country id associate to a country name * return the default country id if not found * The default tone/country are set inside the ToneList constructor * @param countryName countryName, see the ToneList constructor list - * @return Country Id or default Id + * @return COUNTRYID Country Id or default Id */ COUNTRYID getCountryId(const std::string& countryName); + + /** @return int The number of tones */ int getNbTone() { return _nbTone; } + private: void initToneDefinition(); std::string _toneZone[TONE_NBCOUNTRY][TONE_NBTONE]; diff --git a/src/iaxaccount.h b/src/iaxaccount.h index 2cdfb6232ad0dc338cdb708d69bfdbb7ed34b7f2..0d52718e5791b8c76fe4306614a579a78b5ca8ce 100644 --- a/src/iaxaccount.h +++ b/src/iaxaccount.h @@ -25,7 +25,7 @@ /** * @file: iaxaccount.h - * @brief: an IAX Account specify IAX specific functions and objects (IAXCall/IAXVoIPLink) + * @brief An IAX Account specify IAX specific functions and objects (IAXCall/IAXVoIPLink) */ class IAXAccount : public Account { diff --git a/src/iaxcall.h b/src/iaxcall.h index ccfe8c41d5dd3e69b9ba9ef1089cf52c0b225a8f..1fdf5d75e68c78ba1b0721fa39bd532bff355e28 100644 --- a/src/iaxcall.h +++ b/src/iaxcall.h @@ -26,7 +26,7 @@ /** * @file: iaxcall.h - * @brief: IAXCall are IAX implementation of a normal Call + * @brief IAXCall are IAX implementation of a normal Call */ class IAXCall : public Call