This source file includes following definitions.
- resizeSmaller
- scale
- copyFrom
- copyFromRange
- sumFrom
- maxAbsValue
#include "config.h"
#if ENABLE(WEB_AUDIO)
#include "platform/audio/AudioChannel.h"
#include <math.h>
#include <algorithm>
#include "platform/audio/VectorMath.h"
#include "wtf/OwnPtr.h"
namespace WebCore {
using namespace VectorMath;
void AudioChannel::resizeSmaller(size_t newLength)
{
ASSERT(newLength <= m_length);
if (newLength <= m_length)
m_length = newLength;
}
void AudioChannel::scale(float scale)
{
if (isSilent())
return;
vsmul(data(), 1, &scale, mutableData(), 1, length());
}
void AudioChannel::copyFrom(const AudioChannel* sourceChannel)
{
bool isSafe = (sourceChannel && sourceChannel->length() >= length());
ASSERT(isSafe);
if (!isSafe)
return;
if (sourceChannel->isSilent()) {
zero();
return;
}
memcpy(mutableData(), sourceChannel->data(), sizeof(float) * length());
}
void AudioChannel::copyFromRange(const AudioChannel* sourceChannel, unsigned startFrame, unsigned endFrame)
{
bool isRangeSafe = sourceChannel && startFrame < endFrame && endFrame <= sourceChannel->length();
ASSERT(isRangeSafe);
if (!isRangeSafe)
return;
if (sourceChannel->isSilent() && isSilent())
return;
size_t rangeLength = endFrame - startFrame;
bool isRangeLengthSafe = rangeLength <= length();
ASSERT(isRangeLengthSafe);
if (!isRangeLengthSafe)
return;
const float* source = sourceChannel->data();
float* destination = mutableData();
if (sourceChannel->isSilent()) {
if (rangeLength == length())
zero();
else
memset(destination, 0, sizeof(float) * rangeLength);
} else
memcpy(destination, source + startFrame, sizeof(float) * rangeLength);
}
void AudioChannel::sumFrom(const AudioChannel* sourceChannel)
{
bool isSafe = sourceChannel && sourceChannel->length() >= length();
ASSERT(isSafe);
if (!isSafe)
return;
if (sourceChannel->isSilent())
return;
if (isSilent())
copyFrom(sourceChannel);
else
vadd(data(), 1, sourceChannel->data(), 1, mutableData(), 1, length());
}
float AudioChannel::maxAbsValue() const
{
if (isSilent())
return 0;
float max = 0;
vmaxmgv(data(), 1, &max, length());
return max;
}
}
#endif