Пример #1
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);
	}
}
Пример #2
0
JNIEXPORT jobject JNICALL Java_org_jpab_PortAudio_getDefaultHostAPIAsBuffer(JNIEnv *env, jclass paClass) {
    const UINT32 result = Pa_GetDefaultHostApi();
    if (result < 0) {
		org_jpab_throw_exception(env, (PaError *) &result);
		return NULL;
	}
	return Java_org_jpab_PortAudio_getHostAPIAsBuffer(env, paClass, (jint) result);
}
Пример #3
0
static int pa_defaulthostapi(lua_State *L)
{
  int narg = lua_gettop(L);
  if(narg != 0)
    luaL_error(L, "invalid arguments: no argument expected");

  lua_pushnumber(L, Pa_GetDefaultHostApi()+1);
  return 1;
}
Пример #4
0
static const PaHostApiInfo *findHostAPIInfo(const char *hostAPI, PaHostApiIndex *index)
{
  const PaHostApiInfo *hostAPIInfo = NULL;
  PaHostApiIndex i;

  for (i = 0; i < Pa_GetHostApiCount(); i++) {
    hostAPIInfo = Pa_GetHostApiInfo(i);

    if (hostAPIInfo && strcmp(hostAPI, hostAPIInfo->name) == 0) {
      break;
    }
  }
  if (i >= Pa_GetHostApiCount()) {
    i = Pa_GetDefaultHostApi();
    hostAPIInfo = Pa_GetHostApiInfo(i);
  }

  if (index) {
    *index = i;
  }
  return hostAPIInfo;
}
Пример #5
0
void audiosource_portaudio::init() {
	err = Pa_Initialize();
	if( err != paNoError ) {
		std::cerr << "PortAudio error: " << Pa_GetErrorText( err ) << std::endl;
		throw audiosourceexception("Pa_Initialize");
	}

	PaHostApiIndex api_idx;

	const PaHostApiInfo* info = Pa_GetHostApiInfo(Pa_GetDefaultHostApi());

	std::cerr << "Default device: " << info->name << std::endl;

	for (api_idx = 0; api_idx < Pa_GetHostApiCount(); ++api_idx) {
		info = Pa_GetHostApiInfo(api_idx);
		std::cerr << "device " << api_idx << ": " << info->name << std::endl;
	}

	//int frames_per_buffer = get_sample_rate();
	int frames_per_buffer = paFramesPerBufferUnspecified;

	/*
	 * We have two separate streams for input and output to work-around a Debian specific
	 * bug on PortAudio.
	 */

    /* Open an audio I/O stream. */
    err = Pa_OpenDefaultStream( &stream_in,
    							get_in_channel_count(),          /* input channels */
                                0,          /* output */
                                paFloat32,  /* 32 bit floating point output */
                                get_sample_rate(),
                                frames_per_buffer, /* frames per buffer, i.e. the number
                                                   of sample frames that PortAudio will
                                                   request from the callback. Many apps
                                                   may want to use
                                                   paFramesPerBufferUnspecified, which
                                                   tells PortAudio to pick the best,
                                                   possibly changing, buffer size.*/
                                portaudio_in_callback, /* this is your callback function */
                                static_cast<void*>(this) ); /*This is a pointer that will be passed to
                                                   your callback*/
	if( err != paNoError ) {
		std::cerr << "PortAudio error: " << Pa_GetErrorText( err ) << std::endl;
		throw audiosourceexception("Pa_OpenDefaultStream");
	}

	err = Pa_StartStream( stream_in );
	if( err != paNoError ) {
		std::cerr << "PortAudio error: " << Pa_GetErrorText( err ) << std::endl;
		throw audiosourceexception("Pa_StartStream");
	}

    /* Open an audio I/O stream. */
    err = Pa_OpenDefaultStream( &stream_out,
    							0,          /* input channels */
    							get_out_channel_count(),          /* output */
                                paFloat32,  /* 32 bit floating point output */
                                get_sample_rate(),
                                frames_per_buffer, /* frames per buffer, i.e. the number
                                                   of sample frames that PortAudio will
                                                   request from the callback. Many apps
                                                   may want to use
                                                   paFramesPerBufferUnspecified, which
                                                   tells PortAudio to pick the best,
                                                   possibly changing, buffer size.*/
                                portaudio_out_callback, /* this is your callback function */
                                static_cast<void*>(this) ); /*This is a pointer that will be passed to
                                                   your callback*/
	if( err != paNoError ) {
		std::cerr << "PortAudio error: " << Pa_GetErrorText( err ) << std::endl;
		throw audiosourceexception("Pa_OpenDefaultStream");
	}

	err = Pa_StartStream( stream_out );
	if( err != paNoError ) {
		std::cerr << "PortAudio error: " << Pa_GetErrorText( err ) << std::endl;
		throw audiosourceexception("Pa_StartStream");
	}
}
PaHostApiIndex defaultHostApi()
{
    return Pa_GetDefaultHostApi();
}
Пример #7
0
Файл: jpa.c Проект: rjeschke/jpa
JNIEXPORT jint JNICALL Java_com_github_rjeschke_jpa_JPA_getDefaultHostApi(JNIEnv *env, jclass clazz)
{
    return (jint)Pa_GetDefaultHostApi();
}
Пример #8
0
/*fa MTR_AudioInit yes */
MTR_DCLSPC bool MTR_CALL MTR_AudioInit(uint32_t sndDmSize,
 uint32_t sndReservedCount, uint32_t musDmSize, uint32_t musReservedCount,
 int freq, int channels, int chunkSize)
{
    PaError              error;
    int                  hostApiCount;
    const PaHostApiInfo* hostApiInfo;
    int                  deviceIndex;
    int                  devicesCount;
    const PaDeviceInfo*  deviceInfo;
    int                  i;
    int                  j;

    MTR_LogWrite("Initializing audio manager", 0, MTR_LMT_INFO);

    MTR_LogWrite_s("Reporting PortAudio version:", 1, MTR_LMT_INFO,
     Pa_GetVersionInfo()->versionText);

    error = Pa_Initialize();
    if (error != paNoError) {
        MTR_LogWrite("Unable to initialize PortAudio", 0, MTR_LMT_ERROR);
        MTR_LogWrite(Pa_GetErrorText(error), 0, MTR_LMT_ERROR);
        return false;
    }

    MTR_LogWrite("Reporting available devices:", 1, MTR_LMT_INFO);
    devicesCount = Pa_GetDeviceCount();
    for (i = 0; i < devicesCount; i++) {
        deviceInfo = Pa_GetDeviceInfo(i);
        MTR_LogWrite(deviceInfo->name, 2, MTR_LMT_INFO);
        hostApiInfo = Pa_GetHostApiInfo(deviceInfo->hostApi);
        MTR_LogWrite_s("Host API:", 3, MTR_LMT_INFO, hostApiInfo->name);
        MTR_LogWrite_i("Max input channels:", 3, MTR_LMT_INFO,
         deviceInfo->maxInputChannels);
        MTR_LogWrite_i("Max output channels:", 3, MTR_LMT_INFO,
         deviceInfo->maxOutputChannels);
        MTR_LogWrite_d("Default low input latency (sec.):", 3, MTR_LMT_INFO,
         deviceInfo->defaultLowInputLatency);
        MTR_LogWrite_i("Default low output latency (sec.):", 3, MTR_LMT_INFO,
         deviceInfo->defaultLowOutputLatency);
        MTR_LogWrite_d("Default high input latency (sec.):", 3, MTR_LMT_INFO,
         deviceInfo->defaultHighInputLatency);
        MTR_LogWrite_i("Default high output latency (sec.):", 3, MTR_LMT_INFO,
         deviceInfo->defaultHighOutputLatency);
        MTR_LogWrite_i("Default sample rate:", 3, MTR_LMT_INFO,
         deviceInfo->defaultSampleRate);
    }

    MTR_LogWrite("Reporting available hosts APIs:", 1, MTR_LMT_INFO);
    hostApiCount = Pa_GetHostApiCount();
    for (i = 0; i < hostApiCount; i++) {
        hostApiInfo = Pa_GetHostApiInfo(i);
        MTR_LogWrite(hostApiInfo->name, 2, MTR_LMT_INFO);
        MTR_LogWrite("Devices of this host API:", 3, MTR_LMT_INFO);
        devicesCount = hostApiInfo->deviceCount;
        for (j = 0; j < devicesCount; j++) {
            deviceIndex = Pa_HostApiDeviceIndexToDeviceIndex(i, j);
            deviceInfo = Pa_GetDeviceInfo(deviceIndex);
            MTR_LogWrite(deviceInfo->name, 4, MTR_LMT_INFO);
        }
        deviceInfo = Pa_GetDeviceInfo(hostApiInfo->defaultInputDevice);
        MTR_LogWrite_s("Default input device:", 3, MTR_LMT_INFO,
         deviceInfo->name);
        deviceInfo = Pa_GetDeviceInfo(hostApiInfo->defaultOutputDevice);
        MTR_LogWrite_s("Default output device:", 3, MTR_LMT_INFO,
         deviceInfo->name);
    }
    hostApiInfo = Pa_GetHostApiInfo(Pa_GetDefaultHostApi());
    MTR_LogWrite_s("Default host API:", 1, MTR_LMT_INFO, hostApiInfo->name);

//    if (SDL_InitSubSystem(SDL_INIT_AUDIO) == 0)
//        MTR_LogWrite("SDL audio subsystem initialized", 1, MTR_LMT_INFO);
//    else
//        MTR_LogWrite("Unable to initialize SDL audio subsystem", 1,
//         MTR_LMT_INFO);
//
//    initFlags = MIX_INIT_FLAC | MIX_INIT_MOD | MIX_INIT_MODPLUG | MIX_INIT_MP3 |
//     MIX_INIT_OGG | MIX_INIT_FLUIDSYNTH;
//    initResult = Mix_Init(initFlags);
//    if(initResult != initFlags)
//    {
//        if (initResult == 0)
//        {
//            MTR_Notify("Unable to load libraries needed by SDL_mixer", 1,
//             MTR_LMT_ERROR);
//            return false;
//        }
//
//        MTR_LogWrite("Unable to initialize support of this formats:", 1,
//         MTR_LMT_WARNING);
//        if ((initResult & MIX_INIT_FLAC) == 0)
//            MTR_LogWrite("FLAC", 2, MTR_LMT_WARNING);
//        if ((initResult & MIX_INIT_MOD) == 0)
//            MTR_LogWrite("MOD", 2, MTR_LMT_WARNING);
//        if ((initResult & MIX_INIT_MODPLUG) == 0)
//            MTR_LogWrite("MODPlug", 2, MTR_LMT_WARNING);
//        if ((initResult & MIX_INIT_MP3) == 0)
//            MTR_LogWrite("MP3", 2, MTR_LMT_WARNING);
//        if ((initResult & MIX_INIT_OGG) == 0)
//            MTR_LogWrite("OGG", 2, MTR_LMT_WARNING);
//        if ((initResult & MIX_INIT_FLUIDSYNTH) == 0)
//            MTR_LogWrite("FluidSynth", 2, MTR_LMT_WARNING);
//    }
//    else
//        MTR_LogWrite("Support of the every SDL_mixer audio format initialized",
//         1, MTR_LMT_INFO);
//
//    MTR_LogWrite("Preparing parameters for initialize SDL_mixer", 1,
//     MTR_LMT_INFO);
//
//    /* Choosing sampling frequency */
//    if (freq == MTR_AU_FREQ_DEFAULT)
//    {
//        frequency = MIX_DEFAULT_FREQUENCY;
//        MTR_LogWrite_i("Choosed default sampling frequency (Hz): ", 2,
//         MTR_LMT_INFO, MIX_DEFAULT_FREQUENCY);
//    }
//    else if (freq < 11025)
//    {
//        frequency = 11025;
//        MTR_LogWrite_i("Choosed sampling frequency not supported. Using "
//         "minimal supported sampling frequency (Hz): ", 2, MTR_LMT_WARNING,
//         11025);
//    }
//    else
//    {
//        frequency = freq;
//        MTR_LogWrite_i("Choosed sampling frequency (Hz): ", 2, MTR_LMT_INFO,
//         freq);
//    }
//
//    /* Choosing channels count */
//    if (channels == MTR_AU_CHANNELS_DEFAULT)
//    {
//        channelsCount = MIX_DEFAULT_CHANNELS;
//        MTR_LogWrite_s("Choosed default channels count: ", 2, MTR_LMT_INFO,
//         channelsConf[MIX_DEFAULT_CHANNELS - 1]);
//    }
//    else if (channels > 2)
//    {
//        channelsCount = 2;
//        MTR_LogWrite_s("Choosed channels count are not supported. Using max "
//         "supported channels count: ", 2, MTR_LMT_WARNING, channelsConf[2 - 1]);
//    }
//    else
//    {
//        channelsCount = channels;
//        MTR_LogWrite_s("Choosed channels count: ", 2, MTR_LMT_INFO,
//         channelsConf[channels - 1]);
//    }
//
//    /* Choosing chunk size */
//    if (chunkSize == MTR_AU_CHUNK_SIZE_DEFAULT)
//    {
//        finalChunkSize = 4096;
//        MTR_LogWrite_i("Choosed default chunk size (bytes): ", 2, MTR_LMT_INFO,
//         4096);
//    }
//    else if (chunkSize > 8192)
//    {
//        finalChunkSize = 8192;
//        MTR_LogWrite_i("Choosed chunk size not supported. Using max supported "
//         "chunk size (bytes): ", 2, MTR_LMT_WARNING, 8192);
//    }
//    else if (chunkSize < 512)
//    {
//        finalChunkSize = 512;
//        MTR_LogWrite_i("Choosed chunk size not supported. Using minimal "
//         "supported chunk size (bytes): ", 2, MTR_LMT_WARNING, 512);
//    }
//    else
//    {
//        finalChunkSize = chunkSize;
//        MTR_LogWrite_i("Choosed chunk size (bytes): ", 2, MTR_LMT_INFO,
//         chunkSize);
//    }
//
//    if (Mix_OpenAudio(frequency, MIX_DEFAULT_FORMAT, channelsCount,
//     finalChunkSize) == 0)
//    {
//        MTR_LogWrite("SDL_mixer initialized", 1, MTR_LMT_INFO);
//
//        MTR_LogWrite("Reporting built-in SDL_mixer chunk decoders", 1,
//         MTR_LMT_INFO);
//        for (i = 0; i < Mix_GetNumChunkDecoders(); i++)
//            MTR_LogWrite_s("Chunk decoder found: ", 2, MTR_LMT_INFO,
//             Mix_GetChunkDecoder(i));
//        MTR_LogWrite("Reporting built-in SDL_mixer music decoders", 1,
//         MTR_LMT_INFO);
//        for (i = 0; i < Mix_GetNumMusicDecoders(); i++)
//            MTR_LogWrite_s("Music decoder found: ", 2, MTR_LMT_INFO,
//             Mix_GetMusicDecoder(i));
//    }
//    else
//    {
//        MTR_Notify("Unable to initialize SDL2_mixer", 1, MTR_LMT_ERROR);
//        MTR_LogWrite_s("SDL2_mixer error: ", 1, MTR_LMT_ERROR, Mix_GetError());
//        Mix_Quit();
//        return false;
//    }
//    Mix_AllocateChannels(64);
//
//    mtrSoundKeeper = (mtrIndexkeeper_t *)MTR_IndexkeeperCreate(sndDmSize,
//     sndReservedCount, sizeof(mtrSound_t));
//    if (mtrSoundKeeper == NULL)
//    {
//        MTR_Notify("Unable to initialize indexkeeper structure for sounds", 1,
//         MTR_LMT_ERROR);
//        Mix_CloseAudio();
//        Mix_Quit();
//        return false;
//    }
//    else
//        MTR_LogWrite("Indexkeeper structure for sounds initialized", 1,
//         MTR_LMT_INFO);
//
//    mtrMusicKeeper = (mtrIndexkeeper_t *)MTR_IndexkeeperCreate(musDmSize,
//     musReservedCount, sizeof(mtrMusic_t));
//    if (mtrMusicKeeper == NULL)
//    {
//        MTR_Notify("Unable to initialize indexkeeper structure for music", 1,
//         MTR_LMT_ERROR);
//        Mix_CloseAudio();
//        Mix_Quit();
//        return false;
//    }
//    else
//        MTR_LogWrite("Indexkeeper structure for music initialized", 1,
//         MTR_LMT_INFO);
//
//    MTR_LogWrite("Audio manager initialized", 0, MTR_LMT_INFO);

    mtrCurrentMusic = 0U;
    mtrAudioInited = true;
    return true;
}