Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

rewrote enqueueBuffer without allocations #88

Merged
merged 1 commit into from
Aug 23, 2020

Conversation

mgkuhn
Copy link
Contributor

@mgkuhn mgkuhn commented Aug 20, 2020

This new version of enqueueBuffer is now type stable and no longer performs any allocations.

Benefits:

  • better thread safety (Julia does not allow allocations in C callbacks)
  • better real-time performance: less risk of garbage collection during playback.

Other improvements:

  • fixes Artifacts in sound played by wavplay #69 such that enqueueBuffer no longer duplicates last sample of each buf in next buf
  • increases buffer size from 4 kiB to 16 kiB, to reduce risk of dropouts (Artifacts in sound played by wavplay #69)
  • modernized handling of references: callback function now receives Ref{AudioQueueData{T,n}} instead of Ptr{AudioQueueData}, so fewer unsafe_load/store! calls needed
  • replaced UnionAll type Array with concrete type Array{T,N} in userData
  • replaced 1-element Array hacks with Ref{}()
  • AudioQueueEnqueueBuffer is now a simple wrapper, i.e. could now also be used by a future wavrecord() extension to queue empty buffers for recording audio
  • new wavplay parameter assertion limits ndims of input array to 1 or 2 at compile time, thus eliminating a previous run-time check in enqueueBuffer

This new version of `enqueueBuffer` is now type stable and no longer performs any allocations.

Benefits:
* better thread safety (Julia does not allow allocations in C callbacks)
* better real-time performance: less risk of garbage collection during playback.

Other improvements:
* fixes dancasimiro#69 such that enqueueBuffer no longer duplicates last sample of each buf in next buf
* increases buffer size from 4 kiB to 16 kiB, to reduce risk of dropouts (dancasimiro#69)
* modernized handling of references: callback function now receives `Ref{AudioQueueData{T,n}}` instead of `Ptr{AudioQueueData}`, so fewer unsafe_load/store! calls needed
* replaced UnionAll type `Array` with concrete type `Array{T,N}` in `userData`
* replaced 1-element Array hacks with Ref{}()
* `AudioQueueEnqueueBuffer` is now a simple wrapper, i.e. could now also be used by a future wavrecord() extension to queue empty buffers for recording audio
* new wavplay parameter assertion limits ndims of input array to 1 or 2 at compile time, thus eliminating a previous run-time check in enqueueBuffer
@coveralls
Copy link

coveralls commented Aug 20, 2020

Coverage Status

Coverage increased (+1.3%) to 68.282% when pulling b977c03 on mgkuhn:fix-macos-wavplay into 715dfaa on dancasimiro:main.

@dancasimiro dancasimiro merged commit e182794 into dancasimiro:main Aug 23, 2020
@dancasimiro
Copy link
Owner

Thanks for another great contribution!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Artifacts in sound played by wavplay
3 participants