IOReturn eqMac2DriverEngine::performAudioEngineStart() { //IOLog("eqMac2DriverEngine[%p]::performAudioEngineStart()\n", this); // When performAudioEngineStart() gets called, the audio engine should be started from the beginning // of the sample buffer. Because it is starting on the first sample, a new timestamp is needed // to indicate when that sample is being read from/written to. The function takeTimeStamp() // is provided to do that automatically with the current time. // By default takeTimeStamp() will increment the current loop count in addition to taking the current // timestamp. Since we are starting a new audio engine run, and not looping, we don't want the loop count // to be incremented. To accomplish that, false is passed to takeTimeStamp(). // The audio engine will also have to take a timestamp each time the buffer wraps around // How that is implemented depends on the type of hardware - PCI hardware will likely // receive an interrupt to perform that task takeTimeStamp(false); currentBlock = 0; timerEventSource->setTimeout(blockTimeoutNS); uint64_t time; clock_get_uptime(&time); absolutetime_to_nanoseconds(time, &nextTime); nextTime += blockTimeoutNS; return kIOReturnSuccess; }
void PAEngine::writeSamplePointer(struct samplePointerUpdateEvent *ev) { if (ev->samplePointer >= NUM_SAMPLE_FRAMES) { debugIOLog("%s(%p)::%s bogus sample pointer (%d >= %d).\n", getName(), this, __func__, (int) ev->samplePointer, NUM_SAMPLE_FRAMES); return; } samplePointer = ev->samplePointer; if (samplePointer < lastSamplePointer) { samplePointer %= NUM_SAMPLE_FRAMES; takeTimeStamp(); } lastSamplePointer = samplePointer; }
std::uint64_t elapsedNanoseconds() { return takeTimeStamp() - m_startTime; }
double elapsed() const { return double(takeTimeStamp() - m_startTime) * 1e-9; }
void restart() { m_startTime = takeTimeStamp(); }
HighResolutionTimer() : m_startTime(takeTimeStamp()) {}
IOReturn kXAudioEngine::performAudioEngineStart() { // debug("kXAudioEngine[%p]::performAudioEngineStart() - %d\n", this,is_running); // When performAudioEngineStart() gets called, the audio engine should be started from the beginning // of the sample buffer. Because it is starting on the first sample, a new timestamp is needed // to indicate when that sample is being read from/written to. The function takeTimeStamp() // is provided to do that automatically with the current time. // By default takeTimeStamp() will increment the current loop count in addition to taking the current // timestamp. Since we are starting a new audio engine run, and not looping, we don't want the loop count // to be incremented. To accomplish that, false is passed to takeTimeStamp(). dword low=0,high=0; int first=-1; for(int i=0;i<KX_NUMBER_OF_VOICES;i++) { if(hw->voicetable[i].usage&VOICE_USAGE_ASIO && hw->voicetable[i].asio_id==this) { if(i>=32) high|=(1<<(i-32)); else low|=(1<<i); if(first==-1) first=i; } } if(first!=-1) { // zero sample position, too for(int i=0;i<32;i++) { if(low&(1<<i)) kx_wave_set_position(hw,i,0); if(high&(1<<i)) kx_wave_set_position(hw,i+32,0); } // debug("kXAudioEngine[%p]::performAudioEngineStart: start audio [%d; %x %x]\n",this,first,(unsigned)low,(unsigned)high); kx_wave_start_multiple(hw,first,low,high); } // recording dword sz; switch(hw->mtr_buffer.size) { case 384: sz=ADCBS_BUFSIZE_384; break; case 448: sz=ADCBS_BUFSIZE_448; break; case 512: sz=ADCBS_BUFSIZE_512; break; case 640: sz=ADCBS_BUFSIZE_640; break; case 768: sz=ADCBS_BUFSIZE_768; break; case 896: sz=ADCBS_BUFSIZE_896; break; case 1024: sz=ADCBS_BUFSIZE_1024; break; case 1280: sz=ADCBS_BUFSIZE_1280; break; case 1536: sz=ADCBS_BUFSIZE_1536; break; case 1792: sz=ADCBS_BUFSIZE_1792; break; case 2048: sz=ADCBS_BUFSIZE_2048; break; case 2560: sz=ADCBS_BUFSIZE_2560; break; case 3072: sz=ADCBS_BUFSIZE_3072; break; case 3584: sz=ADCBS_BUFSIZE_3584; break; case 4096: sz=ADCBS_BUFSIZE_4096; break; case 5120: sz=ADCBS_BUFSIZE_5120; break; case 6144: sz=ADCBS_BUFSIZE_6144; break; case 7168: sz=ADCBS_BUFSIZE_7168; break; case 8192: sz=ADCBS_BUFSIZE_8192; break; case 10240: sz=ADCBS_BUFSIZE_10240; break; case 12288: sz=ADCBS_BUFSIZE_12288; break; case 14366: sz=ADCBS_BUFSIZE_14366; break; case 16384: sz=ADCBS_BUFSIZE_16384; break; case 20480: sz=ADCBS_BUFSIZE_20480; break; case 24576: sz=ADCBS_BUFSIZE_24576; break; case 28672: sz=ADCBS_BUFSIZE_28672; break; case 32768: sz=ADCBS_BUFSIZE_32768; break; case 40960: sz=ADCBS_BUFSIZE_40960; break; case 49152: sz=ADCBS_BUFSIZE_49152; break; case 57344: sz=ADCBS_BUFSIZE_57344; break; default: case 65536: sz=ADCBS_BUFSIZE_65536; break; } //debug("performAudioEngineStart FXBS:\n"); //kx_writeptr_prof(hw, FXBS, 0, sz); kx_writeptr(hw, FXBS, 0, sz); hw->asio_notification_krnl.active=1; is_running=1; takeTimeStamp(false); return kIOReturnSuccess; }