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

« back to all changes in this revision

Viewing changes to sflphone-common/src/audio/audiorecord.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
/*
 
2
 *  Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010 Savoir-Faire Linux Inc.
 
3
 *  Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
 
4
 *
 
5
 *  This program is free software; you can redistribute it and/or modify
 
6
 *  it under the terms of the GNU General Public License as published by
 
7
 *  the Free Software Foundation; either version 3 of the License, or
 
8
 *  (at your option) any later version.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
18
 *
 
19
 *  Additional permission under GNU GPL version 3 section 7:
 
20
 *
 
21
 *  If you modify this program, or any covered work, by linking or
 
22
 *  combining it with the OpenSSL project's OpenSSL library (or a
 
23
 *  modified version of that library), containing parts covered by the
 
24
 *  terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
 
25
 *  grants you additional permission to convey the resulting work.
 
26
 *  Corresponding Source for a non-source form of such a combination
 
27
 *  shall include the source code for the parts of OpenSSL used as well
 
28
 *  as that of the covered work.
 
29
 */
 
30
 
 
31
#ifndef _AUDIO_RECORD_H
 
32
#define _AUDIO_RECORD_H
 
33
 
 
34
#include <iostream>
 
35
#include <string.h>
 
36
#include <stdlib.h>
 
37
#include <sstream>
 
38
 
 
39
#include "global.h"
 
40
 
 
41
using namespace std;
 
42
 
 
43
typedef std::string CallID;
 
44
 
 
45
class AudioRecord
 
46
{
 
47
 
 
48
    public:
 
49
 
 
50
        AudioRecord();
 
51
 
 
52
        ~AudioRecord();
 
53
 
 
54
        void setSndSamplingRate (int smplRate);
 
55
 
 
56
        void setRecordingOption (FILE_TYPE type, SOUND_FORMAT format, int sndSmplRate, std::string path);
 
57
 
 
58
        void initFileName (std::string peerNumber);
 
59
 
 
60
        /**
 
61
         * Check if no otehr file is opened, then create a new one
 
62
         * @param fileName A string containing teh file (with/without extension)
 
63
         * @param type     The sound file format (FILE_RAW, FILE_WAVE)
 
64
         * @param format   Internal sound format (INT16 / INT32)
 
65
         */
 
66
        void openFile();
 
67
 
 
68
        /**
 
69
         * Close the opend recording file. If wave: cout the number of byte
 
70
         */
 
71
        void closeFile();
 
72
 
 
73
        /**
 
74
         * Check if a file is already opened
 
75
         */
 
76
        bool isOpenFile();
 
77
 
 
78
        /**
 
79
         * Check if a file already exist
 
80
         */
 
81
        bool isFileExist();
 
82
 
 
83
        /**
 
84
         * Check recording state
 
85
         */
 
86
        bool isRecording();
 
87
 
 
88
        /**
 
89
         * Set recording flag
 
90
         */
 
91
        bool setRecording();
 
92
 
 
93
        /**
 
94
         * Stop recording flag
 
95
         */
 
96
        void stopRecording();
 
97
 
 
98
 
 
99
        /**
 
100
         * Record a chunk of data in an internal buffer
 
101
         * @param buffer  The data chunk to be recorded
 
102
         * @param nSamples Number of samples (number of bytes) to be recorded
 
103
         */
 
104
        void recSpkrData (SFLDataFormat* buffer, int nSamples);
 
105
 
 
106
        /**
 
107
         * Record a chunk of data in an internal buffer
 
108
         * @param buffer  The data chunk to be recorded
 
109
         * @param nSamples Number of samples (number of bytes) to be recorded
 
110
         */
 
111
        void recMicData (SFLDataFormat* buffer, int nSamples);
 
112
 
 
113
        /**
 
114
         * Record a chunk of data in an openend file
 
115
         * @param buffer  The data chunk to be recorded
 
116
         * @param nSamples Number of samples (number of bytes) to be recorded
 
117
         */
 
118
        void recData (SFLDataFormat* buffer, int nSamples);
 
119
 
 
120
        /**
 
121
         * Record a chunk of data in an openend file, Mix two differnet buffer
 
122
         * @param buffer_1  The first data chunk to be recorded
 
123
         * @param buffer_2  The second data chunk to be recorded
 
124
         * @param nSamples_1 Number of samples (number of bytes) of buffer_1
 
125
         * @param nSamples_2 Number of samples (number of bytes) of buffer_2
 
126
         */
 
127
        void recData (SFLDataFormat* buffer_1, SFLDataFormat* buffer_2, int nSamples_1, int nSamples_2);
 
128
 
 
129
 
 
130
    protected:
 
131
 
 
132
        /**
 
133
         * Create name file according to current date
 
134
         */
 
135
        void createFilename();
 
136
 
 
137
        /**
 
138
         * Set the header for raw files
 
139
         */
 
140
        bool setRawFile();
 
141
 
 
142
        /**
 
143
         * Set the header for wave files
 
144
         */
 
145
        bool setWavFile();
 
146
 
 
147
        /**
 
148
         * Open an existing raw file, used when the call is set on hold
 
149
         */
 
150
        bool openExistingRawFile();
 
151
 
 
152
        /**
 
153
         * Open an existing wav file, used when the call is set on hold
 
154
         */
 
155
        bool openExistingWavFile();
 
156
 
 
157
        /**
 
158
         * Compute the number of byte recorded and close the file
 
159
         */
 
160
        void closeWavFile();
 
161
 
 
162
 
 
163
        /**
 
164
         * Pointer to the recorded file
 
165
         */
 
166
        FILE *fp;                      //file pointer
 
167
 
 
168
        /**
 
169
         * File format (RAW / WAVE)
 
170
         */
 
171
        FILE_TYPE fileType_;
 
172
 
 
173
        /**
 
174
         * Sound format (SINT16/SINT32)
 
175
         */
 
176
        SOUND_FORMAT sndFormat_;
 
177
 
 
178
        /**
 
179
         * Number of channels
 
180
         */
 
181
        int channels_;
 
182
 
 
183
        /**
 
184
         * Number of byte recorded
 
185
         */
 
186
        unsigned long byteCounter_;
 
187
 
 
188
        /**
 
189
         * Sampling rate
 
190
         */
 
191
        int sndSmplRate_;
 
192
 
 
193
        /**
 
194
         * number of samples recorded for mic buffer
 
195
         */
 
196
        int nbSamplesMic_;
 
197
 
 
198
        /**
 
199
         * number of samples recorded for speaker buffer
 
200
         */
 
201
        int nbSamplesSpk_;
 
202
 
 
203
        /**
 
204
         * Maximum number of samples
 
205
         */
 
206
        int nbSamplesMax_;
 
207
 
 
208
        /**
 
209
         * Recording flage
 
210
         */
 
211
        bool recordingEnabled_;
 
212
 
 
213
        /**
 
214
         * Buffer used for mixing two channels
 
215
         */
 
216
        SFLDataFormat* mixBuffer_;
 
217
 
 
218
        /**
 
219
         * Buffer used to copy mic info
 
220
         */
 
221
        SFLDataFormat* micBuffer_;
 
222
 
 
223
        /**
 
224
         * Buffer used to copy spkr info
 
225
         */
 
226
        SFLDataFormat* spkBuffer_;
 
227
 
 
228
        /**
 
229
         * Filename for this recording
 
230
         */
 
231
        char fileName_[8192];
 
232
 
 
233
        /**
 
234
         * Path for this recording
 
235
         */
 
236
        std::string savePath_;
 
237
 
 
238
};
 
239
 
 
240
#endif // _AUDIO_RECORD_H