]> git.saurik.com Git - wxWidgets.git/commitdiff
* Fixes and updates on wxMMedia.
authorGuilhem Lavaux <lavaux@easynet.fr>
Thu, 18 Feb 1999 18:18:06 +0000 (18:18 +0000)
committerGuilhem Lavaux <lavaux@easynet.fr>
Thu, 18 Feb 1999 18:18:06 +0000 (18:18 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1722 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

12 files changed:
utils/wxMMedia/cdunix.cpp
utils/wxMMedia/mmdata.cpp
utils/wxMMedia/sndadpcm.cpp
utils/wxMMedia/sndaiff.cpp
utils/wxMMedia/sndfile.cpp
utils/wxMMedia/sndfile.h
utils/wxMMedia/sndfrag.cpp
utils/wxMMedia/sndfrmt.cpp
utils/wxMMedia/sndfrmt.h
utils/wxMMedia/snduss.cpp
utils/wxMMedia/sndwav.cpp
utils/wxMMedia/vidxanm.cpp

index 07f5ea0598978a8427d0eecdc1403bcf012a69b1..92bf9fd72b314f5dca58a3c9e938eccafbbdae11 100644 (file)
@@ -5,6 +5,7 @@
 // Created:    1997
 // Updated:    1998
 // Copyright:  (C) 1997, 1998, Guilhem Lavaux
+// CVS Id: $Id$
 // License:    wxWindows license
 ////////////////////////////////////////////////////////////////////////////////
 #ifdef __GNUG__
index abcf3eaea91dbaf87f3c2c4eb46c39387e572ec4..ebd196874f5a52a5b182ce03cfde3c09e2005ad1 100644 (file)
@@ -23,6 +23,7 @@
 #include "sndau.h"
 #include "sndpcm.h"
 #include "sndmulaw.h"
+#include "sndadpcm.h"
 #include "vidbase.h"
 #if defined(__X__) || defined(__WXGTK__)
 #include "vidxanm.h"
@@ -50,6 +51,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxSndSimpleBuffer, wxSndBuffer)
 IMPLEMENT_ABSTRACT_CLASS(wxSoundCodec, wxObject)
 IMPLEMENT_DYNAMIC_CLASS(wxSoundPcmCodec, wxSoundCodec)
 IMPLEMENT_DYNAMIC_CLASS(wxSoundMulawCodec, wxSoundCodec)
+IMPLEMENT_DYNAMIC_CLASS(wxSoundAdpcmCodec, wxSoundCodec)
 
 #ifdef __UNIX__
 IMPLEMENT_DYNAMIC_CLASS(wxUssSound, wxSound)
@@ -66,7 +68,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxSndAiffCodec, wxSndFileCodec)
 IMPLEMENT_ABSTRACT_CLASS(wxVideoBaseDriver, wxMMediaFile)
 IMPLEMENT_DYNAMIC_CLASS(wxVideoOutput, wxWindow)
 #if defined(__X__) || defined(__WXGTK__)
-// IMPLEMENT_DYNAMIC_CLASS(wxVideoXANIM, wxVideoBaseDriver)
+IMPLEMENT_DYNAMIC_CLASS(wxVideoXANIM, wxVideoBaseDriver)
 #endif
 #ifdef __WINDOWS__
 IMPLEMENT_DYNAMIC_CLASS(wxVideoWindows, wxVideoBaseDriver)
@@ -88,7 +90,7 @@ MMD_REGISTER_FILE("audio/x-wav", "Wav Player", wxSndWavCodec, "wav")
 MMD_REGISTER_FILE("audio/x-aiff", "Aiff Player", wxSndAiffCodec, "aif")
 MMD_REGISTER_FILE("audio/x-au", "Sun Audio File Player", wxSndAuCodec, "au")
 #if defined(__X__) || defined(__WXGTK__)
-// MMD_REGISTER_FILE("video/*", "Video Player", wxVideoXANIM, "mov")
+MMD_REGISTER_FILE("video/*", "Video Player", wxVideoXANIM, "mov")
 #else
 MMD_REGISTER_FILE("video/avi", "AVI Player", wxVideoWindows, "avi")
 #endif
index 9e7473f093356ae85716a0d06b362a517b617132..88b22e1c166aada45983501ccb820b5e6acd8204 100644 (file)
 wxSoundAdpcmCodec::wxSoundAdpcmCodec()
   : wxSoundCodec()
 {
-  g72x_init_state(codec_state);
+  // TODO: For the moment, only 1 channel is supported.
+  m_codec_state = new g72x_state;
+  g72x_init_state(m_codec_state);
 }
 
 wxSoundAdpcmCodec::~wxSoundAdpcmCodec()
 {
 }
 
+void wxSoundAdpcmCodec::InitWith(const wxSoundDataFormat& format)
+{
+  m_srate = format.GetSampleRate();
+}
+
 int wxSoundAdpcmCodec::GetBits(int nbits)
 {
   unsigned int mask;
   int bits;
 
-  if (bits_waiting == 0)
-    current_byte = m_in_sound->GetChar();
+  if (m_bits_waiting == 0)
+    m_current_byte = m_in_sound->GetChar();
 
   mask = (1 << nbits) - 1;
-  bits = current_byte & mask;
-  current_byte >>= nbits;
+  bits = m_current_byte & mask;
+  m_current_byte >>= nbits;
+  m_bits_waiting -= nbits;
   return bits;
 }
 
-
 void wxSoundAdpcmCodec::Decode()
 {
-  int smp;
+  int smp, bits;
   wxSoundDataFormat pref_frmt;
 
   pref_frmt = GetPreferredFormat(0);
@@ -44,14 +51,14 @@ void wxSoundAdpcmCodec::Decode()
   bits = GetBits(4);
   if (m_io_format.GetByteOrder() == wxSND_SAMPLE_LE) {
     while (!StreamOk()) {
-      smp = g721_decoder(bits, AUDIO_ENCODING_LINEAR, codec_state);
+      smp = g721_decoder(bits, AUDIO_ENCODING_LINEAR, m_codec_state);
       m_out_sound->PutChar(smp & 0x00ff);
       m_out_sound->PutChar((smp & 0xff00) >> 8);
       bits = GetBits(4);
     }
   } else {
     while (!StreamOk()) {
-      smp = g721_decoder(bits, AUDIO_ENCODING_LINEAR, codec_state);
+      smp = g721_decoder(bits, AUDIO_ENCODING_LINEAR, m_codec_state);
       m_out_sound->PutChar((smp & 0xff00) >> 8);
       m_out_sound->PutChar(smp & 0x00ff);
       bits = GetBits(4);
@@ -59,16 +66,41 @@ void wxSoundAdpcmCodec::Decode()
   }
 }
 
-void wxSoundMulawCodec::Encode()
+void wxSoundAdpcmCodec::Encode()
 {
+/*
+  int smp;
+  wxSoundDataFormat pref_frmt;
+
+  pref_frmt = GetPreferredFormat(0);
+  if (!(m_io_format == pref_frmt))
+    ChainCodecAfter(pref_frmt);
+
+  bits = GetBits(4);
+  if (m_io_format.GetByteOrder() == wxSND_SAMPLE_LE) {
+    while (!StreamOk()) {
+      smp = g721_decoder(bits, AUDIO_ENCODING_LINEAR, codec_state);
+      m_out_sound->PutChar(smp & 0x00ff);
+      m_out_sound->PutChar((smp & 0xff00) >> 8);
+      bits = GetBits(4);
+    }
+  } else {
+    while (!StreamOk()) {
+      smp = g721_decoder(bits, AUDIO_ENCODING_LINEAR, codec_state);
+      m_out_sound->PutChar((smp & 0xff00) >> 8);
+      m_out_sound->PutChar(smp & 0x00ff);
+      bits = GetBits(4);
+    }
+  }
+*/
 }
 
-size_t wxSoundMulawCodec::GetByteRate() const
+size_t wxSoundAdpcmCodec::GetByteRate() const
 {
-  return m_srate;
+  return (m_io_format.GetSampleRate() * m_io_format.GetChannels()) / 2;
 }
 
-wxSoundDataFormat wxSoundMulawCodec::GetPreferredFormat(int WXUNUSED(no)) const
+wxSoundDataFormat wxSoundAdpcmCodec::GetPreferredFormat(int WXUNUSED(no)) const
 {
   wxSoundDataFormat format;
 
index c890726a53914e64f292e4659cbf154e8eac2c8d..19e67874c65f90976a7b9fa9fc8edb9f9b420af2 100644 (file)
@@ -86,8 +86,6 @@ wxUint32 wxSndAiffCodec::PrepareToPlay()
   char tmp_buf[5];
   wxString chunk_name;
 
-  m_istream->SeekI(0, wxFromStart);
-
   wxSndFileCodec::m_mmerror = wxMMFILE_INVALID;
 
   READ_STRING(chunk_name, 4);
@@ -127,6 +125,8 @@ wxUint32 wxSndAiffCodec::PrepareToPlay()
   wxSndFileCodec::m_mmerror = wxMMFILE_NOERROR;
 
   m_istream->SeekI(m_spos, wxFromStart);
+  wxSndFileCodec::m_fstate = wxSFILE_PREPARED_TO_PLAY;
+
   return m_slen;
 }
 
index a90c24e6ec06f049e95f9f861d70f299c5dbda78..0a5c031b6e292769ed93dd140035c937454b5667 100644 (file)
@@ -60,8 +60,9 @@ void wxSndFileCodec::Play(wxSound& snd)
   if (m_fstate != wxSFILE_STOPPED || IsSet(wxSND_BUFLOCKED))
     return;
 
-  if (!(m_fsize = PrepareToPlay()))
-    return;
+  if (m_fstate != wxSFILE_PREPARED_TO_PLAY)
+    if (!(m_fsize = PrepareToPlay()))
+      return;
 
   m_fpos = 0;
   m_fstate = wxSFILE_PLAYING;
@@ -193,7 +194,7 @@ wxMMtime wxSndFileCodec::GetPosition()
 wxMMtime wxSndFileCodec::GetLength()
 {
   if (m_sndtime.hours == -1 && m_istream)
-    PrepareToPlay();
+    m_fsize = PrepareToPlay();
 
   return m_sndtime;
 }
@@ -202,7 +203,6 @@ bool wxSndFileCodec::TranslateBuffer(wxSndBuffer& buf)
 {
 #define TMP_BUFSIZE 10240
 
-  wxUint32 buf_size;
   wxStreamBuffer *tmp_buf;
   wxSoundCodec *codec_in, *codec_out;
   wxSoundDataFormat std_format;
index 2a1c7e5fa544fe33b61691a88f832f848d91cedf..89e75cd18c8712451aad68f9f8f420c23e40b9c5 100644 (file)
@@ -27,7 +27,9 @@ public:
   typedef enum {
     wxSFILE_STOPPED,
     wxSFILE_PLAYING,
-    wxSFILE_RECORDING
+    wxSFILE_RECORDING,
+    wxSFILE_PREPARED_TO_PLAY,
+    wxSFILE_PREPARED_TO_RECORD,
   } FileState;
 
 protected:
index 2b0db71d6db4a4af6da17f3ce350549cac63e2a2..79c7b9a4470e12bd26da153da8d190d76009ad89 100644 (file)
@@ -81,8 +81,10 @@ bool wxFragmentBuffer::NotifyOutputBuffer(wxSndBuffer *buf)
     if (ptr == NULL)
       return FALSE;
     
+    // Normally, these three functions could be called only once.
     codec->SetOutStream(ptr->sndbuf);
     codec->InitIO(m_drvformat);
+    codec->InitMode(wxSoundCodec::DECODING);
     
     // Fill it up
     codec->Decode();
@@ -190,8 +192,10 @@ void wxFragmentBuffer::ClearBuffer(wxFragBufPtr *ptr)
     } else {
       codec = buf->GetCurrentCodec();
 
+      // Normally, these three functions could be called only once.
       codec->SetInStream(ptr->sndbuf);
       codec->InitIO(m_drvformat);
+      codec->InitMode(wxSoundCodec::ENCODING);
 
       // As there is an "auto-stopper" in the codec, we don't worry ...
       codec->Encode();
@@ -248,10 +252,18 @@ void wxFragmentBuffer::OnBufferFinished(wxFragBufPtr *ptr)
       buf->Clear(wxSND_BUFSTOP);
       continue;
     }
-    if (buf->GetMode() == wxSND_OUTPUT)
+    switch (buf->GetMode()) {
+    case wxSND_OUTPUT:
       ret = NotifyOutputBuffer(buf);
-    else
+      break;
+    case wxSND_INPUT:
       ret = NotifyInputBuffer(buf);
+      break;
+    case wxSND_DUPLEX:
+    case wxSND_OTHER_IO:
+      // ret = NotifyDuplexBuffer(buf);
+      break;
+    }
 
     buf->HardUnlock();
   }
index dc6d653ad9a6836ab2b67c1507452a6c515f2ac3..fc9aa77654e3d0ad19c4a08c7476dae40fcea11c 100644 (file)
@@ -114,6 +114,7 @@ void wxSoundDataFormat::CodecChange()
       break;
     }
   default:
+      codec->InitWith(*this);
       break;
   }
 }
@@ -150,19 +151,19 @@ bool wxSoundDataFormat::operator ==(const wxSoundDataFormat& format) const
 // ----------------------------------------------------------------------------
 
 #include "sndpcm.h"
-//#include "sndadpcm.h"
+#include "sndadpcm.h"
 //#include "sndalaw.h"
 #include "sndmulaw.h"
 
 static wxClassInfo *l_sound_formats[] = {
       NULL,
       CLASSINFO(wxSoundPcmCodec),
-      NULL, //  CLASSINFO(wxSoundAdpcmCodec),
+      CLASSINFO(wxSoundAdpcmCodec),
       NULL,
       NULL,
       NULL,
       NULL, // CLASSINFO(wxSoundAlawCodec),
-      NULL  // CLASSINFO(wxSoundMulawCodec)
+      CLASSINFO(wxSoundMulawCodec)
 };
 
 static int l_nb_formats = WXSIZEOF(l_sound_formats);
index 69635c0e6dcc4a09a3ce3d618ba702e0803867b4..ee686f175381bc7835785cecd9ad7dddcb23ba01 100644 (file)
@@ -85,6 +85,7 @@ class wxSoundCodec : public wxObject, public wxStreamBase {
   size_t Available();
 
   void InitIO(const wxSoundDataFormat& format);
+  virtual void InitWith(const wxSoundDataFormat& format) {}
 
   inline void SetInStream(wxStreamBuffer *s)
           { m_in_sound = s; }
index 81c2a7f4ec9c8e7a12dbec3586867f8f6208d679..a0947d150407fc1400dc2485cf5c902c669a5c7d 100644 (file)
@@ -162,6 +162,9 @@ bool wxUssSound::InitBuffer(wxSndBuffer *buf)
     codec->InitIO(m_ussformat);
     codec->InitMode(wxSoundCodec::DECODING);
     break;
+  case wxSND_DUPLEX:
+  case wxSND_OTHER_IO:
+    break; 
   }
   return TRUE;
 }
@@ -202,6 +205,7 @@ void *wxUssSound::Entry()
     }
     buf->HardUnlock();
     continue;
+
   sound_clean_buffer:
     buf->GetCurrentCodec()->ExitMode();
     delete node;
index 340d8ed2c3bd410b3beb2c816ea80d58e27b5762..05d8019cc62a6b709528ed547a822e2f13a40352 100644 (file)
@@ -106,6 +106,7 @@ wxUint32 wxSndWavCodec::PrepareToPlay()
   m_sndtime.seconds = sec2 % 60;
 
   wxSndFileCodec::m_mmerror = wxMMFILE_NOERROR;
+  wxSndFileCodec::m_fstate = wxSFILE_PREPARED_TO_PLAY;
 
   return riff_codec.GetChunkLength();
 }
index 7a934c20e36219f213c7bd8811ec1f32448a4214..54c3c2e7e799712f4589f2145c4c389842a70b62 100644 (file)
@@ -25,6 +25,7 @@
 #include <X11/Xlib.h>
 #include <X11/Intrinsic.h>
 #ifdef __WXGTK__
+#include <gtk/gtkwidget.h>
 #include <gdk/gdk.h>
 #include <gdk/gdkprivate.h>
 #endif