00001
00002
00003
00004
00005
00006 #ifdef WIN32
00007 #pragma warning (disable:4786)
00008 #endif
00009
00010 #ifdef USE_CLANSOUND
00011
00012 #include <Sound/Sound/ClanSound/mixer.h>
00013 #include <Sound/Sound/ClanSound/cardplayback_clan.h>
00014
00015 #ifdef USE_I386_ASSEMBLER
00016 #if defined(__BORLANDC__) && !defined(USE_TASM)
00017 #undef
00018 #else
00019 #define MIXER_CLIP_ASM
00020 #endif
00021 #endif
00022
00023 #ifdef MIXER_CLIP_ASM
00024 extern "C"
00025 {
00026 void mixer_clip_asm(
00027 int *mix_buffer2,
00028 short *mix_buffer,
00029 int size);
00030 }
00031 #endif
00032
00033 CL_CSMixer::CL_CSMixer()
00034 {
00035 mix_buffer_size = output.get_frag_size()*2;
00036 mix_buffer = new short[mix_buffer_size];
00037 mix_buffer2 = new int[mix_buffer_size];
00038 }
00039
00040 CL_CSMixer::~CL_CSMixer()
00041 {
00042 delete[] mix_buffer;
00043 delete[] mix_buffer2;
00044 }
00045
00046 void CL_CSMixer::add(CL_CardPlayback_ClanSound *playback)
00047 {
00048 playbacks.push_back(playback);
00049 }
00050
00051 void CL_CSMixer::remove(CL_CardPlayback_ClanSound *playback)
00052 {
00053 playbacks.remove(playback);
00054 }
00055
00056 void CL_CSMixer::wait()
00057 {
00058 output.wait();
00059 }
00060
00061 void CL_CSMixer::mix(CL_Mutex *mutex)
00062 {
00063
00064 memset(mix_buffer2, 0, sizeof(int)*mix_buffer_size);
00065
00066
00067
00068
00069 mutex->enter();
00070 for (
00071 std::list<CL_CardPlayback_ClanSound*>::iterator it = playbacks.begin();
00072 it != playbacks.end();
00073 it++)
00074 {
00075 if ((*it)->is_playing() == false) continue;
00076
00077 (*it)->mix_to(mix_buffer2, mix_buffer_size >> 1);
00078 }
00079 mutex->leave();
00080
00081 #ifdef MIXER_CLIP_ASM
00082 mixer_clip_asm(mix_buffer2, mix_buffer, mix_buffer_size);
00083 #else
00084 for (int k=0; k<mix_buffer_size; k++)
00085 {
00086 mix_buffer2[k] >>= 1;
00087
00088 if (mix_buffer2[k] > 32200) mix_buffer[k] = 32200;
00089 else if (mix_buffer2[k] < -32200) mix_buffer[k] = -32200;
00090 else mix_buffer[k] = mix_buffer2[k];
00091 }
00092 #endif
00093
00094 output.write_fragment(mix_buffer);
00095 }
00096
00097 #endif
00098
00099