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