Bug 805254. Part 6: Replace some #ifdefs with if statements. r=kinetik

This is largely obsoleted by part 8. Sorry.
This commit is contained in:
Robert O'Callahan 2012-10-25 23:09:39 +13:00
parent e0ece2f796
commit d92a1b5efc
2 changed files with 49 additions and 50 deletions

View File

@ -179,28 +179,28 @@ nsHTMLAudioElement::MozWriteAudio(const JS::Value& aData, JSContext* aCx, uint32
uint32_t writeLen = NS_MIN(mAudioStream->Available(), dataLength / mChannels); uint32_t writeLen = NS_MIN(mAudioStream->Available(), dataLength / mChannels);
float* frames = JS_GetFloat32ArrayData(tsrc, aCx); float* frames = JS_GetFloat32ArrayData(tsrc, aCx);
#ifdef MOZ_SAMPLE_TYPE_S16 nsresult rv;
// Convert the samples back to integers as we are using fixed point audio in if (nsAudioStream::Format() == FORMAT_S16) {
// the nsAudioStream. // Convert the samples back to integers as we are using fixed point audio in
nsAutoArrayPtr<short> shortsArray(new short[writeLen * mChannels]); // the nsAudioStream.
// Hard clip the samples. nsAutoArrayPtr<short> shortsArray(new short[writeLen * mChannels]);
for (uint32_t i = 0; i < writeLen * mChannels; ++i) { // Hard clip the samples.
float scaled_value = floorf(0.5 + 32768 * frames[i]); for (uint32_t i = 0; i < writeLen * mChannels; ++i) {
if (frames[i] < 0.0) { float scaled_value = floorf(0.5 + 32768 * frames[i]);
shortsArray[i] = (scaled_value < -32768.0) ? if (frames[i] < 0.0) {
-32768 : shortsArray[i] = (scaled_value < -32768.0) ?
short(scaled_value); -32768 :
} else { short(scaled_value);
shortsArray[i] = (scaled_value > 32767.0) ? } else {
32767 : shortsArray[i] = (scaled_value > 32767.0) ?
short(scaled_value); 32767 :
short(scaled_value);
}
} }
rv = mAudioStream->Write(shortsArray, writeLen);
} else {
rv = mAudioStream->Write(frames, writeLen);
} }
nsresult rv = mAudioStream->Write(shortsArray, writeLen);
#else
nsresult rv = mAudioStream->Write(frames, writeLen);
#endif
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
return rv; return rv;

View File

@ -476,27 +476,27 @@ nsresult nsNativeAudioStream::Write(const void* aBuf, uint32_t aFrames)
if (s_data) { if (s_data) {
double scaled_volume = GetVolumeScale() * mVolume; double scaled_volume = GetVolumeScale() * mVolume;
#ifdef MOZ_SAMPLE_TYPE_S16 if (Format() == FORMAT_S16) {
const short* buf = static_cast<const short*>(aBuf); const short* buf = static_cast<const short*>(aBuf);
int32_t volume = int32_t((1 << 16) * scaled_volume); int32_t volume = int32_t((1 << 16) * scaled_volume);
for (uint32_t i = 0; i < samples; ++i) { for (uint32_t i = 0; i < samples; ++i) {
s_data[i] = short((int32_t(buf[i]) * volume) >> 16); s_data[i] = short((int32_t(buf[i]) * volume) >> 16);
} }
#else /* MOZ_SAMPLE_TYPE_FLOAT32 */ } else {
const float* buf = static_cast<const float*>(aBuf); const float* buf = static_cast<const float*>(aBuf);
for (uint32_t i = 0; i < samples; ++i) { for (uint32_t i = 0; i < samples; ++i) {
float scaled_value = floorf(0.5 + 32768 * buf[i] * scaled_volume); float scaled_value = floorf(0.5 + 32768 * buf[i] * scaled_volume);
if (buf[i] < 0.0) { if (buf[i] < 0.0) {
s_data[i] = (scaled_value < -32768.0) ? s_data[i] = (scaled_value < -32768.0) ?
-32768 : -32768 :
short(scaled_value); short(scaled_value);
} else { } else {
s_data[i] = (scaled_value > 32767.0) ? s_data[i] = (scaled_value > 32767.0) ?
32767 : 32767 :
short(scaled_value); short(scaled_value);
}
} }
} }
#endif
} }
if (sa_stream_write(static_cast<sa_stream_t*>(mAudioHandle), if (sa_stream_write(static_cast<sa_stream_t*>(mAudioHandle),
@ -947,13 +947,13 @@ nsBufferedAudioStream::Init(int32_t aNumChannels, int32_t aRate)
cubeb_stream_params params; cubeb_stream_params params;
params.rate = aRate; params.rate = aRate;
params.channels = aNumChannels; params.channels = aNumChannels;
#ifdef MOZ_SAMPLE_TYPE_S16 if (Format() == FORMAT_S16) {
params.format = CUBEB_SAMPLE_S16NE; params.format = CUBEB_SAMPLE_S16NE;
mBytesPerFrame = sizeof(int16_t) * aNumChannels; mBytesPerFrame = sizeof(int16_t) * aNumChannels;
#else /* MOZ_SAMPLE_TYPE_FLOAT32 */ } else {
params.format = CUBEB_SAMPLE_FLOAT32NE; params.format = CUBEB_SAMPLE_FLOAT32NE;
mBytesPerFrame = sizeof(float) * aNumChannels; mBytesPerFrame = sizeof(float) * aNumChannels;
#endif }
{ {
cubeb_stream* stream; cubeb_stream* stream;
@ -1183,9 +1183,8 @@ nsBufferedAudioStream::DataCallback(void* aBuffer, long aFrames)
if (scaled_volume == 1.0) { if (scaled_volume == 1.0) {
memcpy(output, input[i], input_size[i]); memcpy(output, input[i], input_size[i]);
output += input_size[i]; output += input_size[i];
} else { } else if (Format() == FORMAT_S16) {
// Adjust volume as each sample is copied out. // Adjust volume as each sample is copied out.
#ifdef MOZ_SAMPLE_TYPE_S16
int32_t volume = int32_t(1 << 16) * scaled_volume; int32_t volume = int32_t(1 << 16) * scaled_volume;
const short* src = static_cast<const short*>(input[i]); const short* src = static_cast<const short*>(input[i]);
@ -1193,13 +1192,13 @@ nsBufferedAudioStream::DataCallback(void* aBuffer, long aFrames)
for (uint32_t j = 0; j < input_size[i] / (mBytesPerFrame / mChannels); ++j) { for (uint32_t j = 0; j < input_size[i] / (mBytesPerFrame / mChannels); ++j) {
dst[j] = short((int32_t(src[j]) * volume) >> 16); dst[j] = short((int32_t(src[j]) * volume) >> 16);
} }
#else /* MOZ_SAMPLE_TYPE_FLOAT32 */ output += input_size[i];
} else {
const float* src = static_cast<const float*>(input[i]); const float* src = static_cast<const float*>(input[i]);
float* dst = reinterpret_cast<float*>(output); float* dst = reinterpret_cast<float*>(output);
for (uint32_t j = 0; j < input_size[i] / (mBytesPerFrame / mChannels); ++j) { for (uint32_t j = 0; j < input_size[i] / (mBytesPerFrame / mChannels); ++j) {
dst[j] = src[j] * scaled_volume; dst[j] = src[j] * scaled_volume;
} }
#endif
output += input_size[i]; output += input_size[i];
} }
} }