From ef366f35232458dbce12c8e32d1d72d9a34546a0 Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Sat, 12 Feb 2000 12:11:23 +0000 Subject: [PATCH 1/1] * Updated README * Recoded converters (in a cleaner way) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5980 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- utils/wxMMedia2/README | 39 +++++++++ utils/wxMMedia2/lib/converter.def | 135 +++++++----------------------- utils/wxMMedia2/lib/sndbase.cpp | 2 +- utils/wxMMedia2/lib/sndcpcm.cpp | 115 +++++++++++-------------- utils/wxMMedia2/lib/sndoss.cpp | 2 +- utils/wxMMedia2/lib/sndwin.cpp | 2 +- utils/wxMMedia2/lib/vidwin.cpp | 2 +- 7 files changed, 121 insertions(+), 176 deletions(-) diff --git a/utils/wxMMedia2/README b/utils/wxMMedia2/README index e69de29bb2..c77db4f392 100644 --- a/utils/wxMMedia2/README +++ b/utils/wxMMedia2/README @@ -0,0 +1,39 @@ +-------------------------------------------------------------------------- +| wxMultimedia (c) 1998, 1999, 2000 Guilhem Lavaux +| wxWindows license +-------------------------------------------------------------------------- + +This is the wxMultimedia package. It intends to be a portable way to access +some multimedia component on variable system. For the moment, I implemented +sound, video and CD access. + +Sound features: + * low level/OSS style access to the sound card. You can open/setup the + parameters of the sound card then write/read directly to/from it. + * mid level codecs: compressors and sound codec are supported. For the + moment there is a support for G711/G721/G723 and MULAW formats (as well + PCM). + * high level format: WAV file format is supported in read/write and AIFF + format in read only + + +Sound bugs: + * it seems there are still some bugs in the recording code on Windows + on Cygwin B20.1 (to be verified) + * wave files created with wxSoundWave have some problem with Windows Media + Player (not windows recorder) + +Video features: + * high level video file playing: on Unix you can play (through xanim) video + files directly into your application + * MPEG video file to be supported through SMPEG as soon as I have some free + time + +Video bugs: + * Recode windows port + +CD features: + * standard access to the CDAUDIO interface + +CD bugs: + diff --git a/utils/wxMMedia2/lib/converter.def b/utils/wxMMedia2/lib/converter.def index b5279cc03f..21157955f9 100644 --- a/utils/wxMMedia2/lib/converter.def +++ b/utils/wxMMedia2/lib/converter.def @@ -1,110 +1,31 @@ -#define DEFINE_CONV_8(name) \ -static void Convert_##name##_8(const char *buf_in, char *buf_out, wxUint32 len) \ +#define DEFINE_CONV(name, input_type, output_type, convert) \ +static void Convert_##name##(const char *buf_in, char *buf_out, wxUint32 len) \ {\ - wxUint16 val; \ + register input_type src; \ + register const input_type *t_buf_in = (input_type *)buf_in; \ + register output_type *t_buf_out = (output_type *)buf_out; \ \ while (len > 0) { \ - val = *buf_in++; \ - len--; - -#if SWAP_BYTES==0 - -#define DEFINE_CONV_16(name) \ -static void Convert_##name##_16_no(const char *buf_in, char *buf_out, wxUint32 len) \ -{\ - wxUint16 val; \ -\ - while (len > 0) { \ - val = *(wxUint16 *)(buf_in); \ - buf_in += 2; \ - len -= 2; - -#else - -#define DEFINE_CONV_16(name) \ -static void Convert_##name##_16_yes(const char *buf_in, char *buf_out, wxUint32 len) \ -{\ - wxUint16 val; \ -\ - while (len > 0) { \ - val = *(wxUint16 *)(buf_in); \ - val = wxUINT16_SWAP_ALWAYS(val); \ - buf_in += 2; \ - len -= 2; - -#endif - -#define END_CONV } } - -#define PUT16 *((wxUint16 *)buf_out) = val, buf_out += 2; -#define PUT16_SWAP *((wxUint16 *)buf_out) = wxUINT16_SWAP_ALWAYS(val), buf_out += 2; -#define PUT8 *buf_out++ = val; -#define CHANGE16_SIGN val ^= 0x8000; -#define CHANGE8_SIGN val ^= 0x80; -#define REDUCE16_TO_8 val /= 256; -#define AUGMENT8_TO_16 val *= 256; - -DEFINE_CONV_16(16to8) -REDUCE16_TO_8 -PUT8 -END_CONV - -DEFINE_CONV_16(16to8_U2S) -CHANGE16_SIGN -REDUCE16_TO_8 -PUT8 -END_CONV - -DEFINE_CONV_16(U2S) -CHANGE16_SIGN -PUT16 -END_CONV - -DEFINE_CONV_16(U2S_SWAP) -CHANGE16_SIGN -PUT16_SWAP -END_CONV - -#if SWAP_BYTES == 0 - -DEFINE_CONV_16(SWAP) -PUT16_SWAP -END_CONV - -DEFINE_CONV_8(U2S) -CHANGE8_SIGN -PUT8 -END_CONV - -DEFINE_CONV_8(8to16) -AUGMENT8_TO_16 -PUT16 -END_CONV - -DEFINE_CONV_8(8to16_SWAP) -AUGMENT8_TO_16 -PUT16_SWAP -END_CONV - -DEFINE_CONV_8(8to16_U2S) -CHANGE8_SIGN -AUGMENT8_TO_16 -PUT16 -END_CONV - -DEFINE_CONV_8(8to16_U2S_SWAP) -CHANGE8_SIGN -AUGMENT8_TO_16 -PUT16_SWAP -END_CONV - -#endif - -#undef DEFINE_CONV_16 -#undef DEFINE_CONV_8 -#undef END_CONV -#undef CHANGE16_SIGN -#undef CHANGE8_SIGN -#undef PUT16_SWAP -#undef PUT16 -#undef PUT8 + src = *t_buf_in++; \ + *t_buf_out++ = convert; \ + len--; \ + } \ +} + +DEFINE_CONV(8_8_sign, wxUint8, wxUint8, (src ^ 0x80)) + +DEFINE_CONV(8_16, wxUint8, wxUint16, (((wxUint16)src) << 8)) +DEFINE_CONV(8_16_swap, wxUint8, wxUint16, (src)) +DEFINE_CONV(8_16_sign, wxUint8, wxUint16, (((wxUint16)(src ^ 0x80)) << 8)) +DEFINE_CONV(8_16_sign_swap, wxUint8, wxUint16, (src ^ 0x80)) + +DEFINE_CONV(16_8, wxUint16, wxUint8, (wxUint8)(src >> 8)) +DEFINE_CONV(16_8_sign, wxUint16, wxUint8, (wxUint8)((src >> 8) ^ 0x80)) +DEFINE_CONV(16_swap_8, wxUint16, wxUint8, (wxUint8)(src & 0xff)) +DEFINE_CONV(16_swap_8_sign, wxUint16, wxUint8, (wxUint8)((src & 0xff) ^ 0x80)) + +DEFINE_CONV(16_sign, wxUint16, wxUint16, (src ^ 0x8000)) +DEFINE_CONV(16_swap, wxUint16, wxUint16, (((src & 0xff) << 8) | ((src >> 8) & 0xff))) +DEFINE_CONV(16_swap_16_sign, wxUint16, wxUint16, ((((src & 0xff) << 8) | ((src >> 8) & 0xff)) ^ 0x8000)) +DEFINE_CONV(16_sign_16_swap, wxUint16, wxUint16, ((((src & 0xff) << 8) | ((src >> 8) & 0xff)) ^ 0x80)) +DEFINE_CONV(16_swap_16_sign_swap, wxUint16, wxUint16, (src ^ 0x80)) diff --git a/utils/wxMMedia2/lib/sndbase.cpp b/utils/wxMMedia2/lib/sndbase.cpp index 95a51c7179..be6d6d59c7 100644 --- a/utils/wxMMedia2/lib/sndbase.cpp +++ b/utils/wxMMedia2/lib/sndbase.cpp @@ -2,7 +2,7 @@ // Name: sndbase.cpp // Purpose: // Date: 08/11/1999 -// Author: Guilhem Lavaux (C) 1999 +// Author: Guilhem Lavaux (C) 1999, 2000 // CVSID: $Id$ // -------------------------------------------------------------------------- #ifdef __GNUG__ diff --git a/utils/wxMMedia2/lib/sndcpcm.cpp b/utils/wxMMedia2/lib/sndcpcm.cpp index 27dba75dfd..1c4bf09852 100644 --- a/utils/wxMMedia2/lib/sndcpcm.cpp +++ b/utils/wxMMedia2/lib/sndcpcm.cpp @@ -2,7 +2,7 @@ // Name: sndcpcm.cpp // Purpose: // Date: 08/11/1999 -// Author: Guilhem Lavaux (C) 1999 +// Author: Guilhem Lavaux (C) 1999, 2000 // CVSID: $Id$ // -------------------------------------------------------------------------- #ifdef __GNUG__ @@ -26,72 +26,49 @@ wxSoundStreamPcm::~wxSoundStreamPcm() } -#define SWAP_BYTES 0 #include "converter.def" -#undef SWAP_BYTES -#define SWAP_BYTES 1 -#include "converter.def" -#undef SWAP_BYTES - -wxSoundStreamPcm::ConverterType s_convert_out_16_to_8[] = { - Convert_16to8_16_no, - Convert_16to8_U2S_16_no, +wxSoundStreamPcm::ConverterType s_converters[] = { + NULL, + Convert_8_8_sign, /* 8 -> 8 sign */ + NULL, NULL, NULL, - Convert_16to8_U2S_16_yes, - Convert_16to8_16_yes -}; - -wxSoundStreamPcm::ConverterType s_convert_out_16[] = { NULL, - Convert_U2S_16_no, - Convert_U2S_SWAP_16_no, - Convert_U2S_SWAP_16_yes, - Convert_U2S_16_yes, - Convert_SWAP_16_no -}; -wxSoundStreamPcm::ConverterType s_convert_out_8[] = { + Convert_8_16, /* 8 -> 16 */ + Convert_8_16_sign, /* 8 -> 16 sign */ + Convert_8_16_swap, /* 8 -> 16 swapped */ + Convert_8_16_sign_swap, /* 8 -> 16 sign swapped */ + NULL, NULL, - Convert_U2S_8, - Convert_U2S_8, - Convert_U2S_8, - Convert_U2S_8, - NULL -/*, - Convert_U2S_S2M_8, - Convert_U2S_S2M_8, - Convert_U2S_S2M_8, - Convert_U2S_S2M_8, - Convert_S2M_8 */ -}; -wxSoundStreamPcm::ConverterType s_convert_in_8_to_16[] = { - Convert_8to16_8, - Convert_8to16_U2S_8, - Convert_8to16_U2S_SWAP_8, + Convert_16_8, /* 16 -> 8 */ + Convert_16_8_sign, /* 16 -> 8 sign */ + Convert_16_swap_8, /* 16 swapped -> 8 */ + Convert_16_swap_8_sign, /* 16 swapped -> 8 sign */ NULL, NULL, - Convert_8to16_SWAP_8 -}; -wxSoundStreamPcm::ConverterType *s_convert_in_16 = s_convert_out_16; + NULL, /* 16 -> 16 */ + Convert_16_sign, /* 16 -> 16 sign */ + Convert_16_swap, /* 16 swapped -> 16 */ + Convert_16_swap_16_sign, /* 16 swapped -> 16 sign */ + Convert_16_sign_16_swap, /* 16 sign -> 16 swapped */ + Convert_16_swap_16_sign_swap /* 16 swapped -> 16 sign swapped */ +}; -wxSoundStreamPcm::ConverterType *s_convert_in_8 = s_convert_out_8; +#define CONVERT_BPS 0 +#define CONVERT_SIGN 1 +#define CONVERT_SWAP 2 +#define CONVERT_SIGN_SWAP 3 +#define CONVERT_SWAP_SIGN 4 +#define CONVERT_SWAP_SIGN_SWAP 5 -#define CONVERTER 0 -#define CONVERTER_SIGN 1 -#define CONVERTER_SIGN_SWAP 2 -#define CONVERTER_SWAP_SIGN_SWAP 3 -#define CONVERTER_SWAP_SIGN 4 -#define CONVERTER_SWAP 5 -#define CONVERTER_SIGN_STEREO_MONO 6 -#define CONVERTER_SIGN_SWAP_STEREO_MONO 7 -#define CONVERTER_SWAP_SIGN_SWAP_STEREO_MONO 8 -#define CONVERTER_SWAP_SIGN_STEREO_MONO 9 -#define CONVERTER_SWAP_STEREO_MONO 10 -#define CONVERTER_STEREO_MONO 11 +#define CONVERT_BASE_8_8 0 +#define CONVERT_BASE_8_16 6 +#define CONVERT_BASE_16_8 12 +#define CONVERT_BASE_16_16 18 // // TODO: Read() and Write() aren't really safe. If you give it a buffer which @@ -178,14 +155,19 @@ bool wxSoundStreamPcm::SetSoundFormat(const wxSoundFormatBase& format) m_16_to_8 = FALSE; if (pcm_format->GetBPS() != pcm_format2->GetBPS()) { m_16_to_8 = TRUE; - current_table_out = s_convert_out_16_to_8; - current_table_in = s_convert_in_8_to_16; + if (pcm_format2->GetBPS() == 8) { + current_table_out = &s_converters[CONVERT_BASE_16_8]; + current_table_in = &s_converters[CONVERT_BASE_8_16]; + } else { + current_table_out = &s_converters[CONVERT_BASE_8_16]; + current_table_in = &s_converters[CONVERT_BASE_16_8]; + } } else if (pcm_format->GetBPS() == 16) { - current_table_out = s_convert_out_16; - current_table_in = s_convert_in_16; + current_table_out = &s_converters[CONVERT_BASE_16_16]; + current_table_in = &s_converters[CONVERT_BASE_16_16]; } else { - current_table_out = s_convert_out_8; - current_table_in = s_convert_in_8; + current_table_out = &s_converters[CONVERT_BASE_8_8]; + current_table_in = &s_converters[CONVERT_BASE_8_8]; } change_sign = (pcm_format2->Signed() != pcm_format->Signed()); @@ -199,22 +181,25 @@ bool wxSoundStreamPcm::SetSoundFormat(const wxSoundFormatBase& format) if (pcm_format->GetOrder() == OTHER_ORDER && pcm_format2->GetOrder() == OTHER_ORDER && change_sign) - index = CONVERTER_SWAP_SIGN_SWAP; + index = CONVERT_SWAP_SIGN_SWAP; else if (pcm_format->GetOrder() == OTHER_ORDER && pcm_format2->GetOrder() == MY_ORDER && change_sign) - index = CONVERTER_SWAP_SIGN; + index = CONVERT_SWAP_SIGN; else if (pcm_format->GetOrder() == MY_ORDER && pcm_format->GetOrder() == OTHER_ORDER && change_sign) - index = CONVERTER_SIGN_SWAP; + index = CONVERT_SIGN_SWAP; + + else if (change_sign) + index = CONVERT_SIGN; else if (!change_sign && pcm_format->GetOrder() != pcm_format2->GetOrder()) - index = CONVERTER_SWAP; + index = CONVERT_SWAP; else - index = CONVERTER; + index = CONVERT_BPS; m_function_out = current_table_out[index]; m_function_in = current_table_in[index]; diff --git a/utils/wxMMedia2/lib/sndoss.cpp b/utils/wxMMedia2/lib/sndoss.cpp index 875d19b167..cf276aca35 100644 --- a/utils/wxMMedia2/lib/sndoss.cpp +++ b/utils/wxMMedia2/lib/sndoss.cpp @@ -2,7 +2,7 @@ // Name: sndoss.cpp // Purpose: // Date: 08/11/1999 -// Author: Guilhem Lavaux (C) 1999 +// Author: Guilhem Lavaux (C) 1999, 2000 // CVSID: $Id$ // -------------------------------------------------------------------------- #ifdef __GNUG__ diff --git a/utils/wxMMedia2/lib/sndwin.cpp b/utils/wxMMedia2/lib/sndwin.cpp index 0d070fce80..f09231ee0d 100644 --- a/utils/wxMMedia2/lib/sndwin.cpp +++ b/utils/wxMMedia2/lib/sndwin.cpp @@ -2,7 +2,7 @@ // Name: sndwin.cpp // Purpose: // Date: 08/11/1999 -// Author: Guilhem Lavaux (C) 1999 +// Author: Guilhem Lavaux (C) 1999, 2000 // CVSID: $Id$ // -------------------------------------------------------------------------- #include diff --git a/utils/wxMMedia2/lib/vidwin.cpp b/utils/wxMMedia2/lib/vidwin.cpp index a8e83b2dec..5340a0f293 100644 --- a/utils/wxMMedia2/lib/vidwin.cpp +++ b/utils/wxMMedia2/lib/vidwin.cpp @@ -4,7 +4,7 @@ // Author: Guilhem Lavaux // Created: February 1998 // Updated: -// Copyright: (C) 1998, Guilhem Lavaux +// Copyright: (C) 1998, 1999, 2000 Guilhem Lavaux // License: wxWindows license //////////////////////////////////////////////////////////////////////////////// -- 2.47.2