1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/media/webaudio/PeriodicWave.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,68 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim:set ts=2 sw=2 sts=2 et cindent: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#include "PeriodicWave.h" 1.11 +#include "AudioContext.h" 1.12 +#include "mozilla/dom/PeriodicWaveBinding.h" 1.13 + 1.14 +namespace mozilla { 1.15 +namespace dom { 1.16 + 1.17 +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(PeriodicWave, mContext) 1.18 + 1.19 +NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(PeriodicWave, AddRef) 1.20 +NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(PeriodicWave, Release) 1.21 + 1.22 +PeriodicWave::PeriodicWave(AudioContext* aContext, 1.23 + const float* aRealData, 1.24 + const float* aImagData, 1.25 + const uint32_t aLength, 1.26 + ErrorResult& aRv) 1.27 + : mContext(aContext) 1.28 +{ 1.29 + MOZ_ASSERT(aContext); 1.30 + SetIsDOMBinding(); 1.31 + 1.32 + // Caller should have checked this and thrown. 1.33 + MOZ_ASSERT(aLength > 0); 1.34 + MOZ_ASSERT(aLength <= 4096); 1.35 + mLength = aLength; 1.36 + 1.37 + // Copy coefficient data. The two arrays share an allocation. 1.38 + mCoefficients = new ThreadSharedFloatArrayBufferList(2); 1.39 + float* buffer = static_cast<float*>(malloc(aLength*sizeof(float)*2)); 1.40 + if (buffer == nullptr) { 1.41 + aRv.Throw(NS_ERROR_OUT_OF_MEMORY); 1.42 + return; 1.43 + } 1.44 + PodCopy(buffer, aRealData, aLength); 1.45 + mCoefficients->SetData(0, buffer, buffer); 1.46 + PodCopy(buffer+aLength, aImagData, aLength); 1.47 + mCoefficients->SetData(1, nullptr, buffer+aLength); 1.48 +} 1.49 + 1.50 +size_t 1.51 +PeriodicWave::SizeOfExcludingThisIfNotShared(MallocSizeOf aMallocSizeOf) const 1.52 +{ 1.53 + // Not owned: 1.54 + // - mContext 1.55 + size_t amount = 0; 1.56 + if (!mCoefficients->IsShared()) { 1.57 + amount += mCoefficients->SizeOfIncludingThis(aMallocSizeOf); 1.58 + } 1.59 + 1.60 + return amount; 1.61 +} 1.62 + 1.63 +JSObject* 1.64 +PeriodicWave::WrapObject(JSContext* aCx) 1.65 +{ 1.66 + return PeriodicWaveBinding::Wrap(aCx, this); 1.67 +} 1.68 + 1.69 +} // namespace dom 1.70 +} // namespace mozilla 1.71 +