author | schurig <schurig> | 2004-09-10 12:34:40 (UTC) |
---|---|---|
committer | schurig <schurig> | 2004-09-10 12:34:40 (UTC) |
commit | 85928a3781d9a91b58ea414c0d7982459cc21920 (patch) (unidiff) | |
tree | 10aeedf3a79fe2372c55bda730b6913b5562231b | |
parent | 9d0ccc1c5ca687bc017b2b515a9d3a47e98ce521 (diff) | |
download | opie-85928a3781d9a91b58ea414c0d7982459cc21920.zip opie-85928a3781d9a91b58ea414c0d7982459cc21920.tar.gz opie-85928a3781d9a91b58ea414c0d7982459cc21920.tar.bz2 |
support for DEVFS
-rw-r--r-- | noncore/multimedia/opieplayer2/mediaplayer.cpp | 4 | ||||
-rw-r--r-- | noncore/multimedia/opierec/device.cpp | 16 | ||||
-rw-r--r-- | noncore/multimedia/opierec/qtrec.cpp | 7 |
3 files changed, 27 insertions, 0 deletions
diff --git a/noncore/multimedia/opieplayer2/mediaplayer.cpp b/noncore/multimedia/opieplayer2/mediaplayer.cpp index 7b4bfd9..e6afbd8 100644 --- a/noncore/multimedia/opieplayer2/mediaplayer.cpp +++ b/noncore/multimedia/opieplayer2/mediaplayer.cpp | |||
@@ -28,376 +28,380 @@ MediaPlayer::MediaPlayer( PlayListWidget &_playList, MediaPlayerState &_mediaPla | |||
28 | 28 | ||
29 | fd=-1;fl=-1; | 29 | fd=-1;fl=-1; |
30 | playList.setCaption( tr( "OpiePlayer: Initializating" ) ); | 30 | playList.setCaption( tr( "OpiePlayer: Initializating" ) ); |
31 | 31 | ||
32 | qApp->processEvents(); | 32 | qApp->processEvents(); |
33 | // QPEApplication::grabKeyboard(); // EVIL | 33 | // QPEApplication::grabKeyboard(); // EVIL |
34 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); | 34 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); |
35 | 35 | ||
36 | connect( &mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); | 36 | connect( &mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); |
37 | 37 | ||
38 | // What is pauseCheck good for? (Simon) | 38 | // What is pauseCheck good for? (Simon) |
39 | // connect( &mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( pauseCheck(bool) ) ); | 39 | // connect( &mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( pauseCheck(bool) ) ); |
40 | 40 | ||
41 | connect( &mediaPlayerState, SIGNAL( next() ), this, SLOT( next() ) ); | 41 | connect( &mediaPlayerState, SIGNAL( next() ), this, SLOT( next() ) ); |
42 | connect( &mediaPlayerState, SIGNAL( prev() ), this, SLOT( prev() ) ); | 42 | connect( &mediaPlayerState, SIGNAL( prev() ), this, SLOT( prev() ) ); |
43 | connect( &mediaPlayerState, SIGNAL( blankToggled(bool) ), this, SLOT ( blank(bool) ) ); | 43 | connect( &mediaPlayerState, SIGNAL( blankToggled(bool) ), this, SLOT ( blank(bool) ) ); |
44 | 44 | ||
45 | volControl = new VolumeControl; | 45 | volControl = new VolumeControl; |
46 | Config cfg( "OpiePlayer" ); | 46 | Config cfg( "OpiePlayer" ); |
47 | cfg.setGroup("PlayList"); | 47 | cfg.setGroup("PlayList"); |
48 | QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "default"); | 48 | QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "default"); |
49 | playList.setCaption( tr( "OpiePlayer: " ) + QFileInfo(currentPlaylist).baseName() ); | 49 | playList.setCaption( tr( "OpiePlayer: " ) + QFileInfo(currentPlaylist).baseName() ); |
50 | 50 | ||
51 | m_skinLoader = new SkinLoader; | 51 | m_skinLoader = new SkinLoader; |
52 | m_skinLoader->schedule( AudioWidget::guiInfo() ); | 52 | m_skinLoader->schedule( AudioWidget::guiInfo() ); |
53 | m_skinLoader->schedule( VideoWidget::guiInfo() ); | 53 | m_skinLoader->schedule( VideoWidget::guiInfo() ); |
54 | m_skinLoader->start(); | 54 | m_skinLoader->start(); |
55 | } | 55 | } |
56 | 56 | ||
57 | MediaPlayer::~MediaPlayer() { | 57 | MediaPlayer::~MediaPlayer() { |
58 | // this shold never happen, but one never knows... | 58 | // this shold never happen, but one never knows... |
59 | if ( xine ) { | 59 | if ( xine ) { |
60 | xine->ensureInitialized(); | 60 | xine->ensureInitialized(); |
61 | delete xine; | 61 | delete xine; |
62 | } | 62 | } |
63 | delete m_xineControl; | 63 | delete m_xineControl; |
64 | delete m_audioUI; | 64 | delete m_audioUI; |
65 | delete m_videoUI; | 65 | delete m_videoUI; |
66 | delete volControl; | 66 | delete volControl; |
67 | } | 67 | } |
68 | 68 | ||
69 | void MediaPlayer::pauseCheck( bool b ) { | 69 | void MediaPlayer::pauseCheck( bool b ) { |
70 | if ( b && !mediaPlayerState.isPlaying() ) { | 70 | if ( b && !mediaPlayerState.isPlaying() ) { |
71 | mediaPlayerState.setPaused( FALSE ); | 71 | mediaPlayerState.setPaused( FALSE ); |
72 | } | 72 | } |
73 | } | 73 | } |
74 | 74 | ||
75 | void MediaPlayer::play() { | 75 | void MediaPlayer::play() { |
76 | mediaPlayerState.setPlaying( FALSE ); | 76 | mediaPlayerState.setPlaying( FALSE ); |
77 | mediaPlayerState.setPlaying( TRUE ); | 77 | mediaPlayerState.setPlaying( TRUE ); |
78 | } | 78 | } |
79 | 79 | ||
80 | void MediaPlayer::setPlaying( bool play ) { | 80 | void MediaPlayer::setPlaying( bool play ) { |
81 | if ( !play ) { | 81 | if ( !play ) { |
82 | return; | 82 | return; |
83 | } | 83 | } |
84 | 84 | ||
85 | if ( mediaPlayerState.isPaused() ) { | 85 | if ( mediaPlayerState.isPaused() ) { |
86 | mediaPlayerState.setPaused( FALSE ); | 86 | mediaPlayerState.setPaused( FALSE ); |
87 | return; | 87 | return; |
88 | } | 88 | } |
89 | 89 | ||
90 | QString tickerText, time, fileName; | 90 | QString tickerText, time, fileName; |
91 | if ( playList.currentTab() != PlayListWidget::CurrentPlayList ) { | 91 | if ( playList.currentTab() != PlayListWidget::CurrentPlayList ) { |
92 | //if playing in file list.. play in a different way | 92 | //if playing in file list.. play in a different way |
93 | // random and looping settings enabled causes problems here, | 93 | // random and looping settings enabled causes problems here, |
94 | // since there is no selected file in the playlist, but a selected file in the file list, | 94 | // since there is no selected file in the playlist, but a selected file in the file list, |
95 | // so we remember and shutoff | 95 | // so we remember and shutoff |
96 | l = mediaPlayerState.isLooping(); | 96 | l = mediaPlayerState.isLooping(); |
97 | if(l) { | 97 | if(l) { |
98 | mediaPlayerState.setLooping( false ); | 98 | mediaPlayerState.setLooping( false ); |
99 | } | 99 | } |
100 | r = mediaPlayerState.isShuffled(); | 100 | r = mediaPlayerState.isShuffled(); |
101 | mediaPlayerState.setShuffled( false ); | 101 | mediaPlayerState.setShuffled( false ); |
102 | } | 102 | } |
103 | 103 | ||
104 | PlayListWidget::Entry playListEntry = playList.currentEntry(); | 104 | PlayListWidget::Entry playListEntry = playList.currentEntry(); |
105 | fileName = playListEntry.name; | 105 | fileName = playListEntry.name; |
106 | xineControl()->play( playListEntry.file ); | 106 | xineControl()->play( playListEntry.file ); |
107 | 107 | ||
108 | long seconds = mediaPlayerState.length(); | 108 | long seconds = mediaPlayerState.length(); |
109 | time.sprintf("%li:%02i", seconds/60, (int)seconds%60 ); | 109 | time.sprintf("%li:%02i", seconds/60, (int)seconds%60 ); |
110 | 110 | ||
111 | if( fileName.left(4) == "http" ) { | 111 | if( fileName.left(4) == "http" ) { |
112 | fileName = QFileInfo( fileName ).baseName(); | 112 | fileName = QFileInfo( fileName ).baseName(); |
113 | if ( xineControl()->getMetaInfo().isEmpty() ) { | 113 | if ( xineControl()->getMetaInfo().isEmpty() ) { |
114 | tickerText = tr( " File: " ) + fileName; | 114 | tickerText = tr( " File: " ) + fileName; |
115 | } else { | 115 | } else { |
116 | tickerText = xineControl()->getMetaInfo(); | 116 | tickerText = xineControl()->getMetaInfo(); |
117 | } | 117 | } |
118 | } else { | 118 | } else { |
119 | if ( xineControl()->getMetaInfo().isEmpty() ) { | 119 | if ( xineControl()->getMetaInfo().isEmpty() ) { |
120 | tickerText = tr( " File: " ) + fileName + tr( ", Length: " ) + time + " "; | 120 | tickerText = tr( " File: " ) + fileName + tr( ", Length: " ) + time + " "; |
121 | } else { | 121 | } else { |
122 | tickerText = xineControl()->getMetaInfo() + " Length: " + time + " "; | 122 | tickerText = xineControl()->getMetaInfo() + " Length: " + time + " "; |
123 | } | 123 | } |
124 | } | 124 | } |
125 | audioUI()->setTickerText( tickerText ); | 125 | audioUI()->setTickerText( tickerText ); |
126 | } | 126 | } |
127 | 127 | ||
128 | 128 | ||
129 | void MediaPlayer::prev() { | 129 | void MediaPlayer::prev() { |
130 | if( playList.currentTab() == PlayListWidget::CurrentPlayList ) { //if using the playlist | 130 | if( playList.currentTab() == PlayListWidget::CurrentPlayList ) { //if using the playlist |
131 | if ( playList.prev() ) { | 131 | if ( playList.prev() ) { |
132 | play(); | 132 | play(); |
133 | } else if ( mediaPlayerState.isLooping() ) { | 133 | } else if ( mediaPlayerState.isLooping() ) { |
134 | if ( playList.last() ) { | 134 | if ( playList.last() ) { |
135 | play(); | 135 | play(); |
136 | } | 136 | } |
137 | } else { | 137 | } else { |
138 | mediaPlayerState.setList(); | 138 | mediaPlayerState.setList(); |
139 | } | 139 | } |
140 | } | 140 | } |
141 | } | 141 | } |
142 | 142 | ||
143 | 143 | ||
144 | void MediaPlayer::next() { | 144 | void MediaPlayer::next() { |
145 | 145 | ||
146 | if(playList.currentTab() == PlayListWidget::CurrentPlayList) { //if using the playlist | 146 | if(playList.currentTab() == PlayListWidget::CurrentPlayList) { //if using the playlist |
147 | if ( playList.next() ) { | 147 | if ( playList.next() ) { |
148 | play(); | 148 | play(); |
149 | } else if ( mediaPlayerState.isLooping() ) { | 149 | } else if ( mediaPlayerState.isLooping() ) { |
150 | if ( playList.first() ) { | 150 | if ( playList.first() ) { |
151 | play(); | 151 | play(); |
152 | } | 152 | } |
153 | } else { | 153 | } else { |
154 | mediaPlayerState.setList(); | 154 | mediaPlayerState.setList(); |
155 | } | 155 | } |
156 | } else { //if playing from file list, let's just stop | 156 | } else { //if playing from file list, let's just stop |
157 | odebug << "<<<<<<<<<<<<<<<<<stop for filelists" << oendl; | 157 | odebug << "<<<<<<<<<<<<<<<<<stop for filelists" << oendl; |
158 | mediaPlayerState.setPlaying(false); | 158 | mediaPlayerState.setPlaying(false); |
159 | mediaPlayerState.setDisplayType( MediaPlayerState::MediaSelection ); | 159 | mediaPlayerState.setDisplayType( MediaPlayerState::MediaSelection ); |
160 | if(l) mediaPlayerState.setLooping(l); | 160 | if(l) mediaPlayerState.setLooping(l); |
161 | if(r) mediaPlayerState.setShuffled(r); | 161 | if(r) mediaPlayerState.setShuffled(r); |
162 | } | 162 | } |
163 | qApp->processEvents(); | 163 | qApp->processEvents(); |
164 | } | 164 | } |
165 | 165 | ||
166 | 166 | ||
167 | void MediaPlayer::startDecreasingVolume() { | 167 | void MediaPlayer::startDecreasingVolume() { |
168 | volumeDirection = -1; | 168 | volumeDirection = -1; |
169 | startTimer( 100 ); | 169 | startTimer( 100 ); |
170 | volControl->decVol(2); | 170 | volControl->decVol(2); |
171 | } | 171 | } |
172 | 172 | ||
173 | 173 | ||
174 | void MediaPlayer::startIncreasingVolume() { | 174 | void MediaPlayer::startIncreasingVolume() { |
175 | volumeDirection = +1; | 175 | volumeDirection = +1; |
176 | startTimer( 100 ); | 176 | startTimer( 100 ); |
177 | volControl->incVol(2); | 177 | volControl->incVol(2); |
178 | } | 178 | } |
179 | 179 | ||
180 | 180 | ||
181 | bool drawnOnScreenDisplay = FALSE; | 181 | bool drawnOnScreenDisplay = FALSE; |
182 | unsigned int onScreenDisplayVolume = 0; | 182 | unsigned int onScreenDisplayVolume = 0; |
183 | const int yoff = 110; | 183 | const int yoff = 110; |
184 | 184 | ||
185 | void MediaPlayer::stopChangingVolume() { | 185 | void MediaPlayer::stopChangingVolume() { |
186 | killTimers(); | 186 | killTimers(); |
187 | // Get rid of the on-screen display stuff | 187 | // Get rid of the on-screen display stuff |
188 | drawnOnScreenDisplay = FALSE; | 188 | drawnOnScreenDisplay = FALSE; |
189 | onScreenDisplayVolume = 0; | 189 | onScreenDisplayVolume = 0; |
190 | int w=0; | 190 | int w=0; |
191 | int h=0; | 191 | int h=0; |
192 | if( !xineControl()->hasVideo() ) { | 192 | if( !xineControl()->hasVideo() ) { |
193 | w = audioUI()->width(); | 193 | w = audioUI()->width(); |
194 | h = audioUI()->height(); | 194 | h = audioUI()->height(); |
195 | audioUI()->repaint( ( w - 200 ) / 2, h - yoff, 200 + 9, 70, FALSE ); | 195 | audioUI()->repaint( ( w - 200 ) / 2, h - yoff, 200 + 9, 70, FALSE ); |
196 | } else { | 196 | } else { |
197 | w = videoUI()->width(); | 197 | w = videoUI()->width(); |
198 | h = videoUI()->height(); | 198 | h = videoUI()->height(); |
199 | videoUI()->repaint( ( w - 200 ) / 2, h - yoff, 200 + 9, 70, FALSE ); | 199 | videoUI()->repaint( ( w - 200 ) / 2, h - yoff, 200 + 9, 70, FALSE ); |
200 | } | 200 | } |
201 | } | 201 | } |
202 | 202 | ||
203 | 203 | ||
204 | void MediaPlayer::timerEvent( QTimerEvent * ) { | 204 | void MediaPlayer::timerEvent( QTimerEvent * ) { |
205 | if ( volumeDirection == +1 ) { | 205 | if ( volumeDirection == +1 ) { |
206 | volControl->incVol( 2 ); | 206 | volControl->incVol( 2 ); |
207 | } else if ( volumeDirection == -1 ) { | 207 | } else if ( volumeDirection == -1 ) { |
208 | volControl->decVol( 2 ); | 208 | volControl->decVol( 2 ); |
209 | } | 209 | } |
210 | 210 | ||
211 | 211 | ||
212 | // TODO FIXME | 212 | // TODO FIXME |
213 | // huh?? | 213 | // huh?? |
214 | unsigned int v= 0; | 214 | unsigned int v= 0; |
215 | v = volControl->volume(); | 215 | v = volControl->volume(); |
216 | v = v / 10; | 216 | v = v / 10; |
217 | 217 | ||
218 | if ( drawnOnScreenDisplay && onScreenDisplayVolume == v ) { | 218 | if ( drawnOnScreenDisplay && onScreenDisplayVolume == v ) { |
219 | return; | 219 | return; |
220 | } | 220 | } |
221 | 221 | ||
222 | int w=0; int h=0; | 222 | int w=0; int h=0; |
223 | if( !xineControl()->hasVideo() ) { | 223 | if( !xineControl()->hasVideo() ) { |
224 | w = audioUI()->width(); | 224 | w = audioUI()->width(); |
225 | h = audioUI()->height(); | 225 | h = audioUI()->height(); |
226 | 226 | ||
227 | if ( drawnOnScreenDisplay ) { | 227 | if ( drawnOnScreenDisplay ) { |
228 | if ( onScreenDisplayVolume > v ) { | 228 | if ( onScreenDisplayVolume > v ) { |
229 | audioUI()->repaint( ( w - 200 ) / 2 + v * 20 + 0, h - yoff + 40, ( onScreenDisplayVolume - v ) * 20 + 9, 30, FALSE ); | 229 | audioUI()->repaint( ( w - 200 ) / 2 + v * 20 + 0, h - yoff + 40, ( onScreenDisplayVolume - v ) * 20 + 9, 30, FALSE ); |
230 | } | 230 | } |
231 | } | 231 | } |
232 | drawnOnScreenDisplay = TRUE; | 232 | drawnOnScreenDisplay = TRUE; |
233 | onScreenDisplayVolume = v; | 233 | onScreenDisplayVolume = v; |
234 | QPainter p( audioUI() ); | 234 | QPainter p( audioUI() ); |
235 | p.setPen( QColor( 0x10, 0xD0, 0x10 ) ); | 235 | p.setPen( QColor( 0x10, 0xD0, 0x10 ) ); |
236 | p.setBrush( QColor( 0x10, 0xD0, 0x10 ) ); | 236 | p.setBrush( QColor( 0x10, 0xD0, 0x10 ) ); |
237 | 237 | ||
238 | QFont f; | 238 | QFont f; |
239 | f.setPixelSize( 20 ); | 239 | f.setPixelSize( 20 ); |
240 | f.setBold( TRUE ); | 240 | f.setBold( TRUE ); |
241 | p.setFont( f ); | 241 | p.setFont( f ); |
242 | p.drawText( (w - 200) / 2, h - yoff + 20, tr("Volume") ); | 242 | p.drawText( (w - 200) / 2, h - yoff + 20, tr("Volume") ); |
243 | 243 | ||
244 | for ( unsigned int i = 0; i < 10; i++ ) { | 244 | for ( unsigned int i = 0; i < 10; i++ ) { |
245 | if ( v > i ) { | 245 | if ( v > i ) { |
246 | p.drawRect( ( w - 200 ) / 2 + i * 20 + 0, h - yoff + 40, 9, 30 ); | 246 | p.drawRect( ( w - 200 ) / 2 + i * 20 + 0, h - yoff + 40, 9, 30 ); |
247 | } else { | 247 | } else { |
248 | p.drawRect( ( w - 200 ) / 2 + i * 20 + 3, h - yoff + 50, 3, 10 ); | 248 | p.drawRect( ( w - 200 ) / 2 + i * 20 + 3, h - yoff + 50, 3, 10 ); |
249 | } | 249 | } |
250 | } | 250 | } |
251 | } else { | 251 | } else { |
252 | w = videoUI()->width(); | 252 | w = videoUI()->width(); |
253 | h = videoUI()->height(); | 253 | h = videoUI()->height(); |
254 | 254 | ||
255 | if ( drawnOnScreenDisplay ) { | 255 | if ( drawnOnScreenDisplay ) { |
256 | if ( onScreenDisplayVolume > v ) { | 256 | if ( onScreenDisplayVolume > v ) { |
257 | videoUI()->repaint( (w - 200) / 2 + v * 20 + 0, h - yoff + 40, ( onScreenDisplayVolume - v ) * 20 + 9, 30, FALSE ); | 257 | videoUI()->repaint( (w - 200) / 2 + v * 20 + 0, h - yoff + 40, ( onScreenDisplayVolume - v ) * 20 + 9, 30, FALSE ); |
258 | } | 258 | } |
259 | } | 259 | } |
260 | drawnOnScreenDisplay = TRUE; | 260 | drawnOnScreenDisplay = TRUE; |
261 | onScreenDisplayVolume = v; | 261 | onScreenDisplayVolume = v; |
262 | QPainter p( videoUI() ); | 262 | QPainter p( videoUI() ); |
263 | p.setPen( QColor( 0x10, 0xD0, 0x10 ) ); | 263 | p.setPen( QColor( 0x10, 0xD0, 0x10 ) ); |
264 | p.setBrush( QColor( 0x10, 0xD0, 0x10 ) ); | 264 | p.setBrush( QColor( 0x10, 0xD0, 0x10 ) ); |
265 | 265 | ||
266 | QFont f; | 266 | QFont f; |
267 | f.setPixelSize( 20 ); | 267 | f.setPixelSize( 20 ); |
268 | f.setBold( TRUE ); | 268 | f.setBold( TRUE ); |
269 | p.setFont( f ); | 269 | p.setFont( f ); |
270 | p.drawText( (w - 200) / 2, h - yoff + 20, tr( "Volume" ) ); | 270 | p.drawText( (w - 200) / 2, h - yoff + 20, tr( "Volume" ) ); |
271 | 271 | ||
272 | for ( unsigned int i = 0; i < 10; i++ ) { | 272 | for ( unsigned int i = 0; i < 10; i++ ) { |
273 | if ( v > i ) { | 273 | if ( v > i ) { |
274 | p.drawRect( (w - 200) / 2 + i * 20 + 0, h - yoff + 40, 9, 30 ); | 274 | p.drawRect( (w - 200) / 2 + i * 20 + 0, h - yoff + 40, 9, 30 ); |
275 | } else { | 275 | } else { |
276 | p.drawRect( (w - 200) / 2 + i * 20 + 3, h - yoff + 50, 3, 10 ); | 276 | p.drawRect( (w - 200) / 2 + i * 20 + 3, h - yoff + 50, 3, 10 ); |
277 | } | 277 | } |
278 | } | 278 | } |
279 | } | 279 | } |
280 | } | 280 | } |
281 | 281 | ||
282 | 282 | ||
283 | void MediaPlayer::blank( bool b ) { | 283 | void MediaPlayer::blank( bool b ) { |
284 | #ifdef QT_QWS_DEVFS | ||
285 | fd=open("/dev/fb/0",O_RDWR); | ||
286 | #else | ||
284 | fd=open("/dev/fb0",O_RDWR); | 287 | fd=open("/dev/fb0",O_RDWR); |
288 | #endif | ||
285 | #ifdef QT_QWS_SL5XXX | 289 | #ifdef QT_QWS_SL5XXX |
286 | fl= open( "/dev/fl", O_RDWR ); | 290 | fl= open( "/dev/fl", O_RDWR ); |
287 | #endif | 291 | #endif |
288 | if (fd != -1) { | 292 | if (fd != -1) { |
289 | if ( b ) { | 293 | if ( b ) { |
290 | odebug << "do blanking" << oendl; | 294 | odebug << "do blanking" << oendl; |
291 | #ifdef QT_QWS_SL5XXX | 295 | #ifdef QT_QWS_SL5XXX |
292 | ioctl( fd, FBIOBLANK, 1 ); | 296 | ioctl( fd, FBIOBLANK, 1 ); |
293 | if(fl !=-1) { | 297 | if(fl !=-1) { |
294 | ioctl( fl, 2 ); | 298 | ioctl( fl, 2 ); |
295 | ::close(fl); | 299 | ::close(fl); |
296 | } | 300 | } |
297 | #else | 301 | #else |
298 | ioctl( fd, FBIOBLANK, 3 ); | 302 | ioctl( fd, FBIOBLANK, 3 ); |
299 | #endif | 303 | #endif |
300 | isBlanked = TRUE; | 304 | isBlanked = TRUE; |
301 | } else { | 305 | } else { |
302 | odebug << "do unblanking" << oendl; | 306 | odebug << "do unblanking" << oendl; |
303 | ioctl( fd, FBIOBLANK, 0); | 307 | ioctl( fd, FBIOBLANK, 0); |
304 | #ifdef QT_QWS_SL5XXX | 308 | #ifdef QT_QWS_SL5XXX |
305 | if(fl != -1) { | 309 | if(fl != -1) { |
306 | ioctl( fl, 1); | 310 | ioctl( fl, 1); |
307 | ::close(fl); | 311 | ::close(fl); |
308 | } | 312 | } |
309 | #endif | 313 | #endif |
310 | isBlanked = FALSE; | 314 | isBlanked = FALSE; |
311 | } | 315 | } |
312 | close( fd ); | 316 | close( fd ); |
313 | } else { | 317 | } else { |
314 | odebug << "<< /dev/fb0 could not be opened >>" << oendl; | 318 | odebug << "<< /dev/fb0 could not be opened >>" << oendl; |
315 | } | 319 | } |
316 | } | 320 | } |
317 | 321 | ||
318 | void MediaPlayer::keyReleaseEvent( QKeyEvent *e) { | 322 | void MediaPlayer::keyReleaseEvent( QKeyEvent *e) { |
319 | switch ( e->key() ) { | 323 | switch ( e->key() ) { |
320 | ////////////////////////////// Zaurus keys | 324 | ////////////////////////////// Zaurus keys |
321 | case Key_Home: | 325 | case Key_Home: |
322 | break; | 326 | break; |
323 | case Key_F9: //activity | 327 | case Key_F9: //activity |
324 | break; | 328 | break; |
325 | case Key_F10: //contacts | 329 | case Key_F10: //contacts |
326 | break; | 330 | break; |
327 | case Key_F11: //menu | 331 | case Key_F11: //menu |
328 | break; | 332 | break; |
329 | case Key_F12: //home | 333 | case Key_F12: //home |
330 | odebug << "Blank here" << oendl; | 334 | odebug << "Blank here" << oendl; |
331 | // mediaPlayerState->toggleBlank(); | 335 | // mediaPlayerState->toggleBlank(); |
332 | break; | 336 | break; |
333 | case Key_F13: //mail | 337 | case Key_F13: //mail |
334 | odebug << "Blank here" << oendl; | 338 | odebug << "Blank here" << oendl; |
335 | // mediaPlayerState->toggleBlank(); | 339 | // mediaPlayerState->toggleBlank(); |
336 | break; | 340 | break; |
337 | } | 341 | } |
338 | } | 342 | } |
339 | 343 | ||
340 | void MediaPlayer::cleanUp() {// this happens on closing | 344 | void MediaPlayer::cleanUp() {// this happens on closing |
341 | Config cfg( "OpiePlayer" ); | 345 | Config cfg( "OpiePlayer" ); |
342 | mediaPlayerState.writeConfig( cfg ); | 346 | mediaPlayerState.writeConfig( cfg ); |
343 | playList.writeDefaultPlaylist( ); | 347 | playList.writeDefaultPlaylist( ); |
344 | 348 | ||
345 | // QPEApplication::grabKeyboard(); | 349 | // QPEApplication::grabKeyboard(); |
346 | // QPEApplication::ungrabKeyboard(); | 350 | // QPEApplication::ungrabKeyboard(); |
347 | } | 351 | } |
348 | 352 | ||
349 | void MediaPlayer::recreateAudioAndVideoWidgets() const | 353 | void MediaPlayer::recreateAudioAndVideoWidgets() const |
350 | { | 354 | { |
351 | delete m_skinLoader; | 355 | delete m_skinLoader; |
352 | 356 | ||
353 | delete m_xineControl; | 357 | delete m_xineControl; |
354 | delete m_audioUI; | 358 | delete m_audioUI; |
355 | delete m_videoUI; | 359 | delete m_videoUI; |
356 | m_audioUI = new AudioWidget( playList, mediaPlayerState, 0, "audioUI" ); | 360 | m_audioUI = new AudioWidget( playList, mediaPlayerState, 0, "audioUI" ); |
357 | m_videoUI = new VideoWidget( playList, mediaPlayerState, 0, "videoUI" ); | 361 | m_videoUI = new VideoWidget( playList, mediaPlayerState, 0, "videoUI" ); |
358 | 362 | ||
359 | connect( m_audioUI, SIGNAL( moreClicked() ), this, SLOT( startIncreasingVolume() ) ); | 363 | connect( m_audioUI, SIGNAL( moreClicked() ), this, SLOT( startIncreasingVolume() ) ); |
360 | connect( m_audioUI, SIGNAL( lessClicked() ), this, SLOT( startDecreasingVolume() ) ); | 364 | connect( m_audioUI, SIGNAL( lessClicked() ), this, SLOT( startDecreasingVolume() ) ); |
361 | connect( m_audioUI, SIGNAL( moreReleased() ), this, SLOT( stopChangingVolume() ) ); | 365 | connect( m_audioUI, SIGNAL( moreReleased() ), this, SLOT( stopChangingVolume() ) ); |
362 | connect( m_audioUI, SIGNAL( lessReleased() ), this, SLOT( stopChangingVolume() ) ); | 366 | connect( m_audioUI, SIGNAL( lessReleased() ), this, SLOT( stopChangingVolume() ) ); |
363 | 367 | ||
364 | connect( m_videoUI, SIGNAL( moreClicked() ), this, SLOT( startIncreasingVolume() ) ); | 368 | connect( m_videoUI, SIGNAL( moreClicked() ), this, SLOT( startIncreasingVolume() ) ); |
365 | connect( m_videoUI, SIGNAL( lessClicked() ), this, SLOT( startDecreasingVolume() ) ); | 369 | connect( m_videoUI, SIGNAL( lessClicked() ), this, SLOT( startDecreasingVolume() ) ); |
366 | connect( m_videoUI, SIGNAL( moreReleased() ), this, SLOT( stopChangingVolume() ) ); | 370 | connect( m_videoUI, SIGNAL( moreReleased() ), this, SLOT( stopChangingVolume() ) ); |
367 | connect( m_videoUI, SIGNAL( lessReleased() ), this, SLOT( stopChangingVolume() ) ); | 371 | connect( m_videoUI, SIGNAL( lessReleased() ), this, SLOT( stopChangingVolume() ) ); |
368 | 372 | ||
369 | if ( !xine ) | 373 | if ( !xine ) |
370 | xine = new XINE::Lib( XINE::Lib::InitializeImmediately ); | 374 | xine = new XINE::Lib( XINE::Lib::InitializeImmediately ); |
371 | 375 | ||
372 | m_xineControl = new XineControl( xine, m_videoUI->vidWidget(), mediaPlayerState ); | 376 | m_xineControl = new XineControl( xine, m_videoUI->vidWidget(), mediaPlayerState ); |
373 | 377 | ||
374 | xine = 0; | 378 | xine = 0; |
375 | } | 379 | } |
376 | 380 | ||
377 | AudioWidget *MediaPlayer::audioUI() const | 381 | AudioWidget *MediaPlayer::audioUI() const |
378 | { | 382 | { |
379 | if ( !m_audioUI ) | 383 | if ( !m_audioUI ) |
380 | recreateAudioAndVideoWidgets(); | 384 | recreateAudioAndVideoWidgets(); |
381 | return m_audioUI; | 385 | return m_audioUI; |
382 | } | 386 | } |
383 | 387 | ||
384 | VideoWidget *MediaPlayer::videoUI() const | 388 | VideoWidget *MediaPlayer::videoUI() const |
385 | { | 389 | { |
386 | if ( !m_videoUI ) | 390 | if ( !m_videoUI ) |
387 | recreateAudioAndVideoWidgets(); | 391 | recreateAudioAndVideoWidgets(); |
388 | return m_videoUI; | 392 | return m_videoUI; |
389 | } | 393 | } |
390 | 394 | ||
391 | XineControl *MediaPlayer::xineControl() const | 395 | XineControl *MediaPlayer::xineControl() const |
392 | { | 396 | { |
393 | if ( !m_xineControl ) | 397 | if ( !m_xineControl ) |
394 | recreateAudioAndVideoWidgets(); | 398 | recreateAudioAndVideoWidgets(); |
395 | return m_xineControl; | 399 | return m_xineControl; |
396 | } | 400 | } |
397 | 401 | ||
398 | void MediaPlayer::reloadSkins() | 402 | void MediaPlayer::reloadSkins() |
399 | { | 403 | { |
400 | audioUI()->loadSkin(); | 404 | audioUI()->loadSkin(); |
401 | videoUI()->loadSkin(); | 405 | videoUI()->loadSkin(); |
402 | } | 406 | } |
403 | 407 | ||
diff --git a/noncore/multimedia/opierec/device.cpp b/noncore/multimedia/opierec/device.cpp index 683f0a5..cb47b77 100644 --- a/noncore/multimedia/opierec/device.cpp +++ b/noncore/multimedia/opierec/device.cpp | |||
@@ -1,358 +1,374 @@ | |||
1 | // device.cpp | 1 | // device.cpp |
2 | 2 | ||
3 | #include "device.h" | 3 | #include "device.h" |
4 | 4 | ||
5 | #include <qpe/config.h> | 5 | #include <qpe/config.h> |
6 | #include <qpe/qcopenvelope_qws.h> | 6 | #include <qpe/qcopenvelope_qws.h> |
7 | 7 | ||
8 | /* STD */ | 8 | /* STD */ |
9 | #include <fcntl.h> | 9 | #include <fcntl.h> |
10 | #include <stdio.h> | 10 | #include <stdio.h> |
11 | #include <stdlib.h> | 11 | #include <stdlib.h> |
12 | #include <sys/ioctl.h> | 12 | #include <sys/ioctl.h> |
13 | #include <sys/soundcard.h> | 13 | #include <sys/soundcard.h> |
14 | #include <unistd.h> | 14 | #include <unistd.h> |
15 | #include <sys/wait.h> | 15 | #include <sys/wait.h> |
16 | #include <unistd.h> | 16 | #include <unistd.h> |
17 | #include <errno.h> | 17 | #include <errno.h> |
18 | 18 | ||
19 | //extern QtRec *qperec; | 19 | //extern QtRec *qperec; |
20 | 20 | ||
21 | Device::Device( QObject * parent, const char * dsp, const char * mixr, bool record ) | 21 | Device::Device( QObject * parent, const char * dsp, const char * mixr, bool record ) |
22 | : QObject( parent) | 22 | : QObject( parent) |
23 | { | 23 | { |
24 | dspstr = (char *)dsp; | 24 | dspstr = (char *)dsp; |
25 | mixstr = (char *)mixr; | 25 | mixstr = (char *)mixr; |
26 | 26 | ||
27 | devForm=-1; | 27 | devForm=-1; |
28 | devCh=-1; | 28 | devCh=-1; |
29 | devRate=-1; | 29 | devRate=-1; |
30 | 30 | ||
31 | if( !record){ //playing | 31 | if( !record){ //playing |
32 | qDebug( "setting up DSP for playing" ); | 32 | qDebug( "setting up DSP for playing" ); |
33 | flags = O_WRONLY; | 33 | flags = O_WRONLY; |
34 | } else { //recording | 34 | } else { //recording |
35 | qDebug( "setting up DSP for recording" ); | 35 | qDebug( "setting up DSP for recording" ); |
36 | flags = O_RDWR; | 36 | flags = O_RDWR; |
37 | // flags = O_RDONLY; | 37 | // flags = O_RDONLY; |
38 | 38 | ||
39 | // selectMicInput(); | 39 | // selectMicInput(); |
40 | 40 | ||
41 | } | 41 | } |
42 | } | 42 | } |
43 | 43 | ||
44 | bool Device::openDsp() { | 44 | bool Device::openDsp() { |
45 | if( openDevice( flags) == -1) { | 45 | if( openDevice( flags) == -1) { |
46 | perror("<<<<<<<<<<<<<<ioctl(\"Open device\")"); | 46 | perror("<<<<<<<<<<<<<<ioctl(\"Open device\")"); |
47 | return false; | 47 | return false; |
48 | } | 48 | } |
49 | return true; | 49 | return true; |
50 | } | 50 | } |
51 | 51 | ||
52 | int Device::openDevice( int flags) { | 52 | int Device::openDevice( int flags) { |
53 | /* pid_t pid; | 53 | /* pid_t pid; |
54 | int status; | 54 | int status; |
55 | int pipefd[2]; | 55 | int pipefd[2]; |
56 | char message[20]; | 56 | char message[20]; |
57 | if (pipe(pipefd) == -1){ | 57 | if (pipe(pipefd) == -1){ |
58 | perror ("Error creating pipe"); | 58 | perror ("Error creating pipe"); |
59 | exit(1); | 59 | exit(1); |
60 | } | 60 | } |
61 | switch (pid = fork()) { | 61 | switch (pid = fork()) { |
62 | case -1: | 62 | case -1: |
63 | perror("The fork failed!"); | 63 | perror("The fork failed!"); |
64 | break; | 64 | break; |
65 | case 0: { | 65 | case 0: { |
66 | */ | 66 | */ |
67 | qDebug( "Opening %s",dspstr); | 67 | qDebug( "Opening %s",dspstr); |
68 | if (( sd = ::open( dspstr, flags)) == -1) { | 68 | if (( sd = ::open( dspstr, flags)) == -1) { |
69 | perror("open(\"/dev/dsp\")"); | 69 | perror("open(\"/dev/dsp\")"); |
70 | QString errorMsg="Could not open audio device\n /dev/dsp\n" | 70 | QString errorMsg="Could not open audio device\n /dev/dsp\n" |
71 | +(QString)strerror(errno); | 71 | +(QString)strerror(errno); |
72 | qDebug( "XXXXXXXXXXXXXXXXXXXXXXX "+errorMsg ); | 72 | qDebug( "XXXXXXXXXXXXXXXXXXXXXXX "+errorMsg ); |
73 | return -1; | 73 | return -1; |
74 | } | 74 | } |
75 | 75 | ||
76 | qDebug( "Opening mixer" ); | 76 | qDebug( "Opening mixer" ); |
77 | int mixerHandle=0; | 77 | int mixerHandle=0; |
78 | #ifdef QT_QWS_DEVFS | ||
79 | if (( mixerHandle = open("/dev/sound/mixer",O_RDWR))<0) { | ||
80 | #else | ||
78 | if (( mixerHandle = open("/dev/mixer",O_RDWR))<0) { | 81 | if (( mixerHandle = open("/dev/mixer",O_RDWR))<0) { |
82 | #endif | ||
79 | perror("open(\"/dev/mixer\")"); | 83 | perror("open(\"/dev/mixer\")"); |
80 | QString errorMsg="Could not open audio device\n /dev/dsp\n" | 84 | QString errorMsg="Could not open audio device\n /dev/dsp\n" |
81 | +(QString)strerror(errno); | 85 | +(QString)strerror(errno); |
82 | qDebug( "XXXXXXXXXXXXXXXXXXXXXX "+errorMsg ); | 86 | qDebug( "XXXXXXXXXXXXXXXXXXXXXX "+errorMsg ); |
83 | } | 87 | } |
84 | 88 | ||
85 | if(ioctl(sd,SNDCTL_DSP_RESET,0)<0){ | 89 | if(ioctl(sd,SNDCTL_DSP_RESET,0)<0){ |
86 | perror("ioctl RESET"); | 90 | perror("ioctl RESET"); |
87 | } | 91 | } |
88 | // sprintf(message, "%d", sd); | 92 | // sprintf(message, "%d", sd); |
89 | 93 | ||
90 | /* QFile f1("/pid"); | 94 | /* QFile f1("/pid"); |
91 | f1.open(IO_WriteOnly ); | 95 | f1.open(IO_WriteOnly ); |
92 | f1.writeBlock(message, strlen(message)); | 96 | f1.writeBlock(message, strlen(message)); |
93 | f1.close(); | 97 | f1.close(); |
94 | */ | 98 | */ |
95 | /* close(pipefd[0]); | 99 | /* close(pipefd[0]); |
96 | write(pipefd[1], message, sizeof(message)); | 100 | write(pipefd[1], message, sizeof(message)); |
97 | close(pipefd[1]); | 101 | close(pipefd[1]); |
98 | // qDebug( "" + soundDevice->sd ); | 102 | // qDebug( "" + soundDevice->sd ); |
99 | _exit(0); | 103 | _exit(0); |
100 | } | 104 | } |
101 | default: | 105 | default: |
102 | // pid greater than zero is parent getting the child's pid | 106 | // pid greater than zero is parent getting the child's pid |
103 | printf("Child's pid is %d\n",pid); | 107 | printf("Child's pid is %d\n",pid); |
104 | QString s; | 108 | QString s; |
105 | close(pipefd[1]); | 109 | close(pipefd[1]); |
106 | read(pipefd[0], message, sizeof(message)); | 110 | read(pipefd[0], message, sizeof(message)); |
107 | s = message; | 111 | s = message; |
108 | close(pipefd[0]); | 112 | close(pipefd[0]); |
109 | 113 | ||
110 | // while(wait(NULL)!=pid) | 114 | // while(wait(NULL)!=pid) |
111 | // ; | 115 | // ; |
112 | printf("child %ld terminated normally, return status is zero\n", (long) pid); | 116 | printf("child %ld terminated normally, return status is zero\n", (long) pid); |
113 | */ | 117 | */ |
114 | // filePara.sd=(long) pid; | 118 | // filePara.sd=(long) pid; |
115 | /* QFile f2("/pid"); | 119 | /* QFile f2("/pid"); |
116 | f2.open(IO_ReadOnly); | 120 | f2.open(IO_ReadOnly); |
117 | QTextStream t(&f2); | 121 | QTextStream t(&f2); |
118 | // for(int f=0; f < t.atEnd() ;f++) { | 122 | // for(int f=0; f < t.atEnd() ;f++) { |
119 | s = t.readLine(); | 123 | s = t.readLine(); |
120 | // } | 124 | // } |
121 | */ | 125 | */ |
122 | // bool ok; | 126 | // bool ok; |
123 | // sd = s.toInt(&ok, 10); | 127 | // sd = s.toInt(&ok, 10); |
124 | // qDebug( "<<<<<<<<<<<<<>>>>>>>>>>>>"+s ); | 128 | // qDebug( "<<<<<<<<<<<<<>>>>>>>>>>>>"+s ); |
125 | 129 | ||
126 | // f2.close(); | 130 | // f2.close(); |
127 | // } | 131 | // } |
128 | ::close(mixerHandle ); | 132 | ::close(mixerHandle ); |
129 | // qDebug( "open device " + dspstr ); | 133 | // qDebug( "open device " + dspstr ); |
130 | // qDebug( "success! " + sd ); | 134 | // qDebug( "success! " + sd ); |
131 | return sd; | 135 | return sd; |
132 | } | 136 | } |
133 | 137 | ||
134 | 138 | ||
135 | int Device::getOutVolume( ) { | 139 | int Device::getOutVolume( ) { |
136 | unsigned int volume; | 140 | unsigned int volume; |
137 | int mixerHandle = open( mixstr, O_RDWR ); | 141 | int mixerHandle = open( mixstr, O_RDWR ); |
138 | if ( mixerHandle >= 0 ) { | 142 | if ( mixerHandle >= 0 ) { |
139 | if(ioctl( mixerHandle, MIXER_READ(SOUND_MIXER_VOLUME), &volume )==-1) | 143 | if(ioctl( mixerHandle, MIXER_READ(SOUND_MIXER_VOLUME), &volume )==-1) |
140 | perror("<<<<<<<<<<<<<<ioctl(\"MIXER_READ\")"); | 144 | perror("<<<<<<<<<<<<<<ioctl(\"MIXER_READ\")"); |
141 | ::close( mixerHandle ); | 145 | ::close( mixerHandle ); |
142 | } else | 146 | } else |
143 | perror("open(\"/dev/mixer\")"); | 147 | perror("open(\"/dev/mixer\")"); |
144 | printf("<<<<<<<<<<<<<<<<<<<<output volume %d\n",volume); | 148 | printf("<<<<<<<<<<<<<<<<<<<<output volume %d\n",volume); |
145 | 149 | ||
146 | Config cfg("qpe"); | 150 | Config cfg("qpe"); |
147 | cfg.setGroup("Volume"); | 151 | cfg.setGroup("Volume"); |
148 | 152 | ||
149 | return cfg.readNumEntry("VolumePercent"); | 153 | return cfg.readNumEntry("VolumePercent"); |
150 | } | 154 | } |
151 | 155 | ||
152 | int Device::getInVolume() { | 156 | int Device::getInVolume() { |
153 | unsigned int volume=0; | 157 | unsigned int volume=0; |
154 | int mixerHandle = ::open( mixstr, O_RDWR ); | 158 | int mixerHandle = ::open( mixstr, O_RDWR ); |
155 | if ( mixerHandle >= 0 ) { | 159 | if ( mixerHandle >= 0 ) { |
156 | if(ioctl( mixerHandle, MIXER_READ(SOUND_MIXER_MIC), &volume )==-1) | 160 | if(ioctl( mixerHandle, MIXER_READ(SOUND_MIXER_MIC), &volume )==-1) |
157 | perror("<<<<<<<<<<<<<<<ioctl(\"MIXER_READ\")"); | 161 | perror("<<<<<<<<<<<<<<<ioctl(\"MIXER_READ\")"); |
158 | ::close( mixerHandle ); | 162 | ::close( mixerHandle ); |
159 | } else | 163 | } else |
160 | perror("open(\"/dev/mixer\")"); | 164 | perror("open(\"/dev/mixer\")"); |
161 | printf("<<<<<<<<<<<<<<input volume %d\n", volume ); | 165 | printf("<<<<<<<<<<<<<<input volume %d\n", volume ); |
162 | Config cfg("qpe"); | 166 | Config cfg("qpe"); |
163 | cfg.setGroup("Volume"); | 167 | cfg.setGroup("Volume"); |
164 | 168 | ||
165 | return cfg.readNumEntry("Mic"); | 169 | return cfg.readNumEntry("Mic"); |
166 | } | 170 | } |
167 | 171 | ||
168 | void Device::changedOutVolume(int vol) { | 172 | void Device::changedOutVolume(int vol) { |
169 | int level = (vol << 8) + vol; | 173 | int level = (vol << 8) + vol; |
170 | int fd = 0; | 174 | int fd = 0; |
175 | #ifdef QT_QWS_DEVFS | ||
176 | if ((fd = open("/dev/sound/mixer", O_RDWR))>=0) { | ||
177 | #else | ||
171 | if ((fd = open("/dev/mixer", O_RDWR))>=0) { | 178 | if ((fd = open("/dev/mixer", O_RDWR))>=0) { |
179 | #endif | ||
172 | if(ioctl(fd, MIXER_WRITE(SOUND_MIXER_VOLUME), &level) == -1) | 180 | if(ioctl(fd, MIXER_WRITE(SOUND_MIXER_VOLUME), &level) == -1) |
173 | perror("ioctl(\"MIXER_IN_WRITE\")"); | 181 | perror("ioctl(\"MIXER_IN_WRITE\")"); |
174 | 182 | ||
175 | Config cfg("qpe"); | 183 | Config cfg("qpe"); |
176 | cfg.setGroup("Volume"); | 184 | cfg.setGroup("Volume"); |
177 | cfg.writeEntry("VolumePercent", QString::number( vol )); | 185 | cfg.writeEntry("VolumePercent", QString::number( vol )); |
178 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << false; | 186 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << false; |
179 | qDebug("changing output vol %d" ,vol ); | 187 | qDebug("changing output vol %d" ,vol ); |
180 | } | 188 | } |
181 | ::close(fd); | 189 | ::close(fd); |
182 | } | 190 | } |
183 | 191 | ||
184 | void Device::changedInVolume(int vol ) { | 192 | void Device::changedInVolume(int vol ) { |
185 | int level = (vol << 8) + vol; | 193 | int level = (vol << 8) + vol; |
186 | int fd = 0; | 194 | int fd = 0; |
195 | #ifdef QT_QWS_DEVFS | ||
196 | if ((fd = open("/dev/sound/mixer", O_RDWR))>=0) { | ||
197 | #else | ||
187 | if ((fd = open("/dev/mixer", O_RDWR))>=0) { | 198 | if ((fd = open("/dev/mixer", O_RDWR))>=0) { |
199 | #endif | ||
188 | if(ioctl(fd, MIXER_WRITE(SOUND_MIXER_MIC), &level) == -1) | 200 | if(ioctl(fd, MIXER_WRITE(SOUND_MIXER_MIC), &level) == -1) |
189 | perror("ioctl(\"MIXER_IN_WRITE\")"); | 201 | perror("ioctl(\"MIXER_IN_WRITE\")"); |
190 | Config cfg("qpe"); | 202 | Config cfg("qpe"); |
191 | cfg.setGroup("Volume"); | 203 | cfg.setGroup("Volume"); |
192 | cfg.writeEntry("Mic", QString::number(vol )); | 204 | cfg.writeEntry("Mic", QString::number(vol )); |
193 | QCopEnvelope( "QPE/System", "micChange(bool)" ) << false; | 205 | QCopEnvelope( "QPE/System", "micChange(bool)" ) << false; |
194 | qDebug("changing input volume %d",vol); | 206 | qDebug("changing input volume %d",vol); |
195 | } | 207 | } |
196 | ::close(fd); | 208 | ::close(fd); |
197 | } | 209 | } |
198 | 210 | ||
199 | bool Device::selectMicInput() { | 211 | bool Device::selectMicInput() { |
200 | 212 | ||
201 | int md=0; | 213 | int md=0; |
202 | int info=MIXER_WRITE(SOUND_MIXER_MIC); | 214 | int info=MIXER_WRITE(SOUND_MIXER_MIC); |
215 | #ifdef QT_QWS_DEVFS | ||
216 | md = ::open( "/dev/sound/mixer", O_RDWR ); | ||
217 | #else | ||
203 | md = ::open( "/dev/mixer", O_RDWR ); | 218 | md = ::open( "/dev/mixer", O_RDWR ); |
219 | #endif | ||
204 | if ( md == -1) | 220 | if ( md == -1) |
205 | perror("open(\"/dev/mixer\")"); | 221 | perror("open(\"/dev/mixer\")"); |
206 | else { | 222 | else { |
207 | if( ioctl( md, SOUND_MIXER_WRITE_RECSRC, &info) == -1) | 223 | if( ioctl( md, SOUND_MIXER_WRITE_RECSRC, &info) == -1) |
208 | perror("ioctl(\"SOUND_MIXER_WRITE_RECSRC\")"); | 224 | perror("ioctl(\"SOUND_MIXER_WRITE_RECSRC\")"); |
209 | ::close(md); | 225 | ::close(md); |
210 | return false; | 226 | return false; |
211 | } | 227 | } |
212 | ::close(md); | 228 | ::close(md); |
213 | 229 | ||
214 | return true; | 230 | return true; |
215 | } | 231 | } |
216 | 232 | ||
217 | bool Device::closeDevice( bool) { | 233 | bool Device::closeDevice( bool) { |
218 | // if(b) {//close now | 234 | // if(b) {//close now |
219 | // if (ioctl( sd, SNDCTL_DSP_RESET, 0) == -1) { | 235 | // if (ioctl( sd, SNDCTL_DSP_RESET, 0) == -1) { |
220 | // perror("ioctl(\"SNDCTL_DSP_RESET\")"); | 236 | // perror("ioctl(\"SNDCTL_DSP_RESET\")"); |
221 | // } | 237 | // } |
222 | // } else { //let play | 238 | // } else { //let play |
223 | // if (ioctl( sd, SNDCTL_DSP_SYNC, 0) == -1) { | 239 | // if (ioctl( sd, SNDCTL_DSP_SYNC, 0) == -1) { |
224 | // perror("ioctl(\"SNDCTL_DSP_SYNC\")"); | 240 | // perror("ioctl(\"SNDCTL_DSP_SYNC\")"); |
225 | // } | 241 | // } |
226 | // } | 242 | // } |
227 | 243 | ||
228 | ::close( sd); //close sound device | 244 | ::close( sd); //close sound device |
229 | // sdfd=0; | 245 | // sdfd=0; |
230 | // sd=0; | 246 | // sd=0; |
231 | // qDebug( "closed dsp" ); | 247 | // qDebug( "closed dsp" ); |
232 | return true; | 248 | return true; |
233 | } | 249 | } |
234 | 250 | ||
235 | bool Device::setDeviceFormat( int form) { | 251 | bool Device::setDeviceFormat( int form) { |
236 | qDebug( "set device res %d: %d ",form, sd ); | 252 | qDebug( "set device res %d: %d ",form, sd ); |
237 | if (ioctl( sd, SNDCTL_DSP_SETFMT, &form)==-1) { //set format | 253 | if (ioctl( sd, SNDCTL_DSP_SETFMT, &form)==-1) { //set format |
238 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); | 254 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); |
239 | return false; | 255 | return false; |
240 | } | 256 | } |
241 | devRes=form; | 257 | devRes=form; |
242 | return true; | 258 | return true; |
243 | } | 259 | } |
244 | 260 | ||
245 | bool Device::setDeviceChannels( int ch) { | 261 | bool Device::setDeviceChannels( int ch) { |
246 | qDebug( "set channels %d: %d",ch ,sd); | 262 | qDebug( "set channels %d: %d",ch ,sd); |
247 | if (ioctl( sd, SNDCTL_DSP_CHANNELS, &ch)==-1) { | 263 | if (ioctl( sd, SNDCTL_DSP_CHANNELS, &ch)==-1) { |
248 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); | 264 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); |
249 | return false; | 265 | return false; |
250 | } | 266 | } |
251 | devCh=ch; | 267 | devCh=ch; |
252 | return true; | 268 | return true; |
253 | } | 269 | } |
254 | 270 | ||
255 | bool Device::setDeviceRate( int rate) { | 271 | bool Device::setDeviceRate( int rate) { |
256 | qDebug( "set rate %d: %d",rate,sd); | 272 | qDebug( "set rate %d: %d",rate,sd); |
257 | if (ioctl( sd, SNDCTL_DSP_SPEED, &rate) == -1) { | 273 | if (ioctl( sd, SNDCTL_DSP_SPEED, &rate) == -1) { |
258 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); | 274 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); |
259 | return false; | 275 | return false; |
260 | } | 276 | } |
261 | 277 | ||
262 | devRate=rate; | 278 | devRate=rate; |
263 | 279 | ||
264 | return true; | 280 | return true; |
265 | } | 281 | } |
266 | 282 | ||
267 | int Device::getRes() { | 283 | int Device::getRes() { |
268 | return devRes; | 284 | return devRes; |
269 | } | 285 | } |
270 | 286 | ||
271 | int Device::getFormat() { | 287 | int Device::getFormat() { |
272 | return devForm; | 288 | return devForm; |
273 | } | 289 | } |
274 | 290 | ||
275 | int Device::getRate() { | 291 | int Device::getRate() { |
276 | return devRate; | 292 | return devRate; |
277 | } | 293 | } |
278 | 294 | ||
279 | int Device::getChannels() { | 295 | int Device::getChannels() { |
280 | return devCh; | 296 | return devCh; |
281 | } | 297 | } |
282 | 298 | ||
283 | int Device::getDeviceFormat() { | 299 | int Device::getDeviceFormat() { |
284 | return 0; | 300 | return 0; |
285 | } | 301 | } |
286 | 302 | ||
287 | 303 | ||
288 | int Device::getDeviceRate() { | 304 | int Device::getDeviceRate() { |
289 | int dRate=0; | 305 | int dRate=0; |
290 | if (ioctl( sd, SOUND_PCM_READ_RATE, &dRate) == -1) { | 306 | if (ioctl( sd, SOUND_PCM_READ_RATE, &dRate) == -1) { |
291 | perror("ioctl(\"SNDCTL_PCM_READ_RATE\")"); | 307 | perror("ioctl(\"SNDCTL_PCM_READ_RATE\")"); |
292 | } | 308 | } |
293 | return dRate; | 309 | return dRate; |
294 | 310 | ||
295 | } | 311 | } |
296 | 312 | ||
297 | int Device::getDeviceBits() { | 313 | int Device::getDeviceBits() { |
298 | int dBits=0; | 314 | int dBits=0; |
299 | #ifndef QT_QWS_EBX // zaurus doesnt have this | 315 | #ifndef QT_QWS_EBX // zaurus doesnt have this |
300 | if (ioctl( sd, SOUND_PCM_READ_BITS, &dBits) == -1) { | 316 | if (ioctl( sd, SOUND_PCM_READ_BITS, &dBits) == -1) { |
301 | perror("ioctl(\"SNDCTL_PCM_READ_BITS\")"); | 317 | perror("ioctl(\"SNDCTL_PCM_READ_BITS\")"); |
302 | } | 318 | } |
303 | #endif | 319 | #endif |
304 | return dBits; | 320 | return dBits; |
305 | } | 321 | } |
306 | 322 | ||
307 | int Device::getDeviceChannels() { | 323 | int Device::getDeviceChannels() { |
308 | int dCh=0; | 324 | int dCh=0; |
309 | if (ioctl( sd, SOUND_PCM_READ_CHANNELS, &dCh) == -1) { | 325 | if (ioctl( sd, SOUND_PCM_READ_CHANNELS, &dCh) == -1) { |
310 | perror("ioctl(\"SNDCTL_PCM_READ_CHANNELS\")"); | 326 | perror("ioctl(\"SNDCTL_PCM_READ_CHANNELS\")"); |
311 | } | 327 | } |
312 | return dCh; | 328 | return dCh; |
313 | } | 329 | } |
314 | 330 | ||
315 | int Device::getDeviceFragSize() { | 331 | int Device::getDeviceFragSize() { |
316 | int frag_size; | 332 | int frag_size; |
317 | 333 | ||
318 | if (ioctl( sd, SNDCTL_DSP_GETBLKSIZE, &frag_size) == -1) { | 334 | if (ioctl( sd, SNDCTL_DSP_GETBLKSIZE, &frag_size) == -1) { |
319 | qDebug( "no fragsize" ); | 335 | qDebug( "no fragsize" ); |
320 | } else { | 336 | } else { |
321 | qDebug( "driver says frag size is %d",frag_size); | 337 | qDebug( "driver says frag size is %d",frag_size); |
322 | } | 338 | } |
323 | return frag_size; | 339 | return frag_size; |
324 | } | 340 | } |
325 | 341 | ||
326 | bool Device::setFragSize(int frag) { | 342 | bool Device::setFragSize(int frag) { |
327 | if (ioctl(sd, SNDCTL_DSP_SETFRAGMENT, &frag)) { | 343 | if (ioctl(sd, SNDCTL_DSP_SETFRAGMENT, &frag)) { |
328 | perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")"); | 344 | perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")"); |
329 | return false; | 345 | return false; |
330 | } | 346 | } |
331 | return true; | 347 | return true; |
332 | } | 348 | } |
333 | 349 | ||
334 | bool Device::reset() { | 350 | bool Device::reset() { |
335 | closeDevice(true); | 351 | closeDevice(true); |
336 | openDsp(); | 352 | openDsp(); |
337 | if (ioctl( sd, SNDCTL_DSP_RESET, 0) == -1) { | 353 | if (ioctl( sd, SNDCTL_DSP_RESET, 0) == -1) { |
338 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); | 354 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); |
339 | return false; | 355 | return false; |
340 | } | 356 | } |
341 | return true; | 357 | return true; |
342 | } | 358 | } |
343 | 359 | ||
344 | int Device::devRead(int soundDescriptor, short *buf, int size) { | 360 | int Device::devRead(int soundDescriptor, short *buf, int size) { |
345 | Q_UNUSED(soundDescriptor); | 361 | Q_UNUSED(soundDescriptor); |
346 | int number = 0; | 362 | int number = 0; |
347 | number = ::read( sd /*soundDescriptor*/, (char *)buf, size); | 363 | number = ::read( sd /*soundDescriptor*/, (char *)buf, size); |
348 | return number; | 364 | return number; |
349 | } | 365 | } |
350 | 366 | ||
351 | int Device::devWrite(int soundDescriptor, short * buf, int size) { | 367 | int Device::devWrite(int soundDescriptor, short * buf, int size) { |
352 | Q_UNUSED(soundDescriptor); | 368 | Q_UNUSED(soundDescriptor); |
353 | int bytesWritten = 0; | 369 | int bytesWritten = 0; |
354 | bytesWritten = ::write( sd /*soundDescriptor*/, buf, size); | 370 | bytesWritten = ::write( sd /*soundDescriptor*/, buf, size); |
355 | return bytesWritten; | 371 | return bytesWritten; |
356 | } | 372 | } |
357 | 373 | ||
358 | 374 | ||
diff --git a/noncore/multimedia/opierec/qtrec.cpp b/noncore/multimedia/opierec/qtrec.cpp index 1141faa..c237726 100644 --- a/noncore/multimedia/opierec/qtrec.cpp +++ b/noncore/multimedia/opierec/qtrec.cpp | |||
@@ -1,341 +1,348 @@ | |||
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 DSPSTRMIXEROUT "/dev/mixer" | 70 | #define DSPSTRMIXEROUT "/dev/mixer" |
71 | 71 | ||
72 | #ifdef SHARP | 72 | #ifdef SHARP |
73 | #define DSPSTRIN "/dev/dsp1" | 73 | #define DSPSTRIN "/dev/dsp1" |
74 | #define DSPSTRMIXERIN "/dev/mixer1" | 74 | #define DSPSTRMIXERIN "/dev/mixer1" |
75 | #else | 75 | #else |
76 | #define DSPSTRIN "/dev/dsp" | 76 | #define DSPSTRIN "/dev/dsp" |
77 | #define DSPSTRMIXERIN "/dev/mixer" | 77 | #define DSPSTRMIXERIN "/dev/mixer" |
78 | #endif | 78 | #endif |
79 | 79 | ||
80 | #else | 80 | #else |
81 | 81 | ||
82 | #ifdef QT_QWS_DEVFS | ||
83 | #define DSPSTROUT "/dev/sound/dsp" | ||
84 | #define DSPSTRIN "/dev/sound/dsp" | ||
85 | #define DSPSTRMIXERIN "/dev/sound/mixer" | ||
86 | #define DSPSTRMIXEROUT "/dev/sound/mixer" | ||
87 | #else | ||
82 | #define DSPSTROUT "/dev/dsp" | 88 | #define DSPSTROUT "/dev/dsp" |
83 | #define DSPSTRIN "/dev/dsp" | 89 | #define DSPSTRIN "/dev/dsp" |
84 | #define DSPSTRMIXERIN "/dev/mixer" | 90 | #define DSPSTRMIXERIN "/dev/mixer" |
85 | #define DSPSTRMIXEROUT "/dev/mixer" | 91 | #define DSPSTRMIXEROUT "/dev/mixer" |
92 | #endif | ||
86 | 93 | ||
87 | #endif | 94 | #endif |
88 | 95 | ||
89 | //#define ZAURUS 0 | 96 | //#define ZAURUS 0 |
90 | struct adpcm_state encoder_state; | 97 | struct adpcm_state encoder_state; |
91 | struct adpcm_state decoder_state; | 98 | struct adpcm_state decoder_state; |
92 | 99 | ||
93 | typedef struct { | 100 | typedef struct { |
94 | int sampleRate; | 101 | int sampleRate; |
95 | /* int fragSize; */ | 102 | /* int fragSize; */ |
96 | /* int blockSize; */ | 103 | /* int blockSize; */ |
97 | int resolution; //bitrate | 104 | int resolution; //bitrate |
98 | int channels; //number of channels | 105 | int channels; //number of channels |
99 | int fd; //file descriptor | 106 | int fd; //file descriptor |
100 | int sd; //sound device descriptor | 107 | int sd; //sound device descriptor |
101 | int numberSamples; //total number of samples | 108 | int numberSamples; //total number of samples |
102 | int SecondsToRecord; // number of seconds that should be recorded | 109 | int SecondsToRecord; // number of seconds that should be recorded |
103 | float numberOfRecordedSeconds; //total number of samples recorded | 110 | float numberOfRecordedSeconds; //total number of samples recorded |
104 | int samplesToRecord; //number of samples to be recorded | 111 | int samplesToRecord; //number of samples to be recorded |
105 | int inVol; //input volume | 112 | int inVol; //input volume |
106 | int outVol; //output volume | 113 | int outVol; //output volume |
107 | int format; //wavfile format PCM.. ADPCM | 114 | int format; //wavfile format PCM.. ADPCM |
108 | const char *fileName; //name of fiel to be played/recorded | 115 | const char *fileName; //name of fiel to be played/recorded |
109 | } fileParameters; | 116 | } fileParameters; |
110 | 117 | ||
111 | fileParameters filePara; | 118 | fileParameters filePara; |
112 | 119 | ||
113 | bool monitoring, recording, playing; | 120 | bool monitoring, recording, playing; |
114 | bool stopped; | 121 | bool stopped; |
115 | QLabel *timeLabel; | 122 | QLabel *timeLabel; |
116 | QSlider *timeSlider; | 123 | QSlider *timeSlider; |
117 | int sd; | 124 | int sd; |
118 | 125 | ||
119 | Waveform* waveform; | 126 | Waveform* waveform; |
120 | Device *soundDevice; | 127 | Device *soundDevice; |
121 | 128 | ||
122 | 129 | ||
123 | #ifdef THREADED | 130 | #ifdef THREADED |
124 | void quickRec() | 131 | void quickRec() |
125 | #else | 132 | #else |
126 | void QtRec::quickRec() | 133 | void QtRec::quickRec() |
127 | #endif | 134 | #endif |
128 | { | 135 | { |
129 | 136 | ||
130 | odebug << ( filePara.numberSamples/filePara.sampleRate * filePara.channels ) << oendl; | 137 | odebug << ( filePara.numberSamples/filePara.sampleRate * filePara.channels ) << oendl; |
131 | odebug << "samples " << filePara.numberSamples << ", rate " << filePara.sampleRate | 138 | odebug << "samples " << filePara.numberSamples << ", rate " << filePara.sampleRate |
132 | << ", channels " << filePara.channels << oendl; | 139 | << ", channels " << filePara.channels << oendl; |
133 | 140 | ||
134 | int total = 0; // Total number of bytes read in so far. | 141 | int total = 0; // Total number of bytes read in so far. |
135 | int bytesWritten, number; | 142 | int bytesWritten, number; |
136 | 143 | ||
137 | bytesWritten = 0; | 144 | bytesWritten = 0; |
138 | number = 0; | 145 | number = 0; |
139 | QString num; | 146 | QString num; |
140 | int level = 0; | 147 | int level = 0; |
141 | int threshold = 0; | 148 | int threshold = 0; |
142 | int bits = filePara.resolution; | 149 | int bits = filePara.resolution; |
143 | odebug << "bits " << bits << "" << oendl; | 150 | odebug << "bits " << bits << "" << oendl; |
144 | 151 | ||
145 | if( filePara.resolution == 16 ) { //AFMT_S16_LE) | 152 | if( filePara.resolution == 16 ) { //AFMT_S16_LE) |
146 | odebug << "AFMT_S16_LE size " << filePara.SecondsToRecord << "" << oendl; | 153 | odebug << "AFMT_S16_LE size " << filePara.SecondsToRecord << "" << oendl; |
147 | odebug << "samples to record " << filePara.samplesToRecord << "" << oendl; | 154 | odebug << "samples to record " << filePara.samplesToRecord << "" << oendl; |
148 | odebug << "" << filePara.sd << "" << oendl; | 155 | odebug << "" << filePara.sd << "" << oendl; |
149 | level = 7; | 156 | level = 7; |
150 | threshold = 0; | 157 | threshold = 0; |
151 | 158 | ||
152 | if( filePara.format == WAVE_FORMAT_DVI_ADPCM) { | 159 | if( filePara.format == WAVE_FORMAT_DVI_ADPCM) { |
153 | odebug << "start recording WAVE_FORMAT_DVI_ADPCM" << oendl; | 160 | odebug << "start recording WAVE_FORMAT_DVI_ADPCM" << oendl; |
154 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_DVI_ADPCM >>>>>>>>>>>>>>>>>>>>>> | 161 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_DVI_ADPCM >>>>>>>>>>>>>>>>>>>>>> |
155 | char abuf[ BUFSIZE/2 ]; | 162 | char abuf[ BUFSIZE/2 ]; |
156 | short sbuf[ BUFSIZE ]; | 163 | short sbuf[ BUFSIZE ]; |
157 | short sbuf2[ BUFSIZE ]; | 164 | short sbuf2[ BUFSIZE ]; |
158 | memset( abuf, 0, BUFSIZE/2); | 165 | memset( abuf, 0, BUFSIZE/2); |
159 | memset( sbuf, 0, BUFSIZE); | 166 | memset( sbuf, 0, BUFSIZE); |
160 | memset( sbuf2, 0, BUFSIZE); | 167 | memset( sbuf2, 0, BUFSIZE); |
161 | 168 | ||
162 | for(;;) { | 169 | for(;;) { |
163 | if ( stopped) { | 170 | if ( stopped) { |
164 | odebug << "quickRec:: stopped" << oendl; | 171 | odebug << "quickRec:: stopped" << oendl; |
165 | break; | 172 | break; |
166 | } | 173 | } |
167 | 174 | ||
168 | // number=::read( filePara.sd, sbuf, BUFSIZE); | 175 | // number=::read( filePara.sd, sbuf, BUFSIZE); |
169 | number = soundDevice->devRead( filePara.sd, sbuf, BUFSIZE); | 176 | number = soundDevice->devRead( filePara.sd, sbuf, BUFSIZE); |
170 | 177 | ||
171 | if(number <= 0) { | 178 | if(number <= 0) { |
172 | perror("recording error "); | 179 | perror("recording error "); |
173 | odebug << "" << filePara.fileName << " " << number << "" << oendl; | 180 | odebug << "" << filePara.fileName << " " << number << "" << oendl; |
174 | stopped = true; | 181 | stopped = true; |
175 | return; | 182 | return; |
176 | } | 183 | } |
177 | //if(stereo == 2) { | 184 | //if(stereo == 2) { |
178 | // adpcm_coder( sbuf2, abuf, number/2, &encoder_state); | 185 | // adpcm_coder( sbuf2, abuf, number/2, &encoder_state); |
179 | adpcm_coder( sbuf, abuf, number/2, &encoder_state); | 186 | adpcm_coder( sbuf, abuf, number/2, &encoder_state); |
180 | 187 | ||
181 | bytesWritten = ::write( filePara.fd , (short *)abuf, number/4); | 188 | bytesWritten = ::write( filePara.fd , (short *)abuf, number/4); |
182 | 189 | ||
183 | waveform->newSamples( sbuf, number ); | 190 | waveform->newSamples( sbuf, number ); |
184 | 191 | ||
185 | total += bytesWritten; | 192 | total += bytesWritten; |
186 | filePara.numberSamples = total; | 193 | filePara.numberSamples = total; |
187 | timeSlider->setValue( total); | 194 | timeSlider->setValue( total); |
188 | 195 | ||
189 | printf("%d, bytes %d,total %d\r",number, bytesWritten, total); | 196 | printf("%d, bytes %d,total %d\r",number, bytesWritten, total); |
190 | fflush(stdout); | 197 | fflush(stdout); |
191 | 198 | ||
192 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate * (float)2/ filePara.channels; | 199 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate * (float)2/ filePara.channels; |
193 | 200 | ||
194 | qApp->processEvents(); | 201 | qApp->processEvents(); |
195 | if( total >= filePara.samplesToRecord) { | 202 | if( total >= filePara.samplesToRecord) { |
196 | stopped = true; | 203 | stopped = true; |
197 | break; | 204 | break; |
198 | } | 205 | } |
199 | } | 206 | } |
200 | } else { | 207 | } else { |
201 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_PCM >>>>>>>>>>>>>>>>>>>>>> | 208 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_PCM >>>>>>>>>>>>>>>>>>>>>> |
202 | odebug << "start recording WAVE_FORMAT_PCM" << oendl; | 209 | odebug << "start recording WAVE_FORMAT_PCM" << oendl; |
203 | short inbuffer[ BUFSIZE ], outbuffer[ BUFSIZE ]; | 210 | short inbuffer[ BUFSIZE ], outbuffer[ BUFSIZE ]; |
204 | memset( inbuffer, 0, BUFSIZE); | 211 | memset( inbuffer, 0, BUFSIZE); |
205 | memset( outbuffer, 0, BUFSIZE); | 212 | memset( outbuffer, 0, BUFSIZE); |
206 | 213 | ||
207 | for(;;) { | 214 | for(;;) { |
208 | if ( stopped) { | 215 | if ( stopped) { |
209 | odebug << "quickRec:: stopped" << oendl; | 216 | odebug << "quickRec:: stopped" << oendl; |
210 | stopped = true; | 217 | stopped = true; |
211 | break; // stop if playing was set to false | 218 | break; // stop if playing was set to false |
212 | return; | 219 | return; |
213 | } | 220 | } |
214 | 221 | ||
215 | number = soundDevice->devRead( soundDevice->sd /*filePara.sd*/, (short *)inbuffer, BUFSIZE); | 222 | number = soundDevice->devRead( soundDevice->sd /*filePara.sd*/, (short *)inbuffer, BUFSIZE); |
216 | 223 | ||
217 | if( number <= 0) { | 224 | if( number <= 0) { |
218 | perror( "recording error "); | 225 | perror( "recording error "); |
219 | odebug << filePara.fileName << oendl; | 226 | odebug << filePara.fileName << oendl; |
220 | stopped = true; | 227 | stopped = true; |
221 | return; | 228 | return; |
222 | } | 229 | } |
223 | 230 | ||
224 | bytesWritten = ::write( filePara.fd , inbuffer, number); | 231 | bytesWritten = ::write( filePara.fd , inbuffer, number); |
225 | waveform->newSamples( inbuffer, number ); | 232 | waveform->newSamples( inbuffer, number ); |
226 | 233 | ||
227 | if( bytesWritten < 0) { | 234 | if( bytesWritten < 0) { |
228 | perror("File writing error "); | 235 | perror("File writing error "); |
229 | stopped = true; | 236 | stopped = true; |
230 | return; | 237 | return; |
231 | } | 238 | } |
232 | 239 | ||
233 | total += bytesWritten; | 240 | total += bytesWritten; |
234 | 241 | ||
235 | filePara.numberSamples = total; | 242 | filePara.numberSamples = total; |
236 | 243 | ||
237 | if( filePara.SecondsToRecord != 0) | 244 | if( filePara.SecondsToRecord != 0) |
238 | timeSlider->setValue( total); | 245 | timeSlider->setValue( total); |
239 | printf("%d, bytes %d,total %d\r",number, bytesWritten , total); | 246 | printf("%d, bytes %d,total %d\r",number, bytesWritten , total); |
240 | fflush(stdout); | 247 | fflush(stdout); |
241 | 248 | ||
242 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate | 249 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate |
243 | / (float)2/filePara.channels; | 250 | / (float)2/filePara.channels; |
244 | qApp->processEvents(); | 251 | qApp->processEvents(); |
245 | 252 | ||
246 | if( total >= filePara.samplesToRecord) { | 253 | if( total >= filePara.samplesToRecord) { |
247 | stopped = true; | 254 | stopped = true; |
248 | break; | 255 | break; |
249 | } | 256 | } |
250 | } | 257 | } |
251 | } //end main loop | 258 | } //end main loop |
252 | 259 | ||
253 | } else { | 260 | } else { |
254 | // <<<<<<<<<<<<<<<<<<<<<<< format = AFMT_U8; | 261 | // <<<<<<<<<<<<<<<<<<<<<<< format = AFMT_U8; |
255 | unsigned char unsigned_inbuffer[ BUFSIZE ], unsigned_outbuffer[ BUFSIZE ]; | 262 | unsigned char unsigned_inbuffer[ BUFSIZE ], unsigned_outbuffer[ BUFSIZE ]; |
256 | memset( unsigned_inbuffer, 0, BUFSIZE); | 263 | memset( unsigned_inbuffer, 0, BUFSIZE); |
257 | memset( unsigned_outbuffer, 0, BUFSIZE); | 264 | memset( unsigned_outbuffer, 0, BUFSIZE); |
258 | 265 | ||
259 | for(;;) { | 266 | for(;;) { |
260 | if ( stopped) { | 267 | if ( stopped) { |
261 | odebug << "quickRec:: stopped" << oendl; | 268 | odebug << "quickRec:: stopped" << oendl; |
262 | break; // stop if playing was set to false | 269 | break; // stop if playing was set to false |
263 | } | 270 | } |
264 | 271 | ||
265 | number = ::read( soundDevice->sd /*filePara.sd*/ , unsigned_inbuffer, BUFSIZE); | 272 | number = ::read( soundDevice->sd /*filePara.sd*/ , unsigned_inbuffer, BUFSIZE); |
266 | bytesWritten = ::write( filePara.fd , unsigned_inbuffer, number); | 273 | bytesWritten = ::write( filePara.fd , unsigned_inbuffer, number); |
267 | waveform->newSamples( (const short *) unsigned_inbuffer, number ); | 274 | waveform->newSamples( (const short *) unsigned_inbuffer, number ); |
268 | 275 | ||
269 | if(bytesWritten < 0) { | 276 | if(bytesWritten < 0) { |
270 | stopped = true; | 277 | stopped = true; |
271 | QMessageBox::message("Note","<p>There was a problem writing to the file</p>"); | 278 | QMessageBox::message("Note","<p>There was a problem writing to the file</p>"); |
272 | perror("File writing error "); | 279 | perror("File writing error "); |
273 | return; | 280 | return; |
274 | } | 281 | } |
275 | 282 | ||
276 | total += bytesWritten; | 283 | total += bytesWritten; |
277 | filePara.numberSamples = total; | 284 | filePara.numberSamples = total; |
278 | // printf("%d, bytes %d,total %d \r",number, bytesWritten , total); | 285 | // printf("%d, bytes %d,total %d \r",number, bytesWritten , total); |
279 | // fflush(stdout); | 286 | // fflush(stdout); |
280 | if( filePara.SecondsToRecord !=0) | 287 | if( filePara.SecondsToRecord !=0) |
281 | timeSlider->setValue( total); | 288 | timeSlider->setValue( total); |
282 | 289 | ||
283 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate; | 290 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate; |
284 | 291 | ||
285 | qApp->processEvents(); | 292 | qApp->processEvents(); |
286 | if( total >= filePara.samplesToRecord) { | 293 | if( total >= filePara.samplesToRecord) { |
287 | stopped = true; | 294 | stopped = true; |
288 | break; | 295 | break; |
289 | } | 296 | } |
290 | } //end main loop | 297 | } //end main loop |
291 | } | 298 | } |
292 | } /// END quickRec() | 299 | } /// END quickRec() |
293 | 300 | ||
294 | 301 | ||
295 | #ifdef THREADED | 302 | #ifdef THREADED |
296 | void playIt() | 303 | void playIt() |
297 | #else | 304 | #else |
298 | void QtRec::playIt() | 305 | void QtRec::playIt() |
299 | #endif | 306 | #endif |
300 | { | 307 | { |
301 | int bytesWritten = 0; | 308 | int bytesWritten = 0; |
302 | int number = 0; | 309 | int number = 0; |
303 | int total = 0; // Total number of bytes read in so far. | 310 | int total = 0; // Total number of bytes read in so far. |
304 | if( filePara.resolution == 16 ) { //AFMT_S16_LE) { | 311 | if( filePara.resolution == 16 ) { //AFMT_S16_LE) { |
305 | if( filePara.format == WAVE_FORMAT_DVI_ADPCM) { | 312 | if( filePara.format == WAVE_FORMAT_DVI_ADPCM) { |
306 | char abuf[ BUFSIZE / 2 ]; | 313 | char abuf[ BUFSIZE / 2 ]; |
307 | short sbuf[ BUFSIZE ]; | 314 | short sbuf[ BUFSIZE ]; |
308 | short sbuf2[ BUFSIZE * 2 ]; | 315 | short sbuf2[ BUFSIZE * 2 ]; |
309 | memset( abuf, 0, BUFSIZE / 2); | 316 | memset( abuf, 0, BUFSIZE / 2); |
310 | memset( sbuf, 0, BUFSIZE); | 317 | memset( sbuf, 0, BUFSIZE); |
311 | memset( sbuf2, 0, BUFSIZE * 2); | 318 | memset( sbuf2, 0, BUFSIZE * 2); |
312 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_DVI_ADPCM >>>>>>>>>>>>>>>>>>>>>> | 319 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_DVI_ADPCM >>>>>>>>>>>>>>>>>>>>>> |
313 | for(;;) { // play loop | 320 | for(;;) { // play loop |
314 | if ( stopped) { | 321 | if ( stopped) { |
315 | break; | 322 | break; |
316 | return; | 323 | return; |
317 | }// stop if playing was set to false | 324 | }// stop if playing was set to false |
318 | 325 | ||
319 | number = ::read( filePara.fd, abuf, BUFSIZE / 2); | 326 | number = ::read( filePara.fd, abuf, BUFSIZE / 2); |
320 | adpcm_decoder( abuf, sbuf, number * 2, &decoder_state); | 327 | adpcm_decoder( abuf, sbuf, number * 2, &decoder_state); |
321 | 328 | ||
322 | // for (int i=0;i< number * 2; 2 * i++) { //2*i is left channel | 329 | // for (int i=0;i< number * 2; 2 * i++) { //2*i is left channel |
323 | // sbuf2[i+1]=sbuf2[i]=sbuf[i]; | 330 | // sbuf2[i+1]=sbuf2[i]=sbuf[i]; |
324 | // } | 331 | // } |
325 | bytesWritten = write ( filePara.sd, sbuf, number * 4); | 332 | bytesWritten = write ( filePara.sd, sbuf, number * 4); |
326 | waveform->newSamples( (const short *)sbuf, number *4); | 333 | waveform->newSamples( (const short *)sbuf, number *4); |
327 | // if(filePara.channels==1) | 334 | // if(filePara.channels==1) |
328 | // total += bytesWritten/2; //mono | 335 | // total += bytesWritten/2; //mono |
329 | // else | 336 | // else |
330 | total += bytesWritten; | 337 | total += bytesWritten; |
331 | filePara.numberSamples = total/4; | 338 | filePara.numberSamples = total/4; |
332 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / 2; | 339 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / 2; |
333 | 340 | ||
334 | timeSlider->setValue( total/4); | 341 | timeSlider->setValue( total/4); |
335 | // timeString.sprintf("%.2f", filePara.numberOfRecordedSeconds); | 342 | // timeString.sprintf("%.2f", filePara.numberOfRecordedSeconds); |
336 | // if(filePara.numberOfRecordedSeconds>1) | 343 | // if(filePara.numberOfRecordedSeconds>1) |
337 | // timeLabel->setText( timeString+ tr(" seconds")); | 344 | // timeLabel->setText( timeString+ tr(" seconds")); |
338 | // printf("playing number %d, bytes %d, total %d\n",number, bytesWritten, total/4); | 345 | // printf("playing number %d, bytes %d, total %d\n",number, bytesWritten, total/4); |
339 | // fflush(stdout); | 346 | // fflush(stdout); |
340 | 347 | ||
341 | qApp->processEvents(); | 348 | qApp->processEvents(); |