Permalink
Browse files

Merged with github.com:moai/moai-dev.

  • Loading branch information...
2 parents 34c58bc + bc5a132 commit dbfc5b278d130aa492af8e88d02c2895c7166b46 James Rhodes committed Jul 14, 2011
Showing 383 changed files with 24,419 additions and 19,753 deletions.
View
@@ -1,2 +1,6 @@
-*.sh eol=lf
-3rdparty/curl-7.19.7/ eol=lf
+*.sh eol=lf
+3rdparty/curl-7.19.7/ eol=lf
+*.sln eol=crlf
+distribute/moai-sdk/legal.txt eol=crlf
+distribute/moai-sdk/license.txt eol=crlf
+distribute/moai-sdk/README.txt eol=crlf
View
@@ -1,5 +1,2 @@
Thumbs.db
-.DS_Store
-/vs2010/ipch
-/vs2010/bin
-/vs2008/bin
+.DS_Store
@@ -1,44 +1,44 @@
-
-Microsoft Visual Studio Solution File, Format Version 9.00
-# Visual C++ Express 2005
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tinyXmlTest", "tinyXmlTest.vcproj", "{34719950-09E8-457E-BE23-8F1CE3A1F1F6}"
- ProjectSection(ProjectDependencies) = postProject
- {C406DAEC-0886-4771-8DEA-9D7329B46CC1} = {C406DAEC-0886-4771-8DEA-9D7329B46CC1}
- EndProjectSection
-EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tinyXmlTestSTL", "tinyXmlTestSTL.vcproj", "{53ED5965-5BCA-47B5-9EB0-EDD20882F22F}"
- ProjectSection(ProjectDependencies) = postProject
- {A3A84737-5017-4577-B8A2-79429A25B8B6} = {A3A84737-5017-4577-B8A2-79429A25B8B6}
- EndProjectSection
-EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tinyxml", "tinyxml_lib.vcproj", "{C406DAEC-0886-4771-8DEA-9D7329B46CC1}"
-EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tinyxmlSTL", "tinyxmlSTL.vcproj", "{A3A84737-5017-4577-B8A2-79429A25B8B6}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Win32 = Debug|Win32
- Release|Win32 = Release|Win32
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {34719950-09E8-457E-BE23-8F1CE3A1F1F6}.Debug|Win32.ActiveCfg = Debug|Win32
- {34719950-09E8-457E-BE23-8F1CE3A1F1F6}.Debug|Win32.Build.0 = Debug|Win32
- {34719950-09E8-457E-BE23-8F1CE3A1F1F6}.Release|Win32.ActiveCfg = Release|Win32
- {34719950-09E8-457E-BE23-8F1CE3A1F1F6}.Release|Win32.Build.0 = Release|Win32
- {53ED5965-5BCA-47B5-9EB0-EDD20882F22F}.Debug|Win32.ActiveCfg = Debug|Win32
- {53ED5965-5BCA-47B5-9EB0-EDD20882F22F}.Debug|Win32.Build.0 = Debug|Win32
- {53ED5965-5BCA-47B5-9EB0-EDD20882F22F}.Release|Win32.ActiveCfg = Release|Win32
- {53ED5965-5BCA-47B5-9EB0-EDD20882F22F}.Release|Win32.Build.0 = Release|Win32
- {C406DAEC-0886-4771-8DEA-9D7329B46CC1}.Debug|Win32.ActiveCfg = Debug|Win32
- {C406DAEC-0886-4771-8DEA-9D7329B46CC1}.Debug|Win32.Build.0 = Debug|Win32
- {C406DAEC-0886-4771-8DEA-9D7329B46CC1}.Release|Win32.ActiveCfg = Release|Win32
- {C406DAEC-0886-4771-8DEA-9D7329B46CC1}.Release|Win32.Build.0 = Release|Win32
- {A3A84737-5017-4577-B8A2-79429A25B8B6}.Debug|Win32.ActiveCfg = Debug|Win32
- {A3A84737-5017-4577-B8A2-79429A25B8B6}.Debug|Win32.Build.0 = Debug|Win32
- {A3A84737-5017-4577-B8A2-79429A25B8B6}.Release|Win32.ActiveCfg = Release|Win32
- {A3A84737-5017-4577-B8A2-79429A25B8B6}.Release|Win32.Build.0 = Release|Win32
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
-EndGlobal
+
+Microsoft Visual Studio Solution File, Format Version 9.00
+# Visual C++ Express 2005
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tinyXmlTest", "tinyXmlTest.vcproj", "{34719950-09E8-457E-BE23-8F1CE3A1F1F6}"
+ ProjectSection(ProjectDependencies) = postProject
+ {C406DAEC-0886-4771-8DEA-9D7329B46CC1} = {C406DAEC-0886-4771-8DEA-9D7329B46CC1}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tinyXmlTestSTL", "tinyXmlTestSTL.vcproj", "{53ED5965-5BCA-47B5-9EB0-EDD20882F22F}"
+ ProjectSection(ProjectDependencies) = postProject
+ {A3A84737-5017-4577-B8A2-79429A25B8B6} = {A3A84737-5017-4577-B8A2-79429A25B8B6}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tinyxml", "tinyxml_lib.vcproj", "{C406DAEC-0886-4771-8DEA-9D7329B46CC1}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tinyxmlSTL", "tinyxmlSTL.vcproj", "{A3A84737-5017-4577-B8A2-79429A25B8B6}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Win32 = Debug|Win32
+ Release|Win32 = Release|Win32
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {34719950-09E8-457E-BE23-8F1CE3A1F1F6}.Debug|Win32.ActiveCfg = Debug|Win32
+ {34719950-09E8-457E-BE23-8F1CE3A1F1F6}.Debug|Win32.Build.0 = Debug|Win32
+ {34719950-09E8-457E-BE23-8F1CE3A1F1F6}.Release|Win32.ActiveCfg = Release|Win32
+ {34719950-09E8-457E-BE23-8F1CE3A1F1F6}.Release|Win32.Build.0 = Release|Win32
+ {53ED5965-5BCA-47B5-9EB0-EDD20882F22F}.Debug|Win32.ActiveCfg = Debug|Win32
+ {53ED5965-5BCA-47B5-9EB0-EDD20882F22F}.Debug|Win32.Build.0 = Debug|Win32
+ {53ED5965-5BCA-47B5-9EB0-EDD20882F22F}.Release|Win32.ActiveCfg = Release|Win32
+ {53ED5965-5BCA-47B5-9EB0-EDD20882F22F}.Release|Win32.Build.0 = Release|Win32
+ {C406DAEC-0886-4771-8DEA-9D7329B46CC1}.Debug|Win32.ActiveCfg = Debug|Win32
+ {C406DAEC-0886-4771-8DEA-9D7329B46CC1}.Debug|Win32.Build.0 = Debug|Win32
+ {C406DAEC-0886-4771-8DEA-9D7329B46CC1}.Release|Win32.ActiveCfg = Release|Win32
+ {C406DAEC-0886-4771-8DEA-9D7329B46CC1}.Release|Win32.Build.0 = Release|Win32
+ {A3A84737-5017-4577-B8A2-79429A25B8B6}.Debug|Win32.ActiveCfg = Debug|Win32
+ {A3A84737-5017-4577-B8A2-79429A25B8B6}.Debug|Win32.Build.0 = Debug|Win32
+ {A3A84737-5017-4577-B8A2-79429A25B8B6}.Release|Win32.ActiveCfg = Release|Win32
+ {A3A84737-5017-4577-B8A2-79429A25B8B6}.Release|Win32.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
@@ -58,7 +58,7 @@ void AudioMixer::removeSound(int index)
int AudioMixer::process(UInt32 numInputChannels, float* inputBuffer, UInt32 numOutputChannels, float *outputBuffer, UInt32 numFrames)
{
- RScopedLock l(&mLock);
+ mLock.lock();
memset(outputBuffer, 0, sizeof(float) * numFrames * numOutputChannels);
for(UInt32 i = 0; i < mSounds.size(); ++i)
@@ -88,10 +88,16 @@ int AudioMixer::process(UInt32 numInputChannels, float* inputBuffer, UInt32 numO
framesRead >= 0);
if(framesRead < 0)
+ {
+ mLock.unlock();
s->stop();
+ mLock.lock();
+ }
}
}
+ mLock.unlock();
+
return 0;
}
@@ -8,17 +8,18 @@ class AudioSource
AudioSource() : mLooping(false) {};
public:
virtual ~AudioSource() {};
-
+
+ virtual void close() {};
virtual Int64 readFrames(float* buffer, UInt32 numChannels, UInt32 numFrames) = 0;
virtual void setPosition(double position) {};
virtual double getPosition() { return 0; }
virtual UInt32 getBitsPerSample() { return 0; }
virtual double getSampleRate() { return 0; }
virtual UInt32 getNumChannels() { return 0; }
virtual double getLength() { return 0; }
- virtual void setLooping(bool loop) { mLooping = loop; };
- virtual bool isLooping() const { return mLooping; };
-
+
+ void setLooping(bool loop) { mLooping = loop; };
+ bool isLooping() const { return mLooping; };
double convertSamplesToSeconds(Int64 samples)
{
double time = (double)samples;
@@ -9,13 +9,21 @@ BufferedAudioSource::BufferedAudioSource()
BufferedAudioSource::~BufferedAudioSource()
{
- if(!isLoadedInMemory())
- {
- BufferedAudioSourceThread::getInstance()->removeSource(this);
- }
}
-bool BufferedAudioSource::open(const RString& path, bool loadIntoMemory)
+bool BufferedAudioSource::init(float* interleavedData, Int64 numSamples)
+{
+ mCurrentFrame = 0;
+ mLoadedInMemory = true;
+ mEOF = false;
+
+ mBuffer.resize(numSamples);
+ memcpy(&mBuffer[0], interleavedData, sizeof(float) * numSamples);
+
+ return true;
+}
+
+bool BufferedAudioSource::init(const RString& path, bool loadIntoMemory)
{
if(loadIntoMemory)
{
@@ -36,21 +44,35 @@ bool BufferedAudioSource::open(const RString& path, bool loadIntoMemory)
}
else
{
+ RScopedLock l(&mLock);
BufferedAudioSourceThread::getInstance()->addSource(this);
}
mCurrentFrame = 0;
+
return true;
}
+void BufferedAudioSource::close()
+{
+ if(!isLoadedInMemory())
+ {
+ BufferedAudioSourceThread::getInstance()->removeSource(this);
+ }
+}
+
void BufferedAudioSource::setPosition(double seconds)
{
- RScopedLock l(&mLock);
+ RScopedLock l(&mLock);
mCurrentFrame = (Int64)(seconds * getSampleRate());
- mBuffer.clear();
- setDecoderPosition(mCurrentFrame);
- BufferedAudioSourceThread::getInstance()->readMore();
+
+ if(!isLoadedInMemory())
+ {
+ mBuffer.clear();
+ setDecoderPosition(mCurrentFrame);
+ BufferedAudioSourceThread::getInstance()->readMore();
+ }
}
double BufferedAudioSource::getPosition()
@@ -65,21 +87,30 @@ Int64 BufferedAudioSource::readFrames(float* buffer, UInt32 numChannels, UInt32
Int64 framesRead = numFrames;
int framesAvailable = mBuffer.size() / getNumChannels() - mCurrentFrame;
-
+
+ // For disk-streaming sources we calculate available frames using the whole buffer
+ if(!isLoadedInMemory())
+ framesAvailable = mBuffer.size() / getNumChannels();
+
if(framesAvailable > 0)
{
if(framesAvailable < numFrames)
framesRead = framesAvailable;
int sourceChannels = getNumChannels();
-
+ int frameOffset = mCurrentFrame;
+
+ // For disk-streaming sources we always start at the beginning of the buffer
+ if(!isLoadedInMemory())
+ frameOffset = 0;
+
for(UInt32 j = 0; j < numChannels; ++j)
{
float *in = NULL;
if(sourceChannels == 1)
- in = &mBuffer[mCurrentFrame * sourceChannels];
+ in = &mBuffer[frameOffset * sourceChannels];
else
- in = &mBuffer[mCurrentFrame * sourceChannels + j];
+ in = &mBuffer[frameOffset * sourceChannels + j];
for(UInt32 i = 0; i < framesRead; ++i)
{
@@ -88,14 +119,12 @@ Int64 BufferedAudioSource::readFrames(float* buffer, UInt32 numChannels, UInt32
}
}
- if(isLoadedInMemory())
- {
- mCurrentFrame += framesRead;
- }
- else
+ mCurrentFrame += framesRead;
+
+ if(!isLoadedInMemory())
{
mBuffer.erase(mBuffer.begin(), mBuffer.begin() + (framesRead * sourceChannels));
- framesAvailable = mBuffer.size() / sourceChannels - mCurrentFrame;
+ framesAvailable = mBuffer.size() / getNumChannels();
UInt32 minimumFrames = getSampleRate() * SECONDS_TO_BUFFER / 2;
if(framesAvailable <= minimumFrames)
{
@@ -106,12 +135,11 @@ Int64 BufferedAudioSource::readFrames(float* buffer, UInt32 numChannels, UInt32
else
{
framesRead = 0;
+ mCurrentFrame = 0;
if(isLooping() || !isEOF())
{
- if(isLoadedInMemory())
- mCurrentFrame = 0;
- else
+ if(!isLoadedInMemory())
BufferedAudioSourceThread::getInstance()->readMore();
}
else
@@ -12,21 +12,24 @@ class BufferedAudioSource : public AudioSource
friend class BufferedAudioSourceThread;
public:
BufferedAudioSource();
- virtual ~BufferedAudioSource();
+ ~BufferedAudioSource();
// AudioSource
virtual Int64 readFrames(float* buffer, UInt32 numChannels, UInt32 numFrames);
virtual void setPosition(double seconds);
virtual double getPosition();
// BufferedAudioSource
- virtual bool open(const RString& path, bool loadIntoMemory) = 0;
+ virtual bool init(const RString& path, bool loadIntoMemory);
+ virtual bool init(float* interleavedData, Int64 numSamples);
+ virtual void close();
virtual Int64 decodeData(float* buffer, UInt32 numFrames) = 0;
virtual void setDecoderPosition(Int64 startFrame) = 0;
- virtual bool isEOF() { return mEOF; }
- virtual bool isLoadedInMemory() { return mLoadedInMemory; }
protected:
+ bool isEOF() { return mEOF; }
+ bool isLoadedInMemory() { return mLoadedInMemory; }
+
bool mLoadedInMemory;
bool mEOF;
Int64 mCurrentFrame;
@@ -39,6 +39,14 @@ bool BufferedAudioSourceThread::addSource(BufferedAudioSource *source)
{
RScopedLock l(&mLock);
+ for(UInt32 i = 0; i < mSources.size(); ++i)
+ {
+ if(source == mSources[i])
+ {
+ return false; // Already added
+ }
+ }
+
mSources.push_back(source);
if(mSources.size() == 1)
{
@@ -94,8 +102,6 @@ void BufferedAudioSourceThread::run()
for(UInt32 i = 0; i < mSources.size(); ++i)
{
BufferedAudioSource *pSource = mSources[i];
-
-// RScopedLock l(&pSource->mLock);
pSource->mLock.lock();
@@ -142,8 +148,9 @@ void BufferedAudioSourceThread::run()
}
}
- mLock.unlock();
}
+
+ mLock.unlock();
}
}
Oops, something went wrong.

0 comments on commit dbfc5b2

Please sign in to comment.