• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "audio_debug.h"
16 #ifdef AUDIO_DATA_DEBUG
17 #include "intell_voice_log.h"
18 #include "time_util.h"
19 
20 #define LOG_TAG "AudioDebug"
21 #endif
22 
23 namespace OHOS {
24 namespace IntellVoiceEngine {
25 #ifdef AUDIO_DATA_DEBUG
26 
27 static const std::string PCM_DIR = "/data/data/intell_voice/pcm_data/";
28 
CreateAudioDebugFile(const std::string & suffix)29 void AudioDebug::CreateAudioDebugFile(const std::string &suffix)
30 {
31     DestroyAudioDebugFile();
32 
33     auto path = PCM_DIR + OHOS::IntellVoiceUtils::TimeUtil::GetCurrTime() + suffix+ ".pcm";
34     fileStream_ = std::make_unique<std::ofstream>(path);
35     if (fileStream_ == nullptr) {
36         INTELL_VOICE_LOG_ERROR("open debug record file failed");
37         return;
38     }
39 }
40 
WriteData(const char * data,uint32_t length)41 void AudioDebug::WriteData(const char *data, uint32_t length)
42 {
43     if (fileStream_ != nullptr) {
44         fileStream_->write(data, length);
45     }
46 }
47 
DestroyAudioDebugFile()48 void AudioDebug::DestroyAudioDebugFile()
49 {
50     if (fileStream_ != nullptr) {
51         fileStream_->close();
52         fileStream_ = nullptr;
53     }
54 }
55 
56 #else
57 
58 void AudioDebug::CreateAudioDebugFile(const std::string & /* suffix */)
59 {
60 }
61 
62 void AudioDebug::WriteData(const char * /* data */, uint32_t /* length */)
63 {
64 }
65 
66 void AudioDebug::DestroyAudioDebugFile()
67 {
68 }
69 #endif
70 }
71 }
72