Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

soundbuffer_static_clan.cpp

Go to the documentation of this file.
00001 /*
00002         $Id: soundbuffer_static_clan.cpp,v 1.1 2001/03/06 15:09:26 mbn Exp $
00003 
00004         ------------------------------------------------------------------------
00005         ClanLib, the platform independent game SDK.
00006 
00007         This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
00008         version 2. See COPYING for details.
00009 
00010         For a total list of contributers see CREDITS.
00011 
00012         ------------------------------------------------------------------------
00013 
00014         File purpose:
00015                 Sound card impl. that uses the ClanSound library.
00016 
00017 */
00018 
00019 #ifdef WIN32
00020 #pragma warning (disable:4786)
00021 #endif
00022 
00023 #ifdef USE_CLANSOUND
00024 
00025 #include <API/Sound/static_soundprovider.h>
00026 #include "API/Core/System/cl_assert.h"
00027 #include <Sound/Sound/Generic/cardsoundbuffer_playback.h>
00028 #include <Sound/Sound/Generic/cardsoundbuffer_static.h>
00029 #include <Sound/Sound/ClanSound/soundbuffer_static_clan.h>
00030 #include <Sound/Sound/ClanSound/playback_static.h>
00031 #include <Sound/Sound/ClanSound/soundcard_clan.h>
00032 #include "../Generic/soundbuffer_generic.h"
00033 
00034 CL_CardBuffer_Static_ClanSound::CL_CardBuffer_Static_ClanSound(
00035         CL_SoundCard_ClanSound *card,
00036         CL_StaticSoundProvider *provider,
00037         CL_SoundBuffer_Generic *owner)
00038 : CL_CardSoundBuffer_Static(provider)
00039 {
00040         this->owner = owner;
00041         this->card = card;
00042 
00043         provider->lock();
00044         void *input = provider->get_data();
00045         int size = provider->data_size();
00046         switch (provider->get_format())
00047         {
00048         case sf_8bit_signed:
00049                 {
00050                         char *input_c = (char *) input;
00051                         num_samples = size;
00052                         data = new short[num_samples*2];
00053                         for (int i=0; i<num_samples; i++)
00054                         {
00055                                 data[i*2+0] = (((int) input_c[i])/*-128*/)*256;
00056                                 data[i*2+1] = (((int) input_c[i])/*-128*/)*256;
00057                         }
00058                 }
00059                 break;
00060                 
00061         case sf_8bit_signed_stereo:
00062                 {
00063                         char *input_c = (char *) input;
00064                         num_samples = size/2;
00065                         data = new short[num_samples*2];
00066                         for (int i=0; i<num_samples; i++)
00067                         {
00068                                 data[i*2+0] = ((int) input_c[i*2])*256;
00069                                 data[i*2+1] = ((int) input_c[i*2+1])*256;
00070                         }
00071                 }
00072                 break;
00073                 
00074         case sf_16bit_signed:
00075                 {
00076                         short *input_s = (short *) input;
00077                         num_samples = size/2;
00078                         data = new short[num_samples*2];
00079                         for (int i=0; i<num_samples; i++)
00080                         {
00081                                 data[i*2+0] = input_s[i];
00082                                 data[i*2+1] = input_s[i];
00083                         }
00084                 }
00085                 break;
00086                 
00087         case sf_16bit_signed_stereo:
00088                 {
00089                         num_samples = size/4;
00090                         data = new short[num_samples*2];
00091                         memcpy(data, input, size);
00092                 }
00093                 break;
00094                 
00095         default:
00096                 cl_assert(false);
00097         }
00098         
00099         provider->unlock();
00100 }
00101 
00102 CL_CardBuffer_Static_ClanSound::~CL_CardBuffer_Static_ClanSound()
00103 {
00104         delete[] data;
00105 }
00106 
00107 CL_CardSoundBuffer_Playback *CL_CardBuffer_Static_ClanSound::prepare()
00108 {
00109         return new CL_Playback_Static(card, this);
00110 }
00111 
00112 #endif

Generated at Wed Apr 4 19:54:03 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001