2 #pragma implementation "sndpcm.h"
7 #define WX_BIG_ENDIAN 0
9 wxSoundPcmCodec::wxSoundPcmCodec()
12 m_orig_format
.SetCodecCreate(FALSE
);
13 m_orig_format
.SetCodecNo(WXSOUND_PCM
);
16 wxSoundPcmCodec::~wxSoundPcmCodec()
20 size_t wxSoundPcmCodec::GetByteRate() const
22 return (m_orig_format
.GetBps()/8)*
23 m_orig_format
.GetSampleRate()*
24 m_orig_format
.GetChannels();
27 wxSoundDataFormat
wxSoundPcmCodec::GetPreferredFormat(int codec
) const
29 wxSoundDataFormat prefFormat
;
31 prefFormat
= m_orig_format
;
35 // ---------------------------------------------------------------------------
36 // Main part of the decoder
37 // ---------------------------------------------------------------------------
39 void wxSoundPcmCodec::Decode()
42 if (m_io_format
== m_orig_format
) {
49 switch (m_io_format
.GetBps()) {
64 // ---------------------------------------------------------------------------
65 // Change the sign of a 8-bit sample.
67 #define GET() (m_in_sound->GetChar())
68 #define PUT(c) (m_out_sound->PutChar(c))
70 void wxSoundPcmCodec::InputSign8()
72 unsigned char signer
= 0;
74 if (m_io_format
.GetSign() != m_orig_format
.GetSign())
81 // ---------------------------------------------------------------------------
82 // Swap bytes and change the sign of a 16-bit sample.
84 void wxSoundPcmCodec::InputSwapAndSign16()
86 unsigned short signer1
= 0, signer2
= 0;
87 bool swap
= (m_io_format
.GetByteOrder() != m_orig_format
.GetByteOrder());
88 register char temp
, temp2
;
90 if (m_io_format
.GetSign() != m_orig_format
.GetSign()) {
91 if (m_io_format
.GetByteOrder() == wxSND_SAMPLE_LE
)
101 PUT(temp2
^ signer2
);
103 m_in_sound
->WriteBack(temp
);
104 m_in_sound
->WriteBack(temp2
);
114 m_in_sound
->WriteBack(temp
);
117 PUT(GET() ^ signer2
);
122 // ---------------------------------------------------------------------------
124 // ---------------------------------------------------------------------------
126 void wxSoundPcmCodec::OutputSign8()
128 unsigned char signer
= 0;
130 if (m_io_format
.GetSign() != m_orig_format
.GetSign())
134 PUT((char)(GET() + signer
));
137 // ---------------------------------------------------------------------------
139 void wxSoundPcmCodec::OutputSwapAndSign16()
141 bool swap
= (m_io_format
.GetByteOrder() != m_orig_format
.GetByteOrder());
142 unsigned short signer1
= 0, signer2
= 0;
143 register char temp
, temp2
;
145 if (m_io_format
.GetSign() != m_orig_format
.GetSign())
146 if (m_io_format
.GetByteOrder() == wxSND_SAMPLE_LE
)
155 PUT(temp2
^ signer1
);
157 m_in_sound
->WriteBack(temp
);
158 m_in_sound
->WriteBack(temp2
);
169 m_in_sound
->WriteBack(temp
);
172 PUT(temp2
^ signer2
);
178 // ---------------------------------------------------------------------------
180 void wxSoundPcmCodec::Encode()
183 if (m_io_format
== m_orig_format
) {
190 switch (m_io_format
.GetBps()) {
195 OutputSwapAndSign16();