| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/speech/audio_buffer.h" | 5 #include "content/browser/speech/audio_buffer.h" |
| 6 #include "content/browser/speech/endpointer/endpointer.h" | 6 #include "content/browser/speech/endpointer/endpointer.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 8 |
| 9 namespace { | 9 namespace { |
| 10 const int kFrameRate = 50; // 20 ms long frames for AMR encoding. | 10 const int kFrameRate = 50; // 20 ms long frames for AMR encoding. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 // This test instantiates and initializes a stand alone endpointer module. | 66 // This test instantiates and initializes a stand alone endpointer module. |
| 67 // The test creates FrameData objects with random noise and send them | 67 // The test creates FrameData objects with random noise and send them |
| 68 // to the endointer module. The energy of the first 50 frames is low, | 68 // to the endointer module. The energy of the first 50 frames is low, |
| 69 // followed by 500 high energy frames, and another 50 low energy frames. | 69 // followed by 500 high energy frames, and another 50 low energy frames. |
| 70 // We test that the correct start and end frames were detected. | 70 // We test that the correct start and end frames were detected. |
| 71 class EnergyEndpointerFrameProcessor : public FrameProcessor { | 71 class EnergyEndpointerFrameProcessor : public FrameProcessor { |
| 72 public: | 72 public: |
| 73 explicit EnergyEndpointerFrameProcessor(EnergyEndpointer* endpointer) | 73 explicit EnergyEndpointerFrameProcessor(EnergyEndpointer* endpointer) |
| 74 : endpointer_(endpointer) {} | 74 : endpointer_(endpointer) {} |
| 75 | 75 |
| 76 virtual EpStatus ProcessFrame(int64 time, | 76 EpStatus ProcessFrame(int64 time, int16* samples, int frame_size) override { |
| 77 int16* samples, | |
| 78 int frame_size) override { | |
| 79 endpointer_->ProcessAudioFrame(time, samples, kFrameSize, NULL); | 77 endpointer_->ProcessAudioFrame(time, samples, kFrameSize, NULL); |
| 80 int64 ep_time; | 78 int64 ep_time; |
| 81 return endpointer_->Status(&ep_time); | 79 return endpointer_->Status(&ep_time); |
| 82 } | 80 } |
| 83 | 81 |
| 84 private: | 82 private: |
| 85 EnergyEndpointer* endpointer_; | 83 EnergyEndpointer* endpointer_; |
| 86 }; | 84 }; |
| 87 | 85 |
| 88 TEST(EndpointerTest, TestEnergyEndpointerEvents) { | 86 TEST(EndpointerTest, TestEnergyEndpointerEvents) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 111 | 109 |
| 112 endpointer.EndSession(); | 110 endpointer.EndSession(); |
| 113 }; | 111 }; |
| 114 | 112 |
| 115 // Test endpointer wrapper class. | 113 // Test endpointer wrapper class. |
| 116 class EndpointerFrameProcessor : public FrameProcessor { | 114 class EndpointerFrameProcessor : public FrameProcessor { |
| 117 public: | 115 public: |
| 118 explicit EndpointerFrameProcessor(Endpointer* endpointer) | 116 explicit EndpointerFrameProcessor(Endpointer* endpointer) |
| 119 : endpointer_(endpointer) {} | 117 : endpointer_(endpointer) {} |
| 120 | 118 |
| 121 virtual EpStatus ProcessFrame(int64 time, | 119 EpStatus ProcessFrame(int64 time, int16* samples, int frame_size) override { |
| 122 int16* samples, | |
| 123 int frame_size) override { | |
| 124 scoped_refptr<AudioChunk> frame( | 120 scoped_refptr<AudioChunk> frame( |
| 125 new AudioChunk(reinterpret_cast<uint8*>(samples), kFrameSize * 2, 2)); | 121 new AudioChunk(reinterpret_cast<uint8*>(samples), kFrameSize * 2, 2)); |
| 126 endpointer_->ProcessAudio(*frame.get(), NULL); | 122 endpointer_->ProcessAudio(*frame.get(), NULL); |
| 127 int64 ep_time; | 123 int64 ep_time; |
| 128 return endpointer_->Status(&ep_time); | 124 return endpointer_->Status(&ep_time); |
| 129 } | 125 } |
| 130 | 126 |
| 131 private: | 127 private: |
| 132 Endpointer* endpointer_; | 128 Endpointer* endpointer_; |
| 133 }; | 129 }; |
| 134 | 130 |
| 135 TEST(EndpointerTest, TestEmbeddedEndpointerEvents) { | 131 TEST(EndpointerTest, TestEmbeddedEndpointerEvents) { |
| 136 const int kSampleRate = 8000; // 8 k samples per second for AMR encoding. | 132 const int kSampleRate = 8000; // 8 k samples per second for AMR encoding. |
| 137 | 133 |
| 138 Endpointer endpointer(kSampleRate); | 134 Endpointer endpointer(kSampleRate); |
| 139 const int64 kMillisecondsPerMicrosecond = 1000; | 135 const int64 kMillisecondsPerMicrosecond = 1000; |
| 140 const int64 short_timeout = 300 * kMillisecondsPerMicrosecond; | 136 const int64 short_timeout = 300 * kMillisecondsPerMicrosecond; |
| 141 endpointer.set_speech_input_possibly_complete_silence_length(short_timeout); | 137 endpointer.set_speech_input_possibly_complete_silence_length(short_timeout); |
| 142 const int64 long_timeout = 500 * kMillisecondsPerMicrosecond; | 138 const int64 long_timeout = 500 * kMillisecondsPerMicrosecond; |
| 143 endpointer.set_speech_input_complete_silence_length(long_timeout); | 139 endpointer.set_speech_input_complete_silence_length(long_timeout); |
| 144 endpointer.StartSession(); | 140 endpointer.StartSession(); |
| 145 | 141 |
| 146 EndpointerFrameProcessor frame_processor(&endpointer); | 142 EndpointerFrameProcessor frame_processor(&endpointer); |
| 147 RunEndpointerEventsTest(&frame_processor); | 143 RunEndpointerEventsTest(&frame_processor); |
| 148 | 144 |
| 149 endpointer.EndSession(); | 145 endpointer.EndSession(); |
| 150 } | 146 } |
| 151 | 147 |
| 152 } // namespace content | 148 } // namespace content |
| OLD | NEW |