]> git.saurik.com Git - wxWidgets.git/blobdiff - utils/wxMMedia2/lib/sndfile.cpp
Minor changes.
[wxWidgets.git] / utils / wxMMedia2 / lib / sndfile.cpp
index 6525d2bbc6a8b77357e89a22ec4cbbe9bf2f577d..b1be59501fef8d608016b58fce4ff6ea72f1fd52 100644 (file)
@@ -16,6 +16,7 @@
 #include "sndfile.h"
 #include "sndcpcm.h"
 #include "sndulaw.h"
+#include "sndg72x.h"
 
 // --------------------------------------------------------------------------
 // Sound codec router
@@ -33,7 +34,7 @@ wxSoundRouterStream::~wxSoundRouterStream()
     delete m_router;
 }
 
-wxSoundStream& wxSoundRouterStream::Read(void *buffer, size_t len)
+wxSoundStream& wxSoundRouterStream::Read(void *buffer, wxUint32 len)
 {
   if (m_router) {
     m_router->Read(buffer, len);
@@ -47,7 +48,7 @@ wxSoundStream& wxSoundRouterStream::Read(void *buffer, size_t len)
   return *this;
 }
 
-wxSoundStream& wxSoundRouterStream::Write(const void *buffer, size_t len)
+wxSoundStream& wxSoundRouterStream::Write(const void *buffer, wxUint32 len)
 {
   if (m_router) {
     m_router->Write(buffer, len);
@@ -82,11 +83,23 @@ bool wxSoundRouterStream::SetSoundFormat(const wxSoundFormatBase& format)
     m_router = new wxSoundStreamUlaw(*m_sndio);
     m_router->SetSoundFormat(format);
     break;
+  case wxSOUND_G72X:
+    m_router = new wxSoundStreamG72X(*m_sndio);
+    m_router->SetSoundFormat(format);
+    break;
   }
   wxSoundStream::SetSoundFormat(m_router->GetSoundFormat());
   return TRUE;
 }
 
+wxUint32 wxSoundRouterStream::GetBestSize() const
+{
+  if (m_router)
+    return m_router->GetBestSize();
+  else
+    return m_sndio->GetBestSize();
+}
+
 bool wxSoundRouterStream::StartProduction(int evt)
 {
   if (!m_router) {
@@ -158,10 +171,11 @@ bool wxSoundFileStream::Play()
   if (!PrepareToPlay())
     return FALSE;
 
+  m_state = wxSOUND_FILE_PLAYING;
+
   if (!StartProduction(wxSOUND_OUTPUT))
     return FALSE;
 
-  m_state = wxSOUND_FILE_PLAYING;
   return TRUE;
 }
 
@@ -175,10 +189,10 @@ bool wxSoundFileStream::Record(unsigned long time)
 
   m_len = m_sndformat->GetBytesFromTime(time);
 
+  m_state = wxSOUND_FILE_RECORDING;
   if (!StartProduction(wxSOUND_INPUT))
     return FALSE;
 
-  m_state = wxSOUND_FILE_RECORDING;
   return TRUE;
 }
 
@@ -229,13 +243,13 @@ bool wxSoundFileStream::Resume()
   return TRUE;
 }
 
-wxSoundStream& wxSoundFileStream::Read(void *buffer, size_t len)
+wxSoundStream& wxSoundFileStream::Read(void *buffer, wxUint32 len)
 {
   m_lastcount = GetData(buffer, len);
   return *this;
 }
 
-wxSoundStream& wxSoundFileStream::Write(const void *buffer, size_t len)
+wxSoundStream& wxSoundFileStream::Write(const void *buffer, wxUint32 len)
 {
   m_lastcount = PutData(buffer, len);
   return *this;
@@ -262,33 +276,37 @@ bool wxSoundFileStream::StopProduction()
 
 void wxSoundFileStream::OnSoundEvent(int evt)
 {
-  size_t len = m_sndio->GetBestSize();
+  wxUint32 len = m_codec.GetBestSize();
   char *buffer;
 
-  buffer = new char[m_sndio->GetBestSize()];
+  buffer = new char[len];
   wxSoundStream::OnSoundEvent(evt);
 
-  switch(evt) {
-  case wxSOUND_INPUT:
-    if (len > m_len)
-      len = m_len;
-
-    len = m_codec.Read(buffer, len).GetLastAccess();
-    PutData(buffer, len);
-    m_len -= len;
-    if (m_len == 0) {
-      Stop();
-      return;
+  while (!m_sndio->QueueFilled()) {
+    switch(evt) {
+    case wxSOUND_INPUT:
+      if (len > m_len)
+        len = m_len;
+
+      len = m_codec.Read(buffer, len).GetLastAccess();
+      PutData(buffer, len);
+      m_len -= len;
+      if (m_len == 0) {
+        Stop();
+        delete[] buffer;
+        return;
+      }
+      break;
+    case wxSOUND_OUTPUT:
+      len = GetData(buffer, len);
+      if (len == 0) {
+        Stop();
+        delete[] buffer;
+        return;
+      }
+      m_codec.Write(buffer, len);
+      break;
     }
-    break;
-  case wxSOUND_OUTPUT:
-    len = GetData(buffer, len);
-    if (len == 0) {
-      Stop();
-      return;
-    }
-    m_codec.Write(buffer, len);
-    break;
   }
   delete[] buffer;
 }