// Created: 1997
// Updated: 1998
// Copyright: (C) 1997, 1998, Guilhem Lavaux
+// CVS Id: $Id$
// License: wxWindows license
////////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#include "sndau.h"
#include "sndpcm.h"
#include "sndmulaw.h"
+#include "sndadpcm.h"
#include "vidbase.h"
#if defined(__X__) || defined(__WXGTK__)
#include "vidxanm.h"
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)
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)
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
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);
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);
}
}
-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;
char tmp_buf[5];
wxString chunk_name;
- m_istream->SeekI(0, wxFromStart);
-
wxSndFileCodec::m_mmerror = wxMMFILE_INVALID;
READ_STRING(chunk_name, 4);
wxSndFileCodec::m_mmerror = wxMMFILE_NOERROR;
m_istream->SeekI(m_spos, wxFromStart);
+ wxSndFileCodec::m_fstate = wxSFILE_PREPARED_TO_PLAY;
+
return m_slen;
}
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;
wxMMtime wxSndFileCodec::GetLength()
{
if (m_sndtime.hours == -1 && m_istream)
- PrepareToPlay();
+ m_fsize = PrepareToPlay();
return m_sndtime;
}
{
#define TMP_BUFSIZE 10240
- wxUint32 buf_size;
wxStreamBuffer *tmp_buf;
wxSoundCodec *codec_in, *codec_out;
wxSoundDataFormat std_format;
typedef enum {
wxSFILE_STOPPED,
wxSFILE_PLAYING,
- wxSFILE_RECORDING
+ wxSFILE_RECORDING,
+ wxSFILE_PREPARED_TO_PLAY,
+ wxSFILE_PREPARED_TO_RECORD,
} FileState;
protected:
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();
} 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();
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();
}
break;
}
default:
+ codec->InitWith(*this);
break;
}
}
// ----------------------------------------------------------------------------
#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);
size_t Available();
void InitIO(const wxSoundDataFormat& format);
+ virtual void InitWith(const wxSoundDataFormat& format) {}
inline void SetInStream(wxStreamBuffer *s)
{ m_in_sound = s; }
codec->InitIO(m_ussformat);
codec->InitMode(wxSoundCodec::DECODING);
break;
+ case wxSND_DUPLEX:
+ case wxSND_OTHER_IO:
+ break;
}
return TRUE;
}
}
buf->HardUnlock();
continue;
+
sound_clean_buffer:
buf->GetCurrentCodec()->ExitMode();
delete node;
m_sndtime.seconds = sec2 % 60;
wxSndFileCodec::m_mmerror = wxMMFILE_NOERROR;
+ wxSndFileCodec::m_fstate = wxSFILE_PREPARED_TO_PLAY;
return riff_codec.GetChunkLength();
}
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#ifdef __WXGTK__
+#include <gtk/gtkwidget.h>
#include <gdk/gdk.h>
#include <gdk/gdkprivate.h>
#endif