Browse Source

improved WASAPI latency reporting

tags/2021-05-28
Julian Storer 15 years ago
parent
commit
173abbccd2
3 changed files with 72 additions and 39 deletions
  1. +47
    -19
      juce_amalgamated.cpp
  2. +6
    -4
      juce_amalgamated.h
  3. +19
    -16
      src/native/windows/juce_win32_WASAPI.cpp

+ 47
- 19
juce_amalgamated.cpp View File

@@ -81078,7 +81078,7 @@ bool DrawablePath::readXml (const XmlElement& xml)


const String jointStyle (xml.getStringAttribute (T("jointStyle"), String::empty)); const String jointStyle (xml.getStringAttribute (T("jointStyle"), String::empty));
const String endStyle (xml.getStringAttribute (T("capStyle"), String::empty)); const String endStyle (xml.getStringAttribute (T("capStyle"), String::empty));
strokeType = PathStrokeType (xml.getDoubleAttribute (T("strokeWidth"), 0.0),
strokeType = PathStrokeType ((float) xml.getDoubleAttribute (T("strokeWidth"), 0.0),
jointStyle.equalsIgnoreCase (T("curved")) ? PathStrokeType::curved jointStyle.equalsIgnoreCase (T("curved")) ? PathStrokeType::curved
: (jointStyle.equalsIgnoreCase (T("bevel")) ? PathStrokeType::beveled : (jointStyle.equalsIgnoreCase (T("bevel")) ? PathStrokeType::beveled
: PathStrokeType::mitered), : PathStrokeType::mitered),
@@ -246804,17 +246804,15 @@ class WASAPIAudioIODevice : public AudioIODevice,
{ {
public: public:
WASAPIAudioIODevice (const String& deviceName, WASAPIAudioIODevice (const String& deviceName,
const int outputDeviceIndex_, const String& outputDeviceId_,
const int inputDeviceIndex_, const String& inputDeviceId_)
const String& outputDeviceId_,
const String& inputDeviceId_)
: AudioIODevice (deviceName, "Windows Audio"), : AudioIODevice (deviceName, "Windows Audio"),
Thread ("Juce WASAPI"), Thread ("Juce WASAPI"),
isOpen_ (false), isOpen_ (false),
isStarted (false), isStarted (false),
outputDevice (0), outputDevice (0),
outputDeviceIndex (outputDeviceIndex_),
outputDeviceId (outputDeviceId_), outputDeviceId (outputDeviceId_),
inputDevice (0), inputDevice (0),
inputDeviceIndex (inputDeviceIndex_),
inputDeviceId (inputDeviceId_), inputDeviceId (inputDeviceId_),
currentBufferSizeSamples (0), currentBufferSizeSamples (0),
currentSampleRate (0), currentSampleRate (0),
@@ -246867,12 +246865,10 @@ public:
int n = 64; int n = 64;
for (int i = 0; i < 40; ++i) for (int i = 0; i < 40; ++i)
{ {
if (n >= minBufferSize && ! bufferSizes.contains (n))
if (n >= minBufferSize && n <= 2048 && ! bufferSizes.contains (n))
bufferSizes.addSorted (comparator, n); bufferSizes.addSorted (comparator, n);


n += (n < 512) ? 32
: ((n < 1024) ? 64
: ((n < 2048) ? 128 : 256));
n += (n < 512) ? 32 : (n < 1024 ? 64 : 128);
} }


return true; return true;
@@ -246940,20 +246936,28 @@ public:
return lastError; return lastError;
} }


if (inputDevice != 0)
ResetEvent (inputDevice->clientEvent);
if (outputDevice != 0)
ResetEvent (outputDevice->clientEvent);

startThread (8);
Thread::sleep (5);

if (inputDevice != 0 && inputDevice->client != 0) if (inputDevice != 0 && inputDevice->client != 0)
{ {
latencyIn = inputDevice->latencySamples + inputDevice->actualBufferSize + inputDevice->minBufferSize;
HRESULT hr = inputDevice->client->Start(); HRESULT hr = inputDevice->client->Start();
logFailure (hr); //xxx handle this logFailure (hr); //xxx handle this
} }


if (outputDevice != 0 && outputDevice->client != 0) if (outputDevice != 0 && outputDevice->client != 0)
{ {
latencyOut = outputDevice->latencySamples + outputDevice->actualBufferSize + outputDevice->minBufferSize;
HRESULT hr = outputDevice->client->Start(); HRESULT hr = outputDevice->client->Start();
logFailure (hr); //xxx handle this logFailure (hr); //xxx handle this
} }


startThread (8);

isOpen_ = true; isOpen_ = true;
return lastError; return lastError;
} }
@@ -247079,7 +247083,6 @@ public:


juce_UseDebuggingNewOperator juce_UseDebuggingNewOperator


int outputDeviceIndex, inputDeviceIndex;
String outputDeviceId, inputDeviceId; String outputDeviceId, inputDeviceId;
String lastError; String lastError;


@@ -247229,7 +247232,7 @@ public:
jassert (hasScanned); // need to call scanForDevices() before doing this jassert (hasScanned); // need to call scanForDevices() before doing this


return wantInputNames ? inputDeviceNames return wantInputNames ? inputDeviceNames
: outputDeviceNames;
: outputDeviceNames;
} }


int getDefaultDeviceIndex (const bool /*forInput*/) const int getDefaultDeviceIndex (const bool /*forInput*/) const
@@ -247241,9 +247244,9 @@ public:
int getIndexOfDevice (AudioIODevice* device, const bool asInput) const int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
{ {
jassert (hasScanned); // need to call scanForDevices() before doing this jassert (hasScanned); // need to call scanForDevices() before doing this

WASAPIAudioIODevice* const d = dynamic_cast <WASAPIAudioIODevice*> (device); WASAPIAudioIODevice* const d = dynamic_cast <WASAPIAudioIODevice*> (device);
return (d == 0) ? -1 : (asInput ? d->inputDeviceIndex : d->outputDeviceIndex);
return d == 0 ? -1 : (asInput ? inputDeviceIds.indexOf (d->inputDeviceId)
: outputDeviceIds.indexOf (d->outputDeviceId));
} }


bool hasSeparateInputsAndOutputs() const { return true; } bool hasSeparateInputsAndOutputs() const { return true; }
@@ -247262,8 +247265,8 @@ public:
{ {
d = new WASAPIAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName d = new WASAPIAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
: inputDeviceName, : inputDeviceName,
outputIndex, outputDeviceIds [outputIndex],
inputIndex, inputDeviceIds [inputIndex]);
outputDeviceIds [outputIndex],
inputDeviceIds [inputIndex]);


if (! d->initialise()) if (! d->initialise())
deleteAndZero (d); deleteAndZero (d);
@@ -257711,9 +257714,15 @@ bool juce_copyFile (const String& src, const String& dst) throw()
NSFileManager* fm = [NSFileManager defaultManager]; NSFileManager* fm = [NSFileManager defaultManager];


return [fm fileExistsAtPath: juceStringToNS (src)] return [fm fileExistsAtPath: juceStringToNS (src)]
#if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
&& [fm copyItemAtPath: juceStringToNS (src)
toPath: juceStringToNS (dst)
error: nil];
#else
&& [fm copyPath: juceStringToNS (src) && [fm copyPath: juceStringToNS (src)
toPath: juceStringToNS (dst) toPath: juceStringToNS (dst)
handler: nil]; handler: nil];
#endif
} }


const StringArray juce_getFileSystemRoots() throw() const StringArray juce_getFileSystemRoots() throw()
@@ -258260,7 +258269,9 @@ void Desktop::setMousePosition (int x, int y) throw()
// this rubbish needs to be done around the warp call, to avoid causing a // this rubbish needs to be done around the warp call, to avoid causing a
// bizarre glitch.. // bizarre glitch..
CGAssociateMouseAndMouseCursorPosition (false); CGAssociateMouseAndMouseCursorPosition (false);
#if (! defined (MAC_OS_X_VERSION_10_6)) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6
CGSetLocalEventsSuppressionInterval (0); CGSetLocalEventsSuppressionInterval (0);
#endif


CGPoint pos = { x, y }; CGPoint pos = { x, y };
CGWarpMouseCursorPosition (pos); CGWarpMouseCursorPosition (pos);
@@ -258325,8 +258336,13 @@ void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
{ {
if (screenSaverDisablerID == 0) if (screenSaverDisablerID == 0)
{ {
IOPMAssertionCreate (kIOPMAssertionTypeNoIdleSleep,
kIOPMAssertionLevelOn, &screenSaverDisablerID);
#if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
IOPMAssertionCreateWithName (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
CFSTR ("Juce"), &screenSaverDisablerID);
#else
IOPMAssertionCreate (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
&screenSaverDisablerID);
#endif
} }
} }
} }
@@ -258479,7 +258495,11 @@ END_JUCE_NAMESPACE


#define JuceNSWindow MakeObjCClassName(JuceNSWindow) #define JuceNSWindow MakeObjCClassName(JuceNSWindow)


#if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
@interface JuceNSWindow : NSWindow <NSWindowDelegate>
#else
@interface JuceNSWindow : NSWindow @interface JuceNSWindow : NSWindow
#endif
{ {
@private @private
NSViewComponentPeer* owner; NSViewComponentPeer* owner;
@@ -260793,7 +260813,11 @@ using namespace JUCE_NAMESPACE;


#define JuceMenuCallback MakeObjCClassName(JuceMenuCallback) #define JuceMenuCallback MakeObjCClassName(JuceMenuCallback)


#if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
@interface JuceMenuCallback : NSObject <NSMenuDelegate>
#else
@interface JuceMenuCallback : NSObject @interface JuceMenuCallback : NSObject
#endif
{ {
JuceMainMenuHandler* owner; JuceMainMenuHandler* owner;
} }
@@ -261270,7 +261294,11 @@ using namespace JUCE_NAMESPACE;


#define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate) #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)


#if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
@interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
#else
@interface JuceFileChooserDelegate : NSObject @interface JuceFileChooserDelegate : NSObject
#endif
{ {
StringArray* filters; StringArray* filters;
} }


+ 6
- 4
juce_amalgamated.h View File

@@ -37216,7 +37216,9 @@ public:
/** Creates an audio thumbnail. /** Creates an audio thumbnail.


@param sourceSamplesPerThumbnailSample when creating a stored, low-res version @param sourceSamplesPerThumbnailSample when creating a stored, low-res version
of the audio data, this is the scale at which it should be done
of the audio data, this is the scale at which it should be done. (This
number is the number of original samples that will be averaged for each
low-res sample)
@param formatManagerToUse the audio format manager that is used to open the file @param formatManagerToUse the audio format manager that is used to open the file
@param cacheToUse an instance of an AudioThumbnailCache - this provides a background @param cacheToUse an instance of an AudioThumbnailCache - this provides a background
thread and storage that is used to by the thumbnail, and the cache thread and storage that is used to by the thumbnail, and the cache
@@ -37261,7 +37263,7 @@ public:
*/ */
int getNumChannels() const throw(); int getNumChannels() const throw();


/** Returns the length of the audio file.
/** Returns the length of the audio file, in seconds.
*/ */
double getTotalLength() const throw(); double getTotalLength() const throw();


@@ -37277,8 +37279,8 @@ public:
*/ */
void drawChannel (Graphics& g, void drawChannel (Graphics& g,
int x, int y, int w, int h, int x, int y, int w, int h,
double startTime,
double endTime,
double startTimeSeconds,
double endTimeSeconds,
int channelNum, int channelNum,
const float verticalZoomFactor); const float verticalZoomFactor);




+ 19
- 16
src/native/windows/juce_win32_WASAPI.cpp View File

@@ -557,17 +557,15 @@ class WASAPIAudioIODevice : public AudioIODevice,
{ {
public: public:
WASAPIAudioIODevice (const String& deviceName, WASAPIAudioIODevice (const String& deviceName,
const int outputDeviceIndex_, const String& outputDeviceId_,
const int inputDeviceIndex_, const String& inputDeviceId_)
const String& outputDeviceId_,
const String& inputDeviceId_)
: AudioIODevice (deviceName, "Windows Audio"), : AudioIODevice (deviceName, "Windows Audio"),
Thread ("Juce WASAPI"), Thread ("Juce WASAPI"),
isOpen_ (false), isOpen_ (false),
isStarted (false), isStarted (false),
outputDevice (0), outputDevice (0),
outputDeviceIndex (outputDeviceIndex_),
outputDeviceId (outputDeviceId_), outputDeviceId (outputDeviceId_),
inputDevice (0), inputDevice (0),
inputDeviceIndex (inputDeviceIndex_),
inputDeviceId (inputDeviceId_), inputDeviceId (inputDeviceId_),
currentBufferSizeSamples (0), currentBufferSizeSamples (0),
currentSampleRate (0), currentSampleRate (0),
@@ -620,12 +618,10 @@ public:
int n = 64; int n = 64;
for (int i = 0; i < 40; ++i) for (int i = 0; i < 40; ++i)
{ {
if (n >= minBufferSize && ! bufferSizes.contains (n))
if (n >= minBufferSize && n <= 2048 && ! bufferSizes.contains (n))
bufferSizes.addSorted (comparator, n); bufferSizes.addSorted (comparator, n);
n += (n < 512) ? 32
: ((n < 1024) ? 64
: ((n < 2048) ? 128 : 256));
n += (n < 512) ? 32 : (n < 1024 ? 64 : 128);
} }
return true; return true;
@@ -694,20 +690,28 @@ public:
return lastError; return lastError;
} }
if (inputDevice != 0)
ResetEvent (inputDevice->clientEvent);
if (outputDevice != 0)
ResetEvent (outputDevice->clientEvent);
startThread (8);
Thread::sleep (5);
if (inputDevice != 0 && inputDevice->client != 0) if (inputDevice != 0 && inputDevice->client != 0)
{ {
latencyIn = inputDevice->latencySamples + inputDevice->actualBufferSize + inputDevice->minBufferSize;
HRESULT hr = inputDevice->client->Start(); HRESULT hr = inputDevice->client->Start();
logFailure (hr); //xxx handle this logFailure (hr); //xxx handle this
} }
if (outputDevice != 0 && outputDevice->client != 0) if (outputDevice != 0 && outputDevice->client != 0)
{ {
latencyOut = outputDevice->latencySamples + outputDevice->actualBufferSize + outputDevice->minBufferSize;
HRESULT hr = outputDevice->client->Start(); HRESULT hr = outputDevice->client->Start();
logFailure (hr); //xxx handle this logFailure (hr); //xxx handle this
} }
startThread (8);
isOpen_ = true; isOpen_ = true;
return lastError; return lastError;
} }
@@ -835,7 +839,6 @@ public:
juce_UseDebuggingNewOperator juce_UseDebuggingNewOperator
//============================================================================== //==============================================================================
int outputDeviceIndex, inputDeviceIndex;
String outputDeviceId, inputDeviceId; String outputDeviceId, inputDeviceId;
String lastError; String lastError;
@@ -990,7 +993,7 @@ public:
jassert (hasScanned); // need to call scanForDevices() before doing this jassert (hasScanned); // need to call scanForDevices() before doing this
return wantInputNames ? inputDeviceNames return wantInputNames ? inputDeviceNames
: outputDeviceNames;
: outputDeviceNames;
} }
int getDefaultDeviceIndex (const bool /*forInput*/) const int getDefaultDeviceIndex (const bool /*forInput*/) const
@@ -1002,9 +1005,9 @@ public:
int getIndexOfDevice (AudioIODevice* device, const bool asInput) const int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
{ {
jassert (hasScanned); // need to call scanForDevices() before doing this jassert (hasScanned); // need to call scanForDevices() before doing this
WASAPIAudioIODevice* const d = dynamic_cast <WASAPIAudioIODevice*> (device); WASAPIAudioIODevice* const d = dynamic_cast <WASAPIAudioIODevice*> (device);
return (d == 0) ? -1 : (asInput ? d->inputDeviceIndex : d->outputDeviceIndex);
return d == 0 ? -1 : (asInput ? inputDeviceIds.indexOf (d->inputDeviceId)
: outputDeviceIds.indexOf (d->outputDeviceId));
} }
bool hasSeparateInputsAndOutputs() const { return true; } bool hasSeparateInputsAndOutputs() const { return true; }
@@ -1023,8 +1026,8 @@ public:
{ {
d = new WASAPIAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName d = new WASAPIAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
: inputDeviceName, : inputDeviceName,
outputIndex, outputDeviceIds [outputIndex],
inputIndex, inputDeviceIds [inputIndex]);
outputDeviceIds [outputIndex],
inputDeviceIds [inputIndex]);
if (! d->initialise()) if (! d->initialise())
deleteAndZero (d); deleteAndZero (d);


Loading…
Cancel
Save