• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "gtest/gtest.h"
18 
19 #include "chre/core/audio_util.h"
20 
21 using chre::AudioUtil;
22 using chre::Nanoseconds;
23 
TEST(AudioDurationFromSampleCountAndRate,HalfSecond)24 TEST(AudioDurationFromSampleCountAndRate, HalfSecond) {
25   Nanoseconds duration =
26       AudioUtil::getDurationFromSampleCountAndRate(8000, 16000);
27   EXPECT_EQ(duration.toRawNanoseconds(), 500000000ull);
28 }
29 
TEST(AudioDurationFromSampleCountAndRate,OneSecond)30 TEST(AudioDurationFromSampleCountAndRate, OneSecond) {
31   Nanoseconds duration =
32       AudioUtil::getDurationFromSampleCountAndRate(16000, 16000);
33   EXPECT_EQ(duration.toRawNanoseconds(), 1000000000ull);
34 }
35 
TEST(AudioDurationFromSampleCountAndRate,OneHundredSecond)36 TEST(AudioDurationFromSampleCountAndRate, OneHundredSecond) {
37   Nanoseconds duration =
38       AudioUtil::getDurationFromSampleCountAndRate(1600000, 16000);
39   EXPECT_EQ(duration.toRawNanoseconds(), 100000000000ull);
40 }
41 
TEST(AudioSampleCountFromRateAndDuration,OneSample)42 TEST(AudioSampleCountFromRateAndDuration, OneSample) {
43   uint32_t sampleCount =
44       AudioUtil::getSampleCountFromRateAndDuration(16000, Nanoseconds(62500));
45   EXPECT_EQ(sampleCount, 1u);
46 }
47 
TEST(AudioSampleCountFromRateAndDuration,OneHundredSample)48 TEST(AudioSampleCountFromRateAndDuration, OneHundredSample) {
49   uint32_t sampleCount =
50       AudioUtil::getSampleCountFromRateAndDuration(16000, Nanoseconds(6250000));
51   EXPECT_EQ(sampleCount, 100u);
52 }
53 
TEST(AudioSampleCountFromRateAndDuration,OneThousandSample)54 TEST(AudioSampleCountFromRateAndDuration, OneThousandSample) {
55   uint32_t sampleCount = AudioUtil::getSampleCountFromRateAndDuration(
56       16000, Nanoseconds(62500000));
57   EXPECT_EQ(sampleCount, 1000u);
58 }
59