Skip to content

Commit 5eeffe3

Browse files
committed
removed logic from osx driver
1 parent fa5a2b3 commit 5eeffe3

File tree

2 files changed

+26
-142
lines changed

2 files changed

+26
-142
lines changed

src/framework/audio/driver/platform/osx/osxaudiodriver.h

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -44,34 +44,22 @@ class OSXAudioDriver : public IAudioDriver
4444
void init() override;
4545

4646
std::string name() const override;
47+
48+
AudioDeviceID defaultDevice() const override;
49+
4750
bool open(const Spec& spec, Spec* activeSpec) override;
4851
void close() override;
4952
bool isOpened() const override;
5053

5154
const Spec& activeSpec() const override;
5255
async::Channel<Spec> activeSpecChanged() const override;
5356

54-
void resume() override;
55-
void suspend() override;
56-
57-
AudioDeviceID outputDevice() const override;
58-
bool selectOutputDevice(const AudioDeviceID& deviceId) override;
59-
bool resetToDefaultOutputDevice() override;
60-
async::Notification outputDeviceChanged() const override;
61-
6257
AudioDeviceList availableOutputDevices() const override;
6358
async::Notification availableOutputDevicesChanged() const override;
6459
void updateDeviceMap();
6560

66-
bool setOutputDeviceBufferSize(unsigned int bufferSize) override;
67-
async::Notification outputDeviceBufferSizeChanged() const override;
68-
69-
std::vector<unsigned int> availableOutputDeviceBufferSizes() const override;
70-
71-
bool setOutputDeviceSampleRate(unsigned int sampleRate) override;
72-
async::Notification outputDeviceSampleRateChanged() const override;
73-
74-
std::vector<unsigned int> availableOutputDeviceSampleRates() const override;
61+
std::vector<samples_t> availableOutputDeviceBufferSizes() const override;
62+
std::vector<sample_rate_t> availableOutputDeviceSampleRates() const override;
7563

7664
private:
7765
static void OnFillBuffer(void* context, OpaqueAudioQueue* queue, AudioQueueBuffer* buffer);
@@ -89,12 +77,7 @@ class OSXAudioDriver : public IAudioDriver
8977
async::Channel<Spec> m_activeSpecChanged;
9078
std::map<unsigned int, std::string> m_outputDevices = {}, m_inputDevices = {};
9179
mutable std::mutex m_devicesMutex;
92-
async::Notification m_outputDeviceChanged;
9380
async::Notification m_availableOutputDevicesChanged;
94-
AudioDeviceID m_deviceId;
95-
96-
async::Notification m_bufferSizeChanged;
97-
async::Notification m_sampleRateChanged;
9881
};
9982
}
10083
#endif // MUSE_AUDIO_OSXAUDIODRIVER_H

src/framework/audio/driver/platform/osx/osxaudiodriver.mm

Lines changed: 21 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
Spec format;
3939
AudioQueueRef audioQueue;
4040
Callback callback;
41-
void* mUserData;
4241
};
4342

4443
OSXAudioDriver::OSXAudioDriver()
@@ -49,8 +48,6 @@
4948

5049
initDeviceMapListener();
5150
updateDeviceMap();
52-
53-
m_deviceId = DEFAULT_DEVICE_ID;
5451
}
5552

5653
OSXAudioDriver::~OSXAudioDriver()
@@ -64,7 +61,12 @@
6461

6562
std::string OSXAudioDriver::name() const
6663
{
67-
return "MUAUDIO(OSX)";
64+
return "OSX";
65+
}
66+
67+
AudioDeviceID OSXAudioDriver::defaultDevice() const
68+
{
69+
return DEFAULT_DEVICE_ID;
6870
}
6971

7072
bool OSXAudioDriver::open(const Spec& spec, Spec* activeSpec)
@@ -77,9 +79,11 @@
7779
return 0;
7880
}
7981

80-
*activeSpec = spec;
81-
activeSpec->format = Format::AudioF32;
82-
m_data->format = *activeSpec;
82+
if (activeSpec) {
83+
*activeSpec = spec;
84+
}
85+
86+
m_data->format = spec;
8387
m_activeSpecChanged.send(m_data->format);
8488

8589
AudioStreamBasicDescription audioFormat;
@@ -88,21 +92,12 @@
8892
audioFormat.mFramesPerPacket = 1;
8993
audioFormat.mChannelsPerFrame = spec.output.audioChannelCount;
9094
audioFormat.mReserved = 0;
91-
switch (activeSpec->format) {
92-
case Format::AudioF32:
93-
audioFormat.mBitsPerChannel = 32;
94-
audioFormat.mFormatFlags = kLinearPCMFormatFlagIsFloat;
95-
break;
96-
case Format::AudioS16:
97-
audioFormat.mBitsPerChannel = 16;
98-
audioFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
99-
break;
100-
}
95+
audioFormat.mBitsPerChannel = 32;
96+
audioFormat.mFormatFlags = kLinearPCMFormatFlagIsFloat;
10197
audioFormat.mBytesPerPacket = audioFormat.mBitsPerChannel * spec.output.audioChannelCount / 8;
10298
audioFormat.mBytesPerFrame = audioFormat.mBytesPerPacket * audioFormat.mFramesPerPacket;
10399

104100
m_data->callback = spec.callback;
105-
m_data->mUserData = spec.userdata;
106101

107102
OSStatus result = AudioQueueNewOutput(&audioFormat, OnFillBuffer, m_data.get(), NULL, NULL, 0, &m_data->audioQueue);
108103
if (result != noErr) {
@@ -218,7 +213,7 @@
218213

219214
muse::audio::AudioDeviceID OSXAudioDriver::outputDevice() const
220215
{
221-
return m_deviceId;
216+
return m_data->format.deviceId;
222217
}
223218

224219
void OSXAudioDriver::updateDeviceMap()
@@ -306,34 +301,7 @@
306301
m_availableOutputDevicesChanged.notify();
307302
}
308303

309-
bool OSXAudioDriver::setOutputDeviceBufferSize(unsigned int bufferSize)
310-
{
311-
if (m_data->format.output.samplesPerChannel == bufferSize) {
312-
return true;
313-
}
314-
315-
bool reopen = isOpened();
316-
close();
317-
m_data->format.output.samplesPerChannel = bufferSize;
318-
319-
bool ok = true;
320-
if (reopen) {
321-
ok = open(m_data->format, &m_data->format);
322-
}
323-
324-
if (ok) {
325-
m_bufferSizeChanged.notify();
326-
}
327-
328-
return ok;
329-
}
330-
331-
async::Notification OSXAudioDriver::outputDeviceBufferSizeChanged() const
332-
{
333-
return m_bufferSizeChanged;
334-
}
335-
336-
std::vector<unsigned int> OSXAudioDriver::availableOutputDeviceBufferSizes() const
304+
std::vector<samples_t> OSXAudioDriver::availableOutputDeviceBufferSizes() const
337305
{
338306
OSXAudioDeviceID osxDeviceId = this->osxDeviceId();
339307
AudioObjectPropertyAddress bufferFrameSizePropertyAddress = {
@@ -350,11 +318,11 @@
350318
return {};
351319
}
352320

353-
unsigned int minimum = std::max(static_cast<samples_t>(range.mMinimum), MINIMUM_BUFFER_SIZE);
354-
unsigned int maximum = std::min(static_cast<samples_t>(range.mMaximum), MAXIMUM_BUFFER_SIZE);
321+
samples_t minimum = std::max(static_cast<samples_t>(range.mMinimum), MINIMUM_BUFFER_SIZE);
322+
samples_t maximum = std::min(static_cast<samples_t>(range.mMaximum), MAXIMUM_BUFFER_SIZE);
355323

356-
std::vector<unsigned int> result;
357-
for (unsigned int bufferSize = maximum; bufferSize >= minimum;) {
324+
std::vector<samples_t> result;
325+
for (samples_t bufferSize = maximum; bufferSize >= minimum;) {
358326
result.push_back(bufferSize);
359327
bufferSize /= 2;
360328
}
@@ -364,34 +332,7 @@
364332
return result;
365333
}
366334

367-
bool OSXAudioDriver::setOutputDeviceSampleRate(unsigned int sampleRate)
368-
{
369-
if (m_data->format.output.sampleRate == sampleRate) {
370-
return true;
371-
}
372-
373-
bool reopen = isOpened();
374-
close();
375-
m_data->format.output.sampleRate = sampleRate;
376-
377-
bool ok = true;
378-
if (reopen) {
379-
ok = open(m_data->format, &m_data->format);
380-
}
381-
382-
if (ok) {
383-
m_sampleRateChanged.notify();
384-
}
385-
386-
return ok;
387-
}
388-
389-
async::Notification OSXAudioDriver::outputDeviceSampleRateChanged() const
390-
{
391-
return m_sampleRateChanged;
392-
}
393-
394-
std::vector<unsigned int> OSXAudioDriver::availableOutputDeviceSampleRates() const
335+
std::vector<sample_rate_t> OSXAudioDriver::availableOutputDeviceSampleRates() const
395336
{
396337
return {
397338
44100,
@@ -471,46 +412,6 @@
471412
return QString::fromStdString(deviceId).toInt();
472413
}
473414

474-
bool OSXAudioDriver::selectOutputDevice(const AudioDeviceID& deviceId /*, unsigned int bufferSize*/)
475-
{
476-
if (m_deviceId == deviceId) {
477-
return true;
478-
}
479-
480-
bool reopen = isOpened();
481-
close();
482-
m_deviceId = deviceId;
483-
484-
bool ok = true;
485-
if (reopen) {
486-
ok = open(m_data->format, &m_data->format);
487-
}
488-
489-
if (ok) {
490-
m_outputDeviceChanged.notify();
491-
}
492-
493-
return ok;
494-
}
495-
496-
bool OSXAudioDriver::resetToDefaultOutputDevice()
497-
{
498-
return selectOutputDevice(DEFAULT_DEVICE_ID);
499-
}
500-
501-
async::Notification OSXAudioDriver::outputDeviceChanged() const
502-
{
503-
return m_outputDeviceChanged;
504-
}
505-
506-
void OSXAudioDriver::resume()
507-
{
508-
}
509-
510-
void OSXAudioDriver::suspend()
511-
{
512-
}
513-
514415
void OSXAudioDriver::logError(const std::string message, OSStatus error)
515416
{
516417
if (error == noErr) {
@@ -561,6 +462,6 @@ static OSStatus onDeviceListChanged(AudioObjectID inObjectID, UInt32 inNumberAdd
561462
void OSXAudioDriver::OnFillBuffer(void* context, AudioQueueRef, AudioQueueBufferRef buffer)
562463
{
563464
Data* pData = (Data*)context;
564-
pData->callback(pData->mUserData, (uint8_t*)buffer->mAudioData, buffer->mAudioDataByteSize);
465+
pData->callback((uint8_t*)buffer->mAudioData, buffer->mAudioDataByteSize);
565466
AudioQueueEnqueueBuffer(pData->audioQueue, buffer, 0, NULL);
566467
}

0 commit comments

Comments
 (0)