Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
miniaudio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
miniaudio
Commits
9af45f3b
Commit
9af45f3b
authored
Jun 30, 2018
by
David Reid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More tweaks to the Core Audio backend.
parent
1eaf97d0
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
28 deletions
+51
-28
mini_al.h
mini_al.h
+51
-28
No files found.
mini_al.h
View file @
9af45f3b
...
...
@@ -13247,6 +13247,33 @@ mal_result mal_get_AudioObject_closest_buffer_size_in_frames(AudioObjectID devic
return MAL_SUCCESS;
}
mal_result mal_set_AudioObject_buffer_size_in_frames(AudioObjectID deviceObjectID, mal_device_type deviceType, mal_uint32* pBufferSizeInOut)
{
mal_uint32 chosenBufferSizeInFrames;
mal_result result = mal_get_AudioObject_closest_buffer_size_in_frames(deviceObjectID, deviceType, *pBufferSizeInOut, &chosenBufferSizeInFrames);
if (result != MAL_SUCCESS) {
return result;
}
// Try setting the size of the buffer... If this fails we just use whatever is currently set.
AudioObjectPropertyAddress propAddress;
propAddress.mSelector = kAudioDevicePropertyBufferFrameSize;
propAddress.mScope = (deviceType == mal_device_type_playback) ? kAudioObjectPropertyScopeOutput : kAudioObjectPropertyScopeInput;
propAddress.mElement = kAudioObjectPropertyElementMaster;
OSStatus status = AudioObjectSetPropertyData(deviceObjectID, &propAddress, 0, NULL, sizeof(chosenBufferSizeInFrames), &chosenBufferSizeInFrames);
if (status != kAudioHardwareNoError) {
// Getting here means we were unable to set the buffer size. In this case just use whatever is currently selected.
UInt32 dataSize = sizeof(*pBufferSizeInOut);
OSStatus status = AudioObjectGetPropertyData(deviceObjectID, &propAddress, 0, NULL, &dataSize, pBufferSizeInOut);
if (status != kAudioHardwareNoError) {
return mal_result_from_OSStatus(status);
}
}
return MAL_SUCCESS;
}
mal_result mal_find_AudioObjectID(mal_context* pContext, mal_device_type type, const mal_device_id* pDeviceID, AudioObjectID* pDeviceObjectID)
{
...
...
@@ -13758,13 +13785,6 @@ mal_thread_result MAL_THREADCALL mal_AudioQueue_worker_thread__coreaudio(void* p
// An error occurred while stopping the audio queue... just continue on I suppose...
}
#if 0
status = AudioQueueReset((AudioQueueRef)pDevice->coreaudio.audioQueue);
if (status != kAudioHardwareNoError) {
// Don't think we need to do anything if resetting fails.
}
#endif
// Make sure the client is notified that the device has stopped, but make sure it's done after the status has been set.
mal_stop_proc onStop = pDevice->onStop;
if (onStop) {
...
...
@@ -13830,47 +13850,50 @@ mal_result mal_device_init__coreaudio(mal_context* pContext, mal_device_type dev
// Buffer size.
mal_uint32
requestedBufferSizeInFrames = pDevice->bufferSizeInFrames / pDevice->period
s;
if (
requestedBufferSizeInFrames == 0
) {
requestedBufferSizeInFrames = 1
;
mal_uint32
actualBufferSizeInFrames = pDevice->bufferSizeInFrame
s;
if (
actualBufferSizeInFrames < pDevice->periods
) {
actualBufferSizeInFrames = pDevice->periods
;
}
if (pDevice->usingDefaultBufferSize) {
// CPU speed is a factor to consider when determine how large of a buffer we need.
float fCPUSpeed = mal_calculate_cpu_speed_factor();
#if 0 // TODO: Test capture latency.
// In my testing, capture seems to have worse latency than playback for some reason.
float fType;
if (type == mal_device_type_playback) {
fType = 1.0f;
// In my admittedly limited testing, capture latency seems to be about the same as playback with Core Audio, at least on my MacBook Pro. On other
// backends, however, this is often different. I am therefore leaving the logic below in place just in case I need to do some capture/playback
// specific tweaking.
float fDeviceType;
if (deviceType == mal_device_type_playback) {
fDeviceType = 1.0f;
} else {
f
Type = 2
.0f;
f
DeviceType = 1
.0f;
}
#else
float fType = 1.0f;
#endif
// Backend tax. Need to fiddle with this.
float fBackend =
1.5f; // <-- mini_al's implementation is actually kind of bad at the moment. TODO: Revisit this after AudioUnit implementation.
float fBackend =
0.5f;
requestedBufferSizeInFrames = mal_calculate_default_buffer_size_in_frames(pConfig->performanceProfile, pConfig->sampleRate, fCPUSpeed*f
Type*fBackend);
if (
requestedBufferSizeInFrames == 0
) {
requestedBufferSizeInFrames = 1
;
actualBufferSizeInFrames = mal_calculate_default_buffer_size_in_frames(pConfig->performanceProfile, pConfig->sampleRate, fCPUSpeed*fDevice
Type*fBackend);
if (
actualBufferSizeInFrames < pDevice->periods
) {
actualBufferSizeInFrames = pDevice->periods
;
}
}
mal_uint32 closestBufferSizeInFrames;
result = mal_get_AudioObject_closest_buffer_size_in_frames(deviceObjectID, deviceType, requestedBufferSizeInFrames, &closestBufferSizeInFrames);
actualBufferSizeInFrames = actualBufferSizeInFrames / pDevice->periods;
result = mal_set_AudioObject_buffer_size_in_frames(deviceObjectID, deviceType, &actualBufferSizeInFrames);
if (result != MAL_SUCCESS) {
return result;
}
// The audio queue is initialized in the worker thread.
We need a signal to know when the thread has been initialized.
// The audio queue is initialized in the worker thread.
mal_AudioQueue_worker_thread_data__coreaudio threadData;
threadData.pDevice = pDevice;
threadData.queueBufferSizeInBytes = closestBufferSizeInFrames * mal_get_bytes_per_frame(pDevice->internalFormat, pDevice->internalChannels);
// In my testing, it appears that Core Audio likes queue buffers to be larger than device's IO buffer which was set above.
threadData.queueBufferSizeInBytes = actualBufferSizeInFrames*2 * mal_get_bytes_per_frame(pDevice->internalFormat, pDevice->internalChannels);
// We need a signal to know when the thread has been initialized.
mal_event_init(pDevice->pContext, &threadData.initCompletionEvent);
// The Core Audio backend is not using the main worker thread object so we can just reuse that one.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment