Merge remote-tracking branch 'refs/remotes/upstream/master' into luafix-master

This commit is contained in:
YuLei Liao 2012-02-01 22:42:40 +08:00
commit a35faf98c0
20 changed files with 3361 additions and 1968 deletions

View File

@ -47,6 +47,7 @@
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/freetype2"/>
<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
<listOptionValue builtIn="false" value="../../include"/>
<listOptionValue builtIn="false" value="../../../cocos2dx/platform/third_party/qnx"/>
</option>
<inputType id="com.qnx.qcc.inputType.compiler.1849571146" superClass="com.qnx.qcc.inputType.compiler"/>
</tool>
@ -118,6 +119,7 @@
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/freetype2"/>
<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
<listOptionValue builtIn="false" value="../../include"/>
<listOptionValue builtIn="false" value="../../../cocos2dx/platform/third_party/qnx"/>
</option>
<inputType id="com.qnx.qcc.inputType.compiler.82187465" superClass="com.qnx.qcc.inputType.compiler"/>
</tool>
@ -183,6 +185,7 @@
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/freetype2"/>
<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
<listOptionValue builtIn="false" value="../../include"/>
<listOptionValue builtIn="false" value="../../../cocos2dx/platform/third_party/qnx"/>
</option>
<inputType id="com.qnx.qcc.inputType.compiler.2036659301" superClass="com.qnx.qcc.inputType.compiler"/>
</tool>
@ -251,6 +254,7 @@
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/freetype2"/>
<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
<listOptionValue builtIn="false" value="../../include"/>
<listOptionValue builtIn="false" value="../../../cocos2dx/platform/third_party/qnx"/>
</option>
<inputType id="com.qnx.qcc.inputType.compiler.1381169559" superClass="com.qnx.qcc.inputType.compiler"/>
</tool>
@ -317,6 +321,7 @@
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/freetype2"/>
<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
<listOptionValue builtIn="false" value="../../include"/>
<listOptionValue builtIn="false" value="../../../cocos2dx/platform/third_party/qnx"/>
</option>
<inputType id="com.qnx.qcc.inputType.compiler.1896937509" superClass="com.qnx.qcc.inputType.compiler"/>
</tool>
@ -383,6 +388,7 @@
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/freetype2"/>
<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
<listOptionValue builtIn="false" value="../../include"/>
<listOptionValue builtIn="false" value="../../../cocos2dx/platform/third_party/qnx"/>
</option>
<inputType id="com.qnx.qcc.inputType.compiler.746859765" superClass="com.qnx.qcc.inputType.compiler"/>
</tool>
@ -450,6 +456,7 @@
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/freetype2"/>
<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
<listOptionValue builtIn="false" value="../../include"/>
<listOptionValue builtIn="false" value="../../../cocos2dx/platform/third_party/qnx"/>
</option>
<inputType id="com.qnx.qcc.inputType.compiler.1894319763" superClass="com.qnx.qcc.inputType.compiler"/>
</tool>
@ -511,6 +518,8 @@
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="com.qnx.tools.ide.qde.managedbuilder.core.qccScannerInfo"/>
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="refreshScope"/>
<storageModule moduleId="refreshScope" versionNumber="1">
<resource resourceType="PROJECT" workspacePath="/CocosDenshion"/>
</storageModule>
<storageModule moduleId="com.qnx.tools.ide.qde.core.QNXProjectProperties"/>
</cproject>

View File

@ -30,10 +30,8 @@ THE SOFTWARE.
#include <AL/al.h>
#include <AL/alc.h>
#include <AL/alut.h>
#include <mm/renderer.h>
#include <sys/stat.h>
//#include "CCFileUtils.h"
#include <vorbis/vorbisfile.h>
#include "SimpleAudioEngine.h"
@ -56,115 +54,68 @@ namespace CocosDenshion
PAUSED,
} playStatus;
static int s_audioOid;
static float s_volume = 1.0f;
static float s_effectVolume = 1.0f;
static bool s_isBackgroundInitialized = false;
static std::string s_currentBackgroundStr;
static float s_volume = 1.0f;
static float s_effectVolume = 1.0f;
static bool s_isBackgroundInitialized = false;
static bool s_hasMMRError = false;
static playStatus s_playStatus = STOPPED;
static string s_currentBackgroundStr;
static mmr_connection_t *s_mmrConnection = 0;
static mmr_context_t *s_mmrContext = 0;
static strm_dict_t *s_repeatDictionary = 0;
static strm_dict_t *s_volumeDictionary = 0;
ALuint s_backgroundBuffer;
ALuint s_backgroundSource;
static SimpleAudioEngine *s_engine = 0;
static void printALError(int err)
static int checkALError(const char *funcName)
{
switch (err)
int err = alGetError();
if (err != AL_NO_ERROR)
{
case AL_NO_ERROR:
fprintf(stderr, "AL_NO_ERROR");
break;
switch (err)
{
case AL_INVALID_NAME:
fprintf(stderr, "AL_INVALID_NAME in %s\n", funcName);
break;
case AL_INVALID_NAME:
fprintf(stderr, "AL_INVALID_NAME");
break;
case AL_INVALID_ENUM:
fprintf(stderr, "AL_INVALID_ENUM in %s\n", funcName);
break;
case AL_INVALID_ENUM:
fprintf(stderr, "AL_INVALID_ENUM");
break;
case AL_INVALID_VALUE:
fprintf(stderr, "AL_INVALID_VALUE in %s\n", funcName);
break;
case AL_INVALID_VALUE:
fprintf(stderr, "AL_INVALID_VALUE");
break;
case AL_INVALID_OPERATION:
fprintf(stderr, "AL_INVALID_OPERATION in %s\n", funcName);
break;
case AL_INVALID_OPERATION:
fprintf(stderr, "AL_INVALID_OPERATION");
break;
case AL_OUT_OF_MEMORY:
fprintf(stderr, "AL_OUT_OF_MEMORY in %s\n", funcName);
break;
}
}
case AL_OUT_OF_MEMORY:
fprintf(stderr, "AL_OUT_OF_MEMORY");
break;
};
return err;
}
static void mmrerror(mmr_context_t *ctxt, const char *msg)
{
const mmr_error_info_t *err = mmr_error_info( ctxt );
unsigned errcode = (err) ? err->error_code : -1;
const char *name;
fprintf(stderr, "%s: error %d \n", msg, errcode);
s_hasMMRError = true;
}
static void stopBackground(bool bReleaseData)
{
s_playStatus = STOPPED;
if (s_mmrContext)
mmr_stop(s_mmrContext);
alSourceStop(s_backgroundSource);
if (bReleaseData)
{
if (s_mmrContext)
{
mmr_input_detach(s_mmrContext);
mmr_context_destroy(s_mmrContext);
}
if (s_mmrConnection)
mmr_disconnect(s_mmrConnection);
if (s_repeatDictionary)
strm_dict_destroy(s_repeatDictionary);
if (s_volumeDictionary)
strm_dict_destroy(s_volumeDictionary);
s_mmrContext = 0;
s_mmrConnection = 0;
s_repeatDictionary = 0;
s_volumeDictionary = 0;
s_hasMMRError = false;
s_currentBackgroundStr = "";
s_isBackgroundInitialized = false;
alDeleteBuffers(1, &s_backgroundBuffer);
checkALError("stopBackground");
alDeleteSources(1, &s_backgroundSource);
checkALError("stopBackground");
}
}
static void setBackgroundVolume(float volume)
{
if (!s_isBackgroundInitialized)
{
return;
}
char volume_str[128];
// set it up the background volume
strm_dict_t *dictionary = strm_dict_new();
sprintf(volume_str, "%d", (int)(volume * 100) );
s_volumeDictionary = strm_dict_set(dictionary, "volume", volume_str);
if (mmr_output_parameters(s_mmrContext, s_audioOid, s_volumeDictionary) != 0)
{
mmrerror(s_mmrContext, "output parameters");
return;
}
alSourcef(s_backgroundSource, AL_GAIN, volume);
}
SimpleAudioEngine::SimpleAudioEngine()
@ -187,23 +138,22 @@ namespace CocosDenshion
void SimpleAudioEngine::end()
{
checkALError("end");
// clear all the sounds
EffectsMap::const_iterator end = s_effects.end();
for (EffectsMap::iterator it = s_effects.begin(); it != end; it++)
{
alSourceStop(it->second->source);
checkALError("end");
alDeleteBuffers(1, &it->second->buffer);
checkALError("end");
alDeleteSources(1, &it->second->source);
checkALError("end");
delete it->second;
}
s_effects.clear();
if (s_isBackgroundInitialized)
{
s_isBackgroundInitialized = false;
}
// and the background too
stopBackground(true);
}
@ -213,134 +163,170 @@ namespace CocosDenshion
}
//
// background audio (using mmrenderer)
// OGG support
//
static bool isOGGFile(const char *pszFilePath)
{
FILE *file;
OggVorbis_File ogg_file;
int result;
file = fopen(pszFilePath, "rb");
result = ov_test(file, &ogg_file, 0, 0);
ov_clear(&ogg_file);
return (result == 0);
}
static ALuint createBufferFromOGG(const char *pszFilePath)
{
ALuint buffer;
OggVorbis_File ogg_file;
vorbis_info* info;
ALenum format;
int result;
int section;
int err;
unsigned int size = 0;
if (ov_fopen(pszFilePath, &ogg_file) < 0)
{
ov_clear(&ogg_file);
fprintf(stderr, "Could not open OGG file %s\n", pszFilePath);
return -1;
}
info = ov_info(&ogg_file, -1);
if (info->channels == 1)
format = AL_FORMAT_MONO16;
else
format = AL_FORMAT_STEREO16;
// size = #samples * #channels * 2 (for 16 bit)
unsigned int data_size = ov_pcm_total(&ogg_file, -1) * info->channels * 2;
char* data = new char[data_size];
while (size < data_size)
{
result = ov_read(&ogg_file, data + size, data_size - size, 0, 2, 1, &section);
if (result > 0)
{
size += result;
}
else if (result < 0)
{
delete [] data;
fprintf(stderr, "OGG file problem %s\n", pszFilePath);
return -1;
}
else
{
break;
}
}
if (size == 0)
{
delete [] data;
fprintf(stderr, "Unable to read OGG data\n");
return -1;
}
// clear al errors
checkALError("createBufferFromOGG");
// Load audio data into a buffer.
alGenBuffers(1, &buffer);
if (checkALError("createBufferFromOGG") != AL_NO_ERROR)
{
fprintf(stderr, "Couldn't generate a buffer for OGG file\n");
delete [] data;
return buffer;
}
alBufferData(buffer, format, data, data_size, info->rate);
checkALError("createBufferFromOGG");
delete [] data;
ov_clear(&ogg_file);
return buffer;
}
//
// background audio
//
void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath)
{
if (!s_isBackgroundInitialized)
{
const char *mmrname = NULL;
const char *ctxtname = "mmrplayer";
char cwd[PATH_MAX];
mode_t mode = S_IRUSR | S_IXUSR;
if (!s_isBackgroundInitialized || s_currentBackgroundStr != pszFilePath)
{
string path = pszFilePath;
getcwd(cwd, PATH_MAX);
string path = "file://";
path += cwd;
path += "/";
path += pszFilePath;
if (isOGGFile(path.data()))
{
s_backgroundBuffer = createBufferFromOGG(path.data());
}
else
{
s_backgroundBuffer = alutCreateBufferFromFile(path.data());
}
s_mmrConnection = mmr_connect(mmrname);
if (!s_mmrConnection)
{
perror("mmr_connect");
s_hasMMRError = true;
return;
}
checkALError("preloadBackgroundMusic");
s_mmrContext = mmr_context_create(s_mmrConnection, ctxtname, 0, mode);
if (!s_mmrContext)
{
perror(ctxtname);
s_hasMMRError = true;
return;
}
if (s_backgroundBuffer == AL_NONE)
{
fprintf(stderr, "Error loading file: '%s'\n", path.data());
alDeleteBuffers(1, &s_backgroundBuffer);
return;
}
if ((s_audioOid = mmr_output_attach(s_mmrContext, "audio:default", "audio")) < 0)
{
mmrerror(s_mmrContext, "audio:default");
return;
}
alGenSources(1, &s_backgroundSource);
checkALError("preloadBackgroundMusic");
if (mmr_input_attach(s_mmrContext, path.data(), "autolist") < 0)
{
fprintf(stderr, "unable to load %s\n", path.data());
mmrerror(s_mmrContext, path.data());
return;
}
alSourcei(s_backgroundSource, AL_BUFFER, s_backgroundBuffer);
checkALError("preloadBackgroundMusic");
s_currentBackgroundStr = pszFilePath;
s_isBackgroundInitialized = true;
setBackgroundVolume(s_volume);
}
s_currentBackgroundStr = pszFilePath;
}
s_currentBackgroundStr = pszFilePath;
s_isBackgroundInitialized = true;
}
void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath, bool bLoop)
{
if (0 != strcmp(s_currentBackgroundStr.c_str(), pszFilePath))
{
stopBackgroundMusic(true);
}
else
{
if (s_playStatus == PAUSED)
resumeBackgroundMusic();
else
rewindBackgroundMusic();
}
if (!s_isBackgroundInitialized)
preloadBackgroundMusic(pszFilePath);
if (bLoop)
{
// set it up to loop
strm_dict_t *dictionary = strm_dict_new();
s_repeatDictionary = strm_dict_set(dictionary, "repeat", "all");
if (mmr_input_parameters(s_mmrContext, s_repeatDictionary) != 0)
{
mmrerror(s_mmrContext, "input parameters (loop)");
return;
}
}
if (s_hasMMRError || !s_mmrContext)
return;
if (mmr_play(s_mmrContext) < 0)
{
mmrerror(s_mmrContext, "mmr_play");
s_hasMMRError = true;
}
if (!s_hasMMRError)
s_playStatus = PLAYING;
alSourcei(s_backgroundSource, AL_LOOPING, bLoop ? AL_TRUE : AL_FALSE);
alSourcePlay(s_backgroundSource);
checkALError("playBackgroundMusic");
}
void SimpleAudioEngine::stopBackgroundMusic(bool bReleaseData)
{
// if we were paused then we need to resume first so that we can play
if (s_playStatus == PAUSED)
resumeBackgroundMusic();
stopBackground(bReleaseData);
}
void SimpleAudioEngine::pauseBackgroundMusic()
{
if (s_mmrContext && mmr_speed_set(s_mmrContext, 0) < 0)
{
mmrerror(s_mmrContext, "pause");
}
s_playStatus = PAUSED;
alSourcePause(s_backgroundSource);
checkALError("pauseBackgroundMusic");
}
void SimpleAudioEngine::resumeBackgroundMusic()
{
if (s_mmrContext && mmr_speed_set(s_mmrContext, 1000) < 0)
{
mmrerror(s_mmrContext, "resume");
}
s_playStatus = PLAYING;
alSourcePlay(s_backgroundSource);
checkALError("resumeBackgroundMusic");
}
void SimpleAudioEngine::rewindBackgroundMusic()
{
if (s_mmrContext && mmr_seek(s_mmrContext, "1:0") < 0)
{
mmrerror(s_mmrContext, "rewind");
}
alSourceRewind(s_backgroundSource);
checkALError("rewindBackgroundMusic");
}
bool SimpleAudioEngine::willPlayBackgroundMusic()
@ -350,7 +336,10 @@ namespace CocosDenshion
bool SimpleAudioEngine::isBackgroundMusicPlaying()
{
return (s_playStatus == PLAYING) && s_isBackgroundInitialized;
ALint play_status;
alGetSourcei(s_backgroundSource, AL_SOURCE_STATE, &play_status);
return (play_status == AL_PLAYING);
}
float SimpleAudioEngine::getBackgroundMusicVolume()
@ -407,9 +396,11 @@ namespace CocosDenshion
}
}
checkALError("playEffect");
iter->second->isLooped = bLoop;
alSourcei(iter->second->source, AL_LOOPING, iter->second->isLooped ? AL_TRUE : AL_FALSE);
alSourcePlay(iter->second->source);
checkALError("playEffect");
return iter->second->source;
}
@ -417,6 +408,7 @@ namespace CocosDenshion
void SimpleAudioEngine::stopEffect(unsigned int nSoundId)
{
alSourceStop(nSoundId);
checkALError("stopEffect");
}
void SimpleAudioEngine::preloadEffect(const char* pszFilePath)
@ -429,10 +421,19 @@ namespace CocosDenshion
ALuint buffer;
ALuint source;
soundData *data = new soundData;
string path = pszFilePath;
string path = pszFilePath;
checkALError("preloadEffect");
buffer = alutCreateBufferFromFile(path.data());
if (isOGGFile(path.data()))
{
buffer = createBufferFromOGG(path.data());
}
else
{
buffer = alutCreateBufferFromFile(path.data());
checkALError("preloadEffect");
}
if (buffer == AL_NONE)
{
@ -442,7 +443,15 @@ namespace CocosDenshion
}
alGenSources(1, &source);
if (checkALError("preloadEffect") != AL_NO_ERROR)
{
alDeleteBuffers(1, &buffer);
return;
}
alSourcei(source, AL_BUFFER, buffer);
checkALError("preloadEffect");
data->isLooped = false;
data->buffer = buffer;
@ -458,14 +467,17 @@ namespace CocosDenshion
if (iter != s_effects.end())
{
alSourceStop(iter->second->source);
alDeleteSources(1, &iter->second->source);
alDeleteBuffers(1, &iter->second->buffer);
delete iter->second;
checkALError("unloadEffect");
int err = alGetError();
if (err != AL_NO_ERROR)
printALError(err);
alSourceStop(iter->second->source);
checkALError("unloadEffect");
alDeleteSources(1, &iter->second->source);
checkALError("unloadEffect");
alDeleteBuffers(1, &iter->second->buffer);
checkALError("unloadEffect");
delete iter->second;
s_effects.erase(iter);
}
@ -474,6 +486,7 @@ namespace CocosDenshion
void SimpleAudioEngine::pauseEffect(unsigned int nSoundId)
{
alSourcePause(nSoundId);
checkALError("pauseEffect");
}
void SimpleAudioEngine::pauseAllEffects()
@ -483,15 +496,14 @@ namespace CocosDenshion
if (iter != s_effects.end())
{
alSourcePause(iter->second->source);
int err = alGetError();
if (err != AL_NO_ERROR)
printALError(err);
checkALError("pauseAllEffects");
}
}
void SimpleAudioEngine::resumeEffect(unsigned int nSoundId)
{
alSourcePlay(nSoundId);
checkALError("resumeEffect");
}
void SimpleAudioEngine::resumeAllEffects()
@ -500,10 +512,9 @@ namespace CocosDenshion
if (iter != s_effects.end())
{
checkALError("resumeAllEffects");
alSourcePlay(iter->second->source);
int err = alGetError();
if (err != AL_NO_ERROR)
printALError(err);
checkALError("resumeAllEffects");
}
}
@ -513,10 +524,9 @@ namespace CocosDenshion
if (iter != s_effects.end())
{
checkALError("stopAllEffects");
alSourceStop(iter->second->source);
int err = alGetError();
if (err != AL_NO_ERROR)
printALError(err);
checkALError("stopAllEffects");
}
}

View File

@ -74,8 +74,8 @@ public class Cocos2dxBitmap{
// Draw string
FontMetricsInt fm = paint.getFontMetricsInt();
int x = 0;
int y = height == 0 ?(-fm.ascent):
(-fm.ascent + (height - textProperty.totalHeight)/2);
int y = height == 0 ?(-fm.top):
(-fm.top + (height - textProperty.totalHeight)/2);
String[] lines = textProperty.lines;
for (String line : lines){
x = computeX(paint, line, textProperty.maxWidth, alignment);
@ -132,7 +132,7 @@ public class Cocos2dxBitmap{
private static TextProperty computeTextProperty(String content, Paint paint,
int maxWidth, int maxHeight){
FontMetricsInt fm = paint.getFontMetricsInt();
int h = (int)Math.ceil(fm.descent - fm.ascent);
int h = (int)Math.ceil(fm.bottom - fm.top);
int maxContentWidth = 0;
String[] lines = splitString(content, maxHeight, maxWidth, paint);
@ -165,7 +165,7 @@ public class Cocos2dxBitmap{
String[] lines = content.split("\\n");
String[] ret = null;
FontMetricsInt fm = paint.getFontMetricsInt();
int heightPerLine = (int)Math.ceil(fm.descent - fm.ascent);
int heightPerLine = (int)Math.ceil(fm.bottom - fm.top);
int maxLines = maxHeight / heightPerLine;
if (maxWidth != 0){
@ -236,7 +236,7 @@ public class Cocos2dxBitmap{
if (tempWidth >= width){
int lastIndexOfSpace = content.substring(0, i).lastIndexOf(" ");
if (lastIndexOfSpace != -1){
if (lastIndexOfSpace != -1 && lastIndexOfSpace > start){
/**
* Should wrap the word
*/

View File

@ -74,8 +74,8 @@ public class Cocos2dxBitmap{
// Draw string
FontMetricsInt fm = paint.getFontMetricsInt();
int x = 0;
int y = height == 0 ?(-fm.ascent):
(-fm.ascent + (height - textProperty.totalHeight)/2);
int y = height == 0 ?(-fm.top):
(-fm.top + (height - textProperty.totalHeight)/2);
String[] lines = textProperty.lines;
for (String line : lines){
x = computeX(paint, line, textProperty.maxWidth, alignment);
@ -132,7 +132,7 @@ public class Cocos2dxBitmap{
private static TextProperty computeTextProperty(String content, Paint paint,
int maxWidth, int maxHeight){
FontMetricsInt fm = paint.getFontMetricsInt();
int h = (int)Math.ceil(fm.descent - fm.ascent);
int h = (int)Math.ceil(fm.bottom - fm.top);
int maxContentWidth = 0;
String[] lines = splitString(content, maxHeight, maxWidth, paint);
@ -165,7 +165,7 @@ public class Cocos2dxBitmap{
String[] lines = content.split("\\n");
String[] ret = null;
FontMetricsInt fm = paint.getFontMetricsInt();
int heightPerLine = (int)Math.ceil(fm.descent - fm.ascent);
int heightPerLine = (int)Math.ceil(fm.bottom - fm.top);
int maxLines = maxHeight / heightPerLine;
if (maxWidth != 0){
@ -236,7 +236,7 @@ public class Cocos2dxBitmap{
if (tempWidth >= width){
int lastIndexOfSpace = content.substring(0, i).lastIndexOf(" ");
if (lastIndexOfSpace != -1){
if (lastIndexOfSpace != -1 && lastIndexOfSpace > start){
/**
* Should wrap the word
*/

View File

@ -34,10 +34,12 @@ THE SOFTWARE.
namespace cocos2d
{
CCAccelerometer* CCAccelerometer::m_spCCAccelerometer = NULL;
int CCAccelerometer::m_initialOrientationAngle = 0;
CCAccelerometer::CCAccelerometer()
{
m_pAccelDelegate = NULL;
m_initialOrientationAngle = atoi(getenv("ORIENTATION"));
accelerometer_set_update_frequency(FREQ_40_HZ);
}
@ -64,12 +66,33 @@ namespace cocos2d
{
if ( m_pAccelDelegate != NULL)
{
int angle = atoi(getenv("ORIENTATION"));
double x, y, z;
accelerometer_read_forces(&x, &y, &z);
m_accelerationValue.x = x;
m_accelerationValue.y = y;
if (m_initialOrientationAngle == 270)
{
m_accelerationValue.x = y;
m_accelerationValue.y = -x;
}
else if (m_initialOrientationAngle == 90)
{
m_accelerationValue.x = -y;
m_accelerationValue.y = x;
}
else if (m_initialOrientationAngle == 0)
{
m_accelerationValue.x = x;
m_accelerationValue.y = y;
}
else if (m_initialOrientationAngle == 180)
{
m_accelerationValue.x = -x;
m_accelerationValue.y = -y;
}
m_accelerationValue.z = z;
m_accelerationValue.timestamp = (double)timeStamp;

View File

@ -47,6 +47,7 @@ private:
static CCAccelerometer* m_spCCAccelerometer;
CCAccelerometerDelegate* m_pAccelDelegate;
CCAcceleration m_accelerationValue;
static int m_initialOrientationAngle;
};
}//namespace cocos2d

View File

@ -6,6 +6,7 @@
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <bps/locale.h>
#define LOGD(...) fprintf(stderr, __VA_ARGS__)
@ -102,7 +103,44 @@ CCApplication& CCApplication::sharedApplication()
ccLanguageType CCApplication::getCurrentLanguage()
{
return kLanguageEnglish;
ccLanguageType ret_language = kLanguageEnglish;
char *language, *country;
locale_get(&language, &country);
if (strcmp(language, "en") == 0)
{
ret_language = kLanguageEnglish;
}
else if (strcmp(language, "fr") == 0)
{
ret_language = kLanguageFrench;
}
else if (strcmp(language, "de") == 0)
{
ret_language = kLanguageGerman;
}
else if (strcmp(language, "it") == 0)
{
ret_language = kLanguageItalian;
}
else if (strcmp(language, "es") == 0)
{
ret_language = kLanguageSpanish;
}
else if (strcmp(language, "ch") == 0)
{
ret_language = kLanguageChinese;
}
else if (strcmp(language, "ru") == 0)
{
ret_language = kLanguageRussian;
}
free(language);
free(country);
return ret_language;
}
NS_CC_END;

View File

@ -37,6 +37,7 @@ THE SOFTWARE.
#include "CCSet.h"
#include "CCDirector.h"
#include "CCApplication.h"
#include "ccMacros.h"
#include "CCTouch.h"
#include "CCTouchDispatcher.h"
@ -84,7 +85,8 @@ static CCEGLView* s_pInstance = NULL;
CCEGLView::CCEGLView()
: m_pDelegate(NULL),
m_fScreenScaleFactor(1.0),
m_bNotHVGA(false)
m_bNotHVGA(false),
m_isWindowActive(false)
{
s_pInstance = this;
m_eglDisplay = EGL_NO_DISPLAY;
@ -549,7 +551,6 @@ bool CCEGLView::createNativeWindow(const EGLConfig &config)
int usage = SCREEN_USAGE_OPENGL_ES1;
int transp = SCREEN_TRANSPARENCY_NONE;
int pos[2] = { 0, 0 };
int screen_size[2];
int nbuffers = 2;
EGLint interval = 1;
int format;
@ -608,62 +609,70 @@ bool CCEGLView::createNativeWindow(const EGLConfig &config)
return false;
}
err = screen_get_window_property_iv(m_screenWindow, SCREEN_PROPERTY_SIZE, screen_size);
if (err)
screen_display_t screen_disp;
int rc = screen_get_window_property_pv(m_screenWindow, SCREEN_PROPERTY_DISPLAY, (void **)&screen_disp);
if (rc)
{
perror("screen_get_window_property_iv(SCREEN_PROPERTY_SIZE)");
fprintf(stderr, "screen_get_window_property_pv(SCREEN_PROPERTY_DISPLAY)");
return false;
}
switch (CCDirector::sharedDirector()->getDeviceOrientation())
{
case CCDeviceOrientationPortrait:
case CCDeviceOrientationPortraitUpsideDown:
orientation = PORTRAIT;
break;
case CCDeviceOrientationLandscapeLeft:
case CCDeviceOrientationLandscapeRight:
orientation = LANDSCAPE;
break;
}
// handle the orientation
// if (orientation != AUTO)
screen_display_mode_t screen_mode;
rc = screen_get_display_property_pv(screen_disp, SCREEN_PROPERTY_MODE, (void**)&screen_mode);
if (rc)
{
int angle = atoi(getenv("ORIENTATION"));
int buffer_size[2] = { screen_size[0], screen_size[1] };
bool flip = false;
fprintf(stderr, "screen_get_display_property_pv(SCREEN_PROPERTY_MODE)");
return false;
}
if (((orientation == LANDSCAPE) && (angle == 0 || angle == 180) && (buffer_size[0] < buffer_size[1])) ||
((orientation == LANDSCAPE) && (angle == 90 || angle == 270) && (buffer_size[0] > buffer_size[1])) ||
((orientation == PORTRAIT) && (angle == 90 || angle == 270) && (buffer_size[0] > buffer_size[1])) ||
((orientation == PORTRAIT) && (angle == 0 || angle == 180) && (buffer_size[0] < buffer_size[1])))
int size[2];
rc = screen_get_window_property_iv(m_screenWindow, SCREEN_PROPERTY_BUFFER_SIZE, size);
if (rc)
{
fprintf(stderr, "screen_get_window_property_iv(SCREEN_PROPERTY_BUFFER_SIZE)");
return false;
}
int angle = atoi(getenv("ORIENTATION"));
int buffer_size[2] = { size[0], size[1] };
if ((angle == 0) || (angle == 180))
{
if (((screen_mode.width > screen_mode.height) && (size[0] < size[1])) ||
((screen_mode.width < screen_mode.height) && (size[0] > size[1])))
{
buffer_size[0] = screen_size[1];
buffer_size[1] = screen_size[0];
flip = true;
buffer_size[1] = size[0];
buffer_size[0] = size[1];
}
if (flip)
}
else if ((angle == 90) || (angle == 270))
{
if (((screen_mode.width > screen_mode.height) && (size[0] > size[1])) ||
((screen_mode.width < screen_mode.height && size[0] < size[1])))
{
err = screen_set_window_property_iv(m_screenWindow, SCREEN_PROPERTY_ROTATION, &angle);
if (err)
{
perror("screen_set_window_property_iv(SCREEN_PROPERTY_ROTATION)");
return false;
}
err = screen_set_window_property_iv(m_screenWindow, SCREEN_PROPERTY_BUFFER_SIZE, buffer_size);
if (err)
{
perror("screen_set_window_property_iv(SCREEN_PROPERTY_BUFFER_SIZE)");
return false;
}
buffer_size[1] = size[0];
buffer_size[0] = size[1];
}
}
else
{
fprintf(stderr, "Navigator returned an unexpected orientation angle of %d.\n", angle);
return false;
}
rc = screen_set_window_property_iv(m_screenWindow, SCREEN_PROPERTY_BUFFER_SIZE, buffer_size);
if (rc)
{
fprintf(stderr, "screen_set_window_property_iv(SCREEN_PROPERTY_BUFFER_SIZE)");
return false;
}
rc = screen_set_window_property_iv(m_screenWindow, SCREEN_PROPERTY_ROTATION, &angle);
if (rc)
{
fprintf(stderr, "screen_set_window_property_iv(SCREEN_PROPERTY_ROTATION)");
return false;
}
err = screen_create_window_buffers(m_screenWindow, nbuffers);
if (err)
@ -818,25 +827,91 @@ bool CCEGLView::HandleEvents()
int domain = 0;
char buf[4] = {0};
#ifdef BPS_EVENTS
for (;;)
{
rc = bps_get_event(&event, 1);
assert(rc == BPS_SUCCESS);
#ifdef BPS_EVENTS
// break if no more events
if (event == NULL)
break;
#else
if (event != NULL)
{
#endif
domain = bps_event_get_domain(event);
if (domain == screen_get_domain())
if (domain == navigator_get_domain())
{
switch (bps_event_get_code(event))
{
case NAVIGATOR_SWIPE_DOWN:
CCKeypadDispatcher::sharedDispatcher()->dispatchKeypadMSG(kTypeMenuClicked);
break;
case NAVIGATOR_EXIT:
// exit the application
// release();
break;
case NAVIGATOR_WINDOW_INACTIVE:
if(m_isWindowActive)
{
CCApplication::sharedApplication().applicationDidEnterBackground();
m_isWindowActive = false;
}
break;
case NAVIGATOR_WINDOW_ACTIVE:
if(!m_isWindowActive)
{
CCApplication::sharedApplication().applicationWillEnterForeground();
m_isWindowActive = true;
}
break;
case NAVIGATOR_WINDOW_STATE:
{
switch(navigator_event_get_window_state(event))
{
case NAVIGATOR_WINDOW_FULLSCREEN:
if(!m_isWindowActive)
{
CCApplication::sharedApplication().applicationWillEnterForeground();
m_isWindowActive = true;
}
break;
case NAVIGATOR_WINDOW_THUMBNAIL:
if(m_isWindowActive)
{
CCApplication::sharedApplication().applicationDidEnterBackground();
m_isWindowActive = false;
}
break;
}
break;
}
default:
break;
}
}
}
#ifndef BPS_EVENTS
// for now handle screen events separately from BPS events
if (screen_get_event(m_screenContext, m_screenEvent, 0) < 0)
{
// we have an error condition in the screen event
break;
}
else
{
#else
else if (domain == screen_get_domain())
{
m_screenEvent = screen_event_get_event(event);
#else
while (!screen_get_event(m_screenContext, m_screenEvent, 0))
{
#endif
rc = screen_get_event_property_iv(m_screenEvent, SCREEN_PROPERTY_TYPE, &val);
if (rc || val == SCREEN_EVENT_NONE)
@ -859,7 +934,7 @@ bool CCEGLView::HandleEvents()
{
CCSet set;
touch->SetTouchInfo(0, ((float)(mtouch_event.x) - m_rcViewPort.origin.x) / m_fScreenScaleFactor,
((float)(mtouch_event.y) - m_rcViewPort.origin.y) / m_fScreenScaleFactor);
((float)(mtouch_event.y) - m_rcViewPort.origin.y) / m_fScreenScaleFactor);
set.addObject(touch);
m_pDelegate->touchesEnded(&set, NULL);
@ -891,7 +966,7 @@ bool CCEGLView::HandleEvents()
touch = new CCTouch;
touch->SetTouchInfo(0, ((float)(mtouch_event.x) - m_rcViewPort.origin.x) / m_fScreenScaleFactor,
((float)(mtouch_event.y) - m_rcViewPort.origin.y) / m_fScreenScaleFactor);
((float)(mtouch_event.y) - m_rcViewPort.origin.y) / m_fScreenScaleFactor);
s_pTouches[touch_id] = touch;
CCSet set;
@ -912,11 +987,8 @@ bool CCEGLView::HandleEvents()
{
CCSet set;
touch->SetTouchInfo(0, ((float)(mtouch_event.x) - m_rcViewPort.origin.x) / m_fScreenScaleFactor,
((float)(mtouch_event.y) - m_rcViewPort.origin.y) / m_fScreenScaleFactor);
((float)(mtouch_event.y) - m_rcViewPort.origin.y) / m_fScreenScaleFactor);
set.addObject(touch);
// we can likely optimize this call and move it outside of the while loop and just call at the end if we
// have a bunch of move touches all in a row
m_pDelegate->touchesMoved(&set, NULL);
}
}
@ -928,15 +1000,16 @@ bool CCEGLView::HandleEvents()
int buttons;
int pair[2];
static bool mouse_pressed = false;
//This is a mouse move event, it is applicable to a device with a usb mouse or simulator
screen_get_event_property_iv(m_screenEvent, SCREEN_PROPERTY_BUTTONS,
&buttons);
screen_get_event_property_iv(m_screenEvent, SCREEN_PROPERTY_SOURCE_POSITION,
pair);
if (buttons == SCREEN_LEFT_MOUSE_BUTTON) {
if (mouse_pressed) {
//Left mouse button was released, add a cube
// this is a mouse move event, it is applicable to a device with a usb mouse or simulator
screen_get_event_property_iv(m_screenEvent, SCREEN_PROPERTY_BUTTONS, &buttons);
screen_get_event_property_iv(m_screenEvent, SCREEN_PROPERTY_SOURCE_POSITION, pair);
if (buttons & SCREEN_LEFT_MOUSE_BUTTON)
{
if (mouse_pressed)
{
// Left mouse button was released
if (m_pDelegate && touch_id < MAX_TOUCHES)
{
CCTouch* touch = s_pTouches[touch_id];
@ -944,18 +1017,15 @@ bool CCEGLView::HandleEvents()
{
CCSet set;
touch->SetTouchInfo(0, ((float)(pair[0]) - m_rcViewPort.origin.x) / m_fScreenScaleFactor,
((float)(pair[1]) - m_rcViewPort.origin.y) / m_fScreenScaleFactor);
((float)(pair[1]) - m_rcViewPort.origin.y) / m_fScreenScaleFactor);
set.addObject(touch);
// we can likely optimize this call and move it outside of the while loop and just call at the end if we
// have a bunch of move touches all in a row
m_pDelegate->touchesMoved(&set, NULL);
}
}
}
else
{
//Left mouse button is pressed
// Left mouse button is pressed
mouse_pressed = true;
if (m_pDelegate && touch_id < MAX_TOUCHES)
{
@ -964,7 +1034,7 @@ bool CCEGLView::HandleEvents()
touch = new CCTouch;
touch->SetTouchInfo(0, ((float)(pair[0]) - m_rcViewPort.origin.x) / m_fScreenScaleFactor,
((float)(pair[1]) - m_rcViewPort.origin.y) / m_fScreenScaleFactor);
((float)(pair[1]) - m_rcViewPort.origin.y) / m_fScreenScaleFactor);
s_pTouches[touch_id] = touch;
CCSet set;
@ -973,7 +1043,8 @@ bool CCEGLView::HandleEvents()
}
}
}
else {
else
{
if (mouse_pressed)
{
if (m_pDelegate && touch_id < MAX_TOUCHES)
@ -985,7 +1056,7 @@ bool CCEGLView::HandleEvents()
{
CCSet set;
touch->SetTouchInfo(0, ((float)(pair[0]) - m_rcViewPort.origin.x) / m_fScreenScaleFactor,
((float)(pair[1]) - m_rcViewPort.origin.y) / m_fScreenScaleFactor);
((float)(pair[1]) - m_rcViewPort.origin.y) / m_fScreenScaleFactor);
set.addObject(touch);
m_pDelegate->touchesEnded(&set, NULL);
@ -1046,25 +1117,7 @@ bool CCEGLView::HandleEvents()
break;
}
}
#ifdef BPS_EVENTS
else if (domain == navigator_get_domain())
{
switch (bps_event_get_code(event))
{
case NAVIGATOR_SWIPE_DOWN:
CCKeypadDispatcher::sharedDispatcher()->dispatchKeypadMSG(kTypeMenuClicked);
break;
case NAVIGATOR_EXIT:
fprintf(stderr, "navigator exit\n");
// exit the application
release();
break;
}
}
}
#endif
return true;
}
@ -1179,8 +1232,11 @@ void CCEGLView::showKeyboard()
virtualkeyboard_get_height(&height);
CCRect rect_begin(0, 0 - height, m_sSizeInPixel.width, height);
CCRect rect_end(0, 0, m_sSizeInPixel.width, height);
float factor = m_fScreenScaleFactor / CC_CONTENT_SCALE_FACTOR();
height = (float)height / factor;
CCRect rect_begin(0, 0 - height, m_sSizeInPixel.width / factor, height);
CCRect rect_end(0, 0, m_sSizeInPixel.width / factor, height);
CCIMEKeyboardNotificationInfo info;
info.begin = rect_begin;

View File

@ -105,6 +105,8 @@ private:
EGLTouchDelegate *m_pDelegate;
float m_fScreenScaleFactor;
bool m_isWindowActive;
static bool m_initializedFunctions;
static const GLubyte *m_extensions;

View File

@ -58,13 +58,15 @@ const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
// It works like this: if the relative path already includes the resource path
// it will be returned as it is
const std::string relPath = pszRelativePath;
if (relPath.find(s_strResourcePath) == std::string::npos) {
if (relPath.find(s_strResourcePath) == std::string::npos)
{
CCString *pRet = new CCString();
pRet->autorelease();
pRet->m_sString = s_strResourcePath + pszRelativePath;
return pRet->m_sString.c_str();
}
else {
else
{
return pszRelativePath;
}
}
@ -86,7 +88,8 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz
std::string full_path = pszFileName;
// If it is not inside resource path
if (full_path.find(s_strResourcePath) == std::string::npos) {
if (full_path.find(s_strResourcePath) == std::string::npos)
{
full_path = s_strResourcePath + pszFileName;
}

View File

@ -0,0 +1 @@
40ad00822b71014e6d4e665db449339f13fa02bb

View File

@ -0,0 +1 @@
d0b923319368523099b0a89ebd23e18c2faa1e74

View File

@ -0,0 +1,210 @@
/********************************************************************
* *
* THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 *
* by the Xiph.Org Foundation http://www.xiph.org/ *
* *
********************************************************************
function: toplevel libogg include
last mod: $Id: ogg.h 18044 2011-08-01 17:55:20Z gmaxwell $
********************************************************************/
#ifndef _OGG_H
#define _OGG_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stddef.h>
#include <ogg/os_types.h>
typedef struct {
void *iov_base;
size_t iov_len;
} ogg_iovec_t;
typedef struct {
long endbyte;
int endbit;
unsigned char *buffer;
unsigned char *ptr;
long storage;
} oggpack_buffer;
/* ogg_page is used to encapsulate the data in one Ogg bitstream page *****/
typedef struct {
unsigned char *header;
long header_len;
unsigned char *body;
long body_len;
} ogg_page;
/* ogg_stream_state contains the current encode/decode state of a logical
Ogg bitstream **********************************************************/
typedef struct {
unsigned char *body_data; /* bytes from packet bodies */
long body_storage; /* storage elements allocated */
long body_fill; /* elements stored; fill mark */
long body_returned; /* elements of fill returned */
int *lacing_vals; /* The values that will go to the segment table */
ogg_int64_t *granule_vals; /* granulepos values for headers. Not compact
this way, but it is simple coupled to the
lacing fifo */
long lacing_storage;
long lacing_fill;
long lacing_packet;
long lacing_returned;
unsigned char header[282]; /* working space for header encode */
int header_fill;
int e_o_s; /* set when we have buffered the last packet in the
logical bitstream */
int b_o_s; /* set after we've written the initial page
of a logical bitstream */
long serialno;
long pageno;
ogg_int64_t packetno; /* sequence number for decode; the framing
knows where there's a hole in the data,
but we need coupling so that the codec
(which is in a separate abstraction
layer) also knows about the gap */
ogg_int64_t granulepos;
} ogg_stream_state;
/* ogg_packet is used to encapsulate the data and metadata belonging
to a single raw Ogg/Vorbis packet *************************************/
typedef struct {
unsigned char *packet;
long bytes;
long b_o_s;
long e_o_s;
ogg_int64_t granulepos;
ogg_int64_t packetno; /* sequence number for decode; the framing
knows where there's a hole in the data,
but we need coupling so that the codec
(which is in a separate abstraction
layer) also knows about the gap */
} ogg_packet;
typedef struct {
unsigned char *data;
int storage;
int fill;
int returned;
int unsynced;
int headerbytes;
int bodybytes;
} ogg_sync_state;
/* Ogg BITSTREAM PRIMITIVES: bitstream ************************/
extern void oggpack_writeinit(oggpack_buffer *b);
extern int oggpack_writecheck(oggpack_buffer *b);
extern void oggpack_writetrunc(oggpack_buffer *b,long bits);
extern void oggpack_writealign(oggpack_buffer *b);
extern void oggpack_writecopy(oggpack_buffer *b,void *source,long bits);
extern void oggpack_reset(oggpack_buffer *b);
extern void oggpack_writeclear(oggpack_buffer *b);
extern void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
extern void oggpack_write(oggpack_buffer *b,unsigned long value,int bits);
extern long oggpack_look(oggpack_buffer *b,int bits);
extern long oggpack_look1(oggpack_buffer *b);
extern void oggpack_adv(oggpack_buffer *b,int bits);
extern void oggpack_adv1(oggpack_buffer *b);
extern long oggpack_read(oggpack_buffer *b,int bits);
extern long oggpack_read1(oggpack_buffer *b);
extern long oggpack_bytes(oggpack_buffer *b);
extern long oggpack_bits(oggpack_buffer *b);
extern unsigned char *oggpack_get_buffer(oggpack_buffer *b);
extern void oggpackB_writeinit(oggpack_buffer *b);
extern int oggpackB_writecheck(oggpack_buffer *b);
extern void oggpackB_writetrunc(oggpack_buffer *b,long bits);
extern void oggpackB_writealign(oggpack_buffer *b);
extern void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits);
extern void oggpackB_reset(oggpack_buffer *b);
extern void oggpackB_writeclear(oggpack_buffer *b);
extern void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
extern void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits);
extern long oggpackB_look(oggpack_buffer *b,int bits);
extern long oggpackB_look1(oggpack_buffer *b);
extern void oggpackB_adv(oggpack_buffer *b,int bits);
extern void oggpackB_adv1(oggpack_buffer *b);
extern long oggpackB_read(oggpack_buffer *b,int bits);
extern long oggpackB_read1(oggpack_buffer *b);
extern long oggpackB_bytes(oggpack_buffer *b);
extern long oggpackB_bits(oggpack_buffer *b);
extern unsigned char *oggpackB_get_buffer(oggpack_buffer *b);
/* Ogg BITSTREAM PRIMITIVES: encoding **************************/
extern int ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op);
extern int ogg_stream_iovecin(ogg_stream_state *os, ogg_iovec_t *iov,
int count, long e_o_s, ogg_int64_t granulepos);
extern int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og);
extern int ogg_stream_pageout_fill(ogg_stream_state *os, ogg_page *og, int nfill);
extern int ogg_stream_flush(ogg_stream_state *os, ogg_page *og);
extern int ogg_stream_flush_fill(ogg_stream_state *os, ogg_page *og, int nfill);
/* Ogg BITSTREAM PRIMITIVES: decoding **************************/
extern int ogg_sync_init(ogg_sync_state *oy);
extern int ogg_sync_clear(ogg_sync_state *oy);
extern int ogg_sync_reset(ogg_sync_state *oy);
extern int ogg_sync_destroy(ogg_sync_state *oy);
extern int ogg_sync_check(ogg_sync_state *oy);
extern char *ogg_sync_buffer(ogg_sync_state *oy, long size);
extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op);
/* Ogg BITSTREAM PRIMITIVES: general ***************************/
extern int ogg_stream_init(ogg_stream_state *os,int serialno);
extern int ogg_stream_clear(ogg_stream_state *os);
extern int ogg_stream_reset(ogg_stream_state *os);
extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno);
extern int ogg_stream_destroy(ogg_stream_state *os);
extern int ogg_stream_check(ogg_stream_state *os);
extern int ogg_stream_eos(ogg_stream_state *os);
extern void ogg_page_checksum_set(ogg_page *og);
extern int ogg_page_version(const ogg_page *og);
extern int ogg_page_continued(const ogg_page *og);
extern int ogg_page_bos(const ogg_page *og);
extern int ogg_page_eos(const ogg_page *og);
extern ogg_int64_t ogg_page_granulepos(const ogg_page *og);
extern int ogg_page_serialno(const ogg_page *og);
extern long ogg_page_pageno(const ogg_page *og);
extern int ogg_page_packets(const ogg_page *og);
extern void ogg_packet_clear(ogg_packet *op);
#ifdef __cplusplus
}
#endif
#endif /* _OGG_H */

View File

@ -0,0 +1,157 @@
/********************************************************************
* *
* THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
* by the Xiph.Org Foundation http://www.xiph.org/ *
* *
********************************************************************
function: #ifdef jail to whip a few platforms into the UNIX ideal.
last mod: $Id: os_types.h 17712 2010-12-03 17:10:02Z xiphmont $
********************************************************************/
#ifndef _OS_TYPES_H
#define _OS_TYPES_H
/* make it easy on the folks that want to compile the libs with a
different malloc than stdlib */
#define _ogg_malloc malloc
#define _ogg_calloc calloc
#define _ogg_realloc realloc
#define _ogg_free free
#if defined(_WIN32)
# if defined(__CYGWIN__)
# include <stdint.h>
typedef int16_t ogg_int16_t;
typedef uint16_t ogg_uint16_t;
typedef int32_t ogg_int32_t;
typedef uint32_t ogg_uint32_t;
typedef int64_t ogg_int64_t;
typedef uint64_t ogg_uint64_t;
# elif defined(__MINGW32__)
# include <sys/types.h>
typedef short ogg_int16_t;
typedef unsigned short ogg_uint16_t;
typedef int ogg_int32_t;
typedef unsigned int ogg_uint32_t;
typedef long long ogg_int64_t;
typedef unsigned long long ogg_uint64_t;
# elif defined(__MWERKS__)
typedef long long ogg_int64_t;
typedef int ogg_int32_t;
typedef unsigned int ogg_uint32_t;
typedef short ogg_int16_t;
typedef unsigned short ogg_uint16_t;
# else
/* MSVC/Borland */
typedef __int64 ogg_int64_t;
typedef __int32 ogg_int32_t;
typedef unsigned __int32 ogg_uint32_t;
typedef __int16 ogg_int16_t;
typedef unsigned __int16 ogg_uint16_t;
# endif
#elif defined(__MACOS__)
# include <sys/types.h>
typedef SInt16 ogg_int16_t;
typedef UInt16 ogg_uint16_t;
typedef SInt32 ogg_int32_t;
typedef UInt32 ogg_uint32_t;
typedef SInt64 ogg_int64_t;
#elif (defined(__APPLE__) && defined(__MACH__)) /* MacOS X Framework build */
# include <inttypes.h>
typedef int16_t ogg_int16_t;
typedef uint16_t ogg_uint16_t;
typedef int32_t ogg_int32_t;
typedef uint32_t ogg_uint32_t;
typedef int64_t ogg_int64_t;
#elif defined(__HAIKU__)
/* Haiku */
# include <sys/types.h>
typedef short ogg_int16_t;
typedef unsigned short ogg_uint16_t;
typedef int ogg_int32_t;
typedef unsigned int ogg_uint32_t;
typedef long long ogg_int64_t;
#elif defined(__BEOS__)
/* Be */
# include <inttypes.h>
typedef int16_t ogg_int16_t;
typedef uint16_t ogg_uint16_t;
typedef int32_t ogg_int32_t;
typedef uint32_t ogg_uint32_t;
typedef int64_t ogg_int64_t;
#elif defined(__QNX__)
/* QNX */
# include <inttypes.h>
typedef int16_t ogg_int16_t;
typedef uint16_t ogg_uint16_t;
typedef int32_t ogg_int32_t;
typedef uint32_t ogg_uint32_t;
typedef int64_t ogg_int64_t;
#elif defined (__EMX__)
/* OS/2 GCC */
typedef short ogg_int16_t;
typedef unsigned short ogg_uint16_t;
typedef int ogg_int32_t;
typedef unsigned int ogg_uint32_t;
typedef long long ogg_int64_t;
#elif defined (DJGPP)
/* DJGPP */
typedef short ogg_int16_t;
typedef int ogg_int32_t;
typedef unsigned int ogg_uint32_t;
typedef long long ogg_int64_t;
#elif defined(R5900)
/* PS2 EE */
typedef long ogg_int64_t;
typedef int ogg_int32_t;
typedef unsigned ogg_uint32_t;
typedef short ogg_int16_t;
#elif defined(__SYMBIAN32__)
/* Symbian GCC */
typedef signed short ogg_int16_t;
typedef unsigned short ogg_uint16_t;
typedef signed int ogg_int32_t;
typedef unsigned int ogg_uint32_t;
typedef long long int ogg_int64_t;
#elif defined(__TMS320C6X__)
/* TI C64x compiler */
typedef signed short ogg_int16_t;
typedef unsigned short ogg_uint16_t;
typedef signed int ogg_int32_t;
typedef unsigned int ogg_uint32_t;
typedef long long int ogg_int64_t;
#else
# include <ogg/config_types.h>
#endif
#endif /* _OS_TYPES_H */

View File

@ -0,0 +1,243 @@
/********************************************************************
* *
* THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *
* by the Xiph.Org Foundation http://www.xiph.org/ *
********************************************************************
function: libvorbis codec headers
last mod: $Id: codec.h 17021 2010-03-24 09:29:41Z xiphmont $
********************************************************************/
#ifndef _vorbis_codec_h_
#define _vorbis_codec_h_
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
#include <ogg/ogg.h>
typedef struct vorbis_info{
int version;
int channels;
long rate;
/* The below bitrate declarations are *hints*.
Combinations of the three values carry the following implications:
all three set to the same value:
implies a fixed rate bitstream
only nominal set:
implies a VBR stream that averages the nominal bitrate. No hard
upper/lower limit
upper and or lower set:
implies a VBR bitstream that obeys the bitrate limits. nominal
may also be set to give a nominal rate.
none set:
the coder does not care to speculate.
*/
long bitrate_upper;
long bitrate_nominal;
long bitrate_lower;
long bitrate_window;
void *codec_setup;
} vorbis_info;
/* vorbis_dsp_state buffers the current vorbis audio
analysis/synthesis state. The DSP state belongs to a specific
logical bitstream ****************************************************/
typedef struct vorbis_dsp_state{
int analysisp;
vorbis_info *vi;
float **pcm;
float **pcmret;
int pcm_storage;
int pcm_current;
int pcm_returned;
int preextrapolate;
int eofflag;
long lW;
long W;
long nW;
long centerW;
ogg_int64_t granulepos;
ogg_int64_t sequence;
ogg_int64_t glue_bits;
ogg_int64_t time_bits;
ogg_int64_t floor_bits;
ogg_int64_t res_bits;
void *backend_state;
} vorbis_dsp_state;
typedef struct vorbis_block{
/* necessary stream state for linking to the framing abstraction */
float **pcm; /* this is a pointer into local storage */
oggpack_buffer opb;
long lW;
long W;
long nW;
int pcmend;
int mode;
int eofflag;
ogg_int64_t granulepos;
ogg_int64_t sequence;
vorbis_dsp_state *vd; /* For read-only access of configuration */
/* local storage to avoid remallocing; it's up to the mapping to
structure it */
void *localstore;
long localtop;
long localalloc;
long totaluse;
struct alloc_chain *reap;
/* bitmetrics for the frame */
long glue_bits;
long time_bits;
long floor_bits;
long res_bits;
void *internal;
} vorbis_block;
/* vorbis_block is a single block of data to be processed as part of
the analysis/synthesis stream; it belongs to a specific logical
bitstream, but is independent from other vorbis_blocks belonging to
that logical bitstream. *************************************************/
struct alloc_chain{
void *ptr;
struct alloc_chain *next;
};
/* vorbis_info contains all the setup information specific to the
specific compression/decompression mode in progress (eg,
psychoacoustic settings, channel setup, options, codebook
etc). vorbis_info and substructures are in backends.h.
*********************************************************************/
/* the comments are not part of vorbis_info so that vorbis_info can be
static storage */
typedef struct vorbis_comment{
/* unlimited user comment fields. libvorbis writes 'libvorbis'
whatever vendor is set to in encode */
char **user_comments;
int *comment_lengths;
int comments;
char *vendor;
} vorbis_comment;
/* libvorbis encodes in two abstraction layers; first we perform DSP
and produce a packet (see docs/analysis.txt). The packet is then
coded into a framed OggSquish bitstream by the second layer (see
docs/framing.txt). Decode is the reverse process; we sync/frame
the bitstream and extract individual packets, then decode the
packet back into PCM audio.
The extra framing/packetizing is used in streaming formats, such as
files. Over the net (such as with UDP), the framing and
packetization aren't necessary as they're provided by the transport
and the streaming layer is not used */
/* Vorbis PRIMITIVES: general ***************************************/
extern void vorbis_info_init(vorbis_info *vi);
extern void vorbis_info_clear(vorbis_info *vi);
extern int vorbis_info_blocksize(vorbis_info *vi,int zo);
extern void vorbis_comment_init(vorbis_comment *vc);
extern void vorbis_comment_add(vorbis_comment *vc, const char *comment);
extern void vorbis_comment_add_tag(vorbis_comment *vc,
const char *tag, const char *contents);
extern char *vorbis_comment_query(vorbis_comment *vc, const char *tag, int count);
extern int vorbis_comment_query_count(vorbis_comment *vc, const char *tag);
extern void vorbis_comment_clear(vorbis_comment *vc);
extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb);
extern int vorbis_block_clear(vorbis_block *vb);
extern void vorbis_dsp_clear(vorbis_dsp_state *v);
extern double vorbis_granule_time(vorbis_dsp_state *v,
ogg_int64_t granulepos);
extern const char *vorbis_version_string(void);
/* Vorbis PRIMITIVES: analysis/DSP layer ****************************/
extern int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi);
extern int vorbis_commentheader_out(vorbis_comment *vc, ogg_packet *op);
extern int vorbis_analysis_headerout(vorbis_dsp_state *v,
vorbis_comment *vc,
ogg_packet *op,
ogg_packet *op_comm,
ogg_packet *op_code);
extern float **vorbis_analysis_buffer(vorbis_dsp_state *v,int vals);
extern int vorbis_analysis_wrote(vorbis_dsp_state *v,int vals);
extern int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb);
extern int vorbis_analysis(vorbis_block *vb,ogg_packet *op);
extern int vorbis_bitrate_addblock(vorbis_block *vb);
extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,
ogg_packet *op);
/* Vorbis PRIMITIVES: synthesis layer *******************************/
extern int vorbis_synthesis_idheader(ogg_packet *op);
extern int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,
ogg_packet *op);
extern int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi);
extern int vorbis_synthesis_restart(vorbis_dsp_state *v);
extern int vorbis_synthesis(vorbis_block *vb,ogg_packet *op);
extern int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op);
extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb);
extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm);
extern int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm);
extern int vorbis_synthesis_read(vorbis_dsp_state *v,int samples);
extern long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op);
extern int vorbis_synthesis_halfrate(vorbis_info *v,int flag);
extern int vorbis_synthesis_halfrate_p(vorbis_info *v);
/* Vorbis ERRORS and return codes ***********************************/
#define OV_FALSE -1
#define OV_EOF -2
#define OV_HOLE -3
#define OV_EREAD -128
#define OV_EFAULT -129
#define OV_EIMPL -130
#define OV_EINVAL -131
#define OV_ENOTVORBIS -132
#define OV_EBADHEADER -133
#define OV_EVERSION -134
#define OV_ENOTAUDIO -135
#define OV_EBADPACKET -136
#define OV_EBADLINK -137
#define OV_ENOSEEK -138
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif

View File

@ -0,0 +1,436 @@
/********************************************************************
* *
* THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *
* by the Xiph.Org Foundation http://www.xiph.org/ *
* *
********************************************************************
function: vorbis encode-engine setup
last mod: $Id: vorbisenc.h 17021 2010-03-24 09:29:41Z xiphmont $
********************************************************************/
/** \file
* Libvorbisenc is a convenient API for setting up an encoding
* environment using libvorbis. Libvorbisenc encapsulates the
* actions needed to set up the encoder properly.
*/
#ifndef _OV_ENC_H_
#define _OV_ENC_H_
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
#include "codec.h"
/**
* This is the primary function within libvorbisenc for setting up managed
* bitrate modes.
*
* Before this function is called, the \ref vorbis_info
* struct should be initialized by using vorbis_info_init() from the libvorbis
* API. After encoding, vorbis_info_clear() should be called.
*
* The max_bitrate, nominal_bitrate, and min_bitrate settings are used to set
* constraints for the encoded file. This function uses these settings to
* select the appropriate encoding mode and set it up.
*
* \param vi Pointer to an initialized \ref vorbis_info struct.
* \param channels The number of channels to be encoded.
* \param rate The sampling rate of the source audio.
* \param max_bitrate Desired maximum bitrate (limit). -1 indicates unset.
* \param nominal_bitrate Desired average, or central, bitrate. -1 indicates unset.
* \param min_bitrate Desired minimum bitrate. -1 indicates unset.
*
* \return Zero for success, and negative values for failure.
*
* \retval 0 Success.
* \retval OV_EFAULT Internal logic fault; indicates a bug or heap/stack corruption.
* \retval OV_EINVAL Invalid setup request, eg, out of range argument.
* \retval OV_EIMPL Unimplemented mode; unable to comply with bitrate request.
*/
extern int vorbis_encode_init(vorbis_info *vi,
long channels,
long rate,
long max_bitrate,
long nominal_bitrate,
long min_bitrate);
/**
* This function performs step-one of a three-step bitrate-managed encode
* setup. It functions similarly to the one-step setup performed by \ref
* vorbis_encode_init but allows an application to make further encode setup
* tweaks using \ref vorbis_encode_ctl before finally calling \ref
* vorbis_encode_setup_init to complete the setup process.
*
* Before this function is called, the \ref vorbis_info struct should be
* initialized by using vorbis_info_init() from the libvorbis API. After
* encoding, vorbis_info_clear() should be called.
*
* The max_bitrate, nominal_bitrate, and min_bitrate settings are used to set
* constraints for the encoded file. This function uses these settings to
* select the appropriate encoding mode and set it up.
*
* \param vi Pointer to an initialized vorbis_info struct.
* \param channels The number of channels to be encoded.
* \param rate The sampling rate of the source audio.
* \param max_bitrate Desired maximum bitrate (limit). -1 indicates unset.
* \param nominal_bitrate Desired average, or central, bitrate. -1 indicates unset.
* \param min_bitrate Desired minimum bitrate. -1 indicates unset.
*
* \return Zero for success, and negative for failure.
*
* \retval 0 Success
* \retval OV_EFAULT Internal logic fault; indicates a bug or heap/stack corruption.
* \retval OV_EINVAL Invalid setup request, eg, out of range argument.
* \retval OV_EIMPL Unimplemented mode; unable to comply with bitrate request.
*/
extern int vorbis_encode_setup_managed(vorbis_info *vi,
long channels,
long rate,
long max_bitrate,
long nominal_bitrate,
long min_bitrate);
/**
* This function performs step-one of a three-step variable bitrate
* (quality-based) encode setup. It functions similarly to the one-step setup
* performed by \ref vorbis_encode_init_vbr() but allows an application to
* make further encode setup tweaks using \ref vorbis_encode_ctl() before
* finally calling \ref vorbis_encode_setup_init to complete the setup
* process.
*
* Before this function is called, the \ref vorbis_info struct should be
* initialized by using \ref vorbis_info_init() from the libvorbis API. After
* encoding, vorbis_info_clear() should be called.
*
* \param vi Pointer to an initialized vorbis_info struct.
* \param channels The number of channels to be encoded.
* \param rate The sampling rate of the source audio.
* \param quality Desired quality level, currently from -0.1 to 1.0 (lo to hi).
*
* \return Zero for success, and negative values for failure.
*
* \retval 0 Success
* \retval OV_EFAULT Internal logic fault; indicates a bug or heap/stack corruption.
* \retval OV_EINVAL Invalid setup request, eg, out of range argument.
* \retval OV_EIMPL Unimplemented mode; unable to comply with quality level request.
*/
extern int vorbis_encode_setup_vbr(vorbis_info *vi,
long channels,
long rate,
float quality
);
/**
* This is the primary function within libvorbisenc for setting up variable
* bitrate ("quality" based) modes.
*
*
* Before this function is called, the vorbis_info struct should be
* initialized by using vorbis_info_init() from the libvorbis API. After
* encoding, vorbis_info_clear() should be called.
*
* \param vi Pointer to an initialized vorbis_info struct.
* \param channels The number of channels to be encoded.
* \param rate The sampling rate of the source audio.
* \param base_quality Desired quality level, currently from -0.1 to 1.0 (lo to hi).
*
*
* \return Zero for success, or a negative number for failure.
*
* \retval 0 Success
* \retval OV_EFAULT Internal logic fault; indicates a bug or heap/stack corruption.
* \retval OV_EINVAL Invalid setup request, eg, out of range argument.
* \retval OV_EIMPL Unimplemented mode; unable to comply with quality level request.
*/
extern int vorbis_encode_init_vbr(vorbis_info *vi,
long channels,
long rate,
float base_quality
);
/**
* This function performs the last stage of three-step encoding setup, as
* described in the API overview under managed bitrate modes.
*
* Before this function is called, the \ref vorbis_info struct should be
* initialized by using vorbis_info_init() from the libvorbis API, one of
* \ref vorbis_encode_setup_managed() or \ref vorbis_encode_setup_vbr() called to
* initialize the high-level encoding setup, and \ref vorbis_encode_ctl()
* called if necessary to make encoding setup changes.
* vorbis_encode_setup_init() finalizes the highlevel encoding structure into
* a complete encoding setup after which the application may make no further
* setup changes.
*
* After encoding, vorbis_info_clear() should be called.
*
* \param vi Pointer to an initialized \ref vorbis_info struct.
*
* \return Zero for success, and negative values for failure.
*
* \retval 0 Success.
* \retval OV_EFAULT Internal logic fault; indicates a bug or heap/stack corruption.
*
* \retval OV_EINVAL Attempt to use vorbis_encode_setup_init() without first
* calling one of vorbis_encode_setup_managed() or vorbis_encode_setup_vbr() to
* initialize the high-level encoding setup
*
*/
extern int vorbis_encode_setup_init(vorbis_info *vi);
/**
* This function implements a generic interface to miscellaneous encoder
* settings similar to the classic UNIX 'ioctl()' system call. Applications
* may use vorbis_encode_ctl() to query or set bitrate management or quality
* mode details by using one of several \e request arguments detailed below.
* vorbis_encode_ctl() must be called after one of
* vorbis_encode_setup_managed() or vorbis_encode_setup_vbr(). When used
* to modify settings, \ref vorbis_encode_ctl() must be called before \ref
* vorbis_encode_setup_init().
*
* \param vi Pointer to an initialized vorbis_info struct.
*
* \param number Specifies the desired action; See \ref encctlcodes "the list
* of available requests".
*
* \param arg void * pointing to a data structure matching the request
* argument.
*
* \retval 0 Success. Any further return information (such as the result of a
* query) is placed into the storage pointed to by *arg.
*
* \retval OV_EINVAL Invalid argument, or an attempt to modify a setting after
* calling vorbis_encode_setup_init().
*
* \retval OV_EIMPL Unimplemented or unknown request
*/
extern int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg);
/**
* \deprecated This is a deprecated interface. Please use vorbis_encode_ctl()
* with the \ref ovectl_ratemanage2_arg struct and \ref
* OV_ECTL_RATEMANAGE2_GET and \ref OV_ECTL_RATEMANAGE2_SET calls in new code.
*
* The \ref ovectl_ratemanage_arg structure is used with vorbis_encode_ctl()
* and the \ref OV_ECTL_RATEMANAGE_GET, \ref OV_ECTL_RATEMANAGE_SET, \ref
* OV_ECTL_RATEMANAGE_AVG, \ref OV_ECTL_RATEMANAGE_HARD calls in order to
* query and modify specifics of the encoder's bitrate management
* configuration.
*/
struct ovectl_ratemanage_arg {
int management_active; /**< nonzero if bitrate management is active*/
/** hard lower limit (in kilobits per second) below which the stream bitrate
will never be allowed for any given bitrate_hard_window seconds of time.*/
long bitrate_hard_min;
/** hard upper limit (in kilobits per second) above which the stream bitrate
will never be allowed for any given bitrate_hard_window seconds of time.*/
long bitrate_hard_max;
/** the window period (in seconds) used to regulate the hard bitrate minimum
and maximum*/
double bitrate_hard_window;
/** soft lower limit (in kilobits per second) below which the average bitrate
tracker will start nudging the bitrate higher.*/
long bitrate_av_lo;
/** soft upper limit (in kilobits per second) above which the average bitrate
tracker will start nudging the bitrate lower.*/
long bitrate_av_hi;
/** the window period (in seconds) used to regulate the average bitrate
minimum and maximum.*/
double bitrate_av_window;
/** Regulates the relative centering of the average and hard windows; in
libvorbis 1.0 and 1.0.1, the hard window regulation overlapped but
followed the average window regulation. In libvorbis 1.1 a bit-reservoir
interface replaces the old windowing interface; the older windowing
interface is simulated and this field has no effect.*/
double bitrate_av_window_center;
};
/**
* \name struct ovectl_ratemanage2_arg
*
* The ovectl_ratemanage2_arg structure is used with vorbis_encode_ctl() and
* the OV_ECTL_RATEMANAGE2_GET and OV_ECTL_RATEMANAGE2_SET calls in order to
* query and modify specifics of the encoder's bitrate management
* configuration.
*
*/
struct ovectl_ratemanage2_arg {
int management_active; /**< nonzero if bitrate management is active */
/** Lower allowed bitrate limit in kilobits per second */
long bitrate_limit_min_kbps;
/** Upper allowed bitrate limit in kilobits per second */
long bitrate_limit_max_kbps;
long bitrate_limit_reservoir_bits; /**<Size of the bitrate reservoir in bits */
/** Regulates the bitrate reservoir's preferred fill level in a range from 0.0
* to 1.0; 0.0 tries to bank bits to buffer against future bitrate spikes, 1.0
* buffers against future sudden drops in instantaneous bitrate. Default is
* 0.1
*/
double bitrate_limit_reservoir_bias;
/** Average bitrate setting in kilobits per second */
long bitrate_average_kbps;
/** Slew rate limit setting for average bitrate adjustment; sets the minimum
* time in seconds the bitrate tracker may swing from one extreme to the
* other when boosting or damping average bitrate.
*/
double bitrate_average_damping;
};
/**
* \name vorbis_encode_ctl() codes
*
* \anchor encctlcodes
*
* These values are passed as the \c number parameter of vorbis_encode_ctl().
* The type of the referent of that function's \c arg pointer depends on these
* codes.
*/
/*@{*/
/**
* Query the current encoder bitrate management setting.
*
*Argument: <tt>struct ovectl_ratemanage2_arg *</tt>
*
* Used to query the current encoder bitrate management setting. Also used to
* initialize fields of an ovectl_ratemanage2_arg structure for use with
* \ref OV_ECTL_RATEMANAGE2_SET.
*/
#define OV_ECTL_RATEMANAGE2_GET 0x14
/**
* Set the current encoder bitrate management settings.
*
* Argument: <tt>struct ovectl_ratemanage2_arg *</tt>
*
* Used to set the current encoder bitrate management settings to the values
* listed in the ovectl_ratemanage2_arg. Passing a NULL pointer will disable
* bitrate management.
*/
#define OV_ECTL_RATEMANAGE2_SET 0x15
/**
* Returns the current encoder hard-lowpass setting (kHz) in the double
* pointed to by arg.
*
* Argument: <tt>double *</tt>
*/
#define OV_ECTL_LOWPASS_GET 0x20
/**
* Sets the encoder hard-lowpass to the value (kHz) pointed to by arg. Valid
* lowpass settings range from 2 to 99.
*
* Argument: <tt>double *</tt>
*/
#define OV_ECTL_LOWPASS_SET 0x21
/**
* Returns the current encoder impulse block setting in the double pointed
* to by arg.
*
* Argument: <tt>double *</tt>
*/
#define OV_ECTL_IBLOCK_GET 0x30
/**
* Sets the impulse block bias to the the value pointed to by arg.
*
* Argument: <tt>double *</tt>
*
* Valid range is -15.0 to 0.0 [default]. A negative impulse block bias will
* direct to encoder to use more bits when incoding short blocks that contain
* strong impulses, thus improving the accuracy of impulse encoding.
*/
#define OV_ECTL_IBLOCK_SET 0x31
/**
* Returns the current encoder coupling setting in the int pointed
* to by arg.
*
* Argument: <tt>int *</tt>
*/
#define OV_ECTL_COUPLING_GET 0x40
/**
* Enables/disables channel coupling in multichannel encoding according to arg.
*
* Argument: <tt>int *</tt>
*
* Zero disables channel coupling for multichannel inputs, nonzer enables
* channel coupling. Setting has no effect on monophonic encoding or
* multichannel counts that do not offer coupling. At present, coupling is
* available for stereo and 5.1 encoding.
*/
#define OV_ECTL_COUPLING_SET 0x41
/* deprecated rate management supported only for compatibility */
/**
* Old interface to querying bitrate management settings.
*
* Deprecated after move to bit-reservoir style management in 1.1 rendered
* this interface partially obsolete.
* \deprecated Please use \ref OV_ECTL_RATEMANAGE2_GET instead.
*
* Argument: <tt>struct ovectl_ratemanage_arg *</tt>
*/
#define OV_ECTL_RATEMANAGE_GET 0x10
/**
* Old interface to modifying bitrate management settings.
*
* deprecated after move to bit-reservoir style management in 1.1 rendered
* this interface partially obsolete.
*
* \deprecated Please use \ref OV_ECTL_RATEMANAGE2_SET instead.
*
* Argument: <tt>struct ovectl_ratemanage_arg *</tt>
*/
#define OV_ECTL_RATEMANAGE_SET 0x11
/**
* Old interface to setting average-bitrate encoding mode.
*
* Deprecated after move to bit-reservoir style management in 1.1 rendered
* this interface partially obsolete.
*
* \deprecated Please use \ref OV_ECTL_RATEMANAGE2_SET instead.
*
* Argument: <tt>struct ovectl_ratemanage_arg *</tt>
*/
#define OV_ECTL_RATEMANAGE_AVG 0x12
/**
* Old interface to setting bounded-bitrate encoding modes.
*
* deprecated after move to bit-reservoir style management in 1.1 rendered
* this interface partially obsolete.
*
* \deprecated Please use \ref OV_ECTL_RATEMANAGE2_SET instead.
*
* Argument: <tt>struct ovectl_ratemanage_arg *</tt>
*/
#define OV_ECTL_RATEMANAGE_HARD 0x13
/*@}*/
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif

View File

@ -0,0 +1,206 @@
/********************************************************************
* *
* THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 *
* by the Xiph.Org Foundation http://www.xiph.org/ *
* *
********************************************************************
function: stdio-based convenience library for opening/seeking/decoding
last mod: $Id: vorbisfile.h 17182 2010-04-29 03:48:32Z xiphmont $
********************************************************************/
#ifndef _OV_FILE_H_
#define _OV_FILE_H_
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
#include <stdio.h>
#include "codec.h"
/* The function prototypes for the callbacks are basically the same as for
* the stdio functions fread, fseek, fclose, ftell.
* The one difference is that the FILE * arguments have been replaced with
* a void * - this is to be used as a pointer to whatever internal data these
* functions might need. In the stdio case, it's just a FILE * cast to a void *
*
* If you use other functions, check the docs for these functions and return
* the right values. For seek_func(), you *MUST* return -1 if the stream is
* unseekable
*/
typedef struct {
size_t (*read_func) (void *ptr, size_t size, size_t nmemb, void *datasource);
int (*seek_func) (void *datasource, ogg_int64_t offset, int whence);
int (*close_func) (void *datasource);
long (*tell_func) (void *datasource);
} ov_callbacks;
#ifndef OV_EXCLUDE_STATIC_CALLBACKS
/* a few sets of convenient callbacks, especially for use under
* Windows where ov_open_callbacks() should always be used instead of
* ov_open() to avoid problems with incompatible crt.o version linking
* issues. */
static int _ov_header_fseek_wrap(FILE *f,ogg_int64_t off,int whence){
if(f==NULL)return(-1);
#ifdef __MINGW32__
return fseeko64(f,off,whence);
#elif defined (_WIN32)
return _fseeki64(f,off,whence);
#else
return fseek(f,off,whence);
#endif
}
/* These structs below (OV_CALLBACKS_DEFAULT etc) are defined here as
* static data. That means that every file which includes this header
* will get its own copy of these structs whether it uses them or
* not unless it #defines OV_EXCLUDE_STATIC_CALLBACKS.
* These static symbols are essential on platforms such as Windows on
* which several different versions of stdio support may be linked to
* by different DLLs, and we need to be certain we know which one
* we're using (the same one as the main application).
*/
static ov_callbacks OV_CALLBACKS_DEFAULT = {
(size_t (*)(void *, size_t, size_t, void *)) fread,
(int (*)(void *, ogg_int64_t, int)) _ov_header_fseek_wrap,
(int (*)(void *)) fclose,
(long (*)(void *)) ftell
};
static ov_callbacks OV_CALLBACKS_NOCLOSE = {
(size_t (*)(void *, size_t, size_t, void *)) fread,
(int (*)(void *, ogg_int64_t, int)) _ov_header_fseek_wrap,
(int (*)(void *)) NULL,
(long (*)(void *)) ftell
};
static ov_callbacks OV_CALLBACKS_STREAMONLY = {
(size_t (*)(void *, size_t, size_t, void *)) fread,
(int (*)(void *, ogg_int64_t, int)) NULL,
(int (*)(void *)) fclose,
(long (*)(void *)) NULL
};
static ov_callbacks OV_CALLBACKS_STREAMONLY_NOCLOSE = {
(size_t (*)(void *, size_t, size_t, void *)) fread,
(int (*)(void *, ogg_int64_t, int)) NULL,
(int (*)(void *)) NULL,
(long (*)(void *)) NULL
};
#endif
#define NOTOPEN 0
#define PARTOPEN 1
#define OPENED 2
#define STREAMSET 3
#define INITSET 4
typedef struct OggVorbis_File {
void *datasource; /* Pointer to a FILE *, etc. */
int seekable;
ogg_int64_t offset;
ogg_int64_t end;
ogg_sync_state oy;
/* If the FILE handle isn't seekable (eg, a pipe), only the current
stream appears */
int links;
ogg_int64_t *offsets;
ogg_int64_t *dataoffsets;
long *serialnos;
ogg_int64_t *pcmlengths; /* overloaded to maintain binary
compatibility; x2 size, stores both
beginning and end values */
vorbis_info *vi;
vorbis_comment *vc;
/* Decoding working state local storage */
ogg_int64_t pcm_offset;
int ready_state;
long current_serialno;
int current_link;
double bittrack;
double samptrack;
ogg_stream_state os; /* take physical pages, weld into a logical
stream of packets */
vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
vorbis_block vb; /* local working space for packet->PCM decode */
ov_callbacks callbacks;
} OggVorbis_File;
extern int ov_clear(OggVorbis_File *vf);
extern int ov_fopen(const char *path,OggVorbis_File *vf);
extern int ov_open(FILE *f,OggVorbis_File *vf,const char *initial,long ibytes);
extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf,
const char *initial, long ibytes, ov_callbacks callbacks);
extern int ov_test(FILE *f,OggVorbis_File *vf,const char *initial,long ibytes);
extern int ov_test_callbacks(void *datasource, OggVorbis_File *vf,
const char *initial, long ibytes, ov_callbacks callbacks);
extern int ov_test_open(OggVorbis_File *vf);
extern long ov_bitrate(OggVorbis_File *vf,int i);
extern long ov_bitrate_instant(OggVorbis_File *vf);
extern long ov_streams(OggVorbis_File *vf);
extern long ov_seekable(OggVorbis_File *vf);
extern long ov_serialnumber(OggVorbis_File *vf,int i);
extern ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i);
extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i);
extern double ov_time_total(OggVorbis_File *vf,int i);
extern int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos);
extern int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos);
extern int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos);
extern int ov_time_seek(OggVorbis_File *vf,double pos);
extern int ov_time_seek_page(OggVorbis_File *vf,double pos);
extern int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
extern int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
extern int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos);
extern int ov_time_seek_lap(OggVorbis_File *vf,double pos);
extern int ov_time_seek_page_lap(OggVorbis_File *vf,double pos);
extern ogg_int64_t ov_raw_tell(OggVorbis_File *vf);
extern ogg_int64_t ov_pcm_tell(OggVorbis_File *vf);
extern double ov_time_tell(OggVorbis_File *vf);
extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link);
extern long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int samples,
int *bitstream);
extern long ov_read_filter(OggVorbis_File *vf,char *buffer,int length,
int bigendianp,int word,int sgned,int *bitstream,
void (*filter)(float **pcm,long channels,long samples,void *filter_param),void *filter_param);
extern long ov_read(OggVorbis_File *vf,char *buffer,int length,
int bigendianp,int word,int sgned,int *bitstream);
extern int ov_crosslap(OggVorbis_File *vf1,OggVorbis_File *vf2);
extern int ov_halfrate(OggVorbis_File *vf,int flag);
extern int ov_halfrate_p(OggVorbis_File *vf);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif

View File

@ -74,8 +74,8 @@ public class Cocos2dxBitmap{
// Draw string
FontMetricsInt fm = paint.getFontMetricsInt();
int x = 0;
int y = height == 0 ?(-fm.ascent):
(-fm.ascent + (height - textProperty.totalHeight)/2);
int y = height == 0 ?(-fm.top):
(-fm.top + (height - textProperty.totalHeight)/2);
String[] lines = textProperty.lines;
for (String line : lines){
x = computeX(paint, line, textProperty.maxWidth, alignment);
@ -132,7 +132,7 @@ public class Cocos2dxBitmap{
private static TextProperty computeTextProperty(String content, Paint paint,
int maxWidth, int maxHeight){
FontMetricsInt fm = paint.getFontMetricsInt();
int h = (int)Math.ceil(fm.descent - fm.ascent);
int h = (int)Math.ceil(fm.bottom - fm.top);
int maxContentWidth = 0;
String[] lines = splitString(content, maxHeight, maxWidth, paint);
@ -165,7 +165,7 @@ public class Cocos2dxBitmap{
String[] lines = content.split("\\n");
String[] ret = null;
FontMetricsInt fm = paint.getFontMetricsInt();
int heightPerLine = (int)Math.ceil(fm.descent - fm.ascent);
int heightPerLine = (int)Math.ceil(fm.bottom - fm.top);
int maxLines = maxHeight / heightPerLine;
if (maxWidth != 0){
@ -236,7 +236,7 @@ public class Cocos2dxBitmap{
if (tempWidth >= width){
int lastIndexOfSpace = content.substring(0, i).lastIndexOf(" ");
if (lastIndexOfSpace != -1){
if (lastIndexOfSpace != -1 && lastIndexOfSpace > start){
/**
* Should wrap the word
*/

View File

@ -53,14 +53,13 @@
<listOptionValue builtIn="false" value="GLESv1_CM"/>
<listOptionValue builtIn="false" value="bps"/>
<listOptionValue builtIn="false" value="curl"/>
<listOptionValue builtIn="false" value="mmrndclient"/>
<listOptionValue builtIn="false" value="strm"/>
<listOptionValue builtIn="false" value="grskia"/>
<listOptionValue builtIn="false" value="OpenAL"/>
<listOptionValue builtIn="false" value="alut"/>
<listOptionValue builtIn="false" value="curl"/>
<listOptionValue builtIn="false" value="asound"/>
<listOptionValue builtIn="false" value="xml2"/>
<listOptionValue builtIn="false" value="vorbis"/>
</option>
<option id="com.qnx.qcc.option.linker.security.670341600" name="Enhanced Security (-Wl,-z,relro -Wl,-z,now)" superClass="com.qnx.qcc.option.linker.security" value="true" valueType="boolean"/>
<option id="com.qnx.qcc.option.linker.libraryPaths.1640397005" name="Library Paths (-L)" superClass="com.qnx.qcc.option.linker.libraryPaths" valueType="libPaths">
@ -140,14 +139,13 @@
<listOptionValue builtIn="false" value="GLESv1_CM"/>
<listOptionValue builtIn="false" value="bps"/>
<listOptionValue builtIn="false" value="curl"/>
<listOptionValue builtIn="false" value="mmrndclient"/>
<listOptionValue builtIn="false" value="strm"/>
<listOptionValue builtIn="false" value="grskia"/>
<listOptionValue builtIn="false" value="OpenAL"/>
<listOptionValue builtIn="false" value="alut"/>
<listOptionValue builtIn="false" value="curl"/>
<listOptionValue builtIn="false" value="asound"/>
<listOptionValue builtIn="false" value="xml2"/>
<listOptionValue builtIn="false" value="vorbis"/>
</option>
<option id="com.qnx.qcc.option.linker.security.982628496" name="Enhanced Security (-Wl,-z,relro -Wl,-z,now)" superClass="com.qnx.qcc.option.linker.security" value="true" valueType="boolean"/>
<option id="com.qnx.qcc.option.linker.pie.196284652" name="Position Independent Executable (-pie)" superClass="com.qnx.qcc.option.linker.pie" value="true" valueType="boolean"/>
@ -231,14 +229,13 @@
<listOptionValue builtIn="false" value="GLESv1_CM"/>
<listOptionValue builtIn="false" value="bps"/>
<listOptionValue builtIn="false" value="curl"/>
<listOptionValue builtIn="false" value="mmrndclient"/>
<listOptionValue builtIn="false" value="strm"/>
<listOptionValue builtIn="false" value="grskia"/>
<listOptionValue builtIn="false" value="OpenAL"/>
<listOptionValue builtIn="false" value="alut"/>
<listOptionValue builtIn="false" value="curl"/>
<listOptionValue builtIn="false" value="asound"/>
<listOptionValue builtIn="false" value="xml2"/>
<listOptionValue builtIn="false" value="vorbis"/>
</option>
<option id="com.qnx.qcc.option.linker.security.1905389687" name="Enhanced Security (-Wl,-z,relro -Wl,-z,now)" superClass="com.qnx.qcc.option.linker.security" value="true" valueType="boolean"/>
<option id="com.qnx.qcc.option.linker.libraryPaths.1615583479" name="Library Paths (-L)" superClass="com.qnx.qcc.option.linker.libraryPaths" valueType="libPaths">
@ -321,14 +318,13 @@
<listOptionValue builtIn="false" value="GLESv1_CM"/>
<listOptionValue builtIn="false" value="bps"/>
<listOptionValue builtIn="false" value="curl"/>
<listOptionValue builtIn="false" value="mmrndclient"/>
<listOptionValue builtIn="false" value="strm"/>
<listOptionValue builtIn="false" value="grskia"/>
<listOptionValue builtIn="false" value="OpenAL"/>
<listOptionValue builtIn="false" value="alut"/>
<listOptionValue builtIn="false" value="curl"/>
<listOptionValue builtIn="false" value="asound"/>
<listOptionValue builtIn="false" value="xml2"/>
<listOptionValue builtIn="false" value="vorbis"/>
</option>
<option id="com.qnx.qcc.option.linker.security.1324953478" name="Enhanced Security (-Wl,-z,relro -Wl,-z,now)" superClass="com.qnx.qcc.option.linker.security" value="true" valueType="boolean"/>
<option id="com.qnx.qcc.option.linker.libraryPaths.172097509" name="Library Paths (-L)" superClass="com.qnx.qcc.option.linker.libraryPaths" valueType="libPaths">
@ -408,14 +404,13 @@
<listOptionValue builtIn="false" value="GLESv1_CM"/>
<listOptionValue builtIn="false" value="bps"/>
<listOptionValue builtIn="false" value="curl"/>
<listOptionValue builtIn="false" value="mmrndclient"/>
<listOptionValue builtIn="false" value="strm"/>
<listOptionValue builtIn="false" value="grskia"/>
<listOptionValue builtIn="false" value="OpenAL"/>
<listOptionValue builtIn="false" value="alut"/>
<listOptionValue builtIn="false" value="curl"/>
<listOptionValue builtIn="false" value="asound"/>
<listOptionValue builtIn="false" value="xml2"/>
<listOptionValue builtIn="false" value="vorbis"/>
</option>
<option id="com.qnx.qcc.option.linker.security.886524253" name="Enhanced Security (-Wl,-z,relro -Wl,-z,now)" superClass="com.qnx.qcc.option.linker.security" value="true" valueType="boolean"/>
<option id="com.qnx.qcc.option.linker.libraryPaths.880489672" name="Library Paths (-L)" superClass="com.qnx.qcc.option.linker.libraryPaths" valueType="libPaths">
@ -497,14 +492,13 @@
<listOptionValue builtIn="false" value="GLESv1_CM"/>
<listOptionValue builtIn="false" value="bps"/>
<listOptionValue builtIn="false" value="curl"/>
<listOptionValue builtIn="false" value="mmrndclient"/>
<listOptionValue builtIn="false" value="strm"/>
<listOptionValue builtIn="false" value="grskia"/>
<listOptionValue builtIn="false" value="OpenAL"/>
<listOptionValue builtIn="false" value="alut"/>
<listOptionValue builtIn="false" value="curl"/>
<listOptionValue builtIn="false" value="asound"/>
<listOptionValue builtIn="false" value="xml2"/>
<listOptionValue builtIn="false" value="vorbis"/>
</option>
<option id="com.qnx.qcc.option.linker.security.1780600507" name="Enhanced Security (-Wl,-z,relro -Wl,-z,now)" superClass="com.qnx.qcc.option.linker.security" value="true" valueType="boolean"/>
<option id="com.qnx.qcc.option.linker.libraryPaths.1204179500" name="Library Paths (-L)" superClass="com.qnx.qcc.option.linker.libraryPaths" valueType="libPaths">
@ -586,14 +580,13 @@
<listOptionValue builtIn="false" value="GLESv1_CM"/>
<listOptionValue builtIn="false" value="bps"/>
<listOptionValue builtIn="false" value="curl"/>
<listOptionValue builtIn="false" value="mmrndclient"/>
<listOptionValue builtIn="false" value="strm"/>
<listOptionValue builtIn="false" value="grskia"/>
<listOptionValue builtIn="false" value="OpenAL"/>
<listOptionValue builtIn="false" value="alut"/>
<listOptionValue builtIn="false" value="curl"/>
<listOptionValue builtIn="false" value="asound"/>
<listOptionValue builtIn="false" value="xml2"/>
<listOptionValue builtIn="false" value="vorbis"/>
</option>
<option id="com.qnx.qcc.option.linker.security.1136026548" name="Enhanced Security (-Wl,-z,relro -Wl,-z,now)" superClass="com.qnx.qcc.option.linker.security" value="true" valueType="boolean"/>
<option id="com.qnx.qcc.option.linker.libraryPaths.1949291872" name="Library Paths (-L)" superClass="com.qnx.qcc.option.linker.libraryPaths" valueType="libPaths">
@ -653,5 +646,7 @@
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="com.qnx.tools.ide.qde.core.QNXProjectProperties"/>
<storageModule moduleId="refreshScope"/>
<storageModule moduleId="refreshScope" versionNumber="1">
<resource resourceType="PROJECT" workspacePath="/TestCocos2dx"/>
</storageModule>
</cproject>

View File

@ -13,6 +13,8 @@
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
#define MUSIC_FILE "music.mid"
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_QNX)
#define MUSIC_FILE "background.ogg"
#else
#define MUSIC_FILE "background.mp3"
#endif // CC_PLATFORM_WIN32