mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 901633 - Part 12 - Add a function to deinterleave and convert an audio buffer. r=jesup
This commit is contained in:
parent
ae6fa93922
commit
aad35131e4
@ -96,6 +96,51 @@ FloatToAudioSample<int16_t>(float aValue)
|
||||
return int16_t(clamped);
|
||||
}
|
||||
|
||||
template <typename T> T IntegerToAudioSample(int16_t aValue);
|
||||
|
||||
template <> inline float
|
||||
IntegerToAudioSample<float>(int16_t aValue)
|
||||
{
|
||||
return aValue / 32768.0f;
|
||||
}
|
||||
template <> inline int16_t
|
||||
IntegerToAudioSample<int16_t>(int16_t aValue)
|
||||
{
|
||||
return aValue;
|
||||
}
|
||||
|
||||
template<typename SrcT, typename DstT>
|
||||
inline void
|
||||
ConvertAudioSample(SrcT aIn, DstT& aOut);
|
||||
|
||||
template<>
|
||||
inline void
|
||||
ConvertAudioSample(int16_t aIn, int16_t & aOut)
|
||||
{
|
||||
aOut = aIn;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline void
|
||||
ConvertAudioSample(int16_t aIn, float& aOut)
|
||||
{
|
||||
aOut = AudioSampleToFloat(aIn);
|
||||
}
|
||||
|
||||
template<>
|
||||
inline void
|
||||
ConvertAudioSample(float aIn, float& aOut)
|
||||
{
|
||||
aOut = aIn;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline void
|
||||
ConvertAudioSample(float aIn, int16_t& aOut)
|
||||
{
|
||||
aOut = FloatToAudioSample<int16_t>(aIn);
|
||||
}
|
||||
|
||||
// Sample buffer conversion
|
||||
|
||||
template <typename From, typename To> inline void
|
||||
|
@ -57,16 +57,16 @@ const int GUESS_AUDIO_CHANNELS = 2;
|
||||
const uint32_t WEBAUDIO_BLOCK_SIZE_BITS = 7;
|
||||
const uint32_t WEBAUDIO_BLOCK_SIZE = 1 << WEBAUDIO_BLOCK_SIZE_BITS;
|
||||
|
||||
template <class SrcT, class DestT>
|
||||
template <typename SrcT, typename DestT>
|
||||
static void
|
||||
InterleaveAndConvertBuffer(const SrcT* const* aSourceChannels,
|
||||
int32_t aLength, float aVolume,
|
||||
int32_t aChannels,
|
||||
uint32_t aLength, float aVolume,
|
||||
uint32_t aChannels,
|
||||
DestT* aOutput)
|
||||
{
|
||||
DestT* output = aOutput;
|
||||
for (int32_t i = 0; i < aLength; ++i) {
|
||||
for (int32_t channel = 0; channel < aChannels; ++channel) {
|
||||
for (size_t i = 0; i < aLength; ++i) {
|
||||
for (size_t channel = 0; channel < aChannels; ++channel) {
|
||||
float v = AudioSampleToFloat(aSourceChannels[channel][i])*aVolume;
|
||||
*output = FloatToAudioSample<DestT>(v);
|
||||
++output;
|
||||
@ -74,6 +74,22 @@ InterleaveAndConvertBuffer(const SrcT* const* aSourceChannels,
|
||||
}
|
||||
}
|
||||
|
||||
template <typename SrcT, typename DestT>
|
||||
static void
|
||||
DeinterleaveAndConvertBuffer(const SrcT* aSourceBuffer,
|
||||
uint32_t aFrames, uint32_t aChannels,
|
||||
DestT** aOutput)
|
||||
{
|
||||
for (size_t i = 0; i < aChannels; i++) {
|
||||
size_t interleavedIndex = i;
|
||||
for (size_t j = 0; j < aFrames; j++) {
|
||||
ConvertAudioSample(aSourceBuffer[interleavedIndex],
|
||||
aOutput[i][j]);
|
||||
interleavedIndex += aChannels;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SilentChannel
|
||||
{
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user