~ubuntu-branches/ubuntu/saucy/sflphone/saucy

« back to all changes in this revision

Viewing changes to sflphone-common/src/audio/sound/dtmfgenerator.h

  • Committer: Bazaar Package Importer
  • Author(s): Francois Marier
  • Date: 2010-12-24 16:33:55 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20101224163355-tkvvikqxbrbav6up
Tags: 0.9.11-1
* New upstream release
* Add new build dependencies on libwebkit-dev and libyaml-dev

* Bump Standards-Version up to 3.9.1
* Bump debhelper compatibility to 8
* Patch another typo in the upstream code (lintian notice)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 *  Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010 Savoir-Faire Linux Inc.
3
3
 * Author: Yan Morin <yan.morin@savoirfairelinux.com>
4
 
 * Author: Laurielle Lea <laurielle.lea@savoirfairelinux.com> 
 
4
 * Author: Laurielle Lea <laurielle.lea@savoirfairelinux.com>
5
5
 *
6
6
 * Portions (c) 2003 iptel.org
7
7
 *
9
9
 * under the terms of the GNU Library General Public License as published by
10
10
 * the Free Software Foundation; either version 3 of the License, or (at your
11
11
 * option) any later version.
12
 
 * 
 
12
 *
13
13
 * This program is distributed in the hope that it will be useful, but WITHOUT
14
14
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15
15
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
16
16
 * License for more details.
17
 
 * 
 
17
 *
18
18
 * You should have received a copy of the GNU Library General Public License
19
19
 * along with this library; see the file COPYING.LIB.  If not, write to the
20
20
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
49
49
 */
50
50
class DTMFException : public std::exception
51
51
{
52
 
  private:
53
 
 
54
 
    /** Message */
55
 
    const char* reason;
56
 
  public:
57
 
    /**
58
 
     * Constructor
59
 
     * @param _reason An error message
60
 
     */
61
 
    DTMFException(const char* _reason) throw();
62
 
 
63
 
    /**
64
 
     * Destructor
65
 
     */
66
 
    virtual ~DTMFException() throw();
67
 
/*
68
 
    // Copy Constructor
69
 
    DTMFException(const DTMFException& rh) throw();
70
 
 
71
 
    // Assignment Operator
72
 
    DTMFException& operator=( const DTMFException& rh) throw();
73
 
*/ 
74
 
    /**
75
 
     * @return const char* The error
76
 
     */
77
 
    virtual const char* what() const throw();
 
52
    private:
 
53
 
 
54
        /** Message */
 
55
        const char* reason;
 
56
    public:
 
57
        /**
 
58
         * Constructor
 
59
         * @param _reason An error message
 
60
         */
 
61
        DTMFException (const char* _reason) throw();
 
62
 
 
63
        /**
 
64
         * Destructor
 
65
         */
 
66
        virtual ~DTMFException() throw();
 
67
        /*
 
68
            // Copy Constructor
 
69
            DTMFException(const DTMFException& rh) throw();
 
70
 
 
71
            // Assignment Operator
 
72
            DTMFException& operator=( const DTMFException& rh) throw();
 
73
        */
 
74
        /**
 
75
         * @return const char* The error
 
76
         */
 
77
        virtual const char* what() const throw();
78
78
};
79
79
 
80
80
/*
81
81
 * @file dtmfgenerator.h
82
82
 * @brief DTMF Tone Generator
83
83
 */
84
 
class DTMFGenerator 
 
84
class DTMFGenerator
85
85
{
86
 
  private:
87
 
    /** Struct to handle a DTMF */
88
 
    struct DTMFTone {
89
 
      unsigned char code; /** Code of the tone */
90
 
      int lower;          /** Lower frequency */
91
 
      int higher;         /** Higher frequency */
92
 
    };
93
 
 
94
 
     /** State of the DTMF generator */
95
 
    struct DTMFState {
96
 
      unsigned int offset;   /** Offset in the sample currently being played */
97
 
      SFLDataFormat* sample;         /** Currently generated code */
98
 
    };
99
 
 
100
 
    /** State of the DTMF generator */
101
 
    DTMFState state;
102
 
    
103
 
    /** The different kind of tones */
104
 
    static const DTMFTone tones[NUM_TONES];
105
 
 
106
 
    /** Generated samples */
107
 
    SFLDataFormat* samples[NUM_TONES];  
108
 
 
109
 
    /** Sampling rate of generated dtmf */
110
 
    int _sampleRate;
111
 
 
112
 
    /** A tone object */
113
 
    Tone tone;
114
 
 
115
 
  public:
116
 
    /**
117
 
     * DTMF Generator contains frequency of each keys
118
 
     * and can build one DTMF.
119
 
     * @param sampleRate frequency of the sample (ex: 8000 hz)
120
 
     */
121
 
    DTMFGenerator(unsigned int sampleRate);
122
 
    
123
 
    /**
124
 
     * Destructor
125
 
     */
126
 
    ~DTMFGenerator();
127
 
 
128
 
 
129
 
    // Copy Constructor
130
 
    DTMFGenerator(const DTMFGenerator& rh);
131
 
 
132
 
    // Assignment Operator
133
 
    DTMFGenerator& operator=( const DTMFGenerator& rh);
134
 
 
135
 
    /*
136
 
     * Get n samples of the signal of code code
137
 
     * @param buffer a SFLDataFormat pointer to an allocated buffer
138
 
     * @param n      number of sampling to get, should be lower or equal to buffer size
139
 
     * @param code   dtmf code to get sound
140
 
     */
141
 
    void getSamples(SFLDataFormat* buffer, size_t n, unsigned char code) throw (DTMFException);
142
 
 
143
 
    /*
144
 
     * Get next n samples (continues where previous call to
145
 
     * genSample or genNextSamples stopped
146
 
     * @param buffer a SFLDataFormat pointer to an allocated buffer 
147
 
     * @param n      number of sampling to get, should be lower or equal to buffer size
148
 
     */
149
 
    void getNextSamples(SFLDataFormat* buffer, size_t n) throw (DTMFException);
150
 
 
151
 
  private:
152
 
 
153
 
    /**
154
 
     * Generate samples for a specific dtmf code
155
 
     * @param code The code
156
 
     * @return SFLDataFormat* The generated data
157
 
     */
158
 
    SFLDataFormat* generateSample(unsigned char code) throw (DTMFException);
 
86
    private:
 
87
        /** Struct to handle a DTMF */
 
88
        struct DTMFTone {
 
89
            unsigned char code; /** Code of the tone */
 
90
            int lower;          /** Lower frequency */
 
91
            int higher;         /** Higher frequency */
 
92
        };
 
93
 
 
94
        /** State of the DTMF generator */
 
95
        struct DTMFState {
 
96
            unsigned int offset;   /** Offset in the sample currently being played */
 
97
            SFLDataFormat* sample;         /** Currently generated code */
 
98
        };
 
99
 
 
100
        /** State of the DTMF generator */
 
101
        DTMFState state;
 
102
 
 
103
        /** The different kind of tones */
 
104
        static const DTMFTone tones[NUM_TONES];
 
105
 
 
106
        /** Generated samples */
 
107
        SFLDataFormat* samples[NUM_TONES];
 
108
 
 
109
        /** Sampling rate of generated dtmf */
 
110
        int _sampleRate;
 
111
 
 
112
        /** A tone object */
 
113
        Tone tone;
 
114
 
 
115
    public:
 
116
        /**
 
117
         * DTMF Generator contains frequency of each keys
 
118
         * and can build one DTMF.
 
119
         * @param sampleRate frequency of the sample (ex: 8000 hz)
 
120
         */
 
121
        DTMFGenerator (unsigned int sampleRate);
 
122
 
 
123
        /**
 
124
         * Destructor
 
125
         */
 
126
        ~DTMFGenerator();
 
127
 
 
128
 
 
129
        // Copy Constructor
 
130
        DTMFGenerator (const DTMFGenerator& rh);
 
131
 
 
132
        // Assignment Operator
 
133
        DTMFGenerator& operator= (const DTMFGenerator& rh);
 
134
 
 
135
        /*
 
136
         * Get n samples of the signal of code code
 
137
         * @param buffer a SFLDataFormat pointer to an allocated buffer
 
138
         * @param n      number of sampling to get, should be lower or equal to buffer size
 
139
         * @param code   dtmf code to get sound
 
140
         */
 
141
        void getSamples (SFLDataFormat* buffer, size_t n, unsigned char code) throw (DTMFException);
 
142
 
 
143
        /*
 
144
         * Get next n samples (continues where previous call to
 
145
         * genSample or genNextSamples stopped
 
146
         * @param buffer a SFLDataFormat pointer to an allocated buffer
 
147
         * @param n      number of sampling to get, should be lower or equal to buffer size
 
148
         */
 
149
        void getNextSamples (SFLDataFormat* buffer, size_t n) throw (DTMFException);
 
150
 
 
151
    private:
 
152
 
 
153
        /**
 
154
         * Generate samples for a specific dtmf code
 
155
         * @param code The code
 
156
         * @return SFLDataFormat* The generated data
 
157
         */
 
158
        SFLDataFormat* generateSample (unsigned char code) throw (DTMFException);
159
159
};
160
160
 
161
161
#endif // DTMFGENERATOR_H