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 "chre/platform/linux/audio_source.h"
18
19 #include "chre/platform/fatal_error.h"
20
21 namespace chre {
22
AudioSource(const std::string & audioFilename,double minBufferDuration,double maxBufferDuration)23 AudioSource::AudioSource(const std::string &audioFilename,
24 double minBufferDuration, double maxBufferDuration)
25 : audioFilename(audioFilename),
26 minBufferDuration(
27 static_cast<uint64_t>(minBufferDuration * kOneSecondInNanoseconds)),
28 maxBufferDuration(
29 static_cast<uint64_t>(maxBufferDuration * kOneSecondInNanoseconds)) {
30 if (!timer.init()) {
31 FATAL_ERROR("Failed to initialize audio source timer");
32 }
33 }
34
~AudioSource()35 AudioSource::~AudioSource() {
36 if (dataEvent.samplesULaw8 != nullptr) {
37 free(reinterpret_cast<void *>(
38 const_cast<uint8_t *>(dataEvent.samplesULaw8)));
39 }
40 }
41
42 } // namespace chre
43