Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eda323a

Browse files
author
Arlin
committed
Add localizable string by mac
1 parent 7e596fe commit eda323a

File tree

3 files changed

+52
-44
lines changed

3 files changed

+52
-44
lines changed

macOS/APIExample/Examples/Advanced/SpatialAudio/SpatialAudio.storyboard

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
<autoresizingMask key="autoresizingMask"/>
1616
<subviews>
1717
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="UvV-gm-It5">
18-
<rect key="frame" x="179" y="337" width="200" height="19"/>
19-
<textFieldCell key="cell" lineBreakMode="clipping" alignment="center" title="请插入耳机体验3d音效效果" id="0XP-YK-KuI">
20-
<font key="font" metaFont="systemBold" size="15"/>
18+
<rect key="frame" x="28" y="339" width="501" height="17"/>
19+
<textFieldCell key="cell" lineBreakMode="clipping" alignment="center" title="请插入耳机体验空间音效效果" id="0XP-YK-KuI">
20+
<font key="font" metaFont="system" size="14"/>
2121
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
2222
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
2323
</textFieldCell>
@@ -30,7 +30,7 @@
3030
<rect key="frame" x="235" y="43" width="88" height="32"/>
3131
<buttonCell key="cell" type="push" title="点击开始" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="xq7-uK-ra9">
3232
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
33-
<font key="font" size="13" name=".PingFangSC-Regular"/>
33+
<font key="font" metaFont="system"/>
3434
</buttonCell>
3535
<connections>
3636
<action selector="startBtnClicked:" target="bU7-R8-ocO" id="6hd-oy-xrM"/>
@@ -45,8 +45,10 @@
4545
<constraints>
4646
<constraint firstItem="hEk-AE-m2b" firstAttribute="centerX" secondItem="tOy-S4-hL0" secondAttribute="centerX" id="6oe-Hm-eOk"/>
4747
<constraint firstAttribute="bottom" secondItem="hEk-AE-m2b" secondAttribute="bottom" constant="50" id="EgA-UC-GeC"/>
48+
<constraint firstItem="UvV-gm-It5" firstAttribute="leading" secondItem="tOy-S4-hL0" secondAttribute="leading" constant="30" id="HYQ-od-ZcL"/>
4849
<constraint firstItem="2od-fj-kri" firstAttribute="centerX" secondItem="tOy-S4-hL0" secondAttribute="centerX" id="cdY-YD-Z4S"/>
4950
<constraint firstItem="UvV-gm-It5" firstAttribute="top" secondItem="tOy-S4-hL0" secondAttribute="top" constant="35" id="r6L-Tp-InT"/>
51+
<constraint firstAttribute="trailing" secondItem="UvV-gm-It5" secondAttribute="trailing" constant="30" id="sNx-nc-TiX"/>
5052
<constraint firstItem="UvV-gm-It5" firstAttribute="centerX" secondItem="tOy-S4-hL0" secondAttribute="centerX" id="vgg-2s-vB4"/>
5153
<constraint firstItem="2od-fj-kri" firstAttribute="centerY" secondItem="tOy-S4-hL0" secondAttribute="centerY" id="yyy-lM-ah3"/>
5254
</constraints>

macOS/APIExample/Examples/Advanced/SpatialAudio/SpatialAudio.swift

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ class SpatialAudioMain: BaseViewController {
3939
}
4040

4141
func setupUI() {
42-
infoLabel.stringValue = "请插入耳机体验3d音效效果".localized
42+
infoLabel.stringValue = "Please insert headphones to experience the spatial audio effect".localized
43+
startButton.title = "Start".localized
4344

4445
let panGesture = NSPanGestureRecognizer(target: self, action: #selector(panGestureChanged))
4546
self.soundSourceView.addGestureRecognizer(panGesture)
@@ -63,10 +64,12 @@ class SpatialAudioMain: BaseViewController {
6364
self.peopleView.isHidden = false
6465
self.soundSourceView.isHidden = false
6566
} else {
66-
self.infoLabel.stringValue = "你会听到一段音乐, \(self.downCount - timeout)秒后这段音乐会通过空间音效的方式播放"
67+
let text = "You will hear a piece of music, and after 10 seconds this piece of music will be played through spatial audio effects".localized
68+
self.infoLabel.stringValue = "\(text)(\(self.downCount - timeout))"
6769
}
6870
} else {
69-
self.infoLabel.stringValue = "现在您可以移动喇叭图标到不同的位置, 体验空间音效效果(\(self.downCount))".localized
71+
let text = "Now you can move the speaker icon to experience the spatial audio effect".localized
72+
self.infoLabel.stringValue = "\(text)(\(self.downCount))"
7073
if self.downCount == 0 {
7174
self.agoraKit.stopEchoTest()
7275
self.agoraKit.enableSpatialAudio(false)
@@ -75,56 +78,56 @@ class SpatialAudioMain: BaseViewController {
7578
self.peopleView.isHidden = true
7679
self.soundSourceView.isHidden = true
7780
self.startButton.isHidden = false
78-
self.infoLabel.stringValue = "请插入耳机体验空间音效效果".localized
81+
self.infoLabel.stringValue = "Please insert headphones to experience the spatial audio effect".localized
7982
}
8083
}
8184
}
8285
}
8386

8487
@objc func panGestureChanged(gesture: NSPanGestureRecognizer) {
85-
let circleCenter = CGPoint(x: NSMidX(self.peopleView.frame), y: NSMidY(self.peopleView.frame))
8688
let move = gesture.translation(in: self.view)
87-
var newCenter = CGPoint(x: NSMidX(gesture.view!.frame), y: NSMidY(gesture.view!.frame))
88-
newCenter = CGPoint(x: newCenter.x + move.x, y: newCenter.y + move.y)
89-
90-
let deltaX = newCenter.x - circleCenter.x
91-
let deltaY = newCenter.y - circleCenter.y
92-
if deltaX == 0 {return}
93-
94-
// In spatial audio, angle is range [0, 360], it is angle 0 when at Y direction.
95-
let tanValue = abs(deltaY) / abs(deltaX)
96-
let tanAngle = atan(tanValue) * 180.0 / Double.pi
97-
var spatialAngle = 0.0
98-
if deltaX > 0 && deltaY > 0 { // scope I
99-
spatialAngle = 270.0 + tanAngle
100-
} else if deltaX < 0 && deltaY > 0 { // scope II
101-
spatialAngle = 90.0 - tanAngle
102-
} else if deltaX < 0 && deltaY < 0 { // scope III
103-
spatialAngle = 90.0 + tanAngle
104-
} else if deltaX > 0 && deltaY < 0 { // scope IV
105-
spatialAngle = 270.0 - tanAngle
106-
}
89+
var objectCenter = CGPoint(x: NSMidX(gesture.view!.frame), y: NSMidY(gesture.view!.frame))
90+
objectCenter = CGPoint(x: objectCenter.x + move.x, y: objectCenter.y + move.y)
10791

92+
let width = soundSourceView.frame.size.width
93+
soundSourceView.frame = CGRect(origin: CGPoint(x: objectCenter.x - width / 2.0, y: objectCenter.y - width / 2.0), size: CGSize(width: width, height: width))
94+
gesture.setTranslation(.zero, in: self.view)
95+
10896
if gesture.state == .ended {
109-
let L = sqrt(deltaX * deltaX + deltaY * deltaY)
110-
let maxL = (NSScreen.main?.frame.height)! / 2.0
111-
let maxSpatailDistance = 30.0
112-
let spatialDistance = L * maxSpatailDistance / maxL
113-
currentAngle = spatialAngle
114-
currentDistance = spatialDistance
115-
116-
self.updateRemoteUserSpatialAudioPositon()
97+
updatePosition(objectCenter: objectCenter)
11798
}
118-
119-
let width: CGFloat = self.soundSourceView.frame.size.width
120-
self.soundSourceView.frame = CGRect(origin: CGPoint(x: newCenter.x - width / 2.0, y: newCenter.y - width / 2.0), size: CGSize(width: width, height: width))
121-
gesture.setTranslation(.zero, in: self.view)
12299
}
123100

101+
func updatePosition(objectCenter: CGPoint) {
102+
let circleCenter = CGPoint(x: NSMidX(peopleView.frame), y: NSMidY(peopleView.frame))
103+
let deltaX = objectCenter.x - circleCenter.x
104+
let deltaY = objectCenter.y - circleCenter.y
105+
let R = sqrt(deltaX * deltaX + deltaY * deltaY)
106+
107+
// In spatial audio, angle is range [0, 360], it is angle 0 when at Y direction with anti-clockwise
108+
let TwoPI = Double.pi * 2.0
109+
let cosAngle = acos(deltaX / R)
110+
let mathAngle = deltaY > 0 ? cosAngle : (TwoPI - cosAngle)
111+
var spatialAngle = mathAngle - TwoPI / 4.0
112+
if spatialAngle < 0 {
113+
spatialAngle = TwoPI + spatialAngle
114+
}
115+
116+
currentAngle = spatialAngle
117+
currentDistance = R
118+
self.updateRemoteUserSpatialAudioPositon()
119+
}
120+
124121
func updateRemoteUserSpatialAudioPositon() {
122+
let maxR = self.view.frame.height / 2.0
123+
124+
let maxSpatailDistance = 30.0
125+
let spatialDistance = currentDistance * maxSpatailDistance / maxR
126+
let spatialAngle = currentAngle * 180.0 / Double.pi
127+
125128
let spatialParams = AgoraSpatialAudioParams()
126-
spatialParams.speaker_azimuth = .of(Double(currentAngle))
127-
spatialParams.speaker_distance = .of(currentDistance)
129+
spatialParams.speaker_azimuth = .of(spatialAngle)
130+
spatialParams.speaker_distance = .of(spatialDistance)
128131
spatialParams.speaker_elevation = .of(0)
129132
spatialParams.enable_blur = .of(false)
130133
spatialParams.enable_air_absorb = .of(true)

macOS/APIExample/zh-Hans.lproj/Localizable.strings

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,7 @@
171171
"Virtual Background" = "虚拟背景";
172172
"Blur Background" = "背景虚化";
173173
"Spatial Audio" = "空间音效";
174-
174+
"Start" = "点击开始";
175+
"Please insert headphones to experience the spatial audio effect" = "请插入耳机体验空间音效效果";
176+
"You will hear a piece of music, and after 10 seconds this piece of music will be played through spatial audio effects" = "你会听到一段音乐,10秒后这段音乐会通过空间音效的方式播放";
177+
"Now you can move the speaker icon to experience the spatial audio effect" = "现在您可以移动喇叭图标到不同的位置,体验空间音效效果";

0 commit comments

Comments
 (0)