summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2004-08-06 18:53:51 (UTC)
committer llornkcor <llornkcor>2004-08-06 18:53:51 (UTC)
commit75675815cb051e14bf8ad50c4069338bfa83eed1 (patch) (unidiff)
treed09364d5fac22ce9c521ffc010030b8492ff7cdf
parentcf4207c5c299812e46f40aaee307100f58317a97 (diff)
downloadopie-75675815cb051e14bf8ad50c4069338bfa83eed1.zip
opie-75675815cb051e14bf8ad50c4069338bfa83eed1.tar.gz
opie-75675815cb051e14bf8ad50c4069338bfa83eed1.tar.bz2
use openzaurus dsp
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opierec/qtrec.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/noncore/multimedia/opierec/qtrec.cpp b/noncore/multimedia/opierec/qtrec.cpp
index e3385cd..1141faa 100644
--- a/noncore/multimedia/opierec/qtrec.cpp
+++ b/noncore/multimedia/opierec/qtrec.cpp
@@ -1,264 +1,270 @@
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"
11extern "C" { 11extern "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>
22using namespace Opie::Core; 22using 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>
59static int deviceSampleRates[8] = { 32000, 44100, 48000, 88200, 96000, 176400, 192000, -1 }; 59static int deviceSampleRates[8] = { 32000, 44100, 48000, 88200, 96000, 176400, 192000, -1 };
60static int deviceBitRates[] = { 8, 16, 24, 32, -1 }; 60static int deviceBitRates[] = { 8, 16, 24, 32, -1 };
61#else //OSS 61#else //OSS
62static int deviceSampleRates[6] = { 11025, 16000, 22050, 32000, 44100, -1 }; 62static int deviceSampleRates[6] = { 11025, 16000, 22050, 32000, 44100, -1 };
63static int deviceBitRates[] = { 8, 16, -1 }; 63static 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"
71#define DSPSTRMIXEROUT "/dev/mixer" 70#define DSPSTRMIXEROUT "/dev/mixer"
71
72#ifdef SHARP
73#define DSPSTRIN "/dev/dsp1"
72#define DSPSTRMIXERIN "/dev/mixer1" 74#define DSPSTRMIXERIN "/dev/mixer1"
75#else
76#define DSPSTRIN "/dev/dsp"
77#define DSPSTRMIXERIN "/dev/mixer"
78#endif
73 79
74#else 80#else
75 81
76#define DSPSTROUT "/dev/dsp" 82#define DSPSTROUT "/dev/dsp"
77#define DSPSTRIN "/dev/dsp" 83#define DSPSTRIN "/dev/dsp"
78#define DSPSTRMIXERIN "/dev/mixer" 84#define DSPSTRMIXERIN "/dev/mixer"
79#define DSPSTRMIXEROUT "/dev/mixer" 85#define DSPSTRMIXEROUT "/dev/mixer"
80 86
81#endif 87#endif
82 88
83//#define ZAURUS 0 89//#define ZAURUS 0
84struct adpcm_state encoder_state; 90struct adpcm_state encoder_state;
85struct adpcm_state decoder_state; 91struct adpcm_state decoder_state;
86 92
87typedef struct { 93typedef struct {
88 int sampleRate; 94 int sampleRate;
89 /* int fragSize; */ 95 /* int fragSize; */
90 /* int blockSize; */ 96 /* int blockSize; */
91 int resolution; //bitrate 97 int resolution; //bitrate
92 int channels; //number of channels 98 int channels; //number of channels
93 int fd; //file descriptor 99 int fd; //file descriptor
94 int sd; //sound device descriptor 100 int sd; //sound device descriptor
95 int numberSamples; //total number of samples 101 int numberSamples; //total number of samples
96 int SecondsToRecord; // number of seconds that should be recorded 102 int SecondsToRecord; // number of seconds that should be recorded
97 float numberOfRecordedSeconds; //total number of samples recorded 103 float numberOfRecordedSeconds; //total number of samples recorded
98 int samplesToRecord; //number of samples to be recorded 104 int samplesToRecord; //number of samples to be recorded
99 int inVol; //input volume 105 int inVol; //input volume
100 int outVol; //output volume 106 int outVol; //output volume
101 int format; //wavfile format PCM.. ADPCM 107 int format; //wavfile format PCM.. ADPCM
102 const char *fileName; //name of fiel to be played/recorded 108 const char *fileName; //name of fiel to be played/recorded
103} fileParameters; 109} fileParameters;
104 110
105fileParameters filePara; 111fileParameters filePara;
106 112
107bool monitoring, recording, playing; 113bool monitoring, recording, playing;
108bool stopped; 114bool stopped;
109QLabel *timeLabel; 115QLabel *timeLabel;
110QSlider *timeSlider; 116QSlider *timeSlider;
111int sd; 117int sd;
112 118
113Waveform* waveform; 119Waveform* waveform;
114Device *soundDevice; 120Device *soundDevice;
115 121
116 122
117#ifdef THREADED 123#ifdef THREADED
118void quickRec() 124void quickRec()
119#else 125#else
120 void QtRec::quickRec() 126 void QtRec::quickRec()
121#endif 127#endif
122{ 128{
123 129
124 odebug << ( filePara.numberSamples/filePara.sampleRate * filePara.channels ) << oendl; 130 odebug << ( filePara.numberSamples/filePara.sampleRate * filePara.channels ) << oendl;
125 odebug << "samples " << filePara.numberSamples << ", rate " << filePara.sampleRate 131 odebug << "samples " << filePara.numberSamples << ", rate " << filePara.sampleRate
126 << ", channels " << filePara.channels << oendl; 132 << ", channels " << filePara.channels << oendl;
127 133
128 int total = 0; // Total number of bytes read in so far. 134 int total = 0; // Total number of bytes read in so far.
129 int bytesWritten, number; 135 int bytesWritten, number;
130 136
131 bytesWritten = 0; 137 bytesWritten = 0;
132 number = 0; 138 number = 0;
133 QString num; 139 QString num;
134 int level = 0; 140 int level = 0;
135 int threshold = 0; 141 int threshold = 0;
136 int bits = filePara.resolution; 142 int bits = filePara.resolution;
137 odebug << "bits " << bits << "" << oendl; 143 odebug << "bits " << bits << "" << oendl;
138 144
139 if( filePara.resolution == 16 ) { //AFMT_S16_LE) 145 if( filePara.resolution == 16 ) { //AFMT_S16_LE)
140 odebug << "AFMT_S16_LE size " << filePara.SecondsToRecord << "" << oendl; 146 odebug << "AFMT_S16_LE size " << filePara.SecondsToRecord << "" << oendl;
141 odebug << "samples to record " << filePara.samplesToRecord << "" << oendl; 147 odebug << "samples to record " << filePara.samplesToRecord << "" << oendl;
142 odebug << "" << filePara.sd << "" << oendl; 148 odebug << "" << filePara.sd << "" << oendl;
143 level = 7; 149 level = 7;
144 threshold = 0; 150 threshold = 0;
145 151
146 if( filePara.format == WAVE_FORMAT_DVI_ADPCM) { 152 if( filePara.format == WAVE_FORMAT_DVI_ADPCM) {
147 odebug << "start recording WAVE_FORMAT_DVI_ADPCM" << oendl; 153 odebug << "start recording WAVE_FORMAT_DVI_ADPCM" << oendl;
148// <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_DVI_ADPCM >>>>>>>>>>>>>>>>>>>>>> 154// <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_DVI_ADPCM >>>>>>>>>>>>>>>>>>>>>>
149 char abuf[ BUFSIZE/2 ]; 155 char abuf[ BUFSIZE/2 ];
150 short sbuf[ BUFSIZE ]; 156 short sbuf[ BUFSIZE ];
151 short sbuf2[ BUFSIZE ]; 157 short sbuf2[ BUFSIZE ];
152 memset( abuf, 0, BUFSIZE/2); 158 memset( abuf, 0, BUFSIZE/2);
153 memset( sbuf, 0, BUFSIZE); 159 memset( sbuf, 0, BUFSIZE);
154 memset( sbuf2, 0, BUFSIZE); 160 memset( sbuf2, 0, BUFSIZE);
155 161
156 for(;;) { 162 for(;;) {
157 if ( stopped) { 163 if ( stopped) {
158 odebug << "quickRec:: stopped" << oendl; 164 odebug << "quickRec:: stopped" << oendl;
159 break; 165 break;
160 } 166 }
161 167
162// number=::read( filePara.sd, sbuf, BUFSIZE); 168// number=::read( filePara.sd, sbuf, BUFSIZE);
163 number = soundDevice->devRead( filePara.sd, sbuf, BUFSIZE); 169 number = soundDevice->devRead( filePara.sd, sbuf, BUFSIZE);
164 170
165 if(number <= 0) { 171 if(number <= 0) {
166 perror("recording error "); 172 perror("recording error ");
167 odebug << "" << filePara.fileName << " " << number << "" << oendl; 173 odebug << "" << filePara.fileName << " " << number << "" << oendl;
168 stopped = true; 174 stopped = true;
169 return; 175 return;
170 } 176 }
171 //if(stereo == 2) { 177 //if(stereo == 2) {
172// adpcm_coder( sbuf2, abuf, number/2, &encoder_state); 178// adpcm_coder( sbuf2, abuf, number/2, &encoder_state);
173 adpcm_coder( sbuf, abuf, number/2, &encoder_state); 179 adpcm_coder( sbuf, abuf, number/2, &encoder_state);
174 180
175 bytesWritten = ::write( filePara.fd , (short *)abuf, number/4); 181 bytesWritten = ::write( filePara.fd , (short *)abuf, number/4);
176 182
177 waveform->newSamples( sbuf, number ); 183 waveform->newSamples( sbuf, number );
178 184
179 total += bytesWritten; 185 total += bytesWritten;
180 filePara.numberSamples = total; 186 filePara.numberSamples = total;
181 timeSlider->setValue( total); 187 timeSlider->setValue( total);
182 188
183 printf("%d, bytes %d,total %d\r",number, bytesWritten, total); 189 printf("%d, bytes %d,total %d\r",number, bytesWritten, total);
184 fflush(stdout); 190 fflush(stdout);
185 191
186 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate * (float)2/ filePara.channels; 192 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate * (float)2/ filePara.channels;
187 193
188 qApp->processEvents(); 194 qApp->processEvents();
189 if( total >= filePara.samplesToRecord) { 195 if( total >= filePara.samplesToRecord) {
190 stopped = true; 196 stopped = true;
191 break; 197 break;
192 } 198 }
193 } 199 }
194 } else { 200 } else {
195 // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_PCM >>>>>>>>>>>>>>>>>>>>>> 201 // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_PCM >>>>>>>>>>>>>>>>>>>>>>
196 odebug << "start recording WAVE_FORMAT_PCM" << oendl; 202 odebug << "start recording WAVE_FORMAT_PCM" << oendl;
197 short inbuffer[ BUFSIZE ], outbuffer[ BUFSIZE ]; 203 short inbuffer[ BUFSIZE ], outbuffer[ BUFSIZE ];
198 memset( inbuffer, 0, BUFSIZE); 204 memset( inbuffer, 0, BUFSIZE);
199 memset( outbuffer, 0, BUFSIZE); 205 memset( outbuffer, 0, BUFSIZE);
200 206
201 for(;;) { 207 for(;;) {
202 if ( stopped) { 208 if ( stopped) {
203 odebug << "quickRec:: stopped" << oendl; 209 odebug << "quickRec:: stopped" << oendl;
204 stopped = true; 210 stopped = true;
205 break; // stop if playing was set to false 211 break; // stop if playing was set to false
206 return; 212 return;
207 } 213 }
208 214
209 number = soundDevice->devRead( soundDevice->sd /*filePara.sd*/, (short *)inbuffer, BUFSIZE); 215 number = soundDevice->devRead( soundDevice->sd /*filePara.sd*/, (short *)inbuffer, BUFSIZE);
210 216
211 if( number <= 0) { 217 if( number <= 0) {
212 perror( "recording error "); 218 perror( "recording error ");
213 odebug << filePara.fileName << oendl; 219 odebug << filePara.fileName << oendl;
214 stopped = true; 220 stopped = true;
215 return; 221 return;
216 } 222 }
217 223
218 bytesWritten = ::write( filePara.fd , inbuffer, number); 224 bytesWritten = ::write( filePara.fd , inbuffer, number);
219 waveform->newSamples( inbuffer, number ); 225 waveform->newSamples( inbuffer, number );
220 226
221 if( bytesWritten < 0) { 227 if( bytesWritten < 0) {
222 perror("File writing error "); 228 perror("File writing error ");
223 stopped = true; 229 stopped = true;
224 return; 230 return;
225 } 231 }
226 232
227 total += bytesWritten; 233 total += bytesWritten;
228 234
229 filePara.numberSamples = total; 235 filePara.numberSamples = total;
230 236
231 if( filePara.SecondsToRecord != 0) 237 if( filePara.SecondsToRecord != 0)
232 timeSlider->setValue( total); 238 timeSlider->setValue( total);
233 printf("%d, bytes %d,total %d\r",number, bytesWritten , total); 239 printf("%d, bytes %d,total %d\r",number, bytesWritten , total);
234 fflush(stdout); 240 fflush(stdout);
235 241
236 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate 242 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate
237 / (float)2/filePara.channels; 243 / (float)2/filePara.channels;
238 qApp->processEvents(); 244 qApp->processEvents();
239 245
240 if( total >= filePara.samplesToRecord) { 246 if( total >= filePara.samplesToRecord) {
241 stopped = true; 247 stopped = true;
242 break; 248 break;
243 } 249 }
244 } 250 }
245 } //end main loop 251 } //end main loop
246 252
247 } else { 253 } else {
248// <<<<<<<<<<<<<<<<<<<<<<< format = AFMT_U8; 254// <<<<<<<<<<<<<<<<<<<<<<< format = AFMT_U8;
249 unsigned char unsigned_inbuffer[ BUFSIZE ], unsigned_outbuffer[ BUFSIZE ]; 255 unsigned char unsigned_inbuffer[ BUFSIZE ], unsigned_outbuffer[ BUFSIZE ];
250 memset( unsigned_inbuffer, 0, BUFSIZE); 256 memset( unsigned_inbuffer, 0, BUFSIZE);
251 memset( unsigned_outbuffer, 0, BUFSIZE); 257 memset( unsigned_outbuffer, 0, BUFSIZE);
252 258
253 for(;;) { 259 for(;;) {
254 if ( stopped) { 260 if ( stopped) {
255 odebug << "quickRec:: stopped" << oendl; 261 odebug << "quickRec:: stopped" << oendl;
256 break; // stop if playing was set to false 262 break; // stop if playing was set to false
257 } 263 }
258 264
259 number = ::read( soundDevice->sd /*filePara.sd*/ , unsigned_inbuffer, BUFSIZE); 265 number = ::read( soundDevice->sd /*filePara.sd*/ , unsigned_inbuffer, BUFSIZE);
260 bytesWritten = ::write( filePara.fd , unsigned_inbuffer, number); 266 bytesWritten = ::write( filePara.fd , unsigned_inbuffer, number);
261 waveform->newSamples( (const short *) unsigned_inbuffer, number ); 267 waveform->newSamples( (const short *) unsigned_inbuffer, number );
262 268
263 if(bytesWritten < 0) { 269 if(bytesWritten < 0) {
264 stopped = true; 270 stopped = true;