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