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()
41 if (m_io_format
== m_orig_format
) {
47 switch (m_io_format
.GetBps()) {
61 // ---------------------------------------------------------------------------
62 // Change the sign of a 8-bit sample.
64 #define GET() (m_in_sound->GetChar())
65 #define PUT(c) (m_out_sound->PutChar(c))
67 void wxSoundPcmCodec::InputSign8()
69 unsigned char signer
= 0;
71 if (m_io_format
.GetSign() != m_orig_format
.GetSign())
78 // ---------------------------------------------------------------------------
79 // Swap bytes and change the sign of a 16-bit sample.
81 void wxSoundPcmCodec::InputSwapAndSign16()
83 unsigned short signer1
= 0, signer2
= 0;
84 bool swap
= (m_io_format
.GetByteOrder() != m_orig_format
.GetByteOrder());
85 register char temp
, temp2
;
87 if (m_io_format
.GetSign() != m_orig_format
.GetSign()) {
88 if (m_io_format
.GetByteOrder() == wxSND_SAMPLE_LE
)
100 m_in_sound
->WriteBack(temp
);
101 m_in_sound
->WriteBack(temp2
);
111 m_in_sound
->WriteBack(temp
);
114 PUT(GET() ^ signer2
);
119 // ---------------------------------------------------------------------------
121 // ---------------------------------------------------------------------------
123 void wxSoundPcmCodec::OutputSign8()
125 unsigned char signer
= 0;
127 if (m_io_format
.GetSign() != m_orig_format
.GetSign())
131 PUT((char)(GET() + signer
));
134 // ---------------------------------------------------------------------------
136 void wxSoundPcmCodec::OutputSwapAndSign16()
138 bool swap
= (m_io_format
.GetByteOrder() != m_orig_format
.GetByteOrder());
139 unsigned short signer1
= 0, signer2
= 0;
140 register char temp
, temp2
;
142 if (m_io_format
.GetSign() != m_orig_format
.GetSign())
143 if (m_io_format
.GetByteOrder() == wxSND_SAMPLE_LE
)
152 PUT(temp2
^ signer1
);
154 m_in_sound
->WriteBack(temp
);
155 m_in_sound
->WriteBack(temp2
);
166 m_in_sound
->WriteBack(temp
);
169 PUT(temp2
^ signer2
);
175 // ---------------------------------------------------------------------------
177 void wxSoundPcmCodec::Encode()
179 if (m_io_format
== m_orig_format
) {
185 switch (m_io_format
.GetBps()) {
190 OutputSwapAndSign16();