2 #pragma implementation "sndpcm.h"
8 #define WX_BIG_ENDIAN 0
10 wxSoundPcmCodec::wxSoundPcmCodec()
13 m_orig_format
.SetCodecCreate(FALSE
);
14 m_orig_format
.SetCodecNo(1);
18 wxSoundPcmCodec::~wxSoundPcmCodec()
22 size_t wxSoundPcmCodec::GetByteRate() const
24 return (m_orig_format
.GetBps()/8)*
25 m_orig_format
.GetSampleRate()*
26 m_orig_format
.GetChannels();
29 wxSoundDataFormat
wxSoundPcmCodec::GetPreferredFormat(int codec
) const
31 wxSoundDataFormat prefFormat
;
33 prefFormat
= m_orig_format
;
34 prefFormat
.SetCodecNo(WXSOUND_PCM
);
38 // ---------------------------------------------------------------------------
39 // Main part of the decoder
40 // ---------------------------------------------------------------------------
42 void wxSoundPcmCodec::Decode()
45 if (m_io_format
== m_orig_format
) {
52 switch (m_io_format
.GetBps()) {
67 // ---------------------------------------------------------------------------
68 // Change the sign of a 8-bit sample.
70 #define GET() (m_in_sound->GetChar())
71 #define PUT(c) (m_out_sound->PutChar(c))
72 #define OUT_ERROR() (out->LastError() == wxStream_NOERROR)
73 #define IN_ERROR() (in->LastError() == wxStream_NOERROR)
75 void wxSoundPcmCodec::InputSign8()
77 unsigned char signer
= 0;
78 wxStreamBase
*in
= m_out_sound
->Stream(), *out
= m_in_sound
->Stream();
80 if (m_io_format
.GetSign() != m_orig_format
.GetSign())
83 while (IN_ERROR() && OUT_ERROR())
88 // ---------------------------------------------------------------------------
89 // Swap bytes and change the sign of a 16-bit sample.
91 void wxSoundPcmCodec::InputSwapAndSign16()
93 unsigned short signer1
= 0, signer2
= 0;
94 wxStreamBase
*in
= m_out_sound
->Stream(), *out
= m_in_sound
->Stream();
95 bool swap
= (m_io_format
.GetByteOrder() != m_orig_format
.GetByteOrder());
98 if (m_io_format
.GetSign() != m_orig_format
.GetSign()) {
99 if (m_io_format
.GetByteOrder() == wxSND_SAMPLE_LE
)
106 while (IN_ERROR() && OUT_ERROR()) {
107 temp
= GET() ^ signer1
;
108 PUT(GET() ^ signer2
);
117 while (IN_ERROR() && OUT_ERROR()) {
118 PUT(GET() ^ signer1
);
124 PUT(GET() ^ signer2
);
129 // ---------------------------------------------------------------------------
131 // ---------------------------------------------------------------------------
133 void wxSoundPcmCodec::OutputSign8()
135 wxStreamBase
*in
= m_out_sound
->Stream(), *out
= m_in_sound
->Stream();
136 unsigned char signer
= 0;
138 if (m_io_format
.GetSign() != m_orig_format
.GetSign())
141 while (IN_ERROR() && OUT_ERROR())
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;
152 wxStreamBase
*in
= m_out_sound
->Stream(), *out
= m_in_sound
->Stream();
160 if (m_io_format
.GetSign() != m_orig_format
.GetSign())
161 if (m_io_format
.GetByteOrder() == wxSND_SAMPLE_LE
)
169 PUT(GET() ^ signer1
);
171 m_char_stack
= temp
^ signer2
;
179 PUT(GET() ^ signer1
);
181 m_char_stack
= GET() ^ signer2
;
185 PUT(GET() ^ signer2
);
191 // ---------------------------------------------------------------------------
193 void wxSoundPcmCodec::Encode()
196 if (m_io_format
== m_orig_format
) {
203 switch (m_io_format
.GetBps()) {
208 OutputSwapAndSign16();