• 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 #include <cstdio>
16 #include <cstdlib>
17 #include <cstring>
18 #include <iostream>
19 #include <chrono>
20 #include <thread>
21 #include <vector>
22 
23 #include "tone_player_private.h"
24 #include "audio_log.h"
25 
26 using namespace std;
27 using namespace OHOS;
28 using namespace OHOS::AudioStandard;
29 
30 constexpr int32_t REQ_ARG = 2;
main(int argc,char * argv[])31 int main(int argc, char *argv[])
32 {
33     if (argc != REQ_ARG) {
34         AUDIO_ERR_LOG("input parameter number error, argc: %{public}d", argc);
35         return -1;
36     }
37 
38     int32_t toneType = atoi(argv[1]);
39     AudioRendererInfo rendererInfo = {};
40     rendererInfo.contentType = ContentType::CONTENT_TYPE_MUSIC;
41     rendererInfo.streamUsage = StreamUsage::STREAM_USAGE_MEDIA;
42     rendererInfo.rendererFlags = 0;
43     shared_ptr<TonePlayer> lToneGen = TonePlayer::Create(rendererInfo);
44     AUDIO_INFO_LOG("Load Tone for %{public}d ", toneType);
45     lToneGen->LoadTone((ToneType)toneType);
46     AUDIO_INFO_LOG("start Tone.");
47     lToneGen->StartTone();
48     usleep(30000); // 30ms sleep time
49     AUDIO_INFO_LOG("stop Tone.");
50     lToneGen->StopTone();
51     AUDIO_INFO_LOG("release Tone.");
52     lToneGen->Release();
53     return 0;
54 }
55