]> git.saurik.com Git - wxWidgets.git/blobdiff - utils/wxMMedia2/lib/sndfile.cpp
some changes to make wxHtmlHelpController easier to subclass
[wxWidgets.git] / utils / wxMMedia2 / lib / sndfile.cpp
index 6525d2bbc6a8b77357e89a22ec4cbbe9bf2f577d..1234726300e0fec31e4142c34577f8ea97a7cd6f 100644 (file)
@@ -16,6 +16,7 @@
 #include "sndfile.h"
 #include "sndcpcm.h"
 #include "sndulaw.h"
 #include "sndfile.h"
 #include "sndcpcm.h"
 #include "sndulaw.h"
+#include "sndg72x.h"
 
 // --------------------------------------------------------------------------
 // Sound codec router
 
 // --------------------------------------------------------------------------
 // Sound codec router
@@ -33,7 +34,7 @@ wxSoundRouterStream::~wxSoundRouterStream()
     delete m_router;
 }
 
     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);
 {
   if (m_router) {
     m_router->Read(buffer, len);
@@ -47,7 +48,7 @@ wxSoundStream& wxSoundRouterStream::Read(void *buffer, size_t len)
   return *this;
 }
 
   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);
 {
   if (m_router) {
     m_router->Write(buffer, len);
@@ -82,6 +83,10 @@ bool wxSoundRouterStream::SetSoundFormat(const wxSoundFormatBase& format)
     m_router = new wxSoundStreamUlaw(*m_sndio);
     m_router->SetSoundFormat(format);
     break;
     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;
   }
   wxSoundStream::SetSoundFormat(m_router->GetSoundFormat());
   return TRUE;
@@ -158,10 +163,11 @@ bool wxSoundFileStream::Play()
   if (!PrepareToPlay())
     return FALSE;
 
   if (!PrepareToPlay())
     return FALSE;
 
+  m_state = wxSOUND_FILE_PLAYING;
+
   if (!StartProduction(wxSOUND_OUTPUT))
     return FALSE;
 
   if (!StartProduction(wxSOUND_OUTPUT))
     return FALSE;
 
-  m_state = wxSOUND_FILE_PLAYING;
   return TRUE;
 }
 
   return TRUE;
 }
 
@@ -175,10 +181,10 @@ bool wxSoundFileStream::Record(unsigned long time)
 
   m_len = m_sndformat->GetBytesFromTime(time);
 
 
   m_len = m_sndformat->GetBytesFromTime(time);
 
+  m_state = wxSOUND_FILE_RECORDING;
   if (!StartProduction(wxSOUND_INPUT))
     return FALSE;
 
   if (!StartProduction(wxSOUND_INPUT))
     return FALSE;
 
-  m_state = wxSOUND_FILE_RECORDING;
   return TRUE;
 }
 
   return TRUE;
 }
 
@@ -229,13 +235,13 @@ bool wxSoundFileStream::Resume()
   return TRUE;
 }
 
   return TRUE;
 }
 
-wxSoundStream& wxSoundFileStream::Read(void *buffer, size_t len)
+wxSoundStream& wxSoundFileStream::Read(void *buffer, wxUint32 len)
 {
   m_lastcount = GetData(buffer, len);
   return *this;
 }
 
 {
   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;
 {
   m_lastcount = PutData(buffer, len);
   return *this;
@@ -262,33 +268,35 @@ bool wxSoundFileStream::StopProduction()
 
 void wxSoundFileStream::OnSoundEvent(int evt)
 {
 
 void wxSoundFileStream::OnSoundEvent(int evt)
 {
-  size_t len = m_sndio->GetBestSize();
+  wxUint32 len = m_sndio->GetBestSize();
   char *buffer;
 
   char *buffer;
 
-  buffer = new char[m_sndio->GetBestSize()];
+  buffer = new char[len];
   wxSoundStream::OnSoundEvent(evt);
 
   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();
+        return;
+      }
+      break;
+    case wxSOUND_OUTPUT:
+      len = GetData(buffer, len);
+      if (len == 0) {
+        Stop();
+        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;
 }
   }
   delete[] buffer;
 }