Skip to content

Commit a589794

Browse files
committed
[asio] added reset
1 parent bd9eae3 commit a589794

File tree

2 files changed

+45
-13
lines changed

2 files changed

+45
-13
lines changed

src/framework/audio/driver/platform/win/asio/asioaudiodriver.cpp

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
*/
2222
#include "asioaudiodriver.h"
2323

24+
#include "global/async/notification.h"
25+
2426
#undef UNICODE
2527
#include "ASIOSDK/common/asiosys.h"
2628
#include "ASIOSDK/common/asio.h"
@@ -32,6 +34,7 @@ using namespace muse;
3234
using namespace muse::audio;
3335

3436
struct AsioData {
37+
// Drivers list
3538
AsioDrivers drivers;
3639

3740
// ASIOInit()
@@ -64,6 +67,9 @@ struct AsioData {
6467

6568
// ASIOCallbacks
6669
ASIOCallbacks callbacks;
70+
71+
// Reset
72+
async::Notification resetRequest;
6773
};
6874

6975
static AsioData s_adata;
@@ -267,28 +273,29 @@ static ASIOTime* s_bufferSwitchTimeInfo(ASIOTime* /*params*/, long index, ASIOBo
267273
return nullptr;
268274
}
269275

276+
static void s_resetRequest()
277+
{
278+
s_adata.resetRequest.notify();
279+
}
280+
270281
static void s_sampleRateChanged(ASIOSampleRate rate)
271282
{
272283
LOGI() << "rate: " << rate;
284+
s_resetRequest();
273285
}
274286

275-
static long s_asioMessages(long selector, long value, void* message, double* /*opt*/)
287+
static long s_asioMessages(long selector, long value, void* /*message*/, double* /*opt*/)
276288
{
277289
LOGI() << "selector: " << selector
278-
<< "value: " << value
279-
<< "message: " << (const char*)message;
290+
<< " value: " << value;
280291

281292
long ret = 0;
282293
switch (selector) {
283294
case kAsioSelectorSupported:
284295
if (value == kAsioEngineVersion
285-
// || value == kAsioResetRequest
286-
// || value == kAsioResyncRequest
287-
// || value == kAsioLatenciesChanged
288-
// // the following three were added for ASIO 2.0, you don't necessarily have to support them
289-
// || value == kAsioSupportsTimeInfo
290-
// || value == kAsioSupportsTimeCode
291-
// || value == kAsioSupportsInputMonitor
296+
|| value == kAsioResetRequest
297+
|| value == kAsioResyncRequest
298+
|| value == kAsioLatenciesChanged
292299
) {
293300
ret = 1L;
294301
}
@@ -298,22 +305,28 @@ static long s_asioMessages(long selector, long value, void* message, double* /*o
298305
// You cannot reset the driver right now, as this code is called from the driver.
299306
// Reset the driver is done by completely destruct is. I.e. ASIOStop(), ASIODisposeBuffers(), Destruction
300307
// Afterwards you initialize the driver again.
301-
ret = 0L;
308+
s_resetRequest();
309+
ret = 1L;
302310
break;
311+
case kAsioBufferSizeChange:
312+
s_resetRequest();
313+
ret = 1L;
303314
case kAsioResyncRequest:
304315
// This informs the application, that the driver encountered some non fatal data loss.
305316
// It is used for synchronization purposes of different media.
306317
// Added mainly to work around the Win16Mutex problems in Windows 95/98 with the
307318
// Windows Multimedia system, which could loose data because the Mutex was hold too long
308319
// by another thread.
309320
// However a driver can issue it in other situations, too.
321+
s_resetRequest();
310322
ret = 1L;
311323
break;
312324
case kAsioLatenciesChanged:
313325
// This will inform the host application that the drivers were latencies changed.
314326
// Beware, it this does not mean that the buffer sizes have changed!
315327
// You might need to update internal delay data.
316-
ret = 0L;
328+
s_resetRequest();
329+
ret = 1L;
317330
break;
318331
case kAsioEngineVersion:
319332
// return the supported ASIO version of the host application
@@ -489,6 +502,10 @@ bool AsioAudioDriver::doOpen(const AudioDeviceID& device, const Spec& spec, Spec
489502
return ok;
490503
}
491504

505+
s_adata.resetRequest.onNotify(this, [this]() {
506+
reset();
507+
}, async::Asyncable::Mode::SetReplace);
508+
492509
m_running = true;
493510
m_thread = std::thread([this]() {
494511
bool ok = ASIOStart() == ASE_OK;
@@ -532,6 +549,18 @@ void AsioAudioDriver::close()
532549
s_adata.drivers.removeCurrentDriver();
533550
}
534551

552+
void AsioAudioDriver::reset()
553+
{
554+
LOGI() << "! driver reset called";
555+
if (!isOpened()) {
556+
return;
557+
}
558+
559+
Spec spec = s_adata.activeSpec;
560+
close();
561+
open(spec, nullptr);
562+
}
563+
535564
bool AsioAudioDriver::isOpened() const
536565
{
537566
return m_running;

src/framework/audio/driver/platform/win/asio/asioaudiodriver.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626

2727
#include "../../../../iaudiodriver.h"
2828

29+
#include "global/async/asyncable.h"
30+
2931
namespace muse::audio {
30-
class AsioAudioDriver : public IAudioDriver
32+
class AsioAudioDriver : public IAudioDriver, public async::Asyncable
3133
{
3234
public:
3335
AsioAudioDriver();
@@ -63,6 +65,7 @@ class AsioAudioDriver : public IAudioDriver
6365
private:
6466

6567
bool doOpen(const AudioDeviceID& device, const Spec& spec, Spec* activeSpec);
68+
void reset();
6669

6770
std::thread m_thread;
6871
std::atomic<bool> m_running = false;

0 commit comments

Comments
 (0)