Skip to content
Snippets Groups Projects
Select Git revision
  • 03cc5544c2a9fa39e23483c2a1d8d07f8fb0dc24
  • master default protected
  • release/202005
  • release/202001
  • release/201912
  • release/201911
  • release/releaseWindowsTestOne
  • release/windowsReleaseTest
  • release/releaseTest
  • release/releaseWindowsTest
  • release/201910
  • release/qt/201910
  • release/windows-test/201910
  • release/201908
  • release/201906
  • release/201905
  • release/201904
  • release/201903
  • release/201902
  • release/201901
  • release/201812
  • 4.0.0
  • 2.2.0
  • 2.1.0
  • 2.0.1
  • 2.0.0
  • 1.4.1
  • 1.4.0
  • 1.3.0
  • 1.2.0
  • 1.1.0
31 results

dtmfgenerator.h

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    dtmfgenerator.h 2.94 KiB
    /*
     * Copyright (C) 2004-2006 Savoir-Faire Linux inc.
     * Author: Yan Morin <yan.morin@savoirfairelinux.com>
     * Author: Laurielle Lea <laurielle.lea@savoirfairelinux.com> 
     *
     * Portions (c) 2003 iptel.org
     *
     * This program is free software; you can redistribute it and/or modify it
     * under the terms of the GNU Library General Public License as published by
     * the Free Software Foundation; either version 3 of the License, or (at your
     * option) any later version.
     * 
     * This program is distributed in the hope that it will be useful, but WITHOUT
     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
     * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
     * License for more details.
     * 
     * You should have received a copy of the GNU Library General Public License
     * along with this library; see the file COPYING.LIB.  If not, write to the
     * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
     * MA 02111-1307, USA.
     *
     */
    
    #ifndef DTMFGENERATOR_H
    #define DTMFGENERATOR_H
    
    #include <exception>
    #include <string.h>
    
    //#include "tonegenerator.h"
    #include "tone.h"
    
    #define NUM_TONES 16
    
    /*
     * 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();
    };
    
    
    /*
     * 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);
    
    };
    
    
    #endif // DTMFGENERATOR_H