Bug 1296531 - Add AudioGenerator to TestAudioTrackEncoder for simple generation of audio. r=jesup
authorAndreas Pehrson <pehrsons@gmail.com>
Tue, 16 May 2017 12:39:39 +0200
changeset 383037 3c010e4b44e04db2a9517e7eaae8dec04d0d4cb9
parent 383036 a832d1310e6391a32751313b33a566aff47809bd
child 383038 463b0c40f07ec416c279a25e681810c692e0b55e
push id32582
push userkwierso@gmail.com
push dateWed, 27 Sep 2017 00:11:27 +0000
treeherdermozilla-central@70158e4e215d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs1296531
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1296531 - Add AudioGenerator to TestAudioTrackEncoder for simple generation of audio. r=jesup MozReview-Commit-ID: Cj9pyLZ3RR6
dom/media/gtest/TestAudioTrackEncoder.cpp
--- a/dom/media/gtest/TestAudioTrackEncoder.cpp
+++ b/dom/media/gtest/TestAudioTrackEncoder.cpp
@@ -1,18 +1,44 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "gtest/gtest.h"
 #include "OpusTrackEncoder.h"
+#include "SineWaveGenerator.h"
 
 using namespace mozilla;
 
+class AudioGenerator
+{
+public:
+  AudioGenerator(int32_t aChannels, int32_t aSampleRate)
+    : mGenerator(aSampleRate, 1000)
+    , mChannels(aChannels)
+  {}
+
+  void Generate(AudioSegment& aSegment, const int32_t& aSamples)
+  {
+    RefPtr<SharedBuffer> buffer = SharedBuffer::Create(aSamples * sizeof(int16_t));
+    int16_t* dest = static_cast<int16_t*>(buffer->Data());
+    mGenerator.generate(dest, aSamples);
+    AutoTArray<const int16_t*, 1> channels;
+    for (int32_t i = 0; i < mChannels; i++) {
+      channels.AppendElement(dest);
+    }
+    aSegment.AppendFrames(buffer.forget(), channels, aSamples, PRINCIPAL_HANDLE_NONE);
+  }
+
+private:
+  SineWaveGenerator mGenerator;
+  const int32_t mChannels;
+};
+
 class TestOpusTrackEncoder : public OpusTrackEncoder
 {
 public:
   // Return true if it has successfully initialized the Opus encoder.
   bool TestOpusCreation(int aChannels, int aSamplingRate)
   {
     if (Init(aChannels, aSamplingRate) == NS_OK) {
       if (GetPacketDuration()) {