CARingBuffer replacement for Swift

Viewed 324

What might be good Swift replacement for C++ class CARingBuffer in audio application which uses just following API:

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

Thank you!

Update: Interested in pure Swift implementation (without C/C++ bridging).

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

Update 3: Lets assume that linker issues addressed to Whole Module Optimization are temporary and will be solved in newer version of swift toolchain.

Update 4: After implementing CARingBuffer in Swift and running 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 000 000 cycles

  • C++: 47.43s
  • Swift: 58.13s (1.226 slower)
0 Answers
Related