• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
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 __USB_AUDIO_SYNC_H__
16 #define __USB_AUDIO_SYNC_H__
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 #include "plat_types.h"
23 
24 typedef uint32_t (*USB_AUDIO_SYNC_TIME_TO_MS)(uint32_t time);
25 
26 enum UAUD_SYNC_RET_T {
27     UAUD_SYNC_IDLE,
28     UAUD_SYNC_START,
29     UAUD_SYNC_ERR,
30 };
31 
32 struct USB_AUDIO_STREAM_INFO_T {
33     // Difference error threshold
34     uint16_t err_thresh;
35     // Difference synchronization threshold
36     uint16_t sync_thresh;
37     // Sample rate
38     uint32_t samp_rate;
39     // Total sample count of the buffer
40     uint32_t samp_cnt;
41     // The number of value to calculate the average
42     uint8_t diff_avg_cnt;
43     // The stream info ID
44     uint8_t id;
45     // Whether to enable diff_target
46     uint8_t diff_target_enabled;
47     // The Max adjust ratio moving to diff_target
48     float max_target_ratio;
49     // The abosulte difference value between current diff and diff_target to apply max_target_ratio
50     uint32_t max_target_thresh;
51     // The target of the difference
52     int diff_target;
53     // Function to convert timestamp to ms. If NULL, default timer will be used.
54     USB_AUDIO_SYNC_TIME_TO_MS time_to_ms;
55     // Current timestamp. If time_to_ms is NULL, this member will be ignored.
56     uint32_t time;
57     // Internal control block
58     uint32_t ctrl_block[8];
59 };
60 
61 void usb_audio_sync_reset(struct USB_AUDIO_STREAM_INFO_T *info);
62 
63 int usb_audio_sync_normalize_diff(int diff, uint32_t size);
64 
65 enum UAUD_SYNC_RET_T usb_audio_sync(uint32_t pos_a, uint32_t pos_b, struct USB_AUDIO_STREAM_INFO_T *info, float *p_ratio);
66 
67 #ifdef __cplusplus
68 }
69 #endif
70 
71 #endif
72