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 constexpr int32_t REQ_ARG = 2;
main(int argc,char * argv[])35 int main(int argc, char *argv[])
36 {
37     if (argc != REQ_ARG) {
38         AUDIO_ERR_LOG("input parameter number error, argc: %{public}d", argc);
39         return -1;
40     }
41 
42     int32_t toneType = atoi(argv[1]);
43     AudioRendererInfo rendererInfo = {};
44     rendererInfo.contentType = ContentType::CONTENT_TYPE_MUSIC;
45     rendererInfo.streamUsage = StreamUsage::STREAM_USAGE_MEDIA;
46     rendererInfo.rendererFlags = 0;
47     shared_ptr<TonePlayer> lToneGen = TonePlayer::Create(rendererInfo);
48     AUDIO_INFO_LOG("Load Tone for %{public}d ", toneType);
49     lToneGen->LoadTone((ToneType)toneType);
50     AUDIO_INFO_LOG("start Tone.");
51     lToneGen->StartTone();
52     usleep(30000); // 30ms sleep time
53     AUDIO_INFO_LOG("stop Tone.");
54     lToneGen->StopTone();
55     AUDIO_INFO_LOG("release Tone.");
56     lToneGen->Release();
57     return 0;
58 }
59