1 ////////////////////////////////////////////////////////////////////////////////
4 // Author: Guilhem Lavaux
7 // Copyright: (C) 1997, 1998, 1999, Guilhem Lavaux
8 // License: wxWindows license
9 ////////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "sndpcm.h"
16 #define WX_BIG_ENDIAN 0
18 wxSoundPcmCodec::wxSoundPcmCodec()
21 m_orig_format
.SetCodecCreate(FALSE
);
22 m_orig_format
.SetCodecNo(WXSOUND_PCM
);
25 wxSoundPcmCodec::~wxSoundPcmCodec()
29 size_t wxSoundPcmCodec::GetByteRate() const
31 return (m_orig_format
.GetBps()/8)*
32 m_orig_format
.GetSampleRate()*
33 m_orig_format
.GetChannels();
36 wxSoundDataFormat
wxSoundPcmCodec::GetPreferredFormat(int codec
) const
38 wxSoundDataFormat prefFormat
;
40 prefFormat
= m_orig_format
;
44 // ---------------------------------------------------------------------------
45 // Main part of the decoder
46 // ---------------------------------------------------------------------------
48 void wxSoundPcmCodec::Decode()
50 if (m_io_format
== m_orig_format
) {
56 switch (m_io_format
.GetBps()) {
70 // ---------------------------------------------------------------------------
71 // Change the sign of a 8-bit sample.
73 #define GET() (m_in_sound->GetChar())
74 #define PUT(c) (m_out_sound->PutChar(c))
76 void wxSoundPcmCodec::InputSign8()
78 unsigned char signer
= 0;
80 if (m_io_format
.GetSign() != m_orig_format
.GetSign())
87 // ---------------------------------------------------------------------------
88 // Swap bytes and change the sign of a 16-bit sample.
90 void wxSoundPcmCodec::InputSwapAndSign16()
92 unsigned short signer1
= 0, signer2
= 0;
93 bool swap
= (m_io_format
.GetByteOrder() != m_orig_format
.GetByteOrder());
94 register char temp
, temp2
;
96 if (m_io_format
.GetSign() != m_orig_format
.GetSign()) {
97 if (m_io_format
.GetByteOrder() == wxSND_SAMPLE_LE
)
107 PUT(temp2
^ signer2
);
109 m_in_sound
->WriteBack(temp
);
110 m_in_sound
->WriteBack(temp2
);
121 m_in_sound
->WriteBack(temp
);
122 m_in_sound
->WriteBack(temp2
);
125 PUT(GET() ^ signer2
);
130 // ---------------------------------------------------------------------------
132 // ---------------------------------------------------------------------------
134 void wxSoundPcmCodec::OutputSign8()
136 unsigned char signer
= 0;
138 if (m_io_format
.GetSign() != m_orig_format
.GetSign())
142 PUT((char)(GET() + signer
));
145 // ---------------------------------------------------------------------------
147 void wxSoundPcmCodec::OutputSwapAndSign16()
149 bool swap
= (m_io_format
.GetByteOrder() != m_orig_format
.GetByteOrder());
150 unsigned short signer1
= 0, signer2
= 0;
151 register char temp
, temp2
;
153 if (m_io_format
.GetSign() != m_orig_format
.GetSign())
154 if (m_io_format
.GetByteOrder() == wxSND_SAMPLE_LE
)
163 PUT(temp2
^ signer1
);
165 m_in_sound
->WriteBack(temp
);
166 m_in_sound
->WriteBack(temp2
);
177 m_in_sound
->WriteBack(temp
);
178 m_in_sound
->WriteBack(temp2
);
181 PUT(temp2
^ signer2
);
187 // ---------------------------------------------------------------------------
189 void wxSoundPcmCodec::Encode()
191 if (m_io_format
== m_orig_format
) {
197 switch (m_io_format
.GetBps()) {
202 OutputSwapAndSign16();