Пример #1
0
void displayOption()
{
    Pa_Initialize();
    fprintf(stderr, "--------------------------------------------------\n");
    fprintf(stderr, "Input Devices\n");
    fprintf(stderr, "--------------------------------------------------\n");
    for (int i = 0; i < Pa_GetDeviceCount(); i++) {
        const PaDeviceInfo *deviceInfo;
        deviceInfo = Pa_GetDeviceInfo(i);
        if (deviceInfo->maxInputChannels > 0) {
            const PaHostApiInfo *apiInfo;
            apiInfo = Pa_GetHostApiInfo(deviceInfo->hostApi);
            fprintf(stderr, "%2d %s(%s)\n", i, deviceInfo->name, apiInfo->name);
        }
    }

    fprintf(stderr, "\n--------------------------------------------------\n");
    fprintf(stderr, "Output Devices\n");
    fprintf(stderr, "--------------------------------------------------\n");
    for (int i = 0; i < Pa_GetDeviceCount(); i++) {
        const PaDeviceInfo *deviceInfo;
        deviceInfo = Pa_GetDeviceInfo(i);
        if (deviceInfo->maxOutputChannels > 0) {
            const PaHostApiInfo *apiInfo;
            apiInfo = Pa_GetHostApiInfo(deviceInfo->hostApi);
            fprintf(stderr, "%2d %s(%s)\n", i, deviceInfo->name, apiInfo->name);
        }
    }
    Pa_Terminate();
}
Пример #2
0
// print info about the audio device to stdout
void pa_printdevinfo()
{
	mexPrintf("Printing audio devices...\n");

	Pa_Initialize();		

	int dev_type_indx = -1;
	const PaHostApiInfo* Api_Info;
	int num_APIs = (int )Pa_GetHostApiCount();
	for (int i=0; i<num_APIs; i++) {
 		Api_Info = Pa_GetHostApiInfo(i);
		if (strcmp(Api_Info->name,API_NAME)==0)
			dev_type_indx = i;
	}
	if (dev_type_indx == -1) {
		return;
	}
	Api_Info = Pa_GetHostApiInfo(dev_type_indx);


	for( int d = 0; d < Api_Info->deviceCount; d++) {
		//PaDeviceIndex dev_indx = Pa_HostApiDeviceIndexToDeviceIndex(dev_type_indx, d);
		//printdevice((int )dev_indx);
		printdevice(dev_type_indx, d);
	}
	
	Pa_Terminate();
}
Пример #3
0
/* Returns true on success, false on failure */
bool PortAudioStreamer::Start(const PaStreamParameters *inputParams,
                              const PaStreamParameters *outputParams,
                              double sampleRate)
{
  PaError error;

  qDebug("Trying Pa_OpenStream() with sampleRate %g inputLatency %g outputLatency %g innch %d outnch %d",
         sampleRate,
         inputParams->suggestedLatency,
         outputParams->suggestedLatency,
         inputParams->channelCount,
         outputParams->channelCount);
  const PaDeviceInfo *deviceInfo = Pa_GetDeviceInfo(inputParams->device);
  if (deviceInfo) {
    const PaHostApiInfo *hostApiInfo = Pa_GetHostApiInfo(deviceInfo->hostApi);
    qDebug("Input device: %s (%s)", deviceInfo->name,
           hostApiInfo ? hostApiInfo->name : "<invalid host api>");
  }
  deviceInfo = Pa_GetDeviceInfo(outputParams->device);
  if (deviceInfo) {
    const PaHostApiInfo *hostApiInfo = Pa_GetHostApiInfo(deviceInfo->hostApi);
    qDebug("Output device: %s (%s)", deviceInfo->name,
           hostApiInfo ? hostApiInfo->name : "<invalid host api>");
  }

  error = Pa_OpenStream(&stream, inputParams, outputParams,
                        sampleRate, paFramesPerBufferUnspecified,
                        paPrimeOutputBuffersUsingStreamCallback,
                        streamCallbackTrampoline, this);
  if (error != paNoError) {
    logPortAudioError("Pa_OpenStream() failed", error);
    stream = NULL;
    return false;
  }

  m_srate = sampleRate;
  m_innch = inputParams->channelCount;
  m_outnch = outputParams->channelCount;
  m_bps = 32;

  error = Pa_StartStream(stream);
  if (error != paNoError) {
    logPortAudioError("Pa_StartStream() failed", error);
    Pa_CloseStream(stream);
    stream = NULL;
    return false;
  }

  const PaStreamInfo *streamInfo = Pa_GetStreamInfo(stream);
  if (streamInfo) {
    qDebug("Stream started with sampleRate %g inputLatency %g outputLatency %g",
           streamInfo->sampleRate,
           streamInfo->inputLatency,
           streamInfo->outputLatency);
  }

  return true;
}
Пример #4
0
/* Internal: Get PortAudio default output device ID */
static int pa_get_default_output_dev(int channel_count)
{
    int i, count;

    /* Special for Windows - try to use the DirectSound implementation
     * first since it provides better latency.
     */
#if PJMEDIA_PREFER_DIRECT_SOUND
    if (Pa_HostApiTypeIdToHostApiIndex(paDirectSound) >= 0) {
	const PaHostApiInfo *pHI;
	int index = Pa_HostApiTypeIdToHostApiIndex(paDirectSound);
	pHI = Pa_GetHostApiInfo(index);
	if (pHI) {
	    const PaDeviceInfo *paDevInfo = NULL;
	    paDevInfo = Pa_GetDeviceInfo(pHI->defaultOutputDevice);
	    if (paDevInfo && paDevInfo->maxOutputChannels >= channel_count)
		return pHI->defaultOutputDevice;
	}
    }
#endif

    /* Enumerate the host api's for the default devices, and return
     * the device with suitable channels.
     */
    count = Pa_GetHostApiCount();
    for (i=0; i < count; ++i) {
	const PaHostApiInfo *pHAInfo;

	pHAInfo = Pa_GetHostApiInfo(i);
	if (!pHAInfo)
	    continue;

	if (pHAInfo->defaultOutputDevice >= 0) {
	    const PaDeviceInfo *paDevInfo;

	    paDevInfo = Pa_GetDeviceInfo(pHAInfo->defaultOutputDevice);

	    if (paDevInfo->maxOutputChannels >= channel_count)
		return pHAInfo->defaultOutputDevice;
	}
    }

    /* If still no device is found, enumerate all devices */
    count = Pa_GetDeviceCount();
    for (i=0; i<count; ++i) {
	const PaDeviceInfo *paDevInfo;

	paDevInfo = Pa_GetDeviceInfo(i);
	if (paDevInfo->maxOutputChannels >= channel_count)
	    return i;
    }

    return -1;
}
Пример #5
0
	CPAManager::CPAManager(CRefPtr<Audio::IDriver> pDriver) :
		m_pDriver(pDriver),
		m_uDefaultIndex(0)
	{
		Log::Write(L"Initializing PortAudio Audio manager...");

		auto uError = Pa_Initialize();
		if(uError != paNoError){
			CR_THROW(L"Failed to initialize port audio, Error: " + Utils::ToErrorString(uError));
		}

		Log::Write(L"Enumerating audio adapters...", Log::LogLevel::Debug);
		auto uDeviceCount = Pa_GetDeviceCount();
		for(PaDeviceIndex uIndex = 0; uIndex < uDeviceCount; uIndex++){
			auto pInfo = Pa_GetDeviceInfo(uIndex);
			auto pApiInfo = Pa_GetHostApiInfo(pInfo->hostApi);
			
			auto strAdapter = String::FromANSI(reinterpret_cast<const int8*>(pInfo->name));
			auto strHostApi = String::FromANSI(reinterpret_cast<const int8*>(pApiInfo->name));

			strAdapter += L"[" + strHostApi + L"]";

			Log::Write(L"Audio Adapter Found: " + strAdapter, Log::LogLevel::Debug);
			this->m_strAdapterList.Add(strAdapter);
		}
		Log::Write(L"End of enumeration of audio adapters.", Log::LogLevel::Debug);

		if(!this->m_strAdapterList.IsEmpty()){
			Log::Write(L"Finding default audio adapter...", Log::LogLevel::Debug);

			auto uDefaultIndex = Pa_GetDefaultOutputDevice();
			if(uDefaultIndex == paNoDevice){
				Log::Write(L"Got null pointer for default device - assuming default as first in list.");
				uDefaultIndex = 0;
			}

			auto pInfo = Pa_GetDeviceInfo(uDefaultIndex);
			auto pApiInfo = Pa_GetHostApiInfo(pInfo->hostApi);
			
			auto strAdapter = String::FromANSI(reinterpret_cast<const int8*>(pInfo->name));
			auto strHostApi = String::FromANSI(reinterpret_cast<const int8*>(pApiInfo->name));

			strAdapter += L"[" + strHostApi + L"]";
			Log::Write(L"Found default PortAudio adapter: " + strAdapter, Log::LogLevel::Debug);

			this->m_uDefaultIndex = uDefaultIndex;
		}
	}
Пример #6
0
void
CPaCommon::Enumerate(vector < string > &choices, vector < string > &descriptions)
{
    vector < string > tmp;

    names.clear();
    descriptions.clear();
	names.push_back(""); /* default device */
	descriptions.push_back("");

    int numDevices = Pa_GetDeviceCount();
    if (numDevices < 0)
        throw string("PortAudio error: ") + Pa_GetErrorText(numDevices);
    PaHostApiIndex nApis = Pa_GetHostApiCount();

    for (int i = 0; i < numDevices; i++)
    {
        const PaDeviceInfo *deviceInfo = Pa_GetDeviceInfo(i);
        if (( is_capture && deviceInfo->maxInputChannels > 1)
                || ( (!is_capture) && deviceInfo->maxOutputChannels > 1))
        {
            string api="";
            if (nApis>1)
            {
                const PaHostApiInfo* info = Pa_GetHostApiInfo(deviceInfo->hostApi);
                if (info)
                    api = string(info->name)+":";
            }
            names.push_back(api+deviceInfo->name);
            devices.push_back(i);
        }
    }
    choices = names;
}
Пример #7
0
audioSink::audioSink	(int16_t latency,
                         QComboBox *s,
                         RingBuffer<int16_t> *b): audioBase (b) {
    int32_t	i;
    this	-> latency	= latency;
    this	-> streamSelector	= s;

    this	-> CardRate	= 48000;
    this	-> latency	= latency;
    _O_Buffer		= new RingBuffer<float>(2 * 32768);
    portAudio		= false;
    writerRunning		= false;
    if (Pa_Initialize () != paNoError) {
        fprintf (stderr, "Initializing Pa for output failed\n");
        return;
    }

    portAudio	= true;
    qDebug ("Hostapis: %d\n", Pa_GetHostApiCount ());

    for (i = 0; i < Pa_GetHostApiCount (); i ++)
        qDebug ("Api %d is %s\n", i, Pa_GetHostApiInfo (i) -> name);

    numofDevices	= Pa_GetDeviceCount ();
    outTable	= new int16_t [numofDevices + 1];
    for (i = 0; i < numofDevices; i ++)
        outTable [i] = -1;
    ostream		= NULL;
    setupChannels (streamSelector);
    connect (streamSelector, SIGNAL (activated (int)),
             this,  SLOT (set_streamSelector (int)));
    streamSelector	-> show ();
    selectDefaultDevice ();

}
Пример #8
0
void list_devices(void) {
	PaError err;
	int i;

	if ((err = Pa_Initialize()) != paNoError) {
		LOG_WARN("error initialising port audio: %s", Pa_GetErrorText(err));
		return;
	}
	
	printf("Output devices:\n");
#ifndef PA18API
	for (i = 0; i < Pa_GetDeviceCount(); ++i) {
		if (Pa_GetDeviceInfo(i)->maxOutputChannels) {
			printf("  %i - %s [%s]\n", i, Pa_GetDeviceInfo(i)->name, Pa_GetHostApiInfo(Pa_GetDeviceInfo(i)->hostApi)->name);
		}
#else
	for (i = 0; i < Pa_CountDevices(); ++i) {
		printf("  %i - %s\n", i, Pa_GetDeviceInfo(i)->name);
#endif
	}
	printf("\n");
	
	if ((err = Pa_Terminate()) != paNoError) {
		LOG_WARN("error closing port audio: %s", Pa_GetErrorText(err));
	}
}

void set_volume(unsigned left, unsigned right) {
	LOG_DEBUG("setting internal gain left: %u right: %u", left, right);
	LOCK;
	output.gainL = left;
	output.gainR = right;
	UNLOCK;
}
Пример #9
0
JNIEXPORT jobject JNICALL Java_org_jpab_PortAudio_getHostAPIsDevicesAsBuffer(JNIEnv *env, jclass paClass, jint host_api_index) {
	Device * device;
	const PaDeviceInfo * device_info;
	const UINT8 count = Pa_GetHostApiInfo((PaHostApiIndex) host_api_index)->deviceCount;
	UINT16 index, size = DEVICE_SIZE * count, offset = 0, temp;
	char * buffer = (char *)malloc(size);
	for (index = 0; index < count; index ++) {
        device_info = Pa_GetDeviceInfo(index);
		device = (Device *) (buffer + offset);
		device->default_high_input_latency = device_info->defaultHighInputLatency;
		device->default_high_output_latency = device_info->defaultHighOutputLatency;
		device->default_low_input_latency = device_info->defaultLowInputLatency;
		device->default_low_output_latency = device_info->defaultLowOutputLatency;
		device->default_sample_rate = device_info->defaultSampleRate;
		device->index = index;
		device->host_api = host_api_index;
		device->max_input_channels = device_info->maxInputChannels;
		device->max_output_channels = device_info->maxOutputChannels;
		temp = strlen(device_info->name);
		device->name_length = temp;
		size += temp;
		buffer = (char *) realloc(buffer, size);
		offset += DEVICE_SIZE;
		memcpy(buffer + offset, device_info->name, temp);
		offset += temp;
	}
	return env->NewDirectByteBuffer(buffer, (jint) size);
}
Пример #10
0
JNIEXPORT jobject JNICALL Java_org_jpab_PortAudio_getHostAPIsAsBuffer(JNIEnv *env, jclass paClass) {
	HostAPI * host_api;
	const PaHostApiInfo * host_api_info;
	const UINT8 count = Pa_GetHostApiCount();
	UINT16 index, size = HOST_API_SIZE * count, offset = 0, temp;
	char * buffer = (char *)malloc(size);
	for (index = 0; index < count; index ++) {
        host_api_info = Pa_GetHostApiInfo(index);
		host_api = (HostAPI *) (buffer + offset);
		host_api->default_input_device = host_api_info->defaultInputDevice == -1 ? -1 : Pa_HostApiDeviceIndexToDeviceIndex(index, host_api_info->defaultInputDevice);
		host_api->default_output_device = host_api_info->defaultOutputDevice == -1 ? -1 : Pa_HostApiDeviceIndexToDeviceIndex(index, host_api_info->defaultOutputDevice);
		if (host_api->default_input_device < -1) host_api->default_input_device = -1;
		if (host_api->default_output_device < -1) host_api->default_output_device = -1;
		host_api->device_count = host_api_info->deviceCount;
		host_api->type = host_api_info->type;
		host_api->index = index;
		temp = strlen(host_api_info->name);
		host_api->name_length = temp;
		size += temp;
		buffer = (char *) realloc(buffer, size);
		offset += HOST_API_SIZE;
		memcpy(buffer + offset, host_api_info->name, temp);
		offset += temp;
	}
	return env->NewDirectByteBuffer(buffer, (jint) size);
}
// Get device list
// If first argument is NULL, return the maximum number of devices
int
get_device_list(int *devidlist, char **namelist, int maxstrlen, int maxnum)
{
  PaDeviceIndex numDevice = Pa_GetDeviceCount(), i;
  const PaDeviceInfo *deviceInfo;
  const PaHostApiInfo *apiInfo;
  static char buf[256];
  int n;

  n = 0;
  for(i=0;i<numDevice;i++) {
    deviceInfo = Pa_GetDeviceInfo(i);
    if (!deviceInfo) continue;
    if (deviceInfo->maxInputChannels <= 0) continue;
    apiInfo = Pa_GetHostApiInfo(deviceInfo->hostApi);
    if (!apiInfo) continue;
    if (devidlist != NULL) {
      if ( n >= maxnum ) break;
      snprintf(buf, 255, "%s: %s", apiInfo->name, deviceInfo->name);
      buf[255] = '\0';
      devidlist[n] = i;
      strncpy(namelist[n], buf, maxstrlen);
    }
    n++;
  }
  
  return n;
}
Пример #12
0
/*
 *	The class is the sink for the data generated.
 *	It will send the data to the soundcard
 */
	paWriter::paWriter	(int32_t cardRate,
	                         uint8_t  Latency) {
int32_t	i;

	CardRate		= cardRate;
	this -> Latency		= Latency;
	this	-> Latency	= LOWLATENCY;
	_O_Buffer		= new RingBuffer<float>(4 * 16384);
	portAudio		= false;
	writerRunning		= false;

	if (Pa_Initialize () != paNoError) {
	   fprintf (stderr, "Initializing Pa for output failed\n");
	   return;
	}
	portAudio	= true;

	qDebug ("Hostapis: %d\n", Pa_GetHostApiCount ());

	for (i = 0; i < Pa_GetHostApiCount (); i ++)
	   qDebug ("Api %d is %s\n", i, Pa_GetHostApiInfo (i) -> name);

	numofDevices	= Pa_GetDeviceCount ();
	ostream		= NULL;
}
const char* PA_AudioIO::getApi(){
    PaDeviceIndex DevInd = m_PaParams.device;
    const PaDeviceInfo* DevInf = Pa_GetDeviceInfo(DevInd);
    PaHostApiIndex ApiInd = DevInf->hostApi;
    const PaHostApiInfo* ApiInf = Pa_GetHostApiInfo(ApiInd);
    return ApiInf->name;
}
Пример #14
0
static int paqaVerifySuggestedLatency( void )
{
    PaDeviceIndex id;
    int result = 0;
    const PaDeviceInfo *pdi;
    int numDevices = Pa_GetDeviceCount();
    
    printf("\n ------------------------ paqaVerifySuggestedLatency\n");
    for( id=0; id<numDevices; id++ )            /* Iterate through all devices. */
    {
        pdi = Pa_GetDeviceInfo( id );
        printf("\nUsing device #%d: '%s' (%s)\n", id, pdi->name, Pa_GetHostApiInfo(pdi->hostApi)->name);
        if( pdi->maxOutputChannels > 0 )
        {
            if( paqaCheckMultipleSuggested( id, 0 ) < 0 )
            {
                printf("OUTPUT CHECK FAILED !!! #%d: '%s'\n", id, pdi->name);
                result -= 1;
        }
        }
        if( pdi->maxInputChannels > 0 )
        {
            if( paqaCheckMultipleSuggested( id, 1 ) < 0 )
            {
                printf("INPUT CHECK FAILED !!! #%d: '%s'\n", id, pdi->name);
                result -= 1;
        }
    }
    }
    return result;
}
Пример #15
0
static const PaDeviceInfo *findDeviceInfo(PaHostApiIndex hostAPI, const char *name,
                                          PaDeviceIndex *index)
{
  const PaHostApiInfo *hostAPIInfo = Pa_GetHostApiInfo(hostAPI);
  if (!hostAPIInfo) {
    return NULL;
  }

  const PaDeviceInfo *deviceInfo;
  PaDeviceIndex deviceIndex;
  int i;
  for (i = 0; i < hostAPIInfo->deviceCount; i++) {
    deviceIndex = Pa_HostApiDeviceIndexToDeviceIndex(hostAPI, i);
    if (deviceIndex < 0) {
      continue;
    }

    deviceInfo = Pa_GetDeviceInfo(deviceIndex);
    if (deviceInfo && strcmp(name, deviceInfo->name) == 0) {
      break;
    }
  }
  if (i >= hostAPIInfo->deviceCount) {
    deviceIndex = hostAPIInfo->defaultInputDevice;
    deviceInfo = Pa_GetDeviceInfo(deviceIndex);
  }

  if (index) {
    *index = deviceIndex;
  }
  return deviceInfo;
}
Пример #16
0
/*
 * Try to intelligently fetch a default audio input device
 */
static PaDeviceIndex
GetDefaultInputDevice()
{
    int i, n;
    PaDeviceIndex def;
    const PaDeviceInfo *deviceInfo;
    
    n = Pa_GetDeviceCount();
    if (n < 0) {
        return paNoDevice;
    }
    
    /* Try default input */
    if ((def = Pa_GetDefaultInputDevice()) != paNoDevice) {
        return def;
    }
    
    /* No luck, iterate and check for API specific input device */
    for (i = 0; i < n; i++) {
        deviceInfo = Pa_GetDeviceInfo(i);
        if (i == Pa_GetHostApiInfo(deviceInfo->hostApi)->defaultInputDevice) {
            return i;
        }
    }
    /* No device :( */
    return paNoDevice;
}
Пример #17
0
void AudioPortAudioSetupUtil::updateDevices()
{
	PaError err = Pa_Initialize();
	if( err != paNoError ) {
		printf( "Couldn't initialize PortAudio: %s\n", Pa_GetErrorText( err ) );
		return;
	}

	// get active backend 
	const QString& backend = m_backendModel.currentText();
	int hostApi = 0;
	const PaHostApiInfo * hi;
	for( int i = 0; i < Pa_GetHostApiCount(); ++i )
	{
		hi = Pa_GetHostApiInfo( i );
		if( backend == hi->name )
		{
			hostApi = i;
			break;
		}
	}

	// get devices for selected backend
	m_deviceModel.clear();
	const PaDeviceInfo * di;
	for( int i = 0; i < Pa_GetDeviceCount(); ++i )
	{
		di = Pa_GetDeviceInfo( i );
		if( di->hostApi == hostApi )
		{
			m_deviceModel.addItem( di->name );
		}
	}
	Pa_Terminate();
}
Пример #18
0
void GetAudioInfo()
{
	PaHostApiIndex ApiCount = Pa_GetHostApiCount();

	Log::Logf("AUDIO: The default API is %d\n", Pa_GetDefaultHostApi());

	for (PaHostApiIndex i = 0; i < ApiCount; i++)
	{
		const PaHostApiInfo* Index = Pa_GetHostApiInfo(i);
		Log::Logf("(%d) %s: %d (%d)\n", i, Index->name, Index->defaultOutputDevice, Index->type);

#ifdef WIN32
		if (Index->type == paWASAPI)
			DefaultWasapiDevice = Index->defaultOutputDevice;
		else if (Index->type == paDirectSound)
			DefaultDSDevice = Index->defaultOutputDevice;
#endif
	}

	Log::Logf("\nAUDIO: The audio devices are\n");

	PaDeviceIndex DevCount = Pa_GetDeviceCount();
	for (PaDeviceIndex i = 0; i < DevCount; i++)
	{
		const PaDeviceInfo *Info = Pa_GetDeviceInfo(i);
		Log::Logf("(%d): %s\n", i, Info->name);
		Log::Logf("\thighLat: %f, lowLat: %f\n", Info->defaultHighOutputLatency, Info->defaultLowOutputLatency);
		Log::Logf("\tsampleRate: %f, hostApi: %d\n", Info->defaultSampleRate, Info->hostApi);
		Log::Logf("\tmaxchannels: %d\n", Info->maxOutputChannels);
	}
}
void PortAudioSettingsPage::autoselectDevice()
{
  int index = hostAPIList->currentIndex();
  if (index < 0) {
    return;
  }

  PaHostApiIndex apiIndex = hostAPIList->itemData(index).toInt(NULL);
  const PaHostApiInfo *hostAPIInfo = Pa_GetHostApiInfo(apiIndex);
  if (!hostAPIInfo) {
    return;
  }

  int i;
  for (i = 0; i < inputDeviceList->count(); i++) {
    if (hostAPIInfo->defaultInputDevice ==
        inputDeviceList->itemData(i).toInt(NULL)) {
      inputDeviceList->setCurrentIndex(i);
      break;
    }
  }
  for (i = 0; i < outputDeviceList->count(); i++) {
    if (hostAPIInfo->defaultOutputDevice ==
        outputDeviceList->itemData(i).toInt(NULL)) {
      outputDeviceList->setCurrentIndex(i);
      break;
    }
  }
}
Пример #20
0
static int pa_hostapiinfo(lua_State *L)
{
  int narg = lua_gettop(L);
  PaHostApiIndex apiidx = 0;
  const PaHostApiInfo *info;

  if(narg == 1 && lua_isnumber(L, 1))
    apiidx = (PaHostApiIndex)lua_tonumber(L, 1)-1;
  else
    luaL_error(L, "expected arguments: number");
  
  info = Pa_GetHostApiInfo(apiidx);
  if(info)
  {
    lua_newtable(L);
    lua_pushstring(L, info->name);
    lua_setfield(L, -2, "name");
    lua_pushnumber(L, info->deviceCount);
    lua_setfield(L, -2, "devicecount");
    lua_pushnumber(L, info->defaultInputDevice+1);
    lua_setfield(L, -2, "defaultinputdevice");
    lua_pushnumber(L, info->defaultOutputDevice+1);
    lua_setfield(L, -2, "defaultoutputdevice");
    return 1;
  }

  return 0;
}
void PortAudioSettingsPage::populateDeviceList()
{
  int index = hostAPIList->currentIndex();

  inputDeviceList->clear();
  outputDeviceList->clear();

  if (index < 0) {
    return;
  }

  PaHostApiIndex apiIndex = hostAPIList->itemData(index).toInt(NULL);
  const PaHostApiInfo *hostAPIInfo = Pa_GetHostApiInfo(apiIndex);
  if (!hostAPIInfo) {
    return;
  }

  int i;
  for (i = 0; i < hostAPIInfo->deviceCount; i++) {
    PaDeviceIndex devIndex = Pa_HostApiDeviceIndexToDeviceIndex(apiIndex, i);
    const PaDeviceInfo *devInfo = Pa_GetDeviceInfo(devIndex);
    QString name = QString::fromUtf8(devInfo->name);

    if (devInfo->maxInputChannels > 0) {
      inputDeviceList->addItem(name, devIndex);
    }
    if (devInfo->maxOutputChannels > 0) {
      outputDeviceList->addItem(name, devIndex);
    }
  }
}
std::vector<ApiInfo> getHostApis(){
    // Returns information about available host apis. Currently uses portaudio.
    if( Pa_Initialize() != paNoError ) throw std::runtime_error("Portaudio could not be initialized during 'getHostApis'.");

    PaHostApiIndex apiCount = Pa_GetHostApiCount();
    PaDeviceIndex devCount = 0;
    PaDeviceIndex devNum = 0;
    std::vector<DevInfo> devInf;
    const PaHostApiInfo* p_ApiInf;
    const PaDeviceInfo* p_DevInf;
    std::vector<ApiInfo> vApiInf(apiCount);

    for(int api=0; api<apiCount; ++api){
        p_ApiInf = Pa_GetHostApiInfo(api);
        vApiInf[api].apiName = p_ApiInf->name;
        devCount = p_ApiInf->deviceCount;
        devInf.resize(devCount);
        for(int dev=0; dev<devCount; ++dev){
            devNum = Pa_HostApiDeviceIndexToDeviceIndex(api, dev);
            p_DevInf = Pa_GetDeviceInfo(devNum);
            devInf[dev].devName = p_DevInf->name;
            devInf[dev].numInputs = p_DevInf->maxInputChannels;
            devInf[dev].numOutputs= p_DevInf->maxOutputChannels;
            vApiInf[api].devices = devInf;
		}
    }
    if( Pa_Terminate() != paNoError ) throw std::runtime_error("Error terminating portaudio during 'getHostApis'.");
    return vApiInf;
}
Пример #23
0
static int paqaVerifyDeviceInfoLatency( void )
{
    PaDeviceIndex id;
    const PaDeviceInfo *pdi;
    int numDevices = Pa_GetDeviceCount();
    
    printf("\n ------------------------ paqaVerifyDeviceInfoLatency\n");
    for( id=0; id<numDevices; id++ ) /* Iterate through all devices. */
    {
        pdi = Pa_GetDeviceInfo( id );
        printf("Using device #%d: '%s' (%s)\n", id, pdi->name, Pa_GetHostApiInfo(pdi->hostApi)->name);
        if( pdi->maxOutputChannels > 0 )
        {
            printf("  Output defaultLowOutputLatency  = %f seconds\n", pdi->defaultLowOutputLatency);
            printf("  Output defaultHighOutputLatency = %f seconds\n", pdi->defaultHighOutputLatency);
            QA_ASSERT_TRUE( "defaultLowOutputLatency should be > 0", (pdi->defaultLowOutputLatency > 0.0) );
            QA_ASSERT_TRUE( "defaultHighOutputLatency should be > 0", (pdi->defaultHighOutputLatency > 0.0) );
            QA_ASSERT_TRUE( "defaultHighOutputLatency should be >= Low", (pdi->defaultHighOutputLatency >= pdi->defaultLowOutputLatency) );
        }
        if( pdi->maxInputChannels > 0 )
        {
            printf("  Input defaultLowInputLatency  = %f seconds\n", pdi->defaultLowInputLatency);
            printf("  Input defaultHighInputLatency = %f seconds\n", pdi->defaultHighInputLatency);
            QA_ASSERT_TRUE( "defaultLowInputLatency should be > 0", (pdi->defaultLowInputLatency > 0.0) );
            QA_ASSERT_TRUE( "defaultHighInputLatency should be > 0", (pdi->defaultHighInputLatency > 0.0) );
            QA_ASSERT_TRUE( "defaultHighInputLatency should be >= Low", (pdi->defaultHighInputLatency >= pdi->defaultLowInputLatency) );
        }
    }
    return 0;
error:
    return -1;
}
Пример #24
0
/// Gets a NEW list of devices by terminating and restarting portaudio
/// Assumes that DeviceManager is only used on the main thread.
void DeviceManager::Rescan()
{
   // get rid of the previous scan info
   this->mInputDeviceSourceMaps.clear();
   this->mOutputDeviceSourceMaps.clear();

   // if we are doing a second scan then restart portaudio to get NEW devices
   if (m_inited) {
      // check to see if there is a stream open - can happen if monitoring,
      // but otherwise Rescan() should not be available to the user.
      if (gAudioIO) {
         if (gAudioIO->IsMonitoring())
         {
            gAudioIO->StopStream();
            while (gAudioIO->IsBusy())
               wxMilliSleep(100);
         }
      }

      // restart portaudio - this updates the device list
      // FIXME: TRAP_ERR restarting PortAudio
      Pa_Terminate();
      Pa_Initialize();
   }

   // FIXME: TRAP_ERR PaErrorCode not handled in ReScan()
   int nDevices = Pa_GetDeviceCount();

   //The heirarchy for devices is Host/device/source.
   //Some newer systems aggregate this.
   //So we need to call port mixer for every device to get the sources
   for (int i = 0; i < nDevices; i++) {
      const PaDeviceInfo *info = Pa_GetDeviceInfo(i);
      if (info->maxOutputChannels > 0) {
         AddSources(i, info->defaultSampleRate, &mOutputDeviceSourceMaps, 0);
      }

      if (info->maxInputChannels > 0) {
#ifdef __WXMSW__
#if !defined(EXPERIMENTAL_FULL_WASAPI)
         if (Pa_GetHostApiInfo(info->hostApi)->type != paWASAPI ||
             PaWasapi_IsLoopback(i) > 0)
#endif
#endif
         AddSources(i, info->defaultSampleRate, &mInputDeviceSourceMaps, 1);
      }
   }

   // If this was not an initial scan update each device toolbar.
   // Hosts may have disappeared or appeared so a complete repopulate is needed.
   if (m_inited) {
      DeviceToolBar *dt;
      for (size_t i = 0; i < gAudacityProjects.size(); i++) {
         dt = gAudacityProjects[i]->GetDeviceToolBar();
         dt->RefillCombos();
      }
   }
   m_inited = true;
   mRescanTime = std::chrono::steady_clock::now();
}
Пример #25
0
QVariant HostApiList::data(const QModelIndex &index, int role) const
{
    if(role == Qt::DisplayRole) {
        const PaHostApiInfo *info = Pa_GetHostApiInfo(index.row());
        return QVariant(QString("%1").arg(info->name));
    } else
        return QVariant();
}
QHash<int, QString> hostApiNames()
{
    QHash<int, QString> names;
    for (int i = 0; i < Pa_GetHostApiCount(); ++i)
       names[i] = Pa_GetHostApiInfo(i)->name;

    return names;
}
Пример #27
0
void MFSound_InitModulePlatformSpecific(int *pSoundDataSize, int *pVoiceDataSize)
{
	MFCALLSTACK;

	// we need to return the size of the internal structures so the platform independant
	// code can make the correct allocations..
	*pSoundDataSize = sizeof(MFSoundDataInternal);

	MFDebug_Log(2, "Initialising PortAudio driver.");

	// init portaudio
	Pa_Initialize();

	// choose the output device
	PaDeviceIndex device = Pa_GetDefaultOutputDevice();

	// HACK: try and find an ALSA device (default OSS sucks)
	PaHostApiIndex alsaAPI = Pa_HostApiTypeIdToHostApiIndex(paALSA);
	if(alsaAPI >= 0)
	{
		int numDevices = Pa_GetDeviceCount();
		for(int a=0; a<numDevices; ++a)
		{
			pDeviceInfo = Pa_GetDeviceInfo(a);
			if(pDeviceInfo->hostApi == alsaAPI)
			{
				device = a;
				break;
			}
		}
	}

	pDeviceInfo = Pa_GetDeviceInfo(device);
	pHostAPIInfo = Pa_GetHostApiInfo(pDeviceInfo->hostApi);

	MFDebug_Log(2, MFStr("PortAudio output: %s", pDeviceInfo->name));
	MFDebug_Log(2, MFStr("PortAudio host: %s", pHostAPIInfo->name));
	MFDebug_Log(2, MFStr("Sample rate: %g", (float)pDeviceInfo->defaultSampleRate));
	MFDebug_Log(2, MFStr("In/Out channels: %d/%d", pDeviceInfo->maxInputChannels, pDeviceInfo->maxOutputChannels));
	MFDebug_Log(2, MFStr("Input latency: %g-%g", (float)pDeviceInfo->defaultLowInputLatency, (float)pDeviceInfo->defaultHighInputLatency));
	MFDebug_Log(2, MFStr("Output latency: %g-%g", (float)pDeviceInfo->defaultLowOutputLatency, (float)pDeviceInfo->defaultHighOutputLatency));

	// create a very low latency audio output stream
	PaStreamParameters params;
	params.device = Pa_GetDefaultOutputDevice();
	params.channelCount = 2;
	params.sampleFormat = paInt16;
	params.suggestedLatency = 0.0167;
	params.hostApiSpecificStreamInfo = NULL;

	PaError error = Pa_OpenStream(&pPAStream, NULL, &params, pDeviceInfo->defaultSampleRate, paFramesPerBufferUnspecified, paPrimeOutputBuffersUsingStreamCallback, MFSound_MixCallback, NULL);

	if(error != paNoError)
		MFDebug_Log(2, MFStr("Error: %s", Pa_GetErrorText(error)));
	else
		Pa_StartStream(pPAStream);
}
Пример #28
0
static void FillHostDeviceInfo(DeviceSourceMap *map, const PaDeviceInfo *info, int deviceIndex, int isInput)
{
   wxString hostapiName(Pa_GetHostApiInfo(info->hostApi)->name, wxConvLocal);
   wxString infoName(info->name, wxConvLocal);

   map->deviceIndex  = deviceIndex;
   map->hostIndex    = info->hostApi;
   map->deviceString = infoName;
   map->hostString   = hostapiName;
   map->numChannels  = isInput ? info->maxInputChannels : info->maxOutputChannels;
}
QHash<PaDeviceIndex, QString> deviceNames(PaHostApiIndex hostApi)
{
    QHash<int, QString> names;
    for (int i = 0; i < Pa_GetHostApiInfo(hostApi)->deviceCount; ++i)
    {
        PaDeviceIndex index = Pa_HostApiDeviceIndexToDeviceIndex(hostApi, i);
        names[index] = Pa_GetDeviceInfo(index)->name;
    }

    return names;
}
Пример #30
0
QStringList Portaudio::apiList() const
      {
      QStringList al;

      PaHostApiIndex apis = Pa_GetHostApiCount();
      for (PaHostApiIndex i = 0; i < apis; ++i) {
            const PaHostApiInfo* info = Pa_GetHostApiInfo(i);
            if (info)
                  al.append(info->name);
            }
      return al;
      }