From 8a7c9dcc1c6424976bc40995bbb1d37154cb69e0 Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Thu, 18 Feb 1999 18:18:06 +0000 Subject: [PATCH] * Fixes and updates on wxMMedia. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1722 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- utils/wxMMedia/cdunix.cpp | 1 + utils/wxMMedia/mmdata.cpp | 6 ++-- utils/wxMMedia/sndadpcm.cpp | 58 ++++++++++++++++++++++++++++--------- utils/wxMMedia/sndaiff.cpp | 4 +-- utils/wxMMedia/sndfile.cpp | 8 ++--- utils/wxMMedia/sndfile.h | 4 ++- utils/wxMMedia/sndfrag.cpp | 16 ++++++++-- utils/wxMMedia/sndfrmt.cpp | 7 +++-- utils/wxMMedia/sndfrmt.h | 1 + utils/wxMMedia/snduss.cpp | 4 +++ utils/wxMMedia/sndwav.cpp | 1 + utils/wxMMedia/vidxanm.cpp | 1 + 12 files changed, 84 insertions(+), 27 deletions(-) diff --git a/utils/wxMMedia/cdunix.cpp b/utils/wxMMedia/cdunix.cpp index 07f5ea0598..92bf9fd72b 100644 --- a/utils/wxMMedia/cdunix.cpp +++ b/utils/wxMMedia/cdunix.cpp @@ -5,6 +5,7 @@ // Created: 1997 // Updated: 1998 // Copyright: (C) 1997, 1998, Guilhem Lavaux +// CVS Id: $Id$ // License: wxWindows license //////////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ diff --git a/utils/wxMMedia/mmdata.cpp b/utils/wxMMedia/mmdata.cpp index abcf3eaea9..ebd196874f 100644 --- a/utils/wxMMedia/mmdata.cpp +++ b/utils/wxMMedia/mmdata.cpp @@ -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 diff --git a/utils/wxMMedia/sndadpcm.cpp b/utils/wxMMedia/sndadpcm.cpp index 9e7473f093..88b22e1c16 100644 --- a/utils/wxMMedia/sndadpcm.cpp +++ b/utils/wxMMedia/sndadpcm.cpp @@ -10,31 +10,38 @@ 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; diff --git a/utils/wxMMedia/sndaiff.cpp b/utils/wxMMedia/sndaiff.cpp index c890726a53..19e67874c6 100644 --- a/utils/wxMMedia/sndaiff.cpp +++ b/utils/wxMMedia/sndaiff.cpp @@ -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; } diff --git a/utils/wxMMedia/sndfile.cpp b/utils/wxMMedia/sndfile.cpp index a90c24e6ec..0a5c031b6e 100644 --- a/utils/wxMMedia/sndfile.cpp +++ b/utils/wxMMedia/sndfile.cpp @@ -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; diff --git a/utils/wxMMedia/sndfile.h b/utils/wxMMedia/sndfile.h index 2a1c7e5fa5..89e75cd18c 100644 --- a/utils/wxMMedia/sndfile.h +++ b/utils/wxMMedia/sndfile.h @@ -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: diff --git a/utils/wxMMedia/sndfrag.cpp b/utils/wxMMedia/sndfrag.cpp index 2b0db71d6d..79c7b9a447 100644 --- a/utils/wxMMedia/sndfrag.cpp +++ b/utils/wxMMedia/sndfrag.cpp @@ -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(); } diff --git a/utils/wxMMedia/sndfrmt.cpp b/utils/wxMMedia/sndfrmt.cpp index dc6d653ad9..fc9aa77654 100644 --- a/utils/wxMMedia/sndfrmt.cpp +++ b/utils/wxMMedia/sndfrmt.cpp @@ -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); diff --git a/utils/wxMMedia/sndfrmt.h b/utils/wxMMedia/sndfrmt.h index 69635c0e6d..ee686f1753 100644 --- a/utils/wxMMedia/sndfrmt.h +++ b/utils/wxMMedia/sndfrmt.h @@ -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; } diff --git a/utils/wxMMedia/snduss.cpp b/utils/wxMMedia/snduss.cpp index 81c2a7f4ec..a0947d1504 100644 --- a/utils/wxMMedia/snduss.cpp +++ b/utils/wxMMedia/snduss.cpp @@ -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; diff --git a/utils/wxMMedia/sndwav.cpp b/utils/wxMMedia/sndwav.cpp index 340d8ed2c3..05d8019cc6 100644 --- a/utils/wxMMedia/sndwav.cpp +++ b/utils/wxMMedia/sndwav.cpp @@ -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(); } diff --git a/utils/wxMMedia/vidxanm.cpp b/utils/wxMMedia/vidxanm.cpp index 7a934c20e3..54c3c2e7e7 100644 --- a/utils/wxMMedia/vidxanm.cpp +++ b/utils/wxMMedia/vidxanm.cpp @@ -25,6 +25,7 @@ #include #include #ifdef __WXGTK__ +#include #include #include #endif -- 2.45.2