Skip to content

Commit 999bece

Browse files
author
zhaoyongqiang
committed
修改pcm sleep时间
1 parent 96a89de commit 999bece

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

iOS/APIExample/Common/ExternalAudio/AgoraPcmSourcePush.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,18 @@ class AgoraPcmSourcePush: NSObject {
5959
let bufferSize = self.samples * self.bitPerSample / 8 * self.channelsPerFrame
6060
let sleepTime = TimeInterval(self.samples) / TimeInterval(self.sampleRate)
6161
let buffer = UnsafeMutablePointer<UInt8>.allocate(capacity: bufferSize)
62+
var index: Double = 0
63+
var firstPush: Double = 0
6264
while input.hasBytesAvailable && self.state == .Play {
63-
let beforePush = CFAbsoluteTimeGetCurrent()
65+
if firstPush == 0 {
66+
firstPush = CFAbsoluteTimeGetCurrent()
67+
}
6468
input.read(buffer, maxLength: bufferSize)
65-
// self.delegate?.onAudioFrame(data: Data(bytes: buffer, count: bufferSize))
6669
self.delegate?.onAudioFrame(data: buffer)
67-
let afterPush = CFAbsoluteTimeGetCurrent()
68-
let sleep = sleepTime - (afterPush - beforePush)
70+
let nextPush = firstPush + index * sleepTime
71+
let sleep = nextPush - CFAbsoluteTimeGetCurrent()
6972
Thread.sleep(forTimeInterval: sleep)
73+
index += 1
7074
}
7175
buffer.deallocate()
7276
input.close()

0 commit comments

Comments
 (0)