• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #ifndef LOG_TAG
16 #define LOG_TAG "AudioTonePlayerTest"
17 #endif
18 
19 #include <cstdio>
20 #include <cstdlib>
21 #include <cstring>
22 #include <iostream>
23 #include <chrono>
24 #include <thread>
25 #include <vector>
26 
27 #include "tone_player_impl.h"
28 #include "audio_common_log.h"
29 
30 using namespace std;
31 using namespace OHOS;
32 using namespace OHOS::AudioStandard;
33 
34 // usgae audio_toneplayer_test 3 1000000
35 constexpr int32_t REQ_ARG = 3;
36 constexpr int32_t MAX_SLEEP_TIME_US = 10000000;
main(int argc,char * argv[])37 int main(int argc, char *argv[])
38 {
39     if (argc != REQ_ARG) {
40         AUDIO_ERR_LOG("input parameter number error, argc: %{public}d", argc);
41         return -1;
42     }
43 
44     char *endptr = nullptr;
45     int32_t toneType = atoi(argv[1]);
46     long sleepTimeTemp = strtol(argv[2], &endptr, 10);
47     if (*endptr != '\0' || sleepTimeTemp <= 0 || sleepTimeTemp > MAX_SLEEP_TIME_US) {
48         AUDIO_ERR_LOG("Invalid Time: %ld", sleepTimeTemp);
49         return -1;
50     }
51     int32_t sleepTime = static_cast<int32_t>(sleepTimeTemp);
52     AudioRendererInfo rendererInfo = {};
53     rendererInfo.streamUsage = StreamUsage::STREAM_USAGE_RINGTONE;
54     rendererInfo.rendererFlags = 0;
55     shared_ptr<TonePlayer> lToneGen = TonePlayer::Create(rendererInfo);
56     AUDIO_INFO_LOG("Load Tone for %{public}d ", toneType);
57     lToneGen->LoadTone((ToneType)toneType);
58     AUDIO_INFO_LOG("start Tone.");
59     lToneGen->StartTone();
60     usleep(sleepTime);
61     AUDIO_INFO_LOG("stop Tone.");
62     lToneGen->StopTone();
63     AUDIO_INFO_LOG("release Tone.");
64     lToneGen->Release();
65     return 0;
66 }
67