1 // --------------------------------------------------------------------------
5 // Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
7 // --------------------------------------------------------------------------
9 #pragma implementation "sndcpcm.cpp"
12 #include <wx/wxprec.h>
17 wxSoundStreamPcm::wxSoundStreamPcm(wxSoundStream
& sndio
)
18 : wxSoundStreamCodec(sndio
)
21 m_function_out
= NULL
;
24 wxSoundStreamPcm::~wxSoundStreamPcm()
30 #include "converter.def"
34 #include "converter.def"
37 wxSoundStreamPcm::ConverterType s_convert_16_to_8
[] = {
39 Convert_16to8_U2S_16_no
,
42 Convert_16to8_U2S_16_yes
,
46 wxSoundStreamPcm::ConverterType s_convert_16
[] = {
49 Convert_U2S_SWAP_16_no
,
50 Convert_U2S_SWAP_16_yes
,
55 wxSoundStreamPcm::ConverterType s_convert_8
[] = {
65 #define CONVERTER_SIGN 1
66 #define CONVERTER_SIGN_SWAP 2
67 #define CONVERTER_SWAP_SIGN_SWAP 3
68 #define CONVERTER_SWAP_SIGN 4
69 #define CONVERTER_SWAP 5
71 wxSoundStream
& wxSoundStreamPcm::Read(void *buffer
, size_t len
)
74 m_sndio
->Read(buffer
, len
);
75 m_lastcount
= m_sndio
->GetLastAccess();
76 m_snderror
= m_sndio
->GetError();
81 m_sndio
->Read(buffer
, len
);
82 m_lastcount
= m_sndio
->GetLastAccess();
83 m_snderror
= m_sndio
->GetError();
87 wxSoundStream
& wxSoundStreamPcm::Write(const void *buffer
, size_t len
)
93 return m_sndio
->Write(buffer
, len
);
95 len2
= (m_16_to_8
) ? len
/ 2 : len
;
97 tmp_buf
= new char[len2
];
98 m_function_out((const char *)buffer
, tmp_buf
, len
);
99 m_sndio
->Write(tmp_buf
, len
);
102 m_lastcount
= (m_16_to_8
) ?
103 (m_sndio
->GetLastAccess() * 2) : m_sndio
->GetLastAccess();
108 bool wxSoundStreamPcm::SetSoundFormat(const wxSoundFormatBase
& format
)
110 wxSoundFormatBase
*new_format
;
111 wxSoundFormatPcm
*pcm_format
, *pcm_format2
;
112 ConverterType
*current_table
;
116 if (m_sndio
->SetSoundFormat(format
)) {
117 m_function_out
= NULL
;
118 m_function_in
= NULL
;
121 if (format
.GetType() != wxSOUND_PCM
) {
122 m_snderror
= wxSOUND_INVFRMT
;
128 new_format
= m_sndio
->GetSoundFormat().Clone();
129 pcm_format
= (wxSoundFormatPcm
*)&format
;
130 pcm_format2
= (wxSoundFormatPcm
*)new_format
;
133 if (pcm_format
->GetBPS() == 16 && pcm_format2
->GetBPS() == 8) {
135 current_table
= s_convert_16_to_8
;
136 } else if (pcm_format
->GetBPS() == 16)
137 current_table
= s_convert_16
;
139 current_table
= s_convert_8
;
141 change_sign
= (pcm_format2
->Signed() != pcm_format
->Signed());
143 #define MY_ORDER wxBYTE_ORDER
144 #if wxBYTE_ORDER == wxLITTLE_ENDIAN
145 #define OTHER_ORDER wxBIG_ENDIAN
147 #define OTHER_ORDER wxLITTLE_ENDIAN
150 if (pcm_format
->GetOrder() == OTHER_ORDER
&&
151 pcm_format2
->GetOrder() == OTHER_ORDER
&& change_sign
)
152 index
= CONVERTER_SWAP_SIGN_SWAP
;
154 else if (pcm_format
->GetOrder() == OTHER_ORDER
&&
155 pcm_format2
->GetOrder() == MY_ORDER
&& change_sign
)
156 index
= CONVERTER_SWAP_SIGN
;
158 else if (pcm_format
->GetOrder() == MY_ORDER
&&
159 pcm_format
->GetOrder() == OTHER_ORDER
&& change_sign
)
160 index
= CONVERTER_SIGN_SWAP
;
162 else if (!change_sign
&&
163 pcm_format
->GetOrder() != pcm_format2
->GetOrder())
164 index
= CONVERTER_SWAP
;
169 m_function_out
= current_table
[index
];
170 // m_function_in = current_table[index+1];
172 m_sndio
->SetSoundFormat(*new_format
);
173 m_sndformat
= new_format
;