Renamed SoundStream::Chunk::NbSamples to SampleCount, and renamed other nbSamples variables to sampleCount

This commit is contained in:
Laurent Gomila 2012-01-13 15:09:30 +01:00
parent c2039e866c
commit e775bd0169
7 changed files with 39 additions and 39 deletions

View File

@ -88,8 +88,8 @@ private :
}
// Fill audio data to pass to the stream
data.Samples = &myTempBuffer[0];
data.NbSamples = myTempBuffer.size();
data.Samples = &myTempBuffer[0];
data.SampleCount = myTempBuffer.size();
// Update the playing offset
myOffset += myTempBuffer.size();
@ -126,14 +126,14 @@ private :
if (id == audioData)
{
// Extract audio samples from the packet, and append it to our samples buffer
const sf::Int16* samples = reinterpret_cast<const sf::Int16*>(packet.GetData() + 1);
std::size_t nbSamples = (packet.GetDataSize() - 1) / sizeof(sf::Int16);
const sf::Int16* samples = reinterpret_cast<const sf::Int16*>(packet.GetData() + 1);
std::size_t sampleCount = (packet.GetDataSize() - 1) / sizeof(sf::Int16);
// Don't forget that the other thread can access the sample array at any time
// (so we protect any operation on it with the mutex)
{
sf::Lock lock(myMutex);
std::copy(samples, samples + nbSamples, std::back_inserter(mySamples));
std::copy(samples, samples + sampleCount, std::back_inserter(mySamples));
}
}
else if (id == endOfStream)

View File

@ -49,8 +49,8 @@ public :
////////////////////////////////////////////////////////////
struct Chunk
{
const Int16* Samples; ///< Pointer to the audio samples
std::size_t NbSamples; ///< Number of samples pointed by Samples
const Int16* Samples; ///< Pointer to the audio samples
std::size_t SampleCount; ///< Number of samples pointed by Samples
};
////////////////////////////////////////////////////////////
@ -351,7 +351,7 @@ private :
/// {
/// // Fill the chunk with audio data from the stream source
/// data.Samples = ...;
/// data.NbSamples = ...;
/// data.SampleCount = ...;
///
/// // Return true to continue playing
/// return true;

View File

@ -118,11 +118,11 @@ bool Music::OnGetData(SoundStream::Chunk& data)
Lock lock(myMutex);
// Fill the chunk parameters
data.Samples = &mySamples[0];
data.NbSamples = myFile->Read(&mySamples[0], mySamples.size());
data.Samples = &mySamples[0];
data.SampleCount = myFile->Read(&mySamples[0], mySamples.size());
// Check if we have reached the end of the audio file
return data.NbSamples == mySamples.size();
return data.SampleCount == mySamples.size();
}

View File

@ -213,13 +213,13 @@ SoundBuffer& SoundBuffer::operator =(const SoundBuffer& right)
bool SoundBuffer::Initialize(priv::SoundFile& file)
{
// Retrieve the sound parameters
std::size_t nbSamples = file.GetSampleCount();
std::size_t sampleCount = file.GetSampleCount();
unsigned int channelCount = file.GetChannelCount();
unsigned int sampleRate = file.GetSampleRate();
// Read the samples from the provided file
mySamples.resize(nbSamples);
if (file.Read(&mySamples[0], nbSamples) == nbSamples)
mySamples.resize(sampleCount);
if (file.Read(&mySamples[0], sampleCount) == sampleCount)
{
// Update the internal buffer with the new samples
return Update(channelCount, sampleRate);

View File

@ -54,7 +54,7 @@ namespace priv
////////////////////////////////////////////////////////////
SoundFile::SoundFile() :
myFile (NULL),
myNbSamples (0),
mySampleCount (0),
myChannelCount(0),
mySampleRate (0)
{
@ -73,7 +73,7 @@ SoundFile::~SoundFile()
////////////////////////////////////////////////////////////
std::size_t SoundFile::GetSampleCount() const
{
return myNbSamples;
return mySampleCount;
}
@ -110,7 +110,7 @@ bool SoundFile::OpenRead(const std::string& filename)
// Set the sound parameters
myChannelCount = fileInfos.channels;
mySampleRate = fileInfos.samplerate;
myNbSamples = static_cast<std::size_t>(fileInfos.frames) * myChannelCount;
mySampleCount = static_cast<std::size_t>(fileInfos.frames) * myChannelCount;
return true;
}
@ -147,7 +147,7 @@ bool SoundFile::OpenRead(const void* data, std::size_t sizeInBytes)
// Set the sound parameters
myChannelCount = fileInfos.channels;
mySampleRate = fileInfos.samplerate;
myNbSamples = static_cast<std::size_t>(fileInfos.frames) * myChannelCount;
mySampleCount = static_cast<std::size_t>(fileInfos.frames) * myChannelCount;
return true;
}
@ -179,7 +179,7 @@ bool SoundFile::OpenRead(InputStream& stream)
// Set the sound parameters
myChannelCount = fileInfos.channels;
mySampleRate = fileInfos.samplerate;
myNbSamples = static_cast<std::size_t>(fileInfos.frames) * myChannelCount;
mySampleCount = static_cast<std::size_t>(fileInfos.frames) * myChannelCount;
return true;
}
@ -218,35 +218,35 @@ bool SoundFile::OpenWrite(const std::string& filename, unsigned int channelCount
// Set the sound parameters
myChannelCount = channelCount;
mySampleRate = sampleRate;
myNbSamples = 0;
mySampleCount = 0;
return true;
}
////////////////////////////////////////////////////////////
std::size_t SoundFile::Read(Int16* data, std::size_t nbSamples)
std::size_t SoundFile::Read(Int16* data, std::size_t sampleCount)
{
if (myFile && data && nbSamples)
return static_cast<std::size_t>(sf_read_short(myFile, data, nbSamples));
if (myFile && data && sampleCount)
return static_cast<std::size_t>(sf_read_short(myFile, data, sampleCount));
else
return 0;
}
////////////////////////////////////////////////////////////
void SoundFile::Write(const Int16* data, std::size_t nbSamples)
void SoundFile::Write(const Int16* data, std::size_t sampleCount)
{
if (myFile && data && nbSamples)
if (myFile && data && sampleCount)
{
// Write small chunks instead of everything at once,
// to avoid a stack overflow in libsndfile (happens only with OGG format)
while (nbSamples > 0)
while (sampleCount > 0)
{
std::size_t count = nbSamples > 10000 ? 10000 : nbSamples;
std::size_t count = sampleCount > 10000 ? 10000 : sampleCount;
sf_write_short(myFile, data, count);
data += count;
nbSamples -= count;
sampleCount -= count;
}
}
}

View File

@ -129,22 +129,22 @@ public :
////////////////////////////////////////////////////////////
/// \brief Read audio samples from the loaded sound
///
/// \param data Pointer to the sample array to fill
/// \param nbSamples Number of samples to read
/// \param data Pointer to the sample array to fill
/// \param sampleCount Number of samples to read
///
/// \return Number of samples actually read (may be less than \a nbSamples)
/// \return Number of samples actually read (may be less than \a sampleCount)
///
////////////////////////////////////////////////////////////
std::size_t Read(Int16* data, std::size_t nbSamples);
std::size_t Read(Int16* data, std::size_t sampleCount);
////////////////////////////////////////////////////////////
/// \brief Write audio samples to the file
///
/// \param data Pointer to the sample array to write
/// \param nbSamples Number of samples to write
/// \param data Pointer to the sample array to write
/// \param sampleCount Number of samples to write
///
////////////////////////////////////////////////////////////
void Write(const Int16* data, std::size_t nbSamples);
void Write(const Int16* data, std::size_t sampleCount);
////////////////////////////////////////////////////////////
/// \brief Change the current read position in the file
@ -200,7 +200,7 @@ private :
////////////////////////////////////////////////////////////
SNDFILE* myFile; ///< File descriptor
Memory myMemory; ///< Memory reading info
std::size_t myNbSamples; ///< Total number of samples in the file
std::size_t mySampleCount; ///< Total number of samples in the file
unsigned int myChannelCount; ///< Number of channels used by the sound
unsigned int mySampleRate; ///< Number of samples per second
};

View File

@ -298,7 +298,7 @@ bool SoundStream::FillAndPushBuffer(unsigned int bufferNum)
OnSeek(0);
// If we previously had no data, try to fill the buffer once again
if (!data.Samples || (data.NbSamples == 0))
if (!data.Samples || (data.SampleCount == 0))
{
return FillAndPushBuffer(bufferNum);
}
@ -311,12 +311,12 @@ bool SoundStream::FillAndPushBuffer(unsigned int bufferNum)
}
// Fill the buffer if some data was returned
if (data.Samples && data.NbSamples)
if (data.Samples && data.SampleCount)
{
unsigned int buffer = myBuffers[bufferNum];
// Fill the buffer
ALsizei size = static_cast<ALsizei>(data.NbSamples) * sizeof(Int16);
ALsizei size = static_cast<ALsizei>(data.SampleCount) * sizeof(Int16);
ALCheck(alBufferData(buffer, myFormat, data.Samples, size, mySampleRate));
// Push it into the sound queue