{
32, 64, 96, 128, 192, 256, 512, 1024, 2048
};
-
+
///< The default SR.
static const int DEFAULT_SR = 44100;
///< Number of stalls to wait before notifying user...
static const int NUM_STALLS_FOR_NOTIFICATION = 100; // 100 corresponds to 100 x 42 ms idle timer - about 4 seconds.
static const int CHANGE_CHECK_COUNTER_PERIOD = 100; // 120 corresponds to 120 x 42 ms idle timer - about 4 seconds.
-
+
#define HUNDRED_NANO_TO_MILLI_CONSTANT 10000
#define CONSUMPTION_CALCULATION_INTERVAL 500 // Milli Seconds
}
else
std::cout << "API::Device " << m_DeviceName << " Device does not support any sample rate of ours" << std::endl;
-
+
//should use a valid current buffer size
if (m_BufferSizes.size())
{
m_CurrentBufferSize = m_BufferSizes[0];
}
}
-
+
//build our input/output level lists
for (unsigned int currentChannel = 0; currentChannel < m_InputChannels.size(); currentChannel++)
{
{
stopStreaming();
}
-
+
//If device is active (meaning stream is open) we need to close it.
if (Active())
{
WTErr WCMRPortAudioDevice::UpdateDeviceInfo ()
{
std::cout << "API::Device (ID:)" << m_DeviceID << " Updating device info" << std::endl;
-
+
SignalObjectAndWait(m_hUpdateDeviceInfoRequestedEvent, m_hUpdateDeviceInfoDone, INFINITE, false);
return eNoErr;
//get device info
const PaDeviceInfo *pDeviceInfo = Pa_GetDeviceInfo(m_DeviceID);
-
+
//update name.
m_DeviceName = pDeviceInfo->name;
////////////////////////////////////////////////////////////////////////////////////
//update list of supported SRs...
m_SamplingRates.clear();
-
+
// now iterate through our standard SRs and check if they are supported by device
// store them for this device
for(int sr=0; gAllSampleRates[sr] > 0; sr++)
// In ASIO Windows, the buffer size is set from the sound device manufacturer's control panel
long minSize, maxSize, preferredSize, granularity;
PaError err = PaAsio_GetAvailableBufferSizes(m_DeviceID, &minSize, &maxSize, &preferredSize, &granularity);
-
+
if (err == paNoError)
{
std::cout << "API::Device " << m_DeviceName << " Buffers: " << minSize << " " << maxSize << " " << preferredSize << std::endl;
-
+
m_BufferSizes.push_back (preferredSize);
useDefaultBuffers = false;
}
{
std::cout << "API::Device" << m_DeviceName << " Preffered buffer size is not supported" << std::endl;
}
-
+
if (useDefaultBuffers)
{
std::cout << "API::Device" << m_DeviceName << " Using default buffer sizes " <<std::endl;
m_InputChannels.push_back (chNameStream.str());
}
-
-
+
+
//Update output channels
m_OutputChannels.clear();
for (int channel = 0; channel < maxOutputChannels; channel++)
{
const char* channelName[32]; // 32 is max leth declared by PortAudio for this operation
std::stringstream chNameStream;
-
+
PaError error = PaAsio_GetOutputChannelName(m_DeviceID, channel, channelName);
-
+
chNameStream << (channel+1) << " - ";
if (error == paNoError)
{
chNameStream << "Output " << (channel+1);
}
-
+
m_OutputChannels.push_back (chNameStream.str());
}
}
pOutS = &outputParameters;
PaStream *portAudioStream = NULL;
-
+
//sometimes devices change buffer size if sample rate changes
//it updates buffer size during stream opening
//we need to find out how device would behave with current sample rate
//try opening test stream to load device driver for current sample rate and buffer size
paErr = Pa_OpenStream (&portAudioStream, pInS, pOutS, sampleRate, bufferSize, paDitherOff, NULL, NULL);
-
+
if (portAudioStream)
{
// close test stream
{
AUTO_FUNC_DEBUG;
//ToDo: Perhaps for ASIO devices that are active, we should retrive the SR from the device...
-
+
return (m_CurrentSamplingRate);
}
WTErr WCMRPortAudioDevice::ResetDevice()
{
std::cout << "API::Device: " << m_DeviceName << " Reseting device" << std::endl;
-
+
SignalObjectAndWait(m_hResetRequestedEvent, m_hResetDone, INFINITE, false);
if (ConnectionStatus() == DeviceErrors)
//changes the status.
int oldRate = CurrentSamplingRate();
bool oldActive = Active();
-
+
//no change, nothing to do
if (oldRate == newRate)
return (retVal);
retVal = eCommandLineParameter;
return (retVal);
}
-
+
if (Streaming())
{
//Can't change, perhaps use an "in use" type of error
retVal = eGenericErr;
return (retVal);
}
-
+
//make the change...
m_CurrentSamplingRate = newRate;
PaError paErr = PaAsio_SetStreamSampleRate (m_PortAudioStream, m_CurrentSamplingRate);
retVal = eWrongObjectState;
}
-
+
return (retVal);
}
AUTO_FUNC_DEBUG;
//ToDo: May want to do something more to extract the actual status!
return (m_ConnectionStatus);
-
+
}
AUTO_FUNC_DEBUG;
PaError paErr = paNoError;
-
+
// if device is not active activate it
if (!Active() )
{
paDitherOff,
WCMRPortAudioDevice::TheCallback,
this);
-
+
if(paErr != paNoError)
{
std::cout << "Cannot open streamm with buffer: "<< m_CurrentBufferSize << " Error: " << Pa_GetErrorText (paErr) << std::endl;
-
+
if (paErr == paUnanticipatedHostError)
std::cout << "Error details: "<< Pa_GetLastHostErrorInfo ()->errorText << "; code: " << Pa_GetLastHostErrorInfo ()->errorCode << std::endl;
}
m_lastErr = eAsioFailed;
}
-
+
}
std::cout << "Activation is DONE "<< std::endl;
AUTO_FUNC_DEBUG;
PaError paErr = paNoError;
-
+
if (Active() )
{
if (Streaming())
{
stopStreaming ();
}
-
+
if (m_PortAudioStream)
{
//close the stream first
m_SampleCounter = 0;
std::cout << "API::Device" << m_DeviceName << " Starting device stream" << std::endl;
-
+
//get device info
const PaDeviceInfo *pDeviceInfo = Pa_GetDeviceInfo(m_DeviceID);
-
+
unsigned int inChannelCount = pDeviceInfo->maxInputChannels;
unsigned int outChannelCount = pDeviceInfo->maxOutputChannels;
-
+
// Prepare for streaming - tell Engine to do the initialization for process callback
m_pMyManager->NotifyClient (WCMRAudioDeviceManagerClient::DeviceStartsStreaming);
m_lastErr = eGenericErr;
}
}
-
+
if (callerIsWaiting)
SetEvent(m_hStartStreamingDone);
}
// Reinitialize PA
Pa_Terminate();
Pa_Initialize();
-
+
std::cout << "Updating device state... " << std::endl;
// update device info
updateDeviceInfo();
};
const size_t hEventsSize = sizeof(hEvents)/sizeof(hEvents[0]);
-
+
initDevice();
for(;;)
AUTO_FUNC_DEBUG;
//This will most likely be overridden, the base class simply
//changes the member.
-
+
m_MonitorGain = newGain;
return (eNoErr);
}
{
AUTO_FUNC_DEBUG;
WTErr retVal = eNoErr;
-
+
if (Active() && !m_ResetRequested )
{
#ifdef PLATFORM_WINDOWS
// show control panel for the device
if (PaAsio_ShowControlPanel (m_DeviceID, pParam) != paNoError)
retVal = eGenericErr;
-
+
// restore previous state for the device
SetActive(true);
if (wasStreaming)
}
#else
pParam = pParam;
-#endif //_windows
+#endif //_windows
}
-
+
return (retVal);
}
(statusFlags & (paInputOverflow | paOutputUnderflow)) != 0);
else
return (true);
-
+
}
//Don't try to access after this call returns!
m_pInputData = NULL;
- m_SampleCounter += framesPerBuffer;
+ m_SampleCounter += framesPerBuffer;
return m_StopRequested;
}
{
AUTO_FUNC_DEBUG;
std::cout << "API::PortAudioDeviceManager::PA Device manager constructor" << std::endl;
-
+
//Always create the None device first...
m_NoneDevice = new WCMRNativeAudioNoneDevice(this);
WCMRPortAudioDeviceManager::~WCMRPortAudioDeviceManager()
{
AUTO_FUNC_DEBUG;
-
+
std::cout << "API::Destroying PortAudioDeviceManager " << std::endl;
try
{
std::cout << "API::PortAudioDeviceManager::Creating PA device: " << devInfo.m_DeviceId << ", Device Name: " << devInfo.m_DeviceName << std::endl;
TRACE_MSG ("API::PortAudioDeviceManager::Creating PA device: " << devInfo.m_DeviceId << ", Device Name: " << devInfo.m_DeviceName);
-
+
m_CurrentDevice = new WCMRPortAudioDevice (this, devInfo.m_DeviceId, m_UseMultithreading, m_bNoCopyAudioBuffer);
}
catch (...)
WTErr WCMRPortAudioDeviceManager::getDeviceAvailableBufferSizes(DeviceID deviceId, std::vector<int>& buffers)
{
WTErr retVal = eNoErr;
-
+
buffers.clear();
//make PA request to get actual device buffer sizes
WTErr WCMRPortAudioDeviceManager::generateDeviceListImpl()
{
std::cout << "API::PortAudioDeviceManager::Generating device list" << std::endl;
-
+
WTErr retVal = eNoErr;
//Initialize PortAudio and ASIO first
{
//if it's of the required type...
const PaDeviceInfo *pPaDeviceInfo = Pa_GetDeviceInfo(thisDeviceID);
-
+
if (Pa_GetHostApiInfo(pPaDeviceInfo->hostApi)->type == paASIO)
{
//build a device object...
WTErr WCMRPortAudioDeviceManager::getDeviceBufferSizesImpl(const std::string & deviceName, std::vector<int>& buffers) const
{
WTErr retVal = eNoErr;
-
+
buffers.clear();
//first check if the request has been made for None device
buffers=m_NoneDevice->BufferSizes();
return retVal;
}
-
+
if (m_CurrentDevice && deviceName == m_CurrentDevice->DeviceName() )
{
buffers=m_CurrentDevice->BufferSizes();