2 #pragma implementation "sndmulaw.h"
8 #include "adpcm/g72x.h"
10 wxSoundAdpcmCodec::wxSoundAdpcmCodec()
13 // TODO: For the moment, only 1 channel is supported.
14 m_codec_state
= new g72x_state
;
15 g72x_init_state(m_codec_state
);
18 wxSoundAdpcmCodec::~wxSoundAdpcmCodec()
22 void wxSoundAdpcmCodec::InitWith(const wxSoundDataFormat
& format
)
24 m_srate
= format
.GetSampleRate();
27 int wxSoundAdpcmCodec::GetBits(int nbits
)
32 if (m_bits_waiting
== 0)
33 m_current_byte
= m_in_sound
->GetChar();
35 mask
= (1 << nbits
) - 1;
36 bits
= m_current_byte
& mask
;
37 m_current_byte
>>= nbits
;
38 m_bits_waiting
-= nbits
;
42 void wxSoundAdpcmCodec::Decode()
45 wxSoundDataFormat pref_frmt
;
47 pref_frmt
= GetPreferredFormat(0);
48 if (!(m_io_format
== pref_frmt
))
49 ChainCodecAfter(pref_frmt
);
52 if (m_io_format
.GetByteOrder() == wxSND_SAMPLE_LE
) {
54 smp
= g721_decoder(bits
, AUDIO_ENCODING_LINEAR
, m_codec_state
);
55 m_out_sound
->PutChar(smp
& 0x00ff);
56 m_out_sound
->PutChar((smp
& 0xff00) >> 8);
61 smp
= g721_decoder(bits
, AUDIO_ENCODING_LINEAR
, m_codec_state
);
62 m_out_sound
->PutChar((smp
& 0xff00) >> 8);
63 m_out_sound
->PutChar(smp
& 0x00ff);
69 void wxSoundAdpcmCodec::Encode()
73 wxSoundDataFormat pref_frmt;
75 pref_frmt = GetPreferredFormat(0);
76 if (!(m_io_format == pref_frmt))
77 ChainCodecAfter(pref_frmt);
80 if (m_io_format.GetByteOrder() == wxSND_SAMPLE_LE) {
82 smp = g721_decoder(bits, AUDIO_ENCODING_LINEAR, codec_state);
83 m_out_sound->PutChar(smp & 0x00ff);
84 m_out_sound->PutChar((smp & 0xff00) >> 8);
89 smp = g721_decoder(bits, AUDIO_ENCODING_LINEAR, codec_state);
90 m_out_sound->PutChar((smp & 0xff00) >> 8);
91 m_out_sound->PutChar(smp & 0x00ff);
98 size_t wxSoundAdpcmCodec::GetByteRate() const
100 return (m_io_format
.GetSampleRate() * m_io_format
.GetChannels()) / 2;
103 wxSoundDataFormat
wxSoundAdpcmCodec::GetPreferredFormat(int WXUNUSED(no
)) const
105 wxSoundDataFormat format
;
107 format
.SetCodecNo(WXSOUND_PCM
);
108 format
.SetSampleRate(m_srate
);
110 format
.SetChannels(1);
111 format
.SetSign(wxSND_SAMPLE_SIGNED
);
113 format
.SetByteOrder(wxSND_SAMPLE_BE
);
115 format
.SetByteOrder(wxSND_SAMPLE_LE
);