File tree Expand file tree Collapse file tree
iOS/APIExample/Common/ExternalAudio Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ( )
You can’t perform that action at this time.
0 commit comments