Merge branch 'testf1016' of github.com:dumganhar/cocos2d-x into FishGameBada

Conflicts:
	CocosDenshion/bada/CCAudioOut.cpp
	CocosDenshion/bada/CCAudioOut.h
This commit is contained in:
dumganhar 2011-10-17 13:45:16 +08:00
commit 6af6257fa9
16 changed files with 370 additions and 41 deletions

View File

@ -2,18 +2,18 @@
<bada>
<type>2</type>
<sdk>C:\bada\2.0.2</sdk>
<model>WaveHVGA</model>
<model>WaveWVGA</model>
<apiversioncheck>true</apiversioncheck>
<priviligecheck>false</priviligecheck>
<properties>
<data0 key="PT CmdArgs Target-Release" value=""/>
<data1 key="PT CertFile Simulator-Debug" value="${project_loc}\.Simulator-Debug\cert.cer"/>
<data2 key="PT Output Simulator-Debug" value="${project_loc}\.Simulator-Debug"/>
<data3 key="PT CertFile Target-Release" value="${project_loc}\.Target-Release\cert.cer"/>
<data2 key="PT CertFile Target-Release" value="${project_loc}\.Target-Release\cert.cer"/>
<data3 key="PT Output Simulator-Debug" value="${project_loc}\.Simulator-Debug"/>
<data4 key="PT CertFile Target-Debug" value="${project_loc}\.Target-Debug\cert.cer"/>
<data5 key="PT CmdArgs Target-Debug" value=""/>
<data6 key="PT CmdArgs Simulator-Debug" value=""/>
<data7 key="PT Output Target-Release" value="${project_loc}\.Target-Release"/>
<data6 key="PT Output Target-Release" value="${project_loc}\.Target-Release"/>
<data7 key="PT CmdArgs Simulator-Debug" value=""/>
<data8 key="PT Output Target-Debug" value="${project_loc}\.Target-Debug"/>
</properties>
</bada>

View File

@ -0,0 +1,295 @@
#include "CCAudioOut.h"
#include <stdio.h>
using namespace Osp::Base;
using namespace Osp::Base::Collection;
using namespace Osp::Media;
#define MAX_BUFFER_SIZE 2520 // 840 byte
typedef struct wave_tag
{
char ChunkID[5];
unsigned long int ChunkSize;
char Format[5];
char SubChunk1ID[5];
unsigned long int SubChunk1Size;
unsigned short int AudioFormat;
unsigned short int NumChannels;
unsigned long int SampleRate;
unsigned long int ByteRate;
unsigned short int BlockAlign;
unsigned short int BitsPerSample;
char SubChunk2ID[5];
unsigned long int SubChunk2Size;
}WAVE;
static bool GetWaveHeadInfo(FILE*stream, WAVE& outWavHead)
{
char szTmp[100] = {0};
int i = 0;
fread(outWavHead.ChunkID, 4, 1, stream);
outWavHead.ChunkID[4] = (char)0;
fread(&(outWavHead.ChunkSize),4, 1, stream);
fread(outWavHead.Format, 4, 1, stream);
outWavHead.Format[4] = (char)0;
fread(outWavHead.SubChunk1ID, 4, 1, stream);
outWavHead.SubChunk1ID[4] = (char)0;
fread(&(outWavHead.SubChunk1Size), 4, 1, stream);
fread(&(outWavHead.AudioFormat), 2, 1, stream);
fread(&(outWavHead.NumChannels), 2, 1, stream);
fread(&(outWavHead.SampleRate), 4, 1, stream);
fread(&(outWavHead.ByteRate), 4, 1, stream);
fread(&(outWavHead.BlockAlign), 2, 1, stream);
fread(&(outWavHead.BitsPerSample), 2, 1, stream);
fseek(stream, 0, SEEK_SET);
fread(szTmp, 64, 1, stream);
for (i = 0; i <= 60; i++)
{
if (szTmp[i] == 'd' && szTmp[i+1] == 'a' && szTmp[i+2] == 't' && szTmp[i+3] == 'a')
{
break;
}
}
fseek(stream, i, SEEK_SET);
fread(outWavHead.SubChunk2ID, 4, 1, stream);
outWavHead.SubChunk2ID[4] = (char)0;
fread(&(outWavHead.SubChunk2Size), 4, 1, stream);
return true;
}
MyAudioOutEventListener::MyAudioOutEventListener()
{
__totalWriteBufferNum = 0;
__playCount = 0;
__pDataArray = null;
__pAudioOut = null;
__pPcmBuffer = null;
__pcmLen = 0;
}
MyAudioOutEventListener::~MyAudioOutEventListener()
{
AppLog("dealoc MyAudioOutEventListener");
if (__pDataArray != null)
{
__pDataArray->RemoveAll(true);
delete __pDataArray;
__pDataArray = null;
}
if (__pAudioOut != null)
{
__pAudioOut->Stop();
__pAudioOut->Unprepare();
delete __pAudioOut;
__pAudioOut = null;
}
if (__pPcmBuffer != null)
{
delete[] __pPcmBuffer;
__pPcmBuffer = null;
}
}
result MyAudioOutEventListener::Construct(const char* pszFilePath)
{
__pAudioOut = new AudioOut();
__pAudioOut->Construct(*this);
WAVE wavHead;
FILE* fp = fopen(pszFilePath, "rb");
if (fp != NULL)
{
if (GetWaveHeadInfo(fp, wavHead))
{
__pPcmBuffer = new char[wavHead.SubChunk2Size];
__pcmLen = wavHead.SubChunk2Size;
fread(__pPcmBuffer, __pcmLen, 1, fp);
fclose(fp);
}
else
{
fclose(fp);
return E_FAILURE;
}
}
__pDataArray = new ArrayList();
// AudioOut Preparation
AudioSampleType audioSampleType;
AudioChannelType audioChannelType;
int audioSampleRate = 0;
if (wavHead.BitsPerSample == 8)
{
audioSampleType = AUDIO_TYPE_PCM_U8;
}
else if (wavHead.BitsPerSample == 16)
{
audioSampleType = AUDIO_TYPE_PCM_S16_LE;
}
else
{
audioSampleType = AUDIO_TYPE_NONE;
}
if (wavHead.NumChannels == 1)
{
audioChannelType = AUDIO_CHANNEL_TYPE_MONO;
}
else if (wavHead.NumChannels == 2)
{
audioChannelType = AUDIO_CHANNEL_TYPE_STEREO;
}
else
{
audioChannelType = AUDIO_CHANNEL_TYPE_NONE;
}
audioSampleRate = wavHead.SampleRate;
result r = __pAudioOut->Prepare(audioSampleType, audioChannelType, audioSampleRate);
AppLog("The audio out prepare result is %s", GetErrorMessage(r));
AppLogDebug("The audio out prepare result in ApplogDebug message");
ByteBuffer* pTotalData = null;
pTotalData = new ByteBuffer();
pTotalData->Construct(__pcmLen);
pTotalData->SetArray((byte*)__pPcmBuffer, 0, __pcmLen);
pTotalData->Flip();
int totalSize = pTotalData->GetLimit();
int currentPosition = 0;
ByteBuffer* pItem = null;
byte givenByte;
// Binding data buffers into the array
if(totalSize > MAX_BUFFER_SIZE)
{
do
{
pItem = new ByteBuffer();
pItem->Construct(MAX_BUFFER_SIZE);
for(int i = 0; i < MAX_BUFFER_SIZE; i++)
{
// Read it per 1 byte
pTotalData->GetByte(currentPosition++,givenByte);
pItem->SetByte(givenByte);
if(currentPosition == totalSize )
break;
}
__pDataArray->Add(*pItem);
}while(currentPosition < totalSize);
__totalWriteBufferNum = __pDataArray->GetCount();
}
else
{
pItem = new ByteBuffer();
pItem->Construct(totalSize);
for(int i = 0; i < totalSize; i++)
{
// Read it per 1 byte
pTotalData->GetByte(i, givenByte);
pItem->SetByte(givenByte);
}
__pDataArray->Add(*pItem);
__totalWriteBufferNum = __pDataArray->GetCount();
// non-case for now, may the size of test file is bigger than MAX size
}
delete pTotalData;
pTotalData = null;
// Start playing until the end of the array
// __pAudioOut->Start();
return r;
}
void MyAudioOutEventListener::Play()
{
if (__pAudioOut->GetState() == AUDIOOUT_STATE_PLAYING)
{
__pAudioOut->Reset();
}
ByteBuffer* pWriteBuffer = null;
for (int i = 0; i < __totalWriteBufferNum; i++)
{
pWriteBuffer = static_cast<ByteBuffer*>(__pDataArray->GetAt(i));
__pAudioOut->WriteBuffer(*pWriteBuffer);
}
__pAudioOut->Start();
__playCount++;
}
void MyAudioOutEventListener::Stop()
{
__pAudioOut->Stop();
}
void MyAudioOutEventListener::SetVolume(int volume)
{
__pAudioOut->SetVolume(volume);
}
/**
* Notifies when the device has written a buffer completely.
*
* @param[in] src A pointer to the AudioOut instance that fired the event
*/
void MyAudioOutEventListener::OnAudioOutBufferEndReached(Osp::Media::AudioOut& src)
{
result r = E_SUCCESS;
if( __playCount == __totalWriteBufferNum)
{
// The End of array, it's time to finish
//cjh r = src.Unprepare();
//Reset Variable
__playCount = 0;
//cjh __totalWriteBufferNum = 0;
}else
{
//Not yet reached the end of array
//Write the next buffer
__playCount++;
// ByteBuffer* pWriteBuffer = static_cast<ByteBuffer*>(__pDataArray->GetAt(__playCount++));
// r = src.WriteBuffer(*pWriteBuffer);
}
}
/**
* Notifies that the output device is being interrupted by a task of higher priority than AudioOut.
*
* @param[in] src A pointer to the AudioOut instance that fired the event
*/
void MyAudioOutEventListener::OnAudioOutInterrupted(Osp::Media::AudioOut& src)
{
AppLog("OnAudioOutInterrupted");
if (__pAudioOut->GetState() == AUDIOOUT_STATE_PLAYING)
{
__pAudioOut->Stop();
}
}
/**
* Notifies that the interrupted output device has been released.
*
* @param[in] src A pointer to the AudioOut instance that fired the event
*/
void MyAudioOutEventListener::OnAudioOutReleased(Osp::Media::AudioOut& src)
{
AppLog("OnAudioOutReleased");
}

View File

@ -0,0 +1,50 @@
#ifndef __CCAUDIOOUT_H__
#define __CCAUDIOOUT_H__
#include <FBase.h>
#include <FMedia.h>
class MyAudioOutEventListener :
public Osp::Media::IAudioOutEventListener
{
public:
MyAudioOutEventListener();
virtual ~MyAudioOutEventListener();
result Construct(const char* pszFilePath);
void Play();
void Stop();
void SetVolume(int volume);
/**
* Notifies when the device has written a buffer completely.
*
* @param[in] src A pointer to the AudioOut instance that fired the event
*/
virtual void OnAudioOutBufferEndReached(Osp::Media::AudioOut& src);
/**
* Notifies that the output device is being interrupted by a task of higher priority than AudioOut.
*
* @param[in] src A pointer to the AudioOut instance that fired the event
*/
virtual void OnAudioOutInterrupted(Osp::Media::AudioOut& src);
/**
* Notifies that the interrupted output device has been released.
*
* @param[in] src A pointer to the AudioOut instance that fired the event
*/
virtual void OnAudioOutReleased(Osp::Media::AudioOut& src);
private:
int __totalWriteBufferNum;
int __playCount;
Osp::Base::Collection::ArrayList* __pDataArray;
Osp::Media::AudioOut* __pAudioOut;
char* __pPcmBuffer;
int __pcmLen;
};
#endif /* MYAUDIOOUTLISTENER_H_ */

View File

@ -449,8 +449,10 @@ void SimpleAudioEngine::preloadEffect(const char* pszFilePath)
s_List.erase(s_List.begin()->first);
}
openMediaPlayer(pEffectPlayer, pszFilePath, false);
s_List.insert(Effect(nRet, pEffectPlayer));
if (openMediaPlayer(pEffectPlayer, pszFilePath, false))
{
s_List.insert(Effect(nRet, pEffectPlayer));
}
} while (0);
}

View File

@ -2,7 +2,7 @@
<bada>
<type>0</type>
<sdk>C:\bada\2.0.2</sdk>
<model>WaveHVGA</model>
<model>WaveWVGA</model>
<apiversioncheck>true</apiversioncheck>
<priviligecheck>false</priviligecheck>
<properties/>

View File

@ -2,7 +2,7 @@
<bada>
<type>0</type>
<sdk>C:\bada\2.0.2</sdk>
<model>WaveHVGA</model>
<model>WaveWVGA</model>
<apiversioncheck>true</apiversioncheck>
<priviligecheck>false</priviligecheck>
<properties/>

View File

@ -24,7 +24,7 @@
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactExtension="exe" artifactName="HelloWorld" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.sharedLib" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug,org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.sharedLib" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.osp.gnu.target.exe.debug.2113673682" name="Target-Debug" parent="cdt.managedbuild.config.osp.gnu.target.exe.debug">
<configuration artifactExtension="exe" artifactName="HelloWorld" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.sharedLib" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug,org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.sharedLib" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.osp.gnu.target.exe.debug.2113673682" name="Target-Debug" parent="cdt.managedbuild.config.osp.gnu.target.exe.debug" prebuildStep="copy ..\..\..\..\cocos2dx\proj.bada\sdk2.0\.Target-Debug\libcocos2dx.so ..\lib">
<folderInfo id="cdt.managedbuild.config.osp.gnu.target.exe.debug.2113673682." name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.osp.gnu.target.exe.debug.2127488964" name="bada GCC ToolChain" superClass="cdt.managedbuild.toolchain.osp.gnu.target.exe.debug">
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.Cygwin_PE;org.eclipse.cdt.core.GNU_ELF;org.eclipse.cdt.core.ELF" id="cdt.managedbuild.target.osp.gnu.target.platform.exe.debug.1117105675" name="Debug Platform" osList="osp" superClass="cdt.managedbuild.target.osp.gnu.target.platform.exe.debug"/>

View File

@ -1,19 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<bada>
<type>2</type>
<type>0</type>
<sdk>C:\bada\2.0.2</sdk>
<model>WaveHVGA</model>
<model>WaveWVGA</model>
<apiversioncheck>true</apiversioncheck>
<priviligecheck>false</priviligecheck>
<properties>
<data0 key="PT CmdArgs Target-Release" value=""/>
<data1 key="PT CertFile Simulator-Debug" value="${project_loc}\.Simulator-Debug\cert.cer"/>
<data2 key="PT Output Simulator-Debug" value="${project_loc}\.Simulator-Debug"/>
<data3 key="PT CertFile Target-Release" value="${project_loc}\.Target-Release\cert.cer"/>
<data4 key="PT CertFile Target-Debug" value="${project_loc}\.Target-Debug\cert.cer"/>
<data5 key="PT CmdArgs Target-Debug" value=""/>
<data6 key="PT CmdArgs Simulator-Debug" value=""/>
<data7 key="PT Output Target-Release" value="${project_loc}\.Target-Release"/>
<data8 key="PT Output Target-Debug" value="${project_loc}\.Target-Debug"/>
</properties>
<properties/>
</bada>

View File

@ -2,7 +2,7 @@
<bada>
<type>0</type>
<sdk>C:\bada\2.0.2</sdk>
<model>WaveHVGA</model>
<model>WaveWVGA</model>
<apiversioncheck>true</apiversioncheck>
<priviligecheck>false</priviligecheck>
<properties/>

View File

@ -2,7 +2,7 @@
<bada>
<type>0</type>
<sdk>C:\bada\2.0.2</sdk>
<model>WaveHVGA</model>
<model>WaveWVGA</model>
<apiversioncheck>true</apiversioncheck>
<priviligecheck>false</priviligecheck>
<properties/>

View File

@ -2,7 +2,7 @@
<bada>
<type>0</type>
<sdk>C:\bada\2.0.2</sdk>
<model>WaveHVGA</model>
<model>WaveWVGA</model>
<apiversioncheck>true</apiversioncheck>
<priviligecheck>false</priviligecheck>
<properties/>

View File

@ -1,16 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<bada>
<type>3</type>
<type>0</type>
<sdk>C:\bada\2.0.2</sdk>
<model>WaveHVGA</model>
<model>WaveWVGA</model>
<apiversioncheck>true</apiversioncheck>
<priviligecheck>false</priviligecheck>
<properties>
<data0 key="PT CmdArgs Target-Release" value=""/>
<data1 key="PT CertFile Target-Release" value="${project_loc}\.Target-Release\cert.cer"/>
<data2 key="PT CertFile Target-Debug" value="${project_loc}\.Target-Debug\cert.cer"/>
<data3 key="PT CmdArgs Target-Debug" value=""/>
<data4 key="PT Output Target-Release" value="${project_loc}\.Target-Release"/>
<data5 key="PT Output Target-Debug" value="${project_loc}\.Target-Debug"/>
</properties>
<properties/>
</bada>

View File

@ -2,7 +2,7 @@
<bada>
<type>0</type>
<sdk>C:\bada\2.0.2</sdk>
<model>WaveHVGA</model>
<model>WaveWVGA</model>
<apiversioncheck>true</apiversioncheck>
<priviligecheck>false</priviligecheck>
<properties/>

View File

@ -55,6 +55,9 @@
<tool id="cdt.managedbuild.tool.osp.gnu.target.cpp.linker.exe.debug.788505068" name="bada C++ Linker" superClass="cdt.managedbuild.tool.osp.gnu.target.cpp.linker.exe.debug">
<option id="osp.gnu.target.cpp.link.debug.exe.option.userobjs.2114182631" name="Other objects" superClass="osp.gnu.target.cpp.link.debug.exe.option.userobjs" valueType="userObjs">
<listOptionValue builtIn="false" value="&quot;${TARGET_LIB_PATH}/osp_rt0.a&quot;"/>
<listOptionValue builtIn="false" value="../../../../Box2D/proj.bada/sdk2.0/.Target-Debug/libBox2D.a"/>
<listOptionValue builtIn="false" value="../../../../chipmunk/proj.bada/sdk2.0/.Target-Debug/libchipmunk.a"/>
<listOptionValue builtIn="false" value="../../../../CocosDenshion/proj.bada/sdk2.0/.Target-Debug/libCocosDenshion.a"/>
<listOptionValue builtIn="false" value="&quot;${TARGET_LIB_PATH}/FOsp.so&quot;"/>
<listOptionValue builtIn="false" value="&quot;${TARGET_LIB_PATH}/FGraphicsOpengl.so&quot;"/>
<listOptionValue builtIn="false" value="&quot;${TARGET_LIB_PATH}/FGraphicsEgl.so&quot;"/>
@ -63,13 +66,9 @@
<option id="osp.gnu.cpp.link.option.other.689865278" name="Other options (-Xlinker [option])" superClass="osp.gnu.cpp.link.option.other"/>
<option id="osp.gnu.target.cpp.link.debug.exe.option.libs.851145674" name="Libraries (-l)" superClass="osp.gnu.target.cpp.link.debug.exe.option.libs" valueType="libs">
<listOptionValue builtIn="false" value="cocos2dx"/>
<listOptionValue builtIn="false" value="CocosDenshion"/>
<listOptionValue builtIn="false" value="Box2D"/>
<listOptionValue builtIn="false" value="chipmunk"/>
</option>
<option id="osp.gnu.target.cpp.link.debug.exe.option.libs.paths.1425715273" name="Library search path (-L)" superClass="osp.gnu.target.cpp.link.debug.exe.option.libs.paths" valueType="libPaths">
<listOptionValue builtIn="false" value="&quot;${TARGET_LIB_PATH}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${PROJECT_ROOT}/lib/Target-Debug&quot;"/>
<listOptionValue builtIn="false" value="&quot;${PROJECT_ROOT}/lib&quot;"/>
</option>
<inputType id="cdt.managedbuild.tool.osp.gnu.cpp.linker.input.7607535" superClass="cdt.managedbuild.tool.osp.gnu.cpp.linker.input">