1 // --------------------------------------------------------------------------
5 // Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
7 // --------------------------------------------------------------------------
9 #pragma implementation "sndcpcm.cpp"
16 wxSoundStreamPcm::wxSoundStreamPcm(wxSoundStream
& sndio
)
17 : wxSoundStreamCodec(sndio
)
20 m_function_out
= NULL
;
23 wxSoundStreamPcm::~wxSoundStreamPcm()
29 #include "converter.def"
33 #include "converter.def"
36 wxSoundStreamPcm::ConverterType s_convert_16_to_8
[] = {
38 Convert_16to8_U2S_16_no
,
41 Convert_16to8_U2S_16_yes
,
45 wxSoundStreamPcm::ConverterType s_convert_16
[] = {
48 Convert_U2S_SWAP_16_no
,
49 Convert_U2S_SWAP_16_yes
,
54 wxSoundStreamPcm::ConverterType s_convert_8
[] = {
64 #define CONVERTER_SIGN 1
65 #define CONVERTER_SIGN_SWAP 2
66 #define CONVERTER_SWAP_SIGN_SWAP 3
67 #define CONVERTER_SWAP_SIGN 4
68 #define CONVERTER_SWAP 5
70 wxSoundStream
& wxSoundStreamPcm::Read(void *buffer
, size_t len
)
73 m_sndio
->Read(buffer
, len
);
74 m_lastcount
= m_sndio
->GetLastAccess();
75 m_snderror
= m_sndio
->GetError();
80 m_sndio
->Read(buffer
, len
);
81 m_lastcount
= m_sndio
->GetLastAccess();
82 m_snderror
= m_sndio
->GetError();
86 wxSoundStream
& wxSoundStreamPcm::Write(const void *buffer
, size_t len
)
92 return m_sndio
->Write(buffer
, len
);
94 len2
= (m_16_to_8
) ? len
/ 2 : len
;
96 tmp_buf
= new char[len2
];
97 m_function_out((const char *)buffer
, tmp_buf
, len
);
98 m_sndio
->Write(tmp_buf
, len
);
101 m_lastcount
= (m_16_to_8
) ?
102 (m_sndio
->GetLastAccess() * 2) : m_sndio
->GetLastAccess();
107 bool wxSoundStreamPcm::SetSoundFormat(const wxSoundFormatBase
& format
)
109 wxSoundFormatBase
*new_format
;
110 wxSoundFormatPcm
*pcm_format
, *pcm_format2
;
111 ConverterType
*current_table
;
115 if (m_sndio
->SetSoundFormat(format
)) {
116 m_function_out
= NULL
;
117 m_function_in
= NULL
;
120 if (format
.GetType() != wxSOUND_PCM
) {
121 m_snderror
= wxSOUND_INVFRMT
;
127 new_format
= m_sndio
->GetSoundFormat().Clone();
128 pcm_format
= (wxSoundFormatPcm
*)&format
;
129 pcm_format2
= (wxSoundFormatPcm
*)new_format
;
132 if (pcm_format
->GetBPS() == 16 && pcm_format2
->GetBPS() == 8) {
134 current_table
= s_convert_16_to_8
;
135 } else if (pcm_format
->GetBPS() == 16)
136 current_table
= s_convert_16
;
138 current_table
= s_convert_8
;
140 change_sign
= (pcm_format2
->Signed() != pcm_format
->Signed());
142 #define MY_ORDER wxBYTE_ORDER
143 #if wxBYTE_ORDER == wxLITTLE_ENDIAN
144 #define OTHER_ORDER wxBIG_ENDIAN
146 #define OTHER_ORDER wxLITTLE_ENDIAN
149 if (pcm_format
->GetOrder() == OTHER_ORDER
&&
150 pcm_format2
->GetOrder() == OTHER_ORDER
&& change_sign
)
151 index
= CONVERTER_SWAP_SIGN_SWAP
;
153 else if (pcm_format
->GetOrder() == OTHER_ORDER
&&
154 pcm_format2
->GetOrder() == MY_ORDER
&& change_sign
)
155 index
= CONVERTER_SWAP_SIGN
;
157 else if (pcm_format
->GetOrder() == MY_ORDER
&&
158 pcm_format
->GetOrder() == OTHER_ORDER
&& change_sign
)
159 index
= CONVERTER_SIGN_SWAP
;
161 else if (!change_sign
&&
162 pcm_format
->GetOrder() != pcm_format2
->GetOrder())
163 index
= CONVERTER_SWAP
;
168 m_function_out
= current_table
[index
];
169 // m_function_in = current_table[index+1];
171 m_sndio
->SetSoundFormat(*new_format
);
172 m_sndformat
= new_format
;