-rw-r--r-- | noncore/multimedia/opierec/qtrec.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/noncore/multimedia/opierec/qtrec.cpp b/noncore/multimedia/opierec/qtrec.cpp index fb2d819..e3385cd 100644 --- a/noncore/multimedia/opierec/qtrec.cpp +++ b/noncore/multimedia/opierec/qtrec.cpp | |||
@@ -1,333 +1,333 @@ | |||
1 | /**************************************************************************** | 1 | /**************************************************************************** |
2 | // qtrec.cpp | 2 | // qtrec.cpp |
3 | Created: Thu Jan 17 11:19:58 2002 | 3 | Created: Thu Jan 17 11:19:58 2002 |
4 | copyright 2002 by L.J. Potter <ljp@llornkcor.com> | 4 | copyright 2002 by L.J. Potter <ljp@llornkcor.com> |
5 | ****************************************************************************/ | 5 | ****************************************************************************/ |
6 | #define DEV_VERSION | 6 | #define DEV_VERSION |
7 | 7 | ||
8 | #include "pixmaps.h" | 8 | #include "pixmaps.h" |
9 | #include "qtrec.h" | 9 | #include "qtrec.h" |
10 | #include "waveform.h" | 10 | #include "waveform.h" |
11 | extern "C" { | 11 | extern "C" { |
12 | #include "adpcm.h" | 12 | #include "adpcm.h" |
13 | } | 13 | } |
14 | 14 | ||
15 | /* OPIE */ | 15 | /* OPIE */ |
16 | #include <opie2/odebug.h> | 16 | #include <opie2/odebug.h> |
17 | #include <qpe/config.h> | 17 | #include <qpe/config.h> |
18 | #include <qpe/qcopenvelope_qws.h> | 18 | #include <qpe/qcopenvelope_qws.h> |
19 | #include <qpe/qpeapplication.h> | 19 | #include <qpe/qpeapplication.h> |
20 | #include <qpe/resource.h> | 20 | #include <qpe/resource.h> |
21 | #include <qpe/storage.h> | 21 | #include <qpe/storage.h> |
22 | using namespace Opie::Core; | 22 | using namespace Opie::Core; |
23 | 23 | ||
24 | /* QT */ | 24 | /* QT */ |
25 | #include <qcheckbox.h> | 25 | #include <qcheckbox.h> |
26 | #include <qcombobox.h> | 26 | #include <qcombobox.h> |
27 | #include <qdir.h> | 27 | #include <qdir.h> |
28 | #include <qgroupbox.h> | 28 | #include <qgroupbox.h> |
29 | #include <qlabel.h> | 29 | #include <qlabel.h> |
30 | #include <qlayout.h> | 30 | #include <qlayout.h> |
31 | #include <qlistview.h> | 31 | #include <qlistview.h> |
32 | #include <qmessagebox.h> | 32 | #include <qmessagebox.h> |
33 | #include <qpopupmenu.h> | 33 | #include <qpopupmenu.h> |
34 | #include <qpushbutton.h> | 34 | #include <qpushbutton.h> |
35 | #include <qslider.h> | 35 | #include <qslider.h> |
36 | #include <qtabwidget.h> | 36 | #include <qtabwidget.h> |
37 | #include <qtimer.h> | 37 | #include <qtimer.h> |
38 | 38 | ||
39 | /* STD */ | 39 | /* STD */ |
40 | #include <errno.h> | 40 | #include <errno.h> |
41 | #include <fcntl.h> | 41 | #include <fcntl.h> |
42 | #include <math.h> | 42 | #include <math.h> |
43 | #include <mntent.h> | 43 | #include <mntent.h> |
44 | #include <stdio.h> | 44 | #include <stdio.h> |
45 | #include <stdlib.h> | 45 | #include <stdlib.h> |
46 | #include <sys/ioctl.h> | 46 | #include <sys/ioctl.h> |
47 | #include <sys/soundcard.h> | 47 | #include <sys/soundcard.h> |
48 | #include <sys/stat.h> | 48 | #include <sys/stat.h> |
49 | #include <sys/time.h> | 49 | #include <sys/time.h> |
50 | #include <sys/types.h> | 50 | #include <sys/types.h> |
51 | #include <sys/vfs.h> | 51 | #include <sys/vfs.h> |
52 | #include <unistd.h> | 52 | #include <unistd.h> |
53 | #include <sys/wait.h> | 53 | #include <sys/wait.h> |
54 | #include <sys/signal.h> | 54 | #include <sys/signal.h> |
55 | #include <pthread.h> | 55 | #include <pthread.h> |
56 | 56 | ||
57 | #ifdef PDAUDIO //ALSA | 57 | #ifdef PDAUDIO //ALSA |
58 | #include <alsa/asoundlib.h> | 58 | #include <alsa/asoundlib.h> |
59 | static int deviceSampleRates[8] = { 32000, 44100, 48000, 88200, 96000, 176400, 192000, -1 }; | 59 | static int deviceSampleRates[8] = { 32000, 44100, 48000, 88200, 96000, 176400, 192000, -1 }; |
60 | static int deviceBitRates[] = { 8, 16, 24, 32, -1 }; | 60 | static int deviceBitRates[] = { 8, 16, 24, 32, -1 }; |
61 | #else //OSS | 61 | #else //OSS |
62 | static int deviceSampleRates[6] = { 11025, 16000, 22050, 32000, 44100, -1 }; | 62 | static int deviceSampleRates[6] = { 11025, 16000, 22050, 32000, 44100, -1 }; |
63 | static int deviceBitRates[] = { 8, 16, -1 }; | 63 | static int deviceBitRates[] = { 8, 16, -1 }; |
64 | #endif | 64 | #endif |
65 | 65 | ||
66 | #if defined(QT_QWS_SL5XXX) | 66 | #if defined(QT_QWS_SL5XXX) |
67 | ///#if defined(QT_QWS_EBX) | 67 | ///#if defined(QT_QWS_EBX) |
68 | 68 | ||
69 | #define DSPSTROUT "/dev/dsp" | 69 | #define DSPSTROUT "/dev/dsp" |
70 | #define DSPSTRIN "/dev/dsp1" | 70 | #define DSPSTRIN "/dev/dsp1" |
71 | #define DSPSTRMIXEROUT "/dev/mixer" | 71 | #define DSPSTRMIXEROUT "/dev/mixer" |
72 | #define DSPSTRMIXERIN "/dev/mixer1" | 72 | #define DSPSTRMIXERIN "/dev/mixer1" |
73 | 73 | ||
74 | #else | 74 | #else |
75 | 75 | ||
76 | #define DSPSTROUT "/dev/dsp1" | 76 | #define DSPSTROUT "/dev/dsp" |
77 | #define DSPSTRIN "/dev/dsp1" | 77 | #define DSPSTRIN "/dev/dsp" |
78 | #define DSPSTRMIXERIN "/dev/mixer" | 78 | #define DSPSTRMIXERIN "/dev/mixer" |
79 | #define DSPSTRMIXEROUT "/dev/mixer" | 79 | #define DSPSTRMIXEROUT "/dev/mixer" |
80 | 80 | ||
81 | #endif | 81 | #endif |
82 | 82 | ||
83 | //#define ZAURUS 0 | 83 | //#define ZAURUS 0 |
84 | struct adpcm_state encoder_state; | 84 | struct adpcm_state encoder_state; |
85 | struct adpcm_state decoder_state; | 85 | struct adpcm_state decoder_state; |
86 | 86 | ||
87 | typedef struct { | 87 | typedef struct { |
88 | int sampleRate; | 88 | int sampleRate; |
89 | /* int fragSize; */ | 89 | /* int fragSize; */ |
90 | /* int blockSize; */ | 90 | /* int blockSize; */ |
91 | int resolution; //bitrate | 91 | int resolution; //bitrate |
92 | int channels; //number of channels | 92 | int channels; //number of channels |
93 | int fd; //file descriptor | 93 | int fd; //file descriptor |
94 | int sd; //sound device descriptor | 94 | int sd; //sound device descriptor |
95 | int numberSamples; //total number of samples | 95 | int numberSamples; //total number of samples |
96 | int SecondsToRecord; // number of seconds that should be recorded | 96 | int SecondsToRecord; // number of seconds that should be recorded |
97 | float numberOfRecordedSeconds; //total number of samples recorded | 97 | float numberOfRecordedSeconds; //total number of samples recorded |
98 | int samplesToRecord; //number of samples to be recorded | 98 | int samplesToRecord; //number of samples to be recorded |
99 | int inVol; //input volume | 99 | int inVol; //input volume |
100 | int outVol; //output volume | 100 | int outVol; //output volume |
101 | int format; //wavfile format PCM.. ADPCM | 101 | int format; //wavfile format PCM.. ADPCM |
102 | const char *fileName; //name of fiel to be played/recorded | 102 | const char *fileName; //name of fiel to be played/recorded |
103 | } fileParameters; | 103 | } fileParameters; |
104 | 104 | ||
105 | fileParameters filePara; | 105 | fileParameters filePara; |
106 | 106 | ||
107 | bool monitoring, recording, playing; | 107 | bool monitoring, recording, playing; |
108 | bool stopped; | 108 | bool stopped; |
109 | QLabel *timeLabel; | 109 | QLabel *timeLabel; |
110 | QSlider *timeSlider; | 110 | QSlider *timeSlider; |
111 | int sd; | 111 | int sd; |
112 | 112 | ||
113 | Waveform* waveform; | 113 | Waveform* waveform; |
114 | Device *soundDevice; | 114 | Device *soundDevice; |
115 | 115 | ||
116 | 116 | ||
117 | #ifdef THREADED | 117 | #ifdef THREADED |
118 | void quickRec() | 118 | void quickRec() |
119 | #else | 119 | #else |
120 | void QtRec::quickRec() | 120 | void QtRec::quickRec() |
121 | #endif | 121 | #endif |
122 | { | 122 | { |
123 | 123 | ||
124 | odebug << ( filePara.numberSamples/filePara.sampleRate * filePara.channels ) << oendl; | 124 | odebug << ( filePara.numberSamples/filePara.sampleRate * filePara.channels ) << oendl; |
125 | odebug << "samples " << filePara.numberSamples << ", rate " << filePara.sampleRate | 125 | odebug << "samples " << filePara.numberSamples << ", rate " << filePara.sampleRate |
126 | << ", channels " << filePara.channels << oendl; | 126 | << ", channels " << filePara.channels << oendl; |
127 | 127 | ||
128 | int total = 0; // Total number of bytes read in so far. | 128 | int total = 0; // Total number of bytes read in so far. |
129 | int bytesWritten, number; | 129 | int bytesWritten, number; |
130 | 130 | ||
131 | bytesWritten = 0; | 131 | bytesWritten = 0; |
132 | number = 0; | 132 | number = 0; |
133 | QString num; | 133 | QString num; |
134 | int level = 0; | 134 | int level = 0; |
135 | int threshold = 0; | 135 | int threshold = 0; |
136 | int bits = filePara.resolution; | 136 | int bits = filePara.resolution; |
137 | odebug << "bits " << bits << "" << oendl; | 137 | odebug << "bits " << bits << "" << oendl; |
138 | 138 | ||
139 | if( filePara.resolution == 16 ) { //AFMT_S16_LE) | 139 | if( filePara.resolution == 16 ) { //AFMT_S16_LE) |
140 | odebug << "AFMT_S16_LE size " << filePara.SecondsToRecord << "" << oendl; | 140 | odebug << "AFMT_S16_LE size " << filePara.SecondsToRecord << "" << oendl; |
141 | odebug << "samples to record " << filePara.samplesToRecord << "" << oendl; | 141 | odebug << "samples to record " << filePara.samplesToRecord << "" << oendl; |
142 | odebug << "" << filePara.sd << "" << oendl; | 142 | odebug << "" << filePara.sd << "" << oendl; |
143 | level = 7; | 143 | level = 7; |
144 | threshold = 0; | 144 | threshold = 0; |
145 | 145 | ||
146 | if( filePara.format == WAVE_FORMAT_DVI_ADPCM) { | 146 | if( filePara.format == WAVE_FORMAT_DVI_ADPCM) { |
147 | odebug << "start recording WAVE_FORMAT_DVI_ADPCM" << oendl; | 147 | odebug << "start recording WAVE_FORMAT_DVI_ADPCM" << oendl; |
148 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_DVI_ADPCM >>>>>>>>>>>>>>>>>>>>>> | 148 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_DVI_ADPCM >>>>>>>>>>>>>>>>>>>>>> |
149 | char abuf[ BUFSIZE/2 ]; | 149 | char abuf[ BUFSIZE/2 ]; |
150 | short sbuf[ BUFSIZE ]; | 150 | short sbuf[ BUFSIZE ]; |
151 | short sbuf2[ BUFSIZE ]; | 151 | short sbuf2[ BUFSIZE ]; |
152 | memset( abuf, 0, BUFSIZE/2); | 152 | memset( abuf, 0, BUFSIZE/2); |
153 | memset( sbuf, 0, BUFSIZE); | 153 | memset( sbuf, 0, BUFSIZE); |
154 | memset( sbuf2, 0, BUFSIZE); | 154 | memset( sbuf2, 0, BUFSIZE); |
155 | 155 | ||
156 | for(;;) { | 156 | for(;;) { |
157 | if ( stopped) { | 157 | if ( stopped) { |
158 | odebug << "quickRec:: stopped" << oendl; | 158 | odebug << "quickRec:: stopped" << oendl; |
159 | break; | 159 | break; |
160 | } | 160 | } |
161 | 161 | ||
162 | // number=::read( filePara.sd, sbuf, BUFSIZE); | 162 | // number=::read( filePara.sd, sbuf, BUFSIZE); |
163 | number = soundDevice->devRead( filePara.sd, sbuf, BUFSIZE); | 163 | number = soundDevice->devRead( filePara.sd, sbuf, BUFSIZE); |
164 | 164 | ||
165 | if(number <= 0) { | 165 | if(number <= 0) { |
166 | perror("recording error "); | 166 | perror("recording error "); |
167 | odebug << "" << filePara.fileName << " " << number << "" << oendl; | 167 | odebug << "" << filePara.fileName << " " << number << "" << oendl; |
168 | stopped = true; | 168 | stopped = true; |
169 | return; | 169 | return; |
170 | } | 170 | } |
171 | //if(stereo == 2) { | 171 | //if(stereo == 2) { |
172 | // adpcm_coder( sbuf2, abuf, number/2, &encoder_state); | 172 | // adpcm_coder( sbuf2, abuf, number/2, &encoder_state); |
173 | adpcm_coder( sbuf, abuf, number/2, &encoder_state); | 173 | adpcm_coder( sbuf, abuf, number/2, &encoder_state); |
174 | 174 | ||
175 | bytesWritten = ::write( filePara.fd , (short *)abuf, number/4); | 175 | bytesWritten = ::write( filePara.fd , (short *)abuf, number/4); |
176 | 176 | ||
177 | waveform->newSamples( sbuf, number ); | 177 | waveform->newSamples( sbuf, number ); |
178 | 178 | ||
179 | total += bytesWritten; | 179 | total += bytesWritten; |
180 | filePara.numberSamples = total; | 180 | filePara.numberSamples = total; |
181 | timeSlider->setValue( total); | 181 | timeSlider->setValue( total); |
182 | 182 | ||
183 | printf("%d, bytes %d,total %d\r",number, bytesWritten, total); | 183 | printf("%d, bytes %d,total %d\r",number, bytesWritten, total); |
184 | fflush(stdout); | 184 | fflush(stdout); |
185 | 185 | ||
186 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate * (float)2/ filePara.channels; | 186 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate * (float)2/ filePara.channels; |
187 | 187 | ||
188 | qApp->processEvents(); | 188 | qApp->processEvents(); |
189 | if( total >= filePara.samplesToRecord) { | 189 | if( total >= filePara.samplesToRecord) { |
190 | stopped = true; | 190 | stopped = true; |
191 | break; | 191 | break; |
192 | } | 192 | } |
193 | } | 193 | } |
194 | } else { | 194 | } else { |
195 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_PCM >>>>>>>>>>>>>>>>>>>>>> | 195 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_PCM >>>>>>>>>>>>>>>>>>>>>> |
196 | odebug << "start recording WAVE_FORMAT_PCM" << oendl; | 196 | odebug << "start recording WAVE_FORMAT_PCM" << oendl; |
197 | short inbuffer[ BUFSIZE ], outbuffer[ BUFSIZE ]; | 197 | short inbuffer[ BUFSIZE ], outbuffer[ BUFSIZE ]; |
198 | memset( inbuffer, 0, BUFSIZE); | 198 | memset( inbuffer, 0, BUFSIZE); |
199 | memset( outbuffer, 0, BUFSIZE); | 199 | memset( outbuffer, 0, BUFSIZE); |
200 | 200 | ||
201 | for(;;) { | 201 | for(;;) { |
202 | if ( stopped) { | 202 | if ( stopped) { |
203 | odebug << "quickRec:: stopped" << oendl; | 203 | odebug << "quickRec:: stopped" << oendl; |
204 | stopped = true; | 204 | stopped = true; |
205 | break; // stop if playing was set to false | 205 | break; // stop if playing was set to false |
206 | return; | 206 | return; |
207 | } | 207 | } |
208 | 208 | ||
209 | number = soundDevice->devRead( soundDevice->sd /*filePara.sd*/, (short *)inbuffer, BUFSIZE); | 209 | number = soundDevice->devRead( soundDevice->sd /*filePara.sd*/, (short *)inbuffer, BUFSIZE); |
210 | 210 | ||
211 | if( number <= 0) { | 211 | if( number <= 0) { |
212 | perror( "recording error "); | 212 | perror( "recording error "); |
213 | odebug << filePara.fileName << oendl; | 213 | odebug << filePara.fileName << oendl; |
214 | stopped = true; | 214 | stopped = true; |
215 | return; | 215 | return; |
216 | } | 216 | } |
217 | 217 | ||
218 | bytesWritten = ::write( filePara.fd , inbuffer, number); | 218 | bytesWritten = ::write( filePara.fd , inbuffer, number); |
219 | waveform->newSamples( inbuffer, number ); | 219 | waveform->newSamples( inbuffer, number ); |
220 | 220 | ||
221 | if( bytesWritten < 0) { | 221 | if( bytesWritten < 0) { |
222 | perror("File writing error "); | 222 | perror("File writing error "); |
223 | stopped = true; | 223 | stopped = true; |
224 | return; | 224 | return; |
225 | } | 225 | } |
226 | 226 | ||
227 | total += bytesWritten; | 227 | total += bytesWritten; |
228 | 228 | ||
229 | filePara.numberSamples = total; | 229 | filePara.numberSamples = total; |
230 | 230 | ||
231 | if( filePara.SecondsToRecord != 0) | 231 | if( filePara.SecondsToRecord != 0) |
232 | timeSlider->setValue( total); | 232 | timeSlider->setValue( total); |
233 | printf("%d, bytes %d,total %d\r",number, bytesWritten , total); | 233 | printf("%d, bytes %d,total %d\r",number, bytesWritten , total); |
234 | fflush(stdout); | 234 | fflush(stdout); |
235 | 235 | ||
236 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate | 236 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate |
237 | / (float)2/filePara.channels; | 237 | / (float)2/filePara.channels; |
238 | qApp->processEvents(); | 238 | qApp->processEvents(); |
239 | 239 | ||
240 | if( total >= filePara.samplesToRecord) { | 240 | if( total >= filePara.samplesToRecord) { |
241 | stopped = true; | 241 | stopped = true; |
242 | break; | 242 | break; |
243 | } | 243 | } |
244 | } | 244 | } |
245 | } //end main loop | 245 | } //end main loop |
246 | 246 | ||
247 | } else { | 247 | } else { |
248 | // <<<<<<<<<<<<<<<<<<<<<<< format = AFMT_U8; | 248 | // <<<<<<<<<<<<<<<<<<<<<<< format = AFMT_U8; |
249 | unsigned char unsigned_inbuffer[ BUFSIZE ], unsigned_outbuffer[ BUFSIZE ]; | 249 | unsigned char unsigned_inbuffer[ BUFSIZE ], unsigned_outbuffer[ BUFSIZE ]; |
250 | memset( unsigned_inbuffer, 0, BUFSIZE); | 250 | memset( unsigned_inbuffer, 0, BUFSIZE); |
251 | memset( unsigned_outbuffer, 0, BUFSIZE); | 251 | memset( unsigned_outbuffer, 0, BUFSIZE); |
252 | 252 | ||
253 | for(;;) { | 253 | for(;;) { |
254 | if ( stopped) { | 254 | if ( stopped) { |
255 | odebug << "quickRec:: stopped" << oendl; | 255 | odebug << "quickRec:: stopped" << oendl; |
256 | break; // stop if playing was set to false | 256 | break; // stop if playing was set to false |
257 | } | 257 | } |
258 | 258 | ||
259 | number = ::read( soundDevice->sd /*filePara.sd*/ , unsigned_inbuffer, BUFSIZE); | 259 | number = ::read( soundDevice->sd /*filePara.sd*/ , unsigned_inbuffer, BUFSIZE); |
260 | bytesWritten = ::write( filePara.fd , unsigned_inbuffer, number); | 260 | bytesWritten = ::write( filePara.fd , unsigned_inbuffer, number); |
261 | waveform->newSamples( (const short *) unsigned_inbuffer, number ); | 261 | waveform->newSamples( (const short *) unsigned_inbuffer, number ); |
262 | 262 | ||
263 | if(bytesWritten < 0) { | 263 | if(bytesWritten < 0) { |
264 | stopped = true; | 264 | stopped = true; |
265 | QMessageBox::message("Note","<p>There was a problem writing to the file</p>"); | 265 | QMessageBox::message("Note","<p>There was a problem writing to the file</p>"); |
266 | perror("File writing error "); | 266 | perror("File writing error "); |
267 | return; | 267 | return; |
268 | } | 268 | } |
269 | 269 | ||
270 | total += bytesWritten; | 270 | total += bytesWritten; |
271 | filePara.numberSamples = total; | 271 | filePara.numberSamples = total; |
272 | // printf("%d, bytes %d,total %d \r",number, bytesWritten , total); | 272 | // printf("%d, bytes %d,total %d \r",number, bytesWritten , total); |
273 | // fflush(stdout); | 273 | // fflush(stdout); |
274 | if( filePara.SecondsToRecord !=0) | 274 | if( filePara.SecondsToRecord !=0) |
275 | timeSlider->setValue( total); | 275 | timeSlider->setValue( total); |
276 | 276 | ||
277 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate; | 277 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate; |
278 | 278 | ||
279 | qApp->processEvents(); | 279 | qApp->processEvents(); |
280 | if( total >= filePara.samplesToRecord) { | 280 | if( total >= filePara.samplesToRecord) { |
281 | stopped = true; | 281 | stopped = true; |
282 | break; | 282 | break; |
283 | } | 283 | } |
284 | } //end main loop | 284 | } //end main loop |
285 | } | 285 | } |
286 | } /// END quickRec() | 286 | } /// END quickRec() |
287 | 287 | ||
288 | 288 | ||
289 | #ifdef THREADED | 289 | #ifdef THREADED |
290 | void playIt() | 290 | void playIt() |
291 | #else | 291 | #else |
292 | void QtRec::playIt() | 292 | void QtRec::playIt() |
293 | #endif | 293 | #endif |
294 | { | 294 | { |
295 | int bytesWritten = 0; | 295 | int bytesWritten = 0; |
296 | int number = 0; | 296 | int number = 0; |
297 | int total = 0; // Total number of bytes read in so far. | 297 | int total = 0; // Total number of bytes read in so far. |
298 | if( filePara.resolution == 16 ) { //AFMT_S16_LE) { | 298 | if( filePara.resolution == 16 ) { //AFMT_S16_LE) { |
299 | if( filePara.format == WAVE_FORMAT_DVI_ADPCM) { | 299 | if( filePara.format == WAVE_FORMAT_DVI_ADPCM) { |
300 | char abuf[ BUFSIZE / 2 ]; | 300 | char abuf[ BUFSIZE / 2 ]; |
301 | short sbuf[ BUFSIZE ]; | 301 | short sbuf[ BUFSIZE ]; |
302 | short sbuf2[ BUFSIZE * 2 ]; | 302 | short sbuf2[ BUFSIZE * 2 ]; |
303 | memset( abuf, 0, BUFSIZE / 2); | 303 | memset( abuf, 0, BUFSIZE / 2); |
304 | memset( sbuf, 0, BUFSIZE); | 304 | memset( sbuf, 0, BUFSIZE); |
305 | memset( sbuf2, 0, BUFSIZE * 2); | 305 | memset( sbuf2, 0, BUFSIZE * 2); |
306 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_DVI_ADPCM >>>>>>>>>>>>>>>>>>>>>> | 306 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_DVI_ADPCM >>>>>>>>>>>>>>>>>>>>>> |
307 | for(;;) { // play loop | 307 | for(;;) { // play loop |
308 | if ( stopped) { | 308 | if ( stopped) { |
309 | break; | 309 | break; |
310 | return; | 310 | return; |
311 | }// stop if playing was set to false | 311 | }// stop if playing was set to false |
312 | 312 | ||
313 | number = ::read( filePara.fd, abuf, BUFSIZE / 2); | 313 | number = ::read( filePara.fd, abuf, BUFSIZE / 2); |
314 | adpcm_decoder( abuf, sbuf, number * 2, &decoder_state); | 314 | adpcm_decoder( abuf, sbuf, number * 2, &decoder_state); |
315 | 315 | ||
316 | // for (int i=0;i< number * 2; 2 * i++) { //2*i is left channel | 316 | // for (int i=0;i< number * 2; 2 * i++) { //2*i is left channel |
317 | // sbuf2[i+1]=sbuf2[i]=sbuf[i]; | 317 | // sbuf2[i+1]=sbuf2[i]=sbuf[i]; |
318 | // } | 318 | // } |
319 | bytesWritten = write ( filePara.sd, sbuf, number * 4); | 319 | bytesWritten = write ( filePara.sd, sbuf, number * 4); |
320 | waveform->newSamples( (const short *)sbuf, number *4); | 320 | waveform->newSamples( (const short *)sbuf, number *4); |
321 | // if(filePara.channels==1) | 321 | // if(filePara.channels==1) |
322 | // total += bytesWritten/2; //mono | 322 | // total += bytesWritten/2; //mono |
323 | // else | 323 | // else |
324 | total += bytesWritten; | 324 | total += bytesWritten; |
325 | filePara.numberSamples = total/4; | 325 | filePara.numberSamples = total/4; |
326 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / 2; | 326 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / 2; |
327 | 327 | ||
328 | timeSlider->setValue( total/4); | 328 | timeSlider->setValue( total/4); |
329 | // timeString.sprintf("%.2f", filePara.numberOfRecordedSeconds); | 329 | // timeString.sprintf("%.2f", filePara.numberOfRecordedSeconds); |
330 | // if(filePara.numberOfRecordedSeconds>1) | 330 | // if(filePara.numberOfRecordedSeconds>1) |
331 | // timeLabel->setText( timeString+ tr(" seconds")); | 331 | // timeLabel->setText( timeString+ tr(" seconds")); |
332 | // printf("playing number %d, bytes %d, total %d\n",number, bytesWritten, total/4); | 332 | // printf("playing number %d, bytes %d, total %d\n",number, bytesWritten, total/4); |
333 | // fflush(stdout); | 333 | // fflush(stdout); |