1999-01-10 20:23:52 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation "sndmulaw.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "sndsnd.h"
|
|
|
|
#include "sndfrmt.h"
|
|
|
|
#include "sndadpcm.h"
|
|
|
|
#include "adpcm/g72x.h"
|
|
|
|
|
|
|
|
wxSoundAdpcmCodec::wxSoundAdpcmCodec()
|
|
|
|
: wxSoundCodec()
|
|
|
|
{
|
1999-02-18 18:18:06 +00:00
|
|
|
// TODO: For the moment, only 1 channel is supported.
|
|
|
|
m_codec_state = new g72x_state;
|
|
|
|
g72x_init_state(m_codec_state);
|
1999-01-10 20:23:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxSoundAdpcmCodec::~wxSoundAdpcmCodec()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1999-02-18 18:18:06 +00:00
|
|
|
void wxSoundAdpcmCodec::InitWith(const wxSoundDataFormat& format)
|
|
|
|
{
|
|
|
|
m_srate = format.GetSampleRate();
|
|
|
|
}
|
|
|
|
|
1999-01-10 20:23:52 +00:00
|
|
|
int wxSoundAdpcmCodec::GetBits(int nbits)
|
|
|
|
{
|
|
|
|
unsigned int mask;
|
|
|
|
int bits;
|
|
|
|
|
1999-02-18 18:18:06 +00:00
|
|
|
if (m_bits_waiting == 0)
|
|
|
|
m_current_byte = m_in_sound->GetChar();
|
1999-01-10 20:23:52 +00:00
|
|
|
|
|
|
|
mask = (1 << nbits) - 1;
|
1999-02-18 18:18:06 +00:00
|
|
|
bits = m_current_byte & mask;
|
|
|
|
m_current_byte >>= nbits;
|
|
|
|
m_bits_waiting -= nbits;
|
1999-01-10 20:23:52 +00:00
|
|
|
return bits;
|
|
|
|
}
|
|
|
|
|
|
|
|
void wxSoundAdpcmCodec::Decode()
|
|
|
|
{
|
1999-02-18 18:18:06 +00:00
|
|
|
int smp, bits;
|
1999-01-10 20:23:52 +00:00
|
|
|
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()) {
|
1999-02-18 18:18:06 +00:00
|
|
|
smp = g721_decoder(bits, AUDIO_ENCODING_LINEAR, m_codec_state);
|
1999-01-10 20:23:52 +00:00
|
|
|
m_out_sound->PutChar(smp & 0x00ff);
|
|
|
|
m_out_sound->PutChar((smp & 0xff00) >> 8);
|
|
|
|
bits = GetBits(4);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
while (!StreamOk()) {
|
1999-02-18 18:18:06 +00:00
|
|
|
smp = g721_decoder(bits, AUDIO_ENCODING_LINEAR, m_codec_state);
|
1999-01-10 20:23:52 +00:00
|
|
|
m_out_sound->PutChar((smp & 0xff00) >> 8);
|
|
|
|
m_out_sound->PutChar(smp & 0x00ff);
|
|
|
|
bits = GetBits(4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-02-18 18:18:06 +00:00
|
|
|
void wxSoundAdpcmCodec::Encode()
|
1999-01-10 20:23:52 +00:00
|
|
|
{
|
1999-02-18 18:18:06 +00:00
|
|
|
/*
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
1999-01-10 20:23:52 +00:00
|
|
|
}
|
|
|
|
|
1999-02-18 18:18:06 +00:00
|
|
|
size_t wxSoundAdpcmCodec::GetByteRate() const
|
1999-01-10 20:23:52 +00:00
|
|
|
{
|
1999-02-18 18:18:06 +00:00
|
|
|
return (m_io_format.GetSampleRate() * m_io_format.GetChannels()) / 2;
|
1999-01-10 20:23:52 +00:00
|
|
|
}
|
|
|
|
|
1999-02-18 18:18:06 +00:00
|
|
|
wxSoundDataFormat wxSoundAdpcmCodec::GetPreferredFormat(int WXUNUSED(no)) const
|
1999-01-10 20:23:52 +00:00
|
|
|
{
|
|
|
|
wxSoundDataFormat format;
|
|
|
|
|
|
|
|
format.SetCodecNo(WXSOUND_PCM);
|
|
|
|
format.SetSampleRate(m_srate);
|
|
|
|
format.SetBps(16);
|
|
|
|
format.SetChannels(1);
|
|
|
|
format.SetSign(wxSND_SAMPLE_SIGNED);
|
|
|
|
#ifdef USE_BE_MACH
|
|
|
|
format.SetByteOrder(wxSND_SAMPLE_BE);
|
|
|
|
#else
|
|
|
|
format.SetByteOrder(wxSND_SAMPLE_LE);
|
|
|
|
#endif
|
|
|
|
return format;
|
|
|
|
}
|