X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c06a465c52c57fa7eee71b6a7c88f797e56ef3ea..9e3d3318dc6f58870d13eb6567da721d060533a6:/utils/wxMMedia/sndadpcm.cpp?ds=inline 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;