00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "Core/precomp.h"
00020
00021 #include <API/Core/Sound/static_soundprovider.h>
00022 #include <Core/Sound/Be/soundbuffer_static_be.h>
00023 #include <Core/Sound/Be/cardplayback_be.h>
00024 #include <Core/Sound/Generic/cardsoundbuffer_playback.h>
00025 #include <Core/Sound/Generic/cardsoundbuffer_static.h>
00026
00027 CL_CardBuffer_Static_Be::CL_CardBuffer_Static_Be(
00028 CL_StaticSoundProvider *provider)
00029 : CL_CardSoundBuffer_Static(provider)
00030 {
00031 int frame_count = 0;
00032 gs_audio_format format;
00033
00034 soundbuffer = NULL;
00035
00036 switch (provider->get_format())
00037 {
00038 case sf_8bit_signed:
00039 format.format = gs_audio_format::B_GS_U8;
00040 format.channel_count = 1;
00041 frame_count = provider->data_size();
00042 break;
00043 case sf_8bit_signed_stereo:
00044 format.format = gs_audio_format::B_GS_U8;
00045 format.channel_count = 2;
00046 frame_count = provider->data_size() / 2;
00047 break;
00048 case sf_16bit_signed:
00049 format.format = gs_audio_format::B_GS_S16;
00050 format.channel_count = 1;
00051 frame_count = provider->data_size() / 2;
00052 break;
00053 case sf_16bit_signed_stereo:
00054 format.format = gs_audio_format::B_GS_S16;
00055 format.channel_count = 2;
00056 frame_count = provider->data_size() / 4;
00057 break;
00058 }
00059
00060 format.frame_rate = provider->get_frequency();
00061 format.buffer_size = provider->data_size();
00062
00063
00064 provider->lock();
00065
00066 char *data = (char*)provider->get_data();
00067 if (format.format == gs_audio_format::B_GS_U8)
00068 {
00069 unsigned char *new_data = new unsigned char[provider->data_size()];
00070
00071 char *pdata = data;
00072 unsigned char *bpos = new_data;
00073 for (int i=0;i<provider->data_size();i++)
00074 {
00075 *(bpos++) = (unsigned char) ((short)(*pdata++)+128);
00076 }
00077
00078 data = (char*)new_data;
00079 }
00080
00081 soundbuffer = new BSimpleGameSound(data,frame_count,&format);
00082 if (soundbuffer->InitCheck() != B_OK)
00083 {
00084 std::cout << "Something went wrong with sound initialization" << std::endl;
00085 delete soundbuffer;
00086 soundbuffer = NULL;
00087 }
00088
00089 provider->unlock();
00090
00091 if (format.format == gs_audio_format::B_GS_U8)
00092 {
00093 delete data;
00094 }
00095 }
00096
00097 CL_CardBuffer_Static_Be::~CL_CardBuffer_Static_Be()
00098 {
00099 if (soundbuffer)
00100 delete soundbuffer;
00101 }
00102
00103 CL_CardSoundBuffer_Playback *CL_CardBuffer_Static_Be::prepare(
00104 CL_SoundPlayBackDesc * )
00105 {
00106 return new CL_CardPlayback_Be(soundbuffer);
00107 }