[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdeaccessibility/kttsd/players/alsaplayer
From:       Gary Cramblitt <garycramblitt () comcast ! net>
Date:       2005-05-31 22:49:39
Message-ID: 1117579779.339208.10051.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 420386 by cramblitt:

Minor fixes.  Implement position, currentTime, and totalTime functions.

 M  +24 -6     alsaplayer.cpp  


--- trunk/KDE/kdeaccessibility/kttsd/players/alsaplayer/alsaplayer.cpp #420385:420386
@@ -226,8 +226,7 @@
                       || (snd_pcm_status_get_state(status) == \
                SND_PCM_STATE_DRAINING);
                 kdDebug() << "AlsaPlayer:playing: state = " << \
snd_pcm_state_name(snd_pcm_status_get_state(status)) << endl;  }
-            // TODO: This crashes.  Why?
-            // snd_pcm_status_free(status);
+            kdDebug() << "position = " << position() << endl;
         }
         m_mutex.unlock();
     }
@@ -249,7 +248,6 @@
                 result = (snd_pcm_status_get_state(status) == SND_PCM_STATE_PAUSED);
                 kdDebug() << "AlsaPlayer:paused: state = " << \
snd_pcm_state_name(snd_pcm_status_get_state(status)) << endl;  }
-            // snd_pcm_status_free(status);
         }
         m_mutex.unlock();
     }
@@ -258,17 +256,35 @@
 
 int AlsaPlayer::totalTime() const
 {
-    return 0;
+    int total = 0;
+    int rate = hwparams.rate;
+    int channels = hwparams.channels;
+    if (rate > 0 && channels > 0) {
+        total = int((double(pbrec_count) / rate) / channels);
+        // kdDebug() << "AlsaPlayer::totalTime: pbrec_count = " << pbrec_count << " \
rate = " << rate << " channels = " << channels << endl; +        // kdDebug() << \
"AlsaPlayer: totalTime = " << total << endl; +    }
+    return total;
 }
 
 int AlsaPlayer::currentTime() const
 {
-    return 0;
+    int current = 0;
+    int rate = hwparams.rate;
+    int channels = hwparams.channels;
+    if (rate > 0 && channels > 0) {
+        current = int((double(fdcount) / rate) / channels);
+        // kdDebug() << "AlsaPlayer::currentTime: fdcount = " << fdcount << " rate = \
" << rate << " channels = " << channels << endl; +        // kdDebug() << \
"AlsaPlayer:: currentTime = " << current << endl; +    }
+    return current;
 }
 
 int AlsaPlayer::position() const
 {
-    return 0;
+    // TODO: Make this more accurate by adding frames that have been so-far
+    // played within the Alsa ring buffer.
+    return pbrec_count > 0 ? int(double(fdcount) * 1000 / pbrec_count + .5) : 0;
 }
 
 /////////////////////////////////////////////////////////////////////////////////
@@ -277,10 +293,12 @@
 
 void AlsaPlayer::seek(int /*seekTime*/)
 {
+    // TODO:
 }
 
 void AlsaPlayer::seekPosition(int /*position*/)
 {
+    // TODO:
 }
 
 /*


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic