]> git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia/sndadpcm.cpp
* Fixes.
[wxWidgets.git] / utils / wxMMedia / sndadpcm.cpp
1 #ifdef __GNUG__
2 #pragma implementation "sndmulaw.h"
3 #endif
4
5 #include "sndsnd.h"
6 #include "sndfrmt.h"
7 #include "sndadpcm.h"
8 #include "adpcm/g72x.h"
9
10 wxSoundAdpcmCodec::wxSoundAdpcmCodec()
11 : wxSoundCodec()
12 {
13 g72x_init_state(codec_state);
14 }
15
16 wxSoundAdpcmCodec::~wxSoundAdpcmCodec()
17 {
18 }
19
20 int wxSoundAdpcmCodec::GetBits(int nbits)
21 {
22 unsigned int mask;
23 int bits;
24
25 if (bits_waiting == 0)
26 current_byte = m_in_sound->GetChar();
27
28 mask = (1 << nbits) - 1;
29 bits = current_byte & mask;
30 current_byte >>= nbits;
31 return bits;
32 }
33
34
35 void wxSoundAdpcmCodec::Decode()
36 {
37 int smp;
38 wxSoundDataFormat pref_frmt;
39
40 pref_frmt = GetPreferredFormat(0);
41 if (!(m_io_format == pref_frmt))
42 ChainCodecAfter(pref_frmt);
43
44 bits = GetBits(4);
45 if (m_io_format.GetByteOrder() == wxSND_SAMPLE_LE) {
46 while (!StreamOk()) {
47 smp = g721_decoder(bits, AUDIO_ENCODING_LINEAR, codec_state);
48 m_out_sound->PutChar(smp & 0x00ff);
49 m_out_sound->PutChar((smp & 0xff00) >> 8);
50 bits = GetBits(4);
51 }
52 } else {
53 while (!StreamOk()) {
54 smp = g721_decoder(bits, AUDIO_ENCODING_LINEAR, codec_state);
55 m_out_sound->PutChar((smp & 0xff00) >> 8);
56 m_out_sound->PutChar(smp & 0x00ff);
57 bits = GetBits(4);
58 }
59 }
60 }
61
62 void wxSoundMulawCodec::Encode()
63 {
64 }
65
66 size_t wxSoundMulawCodec::GetByteRate() const
67 {
68 return m_srate;
69 }
70
71 wxSoundDataFormat wxSoundMulawCodec::GetPreferredFormat(int WXUNUSED(no)) const
72 {
73 wxSoundDataFormat format;
74
75 format.SetCodecNo(WXSOUND_PCM);
76 format.SetSampleRate(m_srate);
77 format.SetBps(16);
78 format.SetChannels(1);
79 format.SetSign(wxSND_SAMPLE_SIGNED);
80 #ifdef USE_BE_MACH
81 format.SetByteOrder(wxSND_SAMPLE_BE);
82 #else
83 format.SetByteOrder(wxSND_SAMPLE_LE);
84 #endif
85 return format;
86 }