Replacing CaringBuffer for Swift

What could be a good Swift replacement for the C ++ CARingBuffer class in a sound application that uses only the following API:

CARingBuffer *mBuffer = new CARingBuffer() mBuffer->Allocate(...) mBuffer->Store(...) mBuffer->Fetch(...) mBuffer->GetTimeBounds(...) 

Thanks!

Update : Interested in a clean Swift implementation (without C / C ++ bridge).

Udpate 2 : the Swift implementation allowed the use of a low-level C API, such as memcpy , OSAtomicCompareAndSwapLongBarrier , etc.

Update 3 . Assume that the linker problems addressed to Whole Module Optimization are temporary and will be resolved in the new version of the swift toolchain.

Update 4 : after implementing CARingBuffer in Swift and performing performance tests (C ++ and Swift), I got some numbers

2,000,000 cycles (2 channels, 44100 Hz, 512 samples per frame, buffer capacity 4096 frames)

  • C ++: 0.48s
  • Swift: 0.58s (1.208 slower)

20,000,000 cycles

  • C ++: 4.8s
  • Swift: 6.3s (1.313 slower)

200 million cycles

  • C ++: 47.43s
  • Swift: 58.13s (1.226 slower)
+6
source share

All Articles