dtmfgenerator.h 2.27 KB
Newer Older
savoirfairelinux's avatar
savoirfairelinux committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
/*
 * Copyright (C) 2004 Savoir-Faire Linux inc.
 * Author: Laurielle Lea <laurielle.lea@savoirfairelinux.com> 
 *
 * Portions (c) 2003 iptel.org
 *
 * This library 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 2 of the License, or (at your
 * option) any later version.
 * 
 * This library 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"

#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 : public ToneGenerator 
{
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
65
		float32* sample;         // Currently generated code
savoirfairelinux's avatar
savoirfairelinux committed
66 67 68 69 70
	};

	DTMFState state;
	static const DTMFTone tones[NUM_TONES];

71
	float32* samples[NUM_TONES];        // Generated samples
savoirfairelinux's avatar
savoirfairelinux committed
72 73 74 75 76 77 78 79

public:
	DTMFGenerator();
	~DTMFGenerator();

/*
 * Get n samples of the signal of code code
 */
80
	void getSamples(float32* buffer, size_t n, unsigned char code) throw (DTMFException);
savoirfairelinux's avatar
savoirfairelinux committed
81 82 83 84 85

/*
 * Get next n samples (continues where previous call to
 * genSample or genNextSamples stopped
 */
86
	void getNextSamples(float32* buffer, size_t n) throw (DTMFException);
savoirfairelinux's avatar
savoirfairelinux committed
87 88

private:
89
	float32* generateSample(unsigned char code) throw (DTMFException);
savoirfairelinux's avatar
savoirfairelinux committed
90 91 92 93 94

};


#endif // DTMFGENERATOR_H