diff options
author | Max Kellermann <max@musicpd.org> | 2020-05-28 15:16:16 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2020-07-01 22:05:11 +0200 |
commit | cdf706259708ad1a96193ce6ac01d9df9e40a9b0 (patch) | |
tree | 5cb94421cb932fd2a95585a835a65a7699608ece /src/apple | |
parent | 346084da1edc6a14e07c147d04915bee381de513 (diff) |
apple/AudioUnit: wrapper functions for AudioObject properties
Diffstat (limited to 'src/apple')
-rw-r--r-- | src/apple/AudioUnit.hxx | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/src/apple/AudioUnit.hxx b/src/apple/AudioUnit.hxx new file mode 100644 index 000000000..99b5b7bf2 --- /dev/null +++ b/src/apple/AudioUnit.hxx @@ -0,0 +1,97 @@ +/* + * Copyright 2020 Max Kellermann <max.kellermann@gmail.com> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef APPLE_AUDIO_OBJECT_HXX +#define APPLE_AUDIO_OBJECT_HXX + +#include "Throw.hxx" +#include "util/AllocatedArray.hxx" + +#include <CoreAudio/AudioHardware.h> + +#include <cstddef> + +std::size_t +AudioObjectGetPropertyDataSize(AudioObjectID inObjectID, + const AudioObjectPropertyAddress &inAddress) +{ + UInt32 size; + OSStatus status = AudioObjectGetPropertyDataSize(inObjectID, + &inAddress, + 0, nullptr, &size); + if (status != noErr) + Apple::ThrowOSStatus(status); + + return size; +} + +template<typename T> +T +AudioObjectGetPropertyDataT(AudioObjectID inObjectID, + const AudioObjectPropertyAddress &inAddress) +{ + OSStatus status; + UInt32 size = sizeof(T); + T value; + + status = AudioObjectGetPropertyData(inObjectID, &inAddress, + 0, nullptr, + &size, &value); + if (status != noErr) + Apple::ThrowOSStatus(status); + + return value; +} + +template<typename T> +AllocatedArray<T> +AudioObjectGetPropertyDataArray(AudioObjectID inObjectID, + const AudioObjectPropertyAddress &inAddress) +{ + OSStatus status; + UInt32 size; + + status = AudioObjectGetPropertyDataSize(inObjectID, + &inAddress, + 0, nullptr, &size); + if (status != noErr) + Apple::ThrowOSStatus(status); + + AllocatedArray<T> result(size / sizeof(T)); + + status = AudioObjectGetPropertyData(inObjectID, &inAddress, + 0, nullptr, + &size, result.begin()); + if (status != noErr) + Apple::ThrowOSStatus(status); + + return result; +} + +#endif |