]> git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia/sndadpcm.cpp
Fixed wxImage GetData and SetData to properly use String objects for
[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 // TODO: For the moment, only 1 channel is supported.
14 m_codec_state = new g72x_state;
15 g72x_init_state(m_codec_state);
16 }
17
18 wxSoundAdpcmCodec::~wxSoundAdpcmCodec()
19 {
20 }
21
22 void wxSoundAdpcmCodec::InitWith(const wxSoundDataFormat& format)
23 {
24 m_srate = format.GetSampleRate();
25 }
26
27 int wxSoundAdpcmCodec::GetBits(int nbits)
28 {
29 unsigned int mask;
30 int bits;
31
32 if (m_bits_waiting == 0)
33 m_current_byte = m_in_sound->GetChar();
34
35 mask = (1 << nbits) - 1;
36 bits = m_current_byte & mask;
37 m_current_byte >>= nbits;
38 m_bits_waiting -= nbits;
39 return bits;
40 }
41
42 void wxSoundAdpcmCodec::Decode()
43 {
44 int smp, bits;
45 wxSoundDataFormat pref_frmt;
46
47 pref_frmt = GetPreferredFormat(0);
48 if (!(m_io_format == pref_frmt))
49 ChainCodecAfter(pref_frmt);
50
51 bits = GetBits(4);
52 if (m_io_format.GetByteOrder() == wxSND_SAMPLE_LE) {
53 while (!StreamOk()) {
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);
57 bits = GetBits(4);
58 }
59 } else {
60 while (!StreamOk()) {
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);
64 bits = GetBits(4);
65 }
66 }
67 }
68
69 void wxSoundAdpcmCodec::Encode()
70 {
71 /*
72 int smp;
73 wxSoundDataFormat pref_frmt;
74
75 pref_frmt = GetPreferredFormat(0);
76 if (!(m_io_format == pref_frmt))
77 ChainCodecAfter(pref_frmt);
78
79 bits = GetBits(4);
80 if (m_io_format.GetByteOrder() == wxSND_SAMPLE_LE) {
81 while (!StreamOk()) {
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);
85 bits = GetBits(4);
86 }
87 } else {
88 while (!StreamOk()) {
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);
92 bits = GetBits(4);
93 }
94 }
95 */
96 }
97
98 size_t wxSoundAdpcmCodec::GetByteRate() const
99 {
100 return (m_io_format.GetSampleRate() * m_io_format.GetChannels()) / 2;
101 }
102
103 wxSoundDataFormat wxSoundAdpcmCodec::GetPreferredFormat(int WXUNUSED(no)) const
104 {
105 wxSoundDataFormat format;
106
107 format.SetCodecNo(WXSOUND_PCM);
108 format.SetSampleRate(m_srate);
109 format.SetBps(16);
110 format.SetChannels(1);
111 format.SetSign(wxSND_SAMPLE_SIGNED);
112 #ifdef USE_BE_MACH
113 format.SetByteOrder(wxSND_SAMPLE_BE);
114 #else
115 format.SetByteOrder(wxSND_SAMPLE_LE);
116 #endif
117 return format;
118 }