Skip to content

Commit

Permalink
#120 seems finally fixed with this
Browse files Browse the repository at this point in the history
  • Loading branch information
Wouter Pasman authored and Wouter Pasman committed Apr 24, 2020
1 parent 0dd03c7 commit 27f0837
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 21 deletions.
7 changes: 7 additions & 0 deletions src/EMUUSBAudio/EMUUSBAudioEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,7 @@ IOReturn EMUUSBAudioEngine::GetDefaultSettings(IOUSBInterface1 *streamInterface
} else {
info = &mOutput;
}
info -> sampleRate = sampleRate.whole;
info->interfaceNumber = ourInterfaceNumber;
info->streamDirection = direction;
info->streamInterface = streamInterface;
Expand Down Expand Up @@ -1192,7 +1193,9 @@ bool EMUUSBAudioEngine::initHardware (IOService *provider) {

CalculateSamplesPerFrame (sampleRate.whole, &averageFrameSamples, &additionalSampleFrameFreq);
// this calcs (frame size, etc.) could probably be simplified, but I'm leaving them this way for now (AC)
usbInputStream.sampleRate = sampleRate.whole;
usbInputStream.multFactor = usbInputStream.numChannels * (mChannelWidth / 8);
mOutput.sampleRate = sampleRate.whole;
mOutput.multFactor = mOutput.numChannels * (mChannelWidth / 8);
usbInputStream.maxFrameSize = (averageFrameSamples + 1) * usbInputStream.multFactor;
mOutput.maxFrameSize = (averageFrameSamples + 1) * mOutput.multFactor;
Expand Down Expand Up @@ -1517,6 +1520,7 @@ IOReturn EMUUSBAudioEngine::performFormatChangeInternal (IOAudioStream *audioStr
//}
usbInputStream.alternateSettingID = newAlternateSettingID;
mChannelWidth = newFormat->fBitWidth;
usbInputStream.sampleRate = sampleRate.whole;
usbInputStream.multFactor = usbInputStream.numChannels * (mChannelWidth / 8);
debugIOLogC("alternateFrameSize is %d", alternateFrameSize);
if (usbInputStream.maxFrameSize != alternateFrameSize) {
Expand Down Expand Up @@ -1556,6 +1560,7 @@ IOReturn EMUUSBAudioEngine::performFormatChangeInternal (IOAudioStream *audioStr
//}
mOutput.alternateSettingID = newAlternateSettingID;
mChannelWidth = newFormat->fBitWidth;
mOutput.sampleRate = sampleRate.whole;
mOutput.multFactor = mOutput.numChannels * (mChannelWidth / 8);
debugIOLogC("alternateFrameSize is %d", alternateFrameSize);
if (mOutput.maxFrameSize != alternateFrameSize) {
Expand Down Expand Up @@ -1742,7 +1747,9 @@ IOReturn EMUUSBAudioEngine::startUSBStream() {
usbInputStream.multFactor,newInputMultFactor,mOutput.multFactor,newOutputMultFactor);
usbInputStream.maxFrameSize = altFrameSampleSize * newInputMultFactor;
mOutput.maxFrameSize = altFrameSampleSize * newOutputMultFactor;
usbInputStream.sampleRate = sampleRate.whole;
usbInputStream.multFactor = newInputMultFactor;
mOutput.sampleRate = sampleRate.whole;
mOutput.multFactor = newOutputMultFactor;
debugIOLogC("pre initBuffers");
beginConfigurationChange();
Expand Down
9 changes: 6 additions & 3 deletions src/EMUUSBAudio/EMUUSBInputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,13 @@ IOReturn EMUUSBInputStream::gatherFromReadList() {

if (mDropStartingFrames <= 0)
{

UInt64 wrapTimeNs;
absolutetime_to_nanoseconds(pFrames[frameIndex].getTime(),&wrapTimeNs);
// FIXME. We should not call from inside locked area.
usbRing-> push(source, size , pFrames[frameIndex].getTime() );
frameSizeQueue-> push(size , pFrames[frameIndex].getTime());
// -0.5/1ms: we need start instead of end of frame. Frame size depends on
// usb microinterval but we don't (yet) have access to that here.
usbRing-> push(source, size ,wrapTimeNs- (sampleRate>96000? 500000: 1000000), 1000000000l/(sampleRate * multFactor) );
frameSizeQueue-> push(size , wrapTimeNs);

// if (frameIndex == 1) {
// debugIOLogC("latency %d",usbRing->available());
Expand Down
2 changes: 1 addition & 1 deletion src/EMUUSBAudio/EMUUSBLogging.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#define DEBUGZEROTIME TRUE
#define DEBUGLOADING TRUE
#define DEBUGTIMESTAMPS TRUE
//#define DEBUGLOGGING TRUE
#define DEBUGLOGGING TRUE


//#include <IOKit/usb/IOUSBLog.h>
Expand Down
2 changes: 1 addition & 1 deletion src/EMUUSBAudio/EMUUSBOutputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ IOReturn EMUUSBOutputStream::PrepareWriteFrameList (UInt32 listNr) {

if (frameSizeQueue->pop(&thisFrameSize) != kIOReturnSuccess) {
debugIOLog("frameSizeQueue empty, guessing some queue size. May need fix..");
thisFrameSize = stockSamplesInFrame * multFactor ;
thisFrameSize = (stockSamplesInFrame+1) * multFactor ;
}

if (thisFrameSize >= numBytesToBufferEnd) {
Expand Down
4 changes: 2 additions & 2 deletions src/EMUUSBAudio/LowPassFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
// to avoid the deviations grow above 1ms, yet as slow as possible
// to maximize the stability of the estimation.
#define K 1 // spring constant for filter
#define M 10000 // mass for the filter
#define DA 200 // 2 Sqrt[M K] for critical damping.
#define M 1000 // mass for the filter
#define DA 63 // 2 Sqrt[M K] for critical damping.


// where is math.h ?
Expand Down
6 changes: 3 additions & 3 deletions src/EMUUSBAudio/RingBufferDefault.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class RingBufferDefault: public RingBufferT<TYPE> {
}


IOReturn push(TYPE object, AbsoluteTime time) override{
IOReturn push(TYPE object, UInt64 time) override{
if (!buffer) {
return kIOReturnNotReady;
}
Expand All @@ -86,7 +86,7 @@ class RingBufferDefault: public RingBufferT<TYPE> {
return kIOReturnSuccess;
}

IOReturn push(TYPE *objects, UInt32 num, AbsoluteTime time) override{
IOReturn push(TYPE *objects, UInt32 num, UInt64 time, UInt32 time_per_obj) override{
if (!buffer) {
return kIOReturnNotReady;
}
Expand All @@ -97,7 +97,7 @@ class RingBufferDefault: public RingBufferT<TYPE> {
}
for ( UInt32 n = 0; n<num; n++) {
buffer[writehead++] = objects[n];
if (writehead == size) { writehead = 0; notifyWrap(time); }
if (writehead == size) { writehead = 0; notifyWrap(time + n * time_per_obj); }
}
return kIOReturnSuccess;
}
Expand Down
10 changes: 5 additions & 5 deletions src/EMUUSBAudio/RingBufferT.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,18 @@ template<typename T> class RingBufferT {
eg a timestamp from a USB frame.
@return kIOReturnSuccess if ok, possibly kIOReturnOverrun */

virtual IOReturn push( T object, AbsoluteTime time) = 0;
virtual IOReturn push( T object, UInt64 time) = 0;

/*! puts num objects in the ring. prints error and continues if overflow.
@param objects array[num] of num objects to push
@param num the number of objects in the array
@param time the time stamp associated with the objects.
@param time the time stamp associated with the first object, in system time ns.
This is typically the lowest level timestamp you can get our hands on,
eg a timestamp from a USB frame.
@param time_per_obj the time per object of type T (ns)
@return kIOReturnSuccess if ok, possibly kIOReturnOverrun */

virtual IOReturn push(T *objects, UInt32 num, AbsoluteTime time) = 0 ;
virtual IOReturn push(T *objects, UInt32 num, UInt64 time, UInt32 time_per_obj) = 0 ;

/* Get one object from the ring.
@param pointer to mem block to contain the object
Expand All @@ -71,10 +72,9 @@ template<typename T> class RingBufferT {

/*! called when the write head wraps back to 0. Overwrite to get notification.
@param time the time associated with the push of the object that caused the wrap.
*/

virtual void notifyWrap(AbsoluteTime time) = 0 ;
virtual void notifyWrap(UInt64 time) = 0 ;

/*! set the current read head position. CoreAudio may start reading at weird positions.
returns kIOReturnUnderrun if the head was repositioned (by lack of better return possibility). */
Expand Down
5 changes: 4 additions & 1 deletion src/EMUUSBAudio/StreamInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ struct StreamInfo {
/*! The point where the next raw USB byte can be written in bufferPtr. Always in [0, bufferSize> */
UInt32 bufferOffset;

/*! =numChannels * #bytes per sample for this stream = frame size.
/*! the current sample rate (sampleframes per second) */
UInt32 sampleRate;

/*! sampleframe size in bytes =numChannels * #bytes per sample for this stream.
this will be 6 for stereo 24 bit audio. */
UInt32 multFactor;

Expand Down
Binary file modified v11/.DS_Store
Binary file not shown.
10 changes: 5 additions & 5 deletions v11/EMUUSBAudio.kext/Contents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>16B2555</string>
<string>17G8030</string>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDisplayName</key>
Expand Down Expand Up @@ -31,17 +31,17 @@
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string>7A1001</string>
<string>7D175</string>
<key>DTPlatformVersion</key>
<string>GM</string>
<key>DTSDKBuild</key>
<string>15A278</string>
<string>15E60</string>
<key>DTSDKName</key>
<string>macosx10.11</string>
<key>DTXcode</key>
<string>0701</string>
<string>0730</string>
<key>DTXcodeBuild</key>
<string>7A1001</string>
<string>7D175</string>
<key>IOKitPersonalities</key>
<dict>
<key>EMUSBAudioTrackerPre</key>
Expand Down
Binary file modified v11/EMUUSBAudio.kext/Contents/MacOS/EMUUSBAudio
Binary file not shown.

0 comments on commit 27f0837

Please sign in to comment.