Пример #1
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;
}
Пример #2
0
const PaDeviceInfo* Pa_GetDeviceInfo( PaDeviceID id )
{
    internalPortAudioDevice *pad;
    if( (id < 0) || ( id >= Pa_CountDevices()) ) return NULL;
    pad = Pa_GetInternalDevice( id );
    return  &pad->pad_Info ;
}
Пример #3
0
int main(void)
{
    int      i,j;
    int      numDevices;
    const    PaDeviceInfo *pdi;
    PaError  err;
    Pa_Initialize();
    numDevices = Pa_CountDevices();
    if( numDevices < 0 )
    {
        printf("ERROR: Pa_CountDevices returned 0x%x\n", numDevices );
        err = numDevices;
        goto error;
    }
    printf("Number of devices = %d\n", numDevices );
    for( i=0; i<numDevices; i++ )
    {
        pdi = Pa_GetDeviceInfo( i );
        printf("---------------------------------------------- #%d", i );
        if( i == Pa_GetDefaultInputDeviceID() ) printf(" DefaultInput");
        if( i == Pa_GetDefaultOutputDeviceID() ) printf(" DefaultOutput");
        printf("\nName         = %s\n", pdi->name );
        printf("Max Inputs   = %d", pdi->maxInputChannels  );
        printf(", Max Outputs = %d\n", pdi->maxOutputChannels  );
        if( pdi->numSampleRates == -1 )
        {
            printf("Sample Rate Range = %f to %f\n", pdi->sampleRates[0], pdi->sampleRates[1] );
        }
        else
        {
            printf("Sample Rates =");
            for( j=0; j<pdi->numSampleRates; j++ )
            {
                printf(" %8.2f,", pdi->sampleRates[j] );
            }
            printf("\n");
        }
        printf("Native Sample Formats = ");
        if( pdi->nativeSampleFormats & paInt8 )        printf("paInt8, ");
        if( pdi->nativeSampleFormats & paUInt8 )       printf("paUInt8, ");
        if( pdi->nativeSampleFormats & paInt16 )       printf("paInt16, ");
        if( pdi->nativeSampleFormats & paInt32 )       printf("paInt32, ");
        if( pdi->nativeSampleFormats & paFloat32 )     printf("paFloat32, ");
        if( pdi->nativeSampleFormats & paInt24 )       printf("paInt24, ");
        if( pdi->nativeSampleFormats & paPackedInt24 ) printf("paPackedInt24, ");
        printf("\n");
    }
    Pa_Terminate();

    printf("----------------------------------------------\n");
    return 0;
error:
    Pa_Terminate();
    fprintf( stderr, "An error occured while using the portaudio stream\n" );
    fprintf( stderr, "Error number: %d\n", err );
    fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
    return err;
}
Пример #4
0
internalPortAudioDevice *Pa_GetInternalDevice( PaDeviceID id )
{
    internalPortAudioDevice *pad;
    if( (id < 0) || ( id >= Pa_CountDevices()) ) return NULL;
    pad = sDeviceList;
    while( id > 0 )
    {
        pad = pad->pad_Next;
        id--;
    }
    return pad;
}
Пример #5
0
long TPortAudioRenderer::OpenDefault(long inChan, long outChan, long bufferSize, long sampleRate)
{
    PaError err;
    const PaDeviceInfo* pdi;
    int numDevices;
    int inDevice;
    int outDevice;

    printf("Opening device : inChan: %ld outChan: %ld bufferSize: %ld sampleRate: %ld\n",
           inChan, outChan, bufferSize, sampleRate);

    numDevices = Pa_CountDevices();
    if (numDevices < 0) {
        printf("ERROR: Pa_CountDevices returned 0x%x\n", numDevices);
        err = numDevices;
        printf("Error while opening device: device open error %s\n", Pa_GetErrorText(err));
		fStream = 0;
		return OPEN_ERR;
    } else {
        DisplayDevices();
    }

    // Compute input and output number : to be checked
    inDevice = Pa_GetDefaultInputDeviceID();
    pdi = Pa_GetDeviceInfo(inDevice);

    if (pdi != 0) {
        if (pdi->maxInputChannels == 0) {
            inDevice = GetFirstValidInputDevice();
            pdi = Pa_GetDeviceInfo(inDevice);
        }
        inChan = (inChan < pdi->maxInputChannels) ? inChan : pdi->maxInputChannels;
        printf("Input channel number %ld\n", inChan);
    }

    outDevice = Pa_GetDefaultOutputDeviceID();
    pdi = Pa_GetDeviceInfo(outDevice);

    if (pdi != 0) {
        if (pdi->maxOutputChannels == 0) {
            outDevice = GetFirstValidOutputDevice();
            pdi = Pa_GetDeviceInfo(outDevice);
        }
        outChan = (outChan < pdi->maxOutputChannels) ? outChan : pdi->maxOutputChannels;
        printf("Output channel number %ld\n", outChan);
    }
	
	return Open(inDevice, outDevice, inChan, outChan, bufferSize, sampleRate);
}
Пример #6
0
int TPortAudioRenderer::GetFirstValidOutputDevice()
{
    const PaDeviceInfo* pdi;
    int i, numDevices;

    numDevices = Pa_CountDevices();
    for (i = 0; i < numDevices; i++) {
        pdi = Pa_GetDeviceInfo(i);
        if (pdi->maxOutputChannels > 0) {
            printf("GetFirstValidOutputDevice: %d\n", i);
            return i;
        }
    }
    return paNoDevice;
}
Пример #7
0
static const PaDeviceInfo *select_device(const char *device)
{
#if (USE_PORTAUDIO == 19)
	int numDevices = Pa_GetDeviceCount();
#else
	int numDevices = Pa_CountDevices();
#endif
	if (numDevices < 0)
		return NULL;

#if (USE_PORTAUDIO == 19)
	PaDeviceIndex i = 0, selectedIndex = 0;
#else
	PaDeviceID i = 0, selectedIndex = 0;
#endif
	const PaDeviceInfo *deviceInfo = NULL;
	const PaDeviceInfo *selectedDeviceInfo = NULL;

	if (option_device_number >= 0) {
		selectedIndex = option_device_number;
		selectedDeviceInfo = Pa_GetDeviceInfo(selectedIndex);
	}

	if (device == NULL) {
#if (USE_PORTAUDIO == 19)
		selectedIndex = Pa_GetDefaultOutputDevice();
#else
		selectedIndex = Pa_GetDefaultOutputDeviceID();
#endif
		selectedDeviceInfo = Pa_GetDeviceInfo(selectedIndex);
	}

	if (selectedDeviceInfo == NULL) {
		for (i = 0; i < numDevices; i++) {
			deviceInfo = Pa_GetDeviceInfo(i);

			if (deviceInfo != NULL && !strcmp(device, deviceInfo->name)) {
				selectedIndex = i;
				selectedDeviceInfo = deviceInfo;
			}
		}
	}

	if (selectedDeviceInfo)
		update_output_parameters(selectedIndex, selectedDeviceInfo);
	return selectedDeviceInfo;
}
Пример #8
0
void TPortAudioRenderer::DisplayDevices()
{
    const PaDeviceInfo *pdi;
    int i, j, numDevices;

    numDevices = Pa_CountDevices();

    printf("Number of devices = %d\n", numDevices);
    for (i = 0; i < numDevices; i++) {
        pdi = Pa_GetDeviceInfo(i);
        printf("---------------------------------------------- #%d", i );
        if (i == Pa_GetDefaultInputDeviceID())
            printf(" DefaultInput");
        if (i == Pa_GetDefaultOutputDeviceID())
            printf(" DefaultOutput");
        printf("\nName         = %s\n", pdi->name);
        printf("Max Inputs   = %d", pdi->maxInputChannels);
        printf(", Max Outputs = %d\n", pdi->maxOutputChannels);
        if (pdi->numSampleRates == -1) {
            printf("Sample Rate Range = %f to %f\n", pdi->sampleRates[0], pdi->sampleRates[1]);
        } else {
            printf("Sample Rates =");
            for (j = 0; j < pdi->numSampleRates; j++) {
                printf(" %8.2f,", pdi->sampleRates[j]);
            }
            printf("\n");
        }
        printf("Native Sample Formats = ");
        if (pdi->nativeSampleFormats & paInt8)
            printf("paInt8, ");
        if (pdi->nativeSampleFormats & paUInt8)
            printf("paUInt8, ");
        if (pdi->nativeSampleFormats & paInt16)
            printf("paInt16, ");
        if (pdi->nativeSampleFormats & paInt32)
            printf("paInt32, ");
        if (pdi->nativeSampleFormats & paFloat32)
            printf("paFloat32, ");
        if (pdi->nativeSampleFormats & paInt24)
            printf("paInt24, ");
        if (pdi->nativeSampleFormats & paPackedInt24)
            printf("paPackedInt24, ");
        printf("\n");
    }
}
Пример #9
0
int main(void)
{
	PortAudioStream *stream;
	PaError err;
	int numDevices = Pa_CountDevices();
	err = Pa_Initialize();
	if( err != paNoError ) goto error;
	printf("PortAudio Test: input device  = %d\n", Pa_GetDefaultInputDeviceID() );
	printf("PortAudio Test: output device = %d\n", Pa_GetDefaultOutputDeviceID() );
	err = Pa_OpenStream(
				&stream,
				Pa_GetDefaultInputDeviceID(), /* default output device */
				2,               /* stereo input */
				PA_SAMPLE_TYPE,	
				NULL,
				Pa_GetDefaultOutputDeviceID(), /* default output device */
				2,               /* stereo output */
				PA_SAMPLE_TYPE, 
				NULL,
				SAMPLE_RATE,
				FRAMES_PER_BUFFER,            /* frames per buffer */
				0,               /* number of buffers, if zero then use default minimum */
				paClipOff,       /* we won't output out of range samples so don't bother clipping them */
				wireCallback,
				NULL );          /* no data */
	if( err != paNoError ) goto error;
	err = Pa_StartStream( stream );
	if( err != paNoError ) goto error;
	printf("Full duplex sound test in progress.\n");
	printf("Hit ENTER to exit test.\n");
	getchar();
	err = Pa_CloseStream( stream );
	if( err != paNoError ) goto error;
	Pa_Terminate();
	printf("Full duplex sound test complete.\n"); fflush(stdout);
	return 0;
error:
	Pa_Terminate();
	fprintf( stderr, "An error occured while using the portaudio stream\n" ); 
	fprintf( stderr, "Error number: %d\n", err );
	fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
	return -1;
}
Пример #10
0
int PaFindDeviceByName( const char *name )
{
    int   i;
    int   numDevices;
    const PaDeviceInfo *pdi;
    int   len = strlen( name );
    PaDeviceID   result = paNoDevice;
    numDevices = Pa_CountDevices();
    for( i=0; i<numDevices; i++ )
    {
        pdi = Pa_GetDeviceInfo( i );
        if( strncmp( name, pdi->name, len ) == 0 )
        {
            result = i;
            break;
        }
    }
    return result;
}
Пример #11
0
/*******************************************************************
* Try each output device, through its full range of capabilities. */
static void TestDevices( int mode )
{
    int id,jc,kr;
    int maxChannels;
    const PaDeviceInfo *pdi;
    int numDevices  = Pa_CountDevices();
    /* Iterate through all devices. */
    for( id=0; id<numDevices; id++ )
    {
        pdi = Pa_GetDeviceInfo( id );
        /* Try 1 to maxChannels on each device. */
        maxChannels = ( mode == MODE_INPUT ) ? pdi->maxInputChannels : pdi->maxOutputChannels;
        for( jc=1; jc<=maxChannels; jc++ )
        {
            printf("Name         = %s\n", pdi->name );
            /* Try each legal sample rate. */
            if( pdi->numSampleRates == -1 )
            {
                double low, high;
                low = pdi->sampleRates[0];
                high = pdi->sampleRates[1];
                if( low < 8000.0 ) low = 8000.0;
                TestFormats( mode, id, low, jc );
#define TESTSR(sr) {if(((sr)>=low) && ((sr)<=high)) TestFormats( mode, id, (sr), jc ); }

                TESTSR(11025.0);
                TESTSR(22050.0);
                TESTSR(34567.0);
                TESTSR(44100.0);
                TestFormats( mode, id, high, jc );
            }
            else
            {
                for( kr=0; kr<pdi->numSampleRates; kr++ )
                {
                    TestFormats( mode, id, pdi->sampleRates[kr], jc );
                }
            }
        }
    }
}
Пример #12
0
/// Gets the lists of names and lists of labels which are
/// used in the choice controls.
/// The names are what the user sees in the wxChoice.
/// The corresponding labels are what gets stored.
void AudioIOPrefs::GetNamesAndLabels()
{
   // Get lists of devices both for play and record.
   int j;
   wxString Name;
   wxString Label;

#if USE_PORTAUDIO_V19
   int nDevices = Pa_GetDeviceCount();
#else
   int nDevices = Pa_CountDevices();
#endif

   for(j=0; j<nDevices; j++) {
      const PaDeviceInfo* info = Pa_GetDeviceInfo(j);
      Name = DeviceName(info);
      Label = Name;
      if (info->maxOutputChannels > 0) {
         mmPlayNames.Add( Name );
         mmPlayLabels.Add( Label );
      }
      if (info->maxInputChannels > 0) {
         mmRecordNames.Add( Name );
         mmRecordLabels.Add( Label );
      }
   }

   // Channel counts, mono, stereo etc...
   const int numChannels = 16;
   for(int c=0; c<numChannels; c++)
   {
      mmChannelNames.Add(  wxString::Format(wxT("%d"), c+1));
      mmChannelLabels.Add( c+1 );
   }
   mmChannelNames[0] = wxString::Format(_("1 (Mono)"));
   mmChannelNames[1] = wxString::Format(_("2 (Stereo)"));
}
Пример #13
0
int main(int argc, char **argv)
{
   int num_mixers;
   int i;
   PaError error;
   PortAudioStream *stream;
   int recDeviceNum;
   int playDeviceNum;
   int inputChannels;
   int outputChannels;
   int num_devices;
   int device;
   int opt;
   int opts=-1, optm=0;
   float optv=-2, opto=-2, opti=-2, opth=-2, optb=-2;
   
   printf("px_test: a program to demonstrate the capabilities of PortMixer\n");
   printf("By Dominic Mazzoni\n");
   printf("\n");
   printf("Usage:\n");
   printf("  -d [device number]\n");
   printf("  -m [mixer number]\n");
   printf("  -v [vol] (Master volume)\n");
   printf("  -o [vol] (PCM output volume)\n");
   printf("  -i [vol] (Input volume)\n");
   printf("  -s [source number] (Input source)\n");
   printf("  -h [vol] (Playthrough)\n");
   printf("  -b [bal] (Balance: -1.0....1.0)\n");
   printf("\n");
   printf("All volumes are between 0.0 and 1.0.\n");
   printf("\n");

   error = Pa_Initialize();
   if (error != 0) {
      printf("PortAudio error: %s\n", Pa_GetErrorText(error));
      return -1;
   }

   num_devices = Pa_CountDevices();

   device = Pa_GetDefaultInputDeviceID();
   recDeviceNum = paNoDevice;
   playDeviceNum = paNoDevice;
   inputChannels = 0;
   outputChannels = 0;

   while(-1 != (opt=getopt(argc, argv, "d:m:v:o:i:s:h:b:"))) {
      switch(opt) {
      case 'd':
         device = atoi(optarg);
         printf("Set device to %d\n", device);
         break;
      case 'm':
         optm = atoi(optarg);
         printf("Set mixer number to %d\n", optm);
         break;
      case 'v':
         optv = getvolarg(optarg); break;
      case 'o':
         opto = getvolarg(optarg); break;
      case 'i':
         opti = getvolarg(optarg); break;
      case 'h':
         opth = getvolarg(optarg); break;
      case 'b':
         optb = atof(optarg); break;
      case 's':
         opts = atoi(optarg); break;
      }
   }

   printf("Devices:\n");
   for(i=0; i<num_devices; i++) {
      const PaDeviceInfo* deviceInfo = Pa_GetDeviceInfo(i);
      if (i==device) {
         printf("* ");
         if (deviceInfo->maxInputChannels > 0) {
            recDeviceNum = device;
            inputChannels = deviceInfo->maxInputChannels;
         }
         if (deviceInfo->maxOutputChannels > 0) {
            playDeviceNum = device;
            outputChannels = deviceInfo->maxOutputChannels;
         }
      }
      else
         printf("  ");
      printf("Device %d: %s in=%d out=%d",
             i, deviceInfo->name,
             deviceInfo->maxInputChannels, deviceInfo->maxOutputChannels);
      if (i == Pa_GetDefaultInputDeviceID())
         printf(" (default input)");
      if (i == Pa_GetDefaultOutputDeviceID())
         printf(" (default output)");
      printf("\n");
   }
   printf("\n");
   
   error = Pa_OpenStream(&stream, recDeviceNum, inputChannels, paFloat32, NULL,
                         playDeviceNum, outputChannels, paFloat32, NULL,
                         44101, 512, 1, paClipOff | paDitherOff,
                         DummyCallbackFunc, NULL);

   if (error) {
      printf("PortAudio error %d: %s\n", error,
             Pa_GetErrorText(error));
      return -1;
   }
   
   num_mixers = Px_GetNumMixers(stream);
   printf("Number of mixers for device %d: %d\n", device, num_mixers);
   for(i=0; i<num_mixers; i++) {
      PxMixer *mixer;
      int num;
      int j;

      printf("Mixer %d: %s\n", i, Px_GetMixerName(stream, i));
      mixer = Px_OpenMixer(stream, i);
      if (!mixer) {
         printf("  Could not open mixer!\n");
         continue;
      }

      if (i == optm) {
         if (optv!=-2) {
            Px_SetMasterVolume(mixer, optv);
            printf("  Set master volume\n");
         }
         if (opto!=-2) {
            Px_SetPCMOutputVolume(mixer, opto);
            printf("  Set output volume\n");
         }
         if (opti!=-2) {
            Px_SetInputVolume(mixer, opti);
            printf("  Set input volume\n");
         }
         if (opth!=-2) {
            Px_SetPlaythrough(mixer, opth);
            printf("  Set playthrough volume\n");
         }
         if (opts!=-2) {
            Px_SetCurrentInputSource(mixer, opts);
            printf("  Set input source\n");
         }
         if (optb!=-2) {
            Px_SetOutputBalance(mixer, optb);
            printf("  Set balance\n");
         }
      }
      
      printf("  Master volume: %.2f\n", Px_GetMasterVolume(mixer));
      printf("  PCM output volume: %.2f\n", Px_GetPCMOutputVolume(mixer));

      num = Px_GetNumOutputVolumes(mixer);
      printf("  Num outputs: %d\n", num);
      for(j=0; j<num; j++) {
         printf("    Output %d (%s): %.2f\n",
                j,
                Px_GetOutputVolumeName(mixer, j),
                Px_GetOutputVolume(mixer, j));
      }

      num = Px_GetNumInputSources(mixer);
      printf("  Num input sources: %d\n", num);
      for(j=0; j<num; j++) {
         printf("    Input %d (%s) %s\n",
                j,
                Px_GetInputSourceName(mixer, j),
                (Px_GetCurrentInputSource(mixer)==j?
                 "SELECTED": ""));
      }
      printf("  Input volume: %.2f\n", Px_GetInputVolume(mixer));

      printf("  Playthrough:");
      if (Px_SupportsPlaythrough(mixer))
         printf(" %.2f\n", Px_GetPlaythrough(mixer));
      else
         printf(" not supported.\n");

      printf("  Output balance:");
      if (Px_SupportsOutputBalance(mixer))
         printf(" %.2f\n", Px_GetOutputBalance(mixer));
      else
         printf(" not supported.\n");

      Px_CloseMixer(mixer);
   }

   Pa_CloseStream(stream);

   Pa_Terminate();

   return 0;
}
Пример #14
0
void DeviceToolBar::Populate()
{
   int i;
   wxArrayString inputs;
   wxArrayString outputs;

#if USE_PORTAUDIO_V19
   int nDevices = Pa_GetDeviceCount();
#else
   int nDevices = Pa_CountDevices();
#endif

   for (i = 0; i < nDevices; i++) {
      const PaDeviceInfo *info = Pa_GetDeviceInfo(i);
      wxString name = DeviceName(info);

      if (info->maxOutputChannels > 0) {
         outputs.Add(name);
      }

      if (info->maxInputChannels > 0) {
         inputs.Add(name);
      }
   }

   wxColour backgroundColour =
      wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);

   // Output device
   mPlayBitmap = new wxBitmap(theTheme.Bitmap(bmpSpeaker));

   Add(new wxStaticBitmap(this,
                          wxID_ANY, 
                          *mPlayBitmap), 0, wxALIGN_CENTER);

   mOutput = new wxChoice(this,
                               wxID_ANY,
                               wxDefaultPosition,
                               wxDefaultSize,
                               outputs);
   mOutput->SetName(_("Output Device"));
#if wxUSE_TOOLTIPS
   mOutput->SetToolTip(_("Output Device"));
#endif
   Add(mOutput, 0, wxALIGN_CENTER);

   if (outputs.GetCount() == 0)
      mOutput->Enable(false);

   // Input device
   mRecordBitmap = new wxBitmap(theTheme.Bitmap(bmpMic));

   Add(new wxStaticBitmap(this,
                          wxID_ANY, 
                          *mRecordBitmap), 0, wxALIGN_CENTER);

   mInput = new wxChoice(this,
                         wxID_ANY,
                         wxDefaultPosition,
                         wxDefaultSize,
                         inputs);
   mInput->SetName(_("Input Device"));
#if wxUSE_TOOLTIPS
   mInput->SetToolTip(_("Input Device"));
#endif
   Add(mInput, 0, wxALIGN_CENTER);

   if (inputs.GetCount() == 0)
      mInput->Enable(false);

   UpdatePrefs();
}
Пример #15
0
/* Find audio devices which support stereo */
PaDeviceIndex GetAudioDevices(PaDeviceIndex default_device, char *default_device_name,
	char *default_hostapi, bool output_change, bool show_list)
{
	int i;
	int err;
	bool bValidDev = false;
	const PaDeviceInfo *pdi;
#ifdef PORTAUDIO_DEV
	const PaHostApiInfo *info;
#endif
	PaDeviceIndex DefaultDevice;
	PaDeviceIndex DeviceCount;

	err = Pa_Initialize();
	if (err != paNoError) {
		printf("PortAudio error4: %s Could not open any audio devices.\n", Pa_GetErrorText(err) );
		exit(-1);
        }

#ifdef PORTAUDIO_DEV
	DeviceCount = Pa_GetDeviceCount();
#else
	DeviceCount = Pa_CountDevices();
#endif

	if ( DeviceCount < 0 )
	{
		printf("PortAudio error5: %s\n", Pa_GetErrorText(DeviceCount) );
		exit(-1);
	}

	if ( output_change )
	{
		/* If name not set, use device index */

		if ( default_device_name == NULL )
			DefaultDevice = default_device;
		else
		{
			/* Set the initial device to the default.
			 * If we find a match the device index will be applied.
			 */
			DefaultDevice = PA_DEFAULT_DEVICE;

		        for ( i = 0; i < DeviceCount; i++ )
		        {
		                pdi = Pa_GetDeviceInfo( i );
		                if ( pdi->name != NULL )
				{
#ifdef PORTAUDIO_DEV
					/* Match on audio system if specified */
					if ( default_hostapi != NULL )
					{
						info = Pa_GetHostApiInfo ( pdi->hostApi );
						if ( info->name != NULL )
						{
							/* No match, next */
							if ( strncasecmp (info->name, default_hostapi, strlen (info->name)) != 0 )
								continue;
						}
					}
#endif

					if ( strncasecmp (pdi->name, default_device_name, strlen (pdi->name)) == 0 )
					{
						DefaultDevice = i;
						break;
					}
				}
	                }

			if ( DefaultDevice == PA_DEFAULT_DEVICE )
			{
				output_change = false;
				fprintf (stderr, "Named device match failed, using default.\n");
			}
		}
	}
	else
		DefaultDevice = PA_DEFAULT_DEVICE;

	if ( DefaultDevice >= DeviceCount || ((DefaultDevice == PA_DEFAULT_DEVICE) && !output_change) )
	{
#ifdef PORTAUDIO_DEV
		DefaultDevice = Pa_GetDefaultOutputDevice();
#else
		DefaultDevice = Pa_GetDefaultOutputDeviceID();
#endif
	}

	if ( DefaultDevice == paNoDevice )
	{
		printf("PortAudio error7: No output devices found.\n" );
		exit(-1);
	}
	
	if ( show_list )
		printf("Output devices:\n");

	for ( i = 0; i < DeviceCount; i++ )
	{
		pdi = Pa_GetDeviceInfo( i );
                if ( pdi->name == NULL )
       	        {
               	        printf("PortAudio error6: GetDeviceInfo failed.\n" );
			exit(-1);
                }

#ifdef PORTAUDIO_DEV
		info = Pa_GetHostApiInfo ( pdi->hostApi );
		if ( info->name == NULL )
		{
			printf("PortAudio error8: GetHostApiInfo failed.\n" );
			exit(-1);
		}
#endif
		if ( pdi->maxOutputChannels >= 2 )
		{
               	        if ( i == DefaultDevice )
				bValidDev = true;

			if ( show_list )
			{
#ifdef PORTAUDIO_DEV
                       	        printf("%c%2d: (%s) %s (%i/%i)\n", i == DefaultDevice ? '*' : ' ', \
						i, info->name, pdi->name,
						(unsigned int) (pdi->defaultLowOutputLatency * 1000.0),
						(unsigned int) (pdi->defaultHighOutputLatency * 1000.0) );
#else
				printf("%c%2d: %s\n", i == DefaultDevice ? '*' : ' ', i, pdi->name);
#endif
			}
		}
	}

	Pa_Terminate();

	if ( !bValidDev )
		DefaultDevice = paNoDevice;

	return (DefaultDevice) ;
}
Пример #16
0
long TPortAudioRenderer::GetDeviceCount()
{
	return Pa_CountDevices();
}
Пример #17
0
int main(void)
{
  //    PortAudioStream *stream;
  //    int inputDevice = Pa_GetDefaultInputDeviceID();
  //    int        i,numDevices;
  //    PaDeviceInfo pdi;


  //    printf("Channel data acquisition configuration test\n");
  //    printf("\n"); fflush(stdout);

  //    numDevices = Pa_CountDevices();
  //    printf(    "Number of total devices : Pa_CountDevices()\t: %d.\n", numDevices );
  //    for( i=0; i<numDevices; i++ ) {
  //        pdi = *Pa_GetDeviceInfo( i );
  //        printf("Device(%d) name  \t: %s.\n", i, pdi.name);
  //        printf("\tMax Inputs   = %d\n", pdi.maxInputChannels  );
  //        printf("\tMax Outputs  = %d\n", pdi.maxOutputChannels  );
  //    }
  //    printf("Default Devic id : %d.\n", Pa_GetDefaultInputDeviceID() );
  int i,numDevices;
  PaDeviceInfo pdi;
  PaError    err;

  err = Pa_Initialize();
  if( err != paNoError )
    goto error;

  numDevices = Pa_CountDevices();
  printf(    "Number of total devices : Pa_CountDevices()\t: %d.\n", numDevices );
  for( i=0; i<numDevices; i++ )
  {
    pdi = *Pa_GetDeviceInfo( i );
    printf("Device(%d) name  \t: %s.\n", i, pdi.name);
    printf("\tMax Inputs   = %d\n", pdi.maxInputChannels  );
    printf("\tMax Outputs  = %d\n", pdi.maxOutputChannels  );
  }
  printf("Default Devic id : %d.\n", Pa_GetDefaultInputDeviceID() );

  Pa_Terminate();
  printf("\n");


  audio_rc_open();

  printf("\nNow display channel acquisition 0 up to 9 during 10seconds!!\n");
  fflush(stdout);


  for( i=0; i<100; i++ )
  {
    Pa_Sleep(100);
    /* launch test */
    audio_rc_test();
    fflush(stdout);
  }

  audio_rc_close();




  return 0;

error:
  Pa_Terminate();
  fprintf( stderr, "An error occured while using the portaudio stream\n" );
  fprintf( stderr, "Error number: %d\n", err );
  fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );

  return -1;
}
Пример #18
0
/** create a new driver instance
 */
static jack_driver_t *
portaudio_driver_new (char *name, 
				jack_client_t* client,
				jack_nframes_t frames_per_cycle,
				jack_nframes_t rate,
				int capturing,
				int playing,
				int chan_in, 
				int chan_out,
				DitherAlgorithm dither,
				char* driver_name)
{
	portaudio_driver_t *driver;
	PaError err = paNoError;
	int numDevices;
	int inputDeviceID,outputDeviceID;
	int found;
	
	PALog("portaudio driver version : %d\n", kVersion);
	PALog("creating portaudio driver ... %" PRIu32 "|%" PRIu32 "\n",
		frames_per_cycle, rate);

	driver = (portaudio_driver_t *) calloc (1, sizeof (portaudio_driver_t));

	jack_driver_init ((jack_driver_t *) driver);

	if (!jack_power_of_two(frames_per_cycle)) {
		jack_error ("PA: -p must be a power of two.");
		goto error;
	}

	driver->frames_per_cycle = frames_per_cycle;
	driver->frame_rate = rate;
	driver->capturing = capturing;
	driver->playing = playing;

	driver->attach = (JackDriverAttachFunction) portaudio_driver_attach;
	driver->detach = (JackDriverDetachFunction) portaudio_driver_detach;
	driver->read = (JackDriverReadFunction) portaudio_driver_read;
	driver->write = (JackDriverReadFunction) portaudio_driver_write;
	driver->null_cycle = (JackDriverNullCycleFunction) portaudio_driver_null_cycle;
	driver->bufsize = (JackDriverBufSizeFunction) portaudio_driver_bufsize;
	driver->start = (JackDriverStartFunction) portaudio_driver_audio_start;
	driver->stop = (JackDriverStopFunction) portaudio_driver_audio_stop;
	driver->stream = NULL;

#ifdef JACK_USE_MACH_THREADS	
	AudioDeviceID device_id;
	if (driver_name) {
		if (get_device_id_from_uid(driver_name, &device_id) != noErr)
			goto error;
		if (get_device_name_from_id(device_id, driver->driver_name) != noErr)
			goto error;
	} else {
		if (get_device_id_from_num(0, &device_id) != noErr)
			goto error; 
		if (get_device_name_from_id(device_id, driver->driver_name) != noErr)
			goto error;
	}
#endif
       
	err = Pa_Initialize();
	PALog("Pa_Initialize OK \n");
	
	PALog("Driver name required %s\n",driver->driver_name);
	numDevices = Pa_CountDevices();
	
	if( numDevices < 0 ){
		PALog("ERROR: Pa_CountDevices returned 0x%x\n", numDevices);
		err = numDevices;
		goto error;
	}
	
	PALog("Number of devices = %d\n", numDevices);

	if (strcmp(driver->driver_name,"") == 0) {
		found = portaudio_load_default(driver,numDevices,capturing,playing,&inputDeviceID,&outputDeviceID);
		if (!found) {
			PALog("ERROR : default driver has not been found\n");
			err = paHostError;
			goto error;
		}
	}else{
		found = portaudio_load_driver(driver,numDevices,capturing,playing,&inputDeviceID,&outputDeviceID,driver->driver_name);
		if (!found) {
			 PALog("ERROR : driver %s has not been found \n",driver->driver_name);
			 err = paHostError;
			 goto error;
		}
	}

	if (err != paNoError) goto error;
	
	PALog("Pa_GetDefaultOutputDeviceID() %ld\n", (long)Pa_GetDefaultOutputDeviceID());
	PALog("Pa_GetDefaultInputDeviceID() %ld\n",  (long)Pa_GetDefaultInputDeviceID());
	
	PALog("--------------------------------------------------\n");
	PALog("CoreAudio driver %s will be loaded\n", driver->driver_name);
	PALog("inputDeviceID %ld\n",  (long)inputDeviceID);
	PALog("outputDeviceID %ld\n",  (long)outputDeviceID);
	PALog("driver->capture_nchannels %ld\n", driver->capture_nchannels);
	PALog("driver->playback_nchannels %ld\n", driver->playback_nchannels);
	
	PALog("chan_in, chan_out %ld %ld\n",  (long)chan_in,  (long)chan_out);
        
	if (chan_in > 0) 
		driver->capture_nchannels = (driver->capture_nchannels < chan_in) ? driver->capture_nchannels : chan_in;
	
	if (chan_out > 0) 
		driver->playback_nchannels = (driver->playback_nchannels < chan_out) ? driver->playback_nchannels : chan_out;
		
	PALog("driver->capture_nchannels %ld\n", driver->capture_nchannels);
	PALog("driver->playback_nchannels %ld\n", driver->playback_nchannels);
	
	err = Pa_OpenStream(&driver->stream,
						((capturing && (driver->capture_nchannels > 0)) ? inputDeviceID : paNoDevice),
						((capturing) ? driver->capture_nchannels : 0),             
						paFloat32,	// 32 bit floating point input 
						NULL,
						((playing && (driver->playback_nchannels > 0)) ? outputDeviceID : paNoDevice),
						((playing) ? driver->playback_nchannels : 0),        
						paFloat32,  // 32 bit floating point output 
						NULL,
						rate,
						frames_per_cycle,            // frames per buffer 
						0,              // number of buffers, if zero then use default minimum 
						paClipOff,      // we won't output out of range samples so don't bother clipping them 
						paCallback,
						driver);
	
	if (err != paNoError) goto error;
	
	driver->client = client; 
	driver->period_usecs = (((float) driver->frames_per_cycle) / driver->frame_rate) * 1000000.0f;
	return((jack_driver_t *) driver);

error:

	Pa_Terminate();
	jack_error("An error occured while using the portaudio stream");
	jack_error("Error number: %d", err);
	jack_error("Error message: %s", Pa_GetErrorText(err));
	free(driver);
	return NULL;
}
Пример #19
0
static int pa_device_id(const char *device) {
	int len = strlen(device);
	int i;

	if (!strncmp(device, "default", 7)) {
#ifndef PA18API
		return Pa_GetDefaultOutputDevice();
#else
		return Pa_GetDefaultOutputDeviceID();
#endif
	}
	if (len >= 1 && len <= 2 && device[0] >= '0' && device[0] <= '9') {
		return atoi(device);
	}

#ifndef PA18API
#define DEVICE_ID_MAXLEN 256
	for (i = 0; i < Pa_GetDeviceCount(); ++i) {
		char tmp[DEVICE_ID_MAXLEN];
		snprintf(tmp, DEVICE_ID_MAXLEN, "%s [%s]", Pa_GetDeviceInfo(i)->name, Pa_GetHostApiInfo(Pa_GetDeviceInfo(i)->hostApi)->name);
		if (!strncmp(tmp, device, len)) {
#else
	for (i = 0; i < Pa_CountDevices(); ++i) {
		if (!strncmp(Pa_GetDeviceInfo(i)->name, device, len)) {
#endif
			return i;
		}
	}

	return -1;
}

#ifndef PA18API
static int pa_callback(const void *pa_input, void *pa_output, unsigned long pa_frames_wanted, 
					   const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags, void *userData);

#else
static int pa_callback(void *pa_input, void *pa_output, unsigned long pa_frames_wanted, 
			   PaTimestamp outTime, void *userData);
#endif
bool test_open(const char *device, unsigned rates[]) {
	PaStreamParameters outputParameters;
	PaError err;
	unsigned ref[] TEST_RATES;
	int device_id, i, ind;

	if ((device_id = pa_device_id(device)) == -1) {
		LOG_INFO("device %s not found", device);
		return false;
	}

	outputParameters.device = device_id;
	outputParameters.channelCount = 2;
	outputParameters.sampleFormat = paInt32;
#ifndef PA18API
	outputParameters.suggestedLatency =
		output.latency ? (double)output.latency/(double)1000 : Pa_GetDeviceInfo(outputParameters.device)->defaultHighOutputLatency;
	outputParameters.hostApiSpecificStreamInfo = NULL;
#endif

	// check supported sample rates
	// Note use Pa_OpenStream as it appears more reliable than Pa_IsFormatSupported on some windows apis
	for (i = 0, ind = 0; ref[i]; ++i) {
#ifndef PA18API
		err = Pa_OpenStream(&pa.stream, NULL, &outputParameters, (double)ref[i], paFramesPerBufferUnspecified, paNoFlag, 
							pa_callback, NULL);
#else
		err = Pa_OpenStream(&pa.stream, paNoDevice, 0, 0, NULL, outputParameters.device,
			outputParameters.channelCount, outputParameters.sampleFormat, NULL, (double)ref[i],
			paFramesPerBuffer, paNumberOfBuffers, paNoFlag, pa_callback, NULL);
#endif
		if (err == paNoError) {
			Pa_CloseStream(pa.stream);
			rates[ind++] = ref[i];
		}
	}

	if (!rates[0]) {
		LOG_WARN("no available rate found");
		return false;
	}

	pa.stream = NULL;
	return true;
}

static void pa_stream_finished(void *userdata) {
	if (running) {
		LOG_INFO("stream finished");
		LOCK;
		output.pa_reopen = true;
		wake_controller();
		UNLOCK;
	}
}

static thread_type monitor_thread;
bool monitor_thread_running = false;

static void *pa_monitor() {
	bool output_off;

	LOCK;

	if (monitor_thread_running) {
		LOG_DEBUG("monitor thread already running");
		UNLOCK;
		return 0;
	}

	LOG_DEBUG("start monitor thread");

	monitor_thread_running = true;
	output_off = (output.state == OUTPUT_OFF);

	while (monitor_thread_running) {
		if (output_off) {
			if (output.state != OUTPUT_OFF) {
				LOG_INFO("output on");
				break;
			}
		} else {
			// this is a hack to partially support hot plugging of devices
			// we rely on terminating and reinitalising PA to get an updated list of devices and use name for output.device
			LOG_INFO("probing device %s", output.device);
			Pa_Terminate();
			Pa_Initialize();
			pa.stream = NULL;
			if (pa_device_id(output.device) != -1) {
				LOG_INFO("device reopen");
				break;
			}
		}

		UNLOCK;
		sleep(output_off ? 1 : 5);
		LOCK;
	}

	LOG_DEBUG("end monitor thread");

	monitor_thread_running = false;
	pa.stream = NULL;

	_pa_open();

	UNLOCK;

	return 0;
}
Пример #20
0
static internalPortAudioDevice *Pa_GetInternalDevice( PaDeviceID id )
{
	if( (id < 0) || ( id >= Pa_CountDevices()) ) return NULL;
	return &sDevices[id];
}
Пример #21
0
PaError PaHost_OpenStream( internalPortAudioStream   *past )
{
	HRESULT          hr;
	PaError          result = paNoError;
	PaHostSoundControl *pahsc;
	int              numBytes, maxChannels;
	unsigned int     minNumBuffers;
	internalPortAudioDevice *pad;
	DSoundWrapper   *dsw;
/* Allocate and initialize host data. */
	pahsc = (PaHostSoundControl *) PaHost_AllocateFastMemory(sizeof(PaHostSoundControl)); /* MEM */
	if( pahsc == NULL )
	{
		result = paInsufficientMemory;
		goto error;
	}
	memset( pahsc, 0, sizeof(PaHostSoundControl) );
	past->past_DeviceData = (void *) pahsc;
	pahsc->pahsc_TimerID = 0;
	dsw = &pahsc->pahsc_DSoundWrapper;
	DSW_Init( dsw );
/* Allocate native buffer. */
	maxChannels = ( past->past_NumOutputChannels > past->past_NumInputChannels ) ?
		past->past_NumOutputChannels : past->past_NumInputChannels;
	pahsc->pahsc_BytesPerBuffer = past->past_FramesPerUserBuffer * maxChannels * sizeof(short);
	if( maxChannels > 0 )
	{
		pahsc->pahsc_NativeBuffer = (short *) PaHost_AllocateFastMemory(pahsc->pahsc_BytesPerBuffer); /* MEM */
		if( pahsc->pahsc_NativeBuffer == NULL )
		{
			result = paInsufficientMemory;
			goto error;
		}
	}
	else
	{
		result = paInvalidChannelCount;
		goto error;
	}
	
	DBUG(("PaHost_OpenStream: pahsc_MinFramesPerHostBuffer = %d\n", pahsc->pahsc_MinFramesPerHostBuffer ));
	minNumBuffers = Pa_GetMinNumBuffers( past->past_FramesPerUserBuffer, past->past_SampleRate );
	past->past_NumUserBuffers = ( minNumBuffers > past->past_NumUserBuffers ) ? minNumBuffers : past->past_NumUserBuffers;
	numBytes = pahsc->pahsc_BytesPerBuffer * past->past_NumUserBuffers;
	if( numBytes < DSBSIZE_MIN )
	{
		result = paBufferTooSmall;
		goto error;
	}
	if( numBytes > DSBSIZE_MAX )
	{
		result = paBufferTooBig;
		goto error;
	}
	pahsc->pahsc_FramesPerDSBuffer = past->past_FramesPerUserBuffer * past->past_NumUserBuffers;
	{
		int msecLatency = (int) ((pahsc->pahsc_FramesPerDSBuffer * 1000) / past->past_SampleRate);
		PRINT(("PortAudio on DirectSound - Latency = %d frames, %d msec\n", pahsc->pahsc_FramesPerDSBuffer, msecLatency ));
	}
/* ------------------ OUTPUT */
	if( (past->past_OutputDeviceID >= 0) && (past->past_NumOutputChannels > 0) )
	{
		DBUG(("PaHost_OpenStream: deviceID = 0x%x\n", past->past_OutputDeviceID));
		pad = Pa_GetInternalDevice( past->past_OutputDeviceID );
		hr = DirectSoundCreate( pad->pad_lpGUID, &dsw->dsw_pDirectSound,   NULL );
/* If this fails, then try each output device until we find one that works. */
		if( hr != DS_OK )
		{
			int i;
			ERR_RPT(("Creation of requested Audio Output device '%s' failed.\n",
				((pad->pad_lpGUID == NULL) ? "Default" : pad->pad_Info.name) ));
			for( i=0; i<Pa_CountDevices(); i++ )
			{
				pad = Pa_GetInternalDevice( i );
				if( pad->pad_Info.maxOutputChannels >= past->past_NumOutputChannels )
				{
					DBUG(("Try device '%s' instead.\n", pad->pad_Info.name ));
					hr = DirectSoundCreate( pad->pad_lpGUID, &dsw->dsw_pDirectSound,   NULL );
					if( hr == DS_OK )
					{
						ERR_RPT(("Using device '%s' instead.\n", pad->pad_Info.name ));
						break;
					}
				}
			}
		}
		if( hr != DS_OK )
		{
			ERR_RPT(("PortAudio: DirectSoundCreate() failed!\n"));
			result = paHostError;
			sPaHostError = hr;
			goto error;
		}
		hr = DSW_InitOutputBuffer( dsw,
			(unsigned long) (past->past_SampleRate + 0.5),
			past->past_NumOutputChannels, numBytes );
		DBUG(("DSW_InitOutputBuffer() returns %x\n", hr));
		if( hr != DS_OK )
		{
			result = paHostError;
			sPaHostError = hr;
			goto error;
		}
		past->past_FrameCount = pahsc->pahsc_DSoundWrapper.dsw_FramesWritten;
	}
#if SUPPORT_AUDIO_CAPTURE
/* ------------------ INPUT */
	if( (past->past_InputDeviceID >= 0) && (past->past_NumInputChannels > 0) )
	{
		pad = Pa_GetInternalDevice( past->past_InputDeviceID );
		hr = DirectSoundCaptureCreate( pad->pad_lpGUID, &dsw->dsw_pDirectSoundCapture,   NULL );
/* If this fails, then try each input device until we find one that works. */
		if( hr != DS_OK )
		{
			int i;
			ERR_RPT(("Creation of requested Audio Capture device '%s' failed.\n",
				((pad->pad_lpGUID == NULL) ? "Default" : pad->pad_Info.name) ));
			for( i=0; i<Pa_CountDevices(); i++ )
			{
				pad = Pa_GetInternalDevice( i );
				if( pad->pad_Info.maxInputChannels >= past->past_NumInputChannels )
				{
					PRINT(("Try device '%s' instead.\n", pad->pad_Info.name ));
					hr = DirectSoundCaptureCreate( pad->pad_lpGUID, &dsw->dsw_pDirectSoundCapture,   NULL );
					if( hr == DS_OK ) break;
				}
			}
		}
		if( hr != DS_OK )
		{
			ERR_RPT(("PortAudio: DirectSoundCaptureCreate() failed!\n"));
			result = paHostError;
			sPaHostError = hr;
			goto error;
		}
		hr = DSW_InitInputBuffer( dsw,
			(unsigned long) (past->past_SampleRate + 0.5),
			past->past_NumInputChannels, numBytes );
		DBUG(("DSW_InitInputBuffer() returns %x\n", hr));
		if( hr != DS_OK )
		{
			ERR_RPT(("PortAudio: DSW_InitInputBuffer() returns %x\n", hr));
			result = paHostError;
			sPaHostError = hr;
			goto error;
		}
	}
#endif /* SUPPORT_AUDIO_CAPTURE */
	/* Calculate scalar used in CPULoad calculation. */ 
	{
		LARGE_INTEGER frequency;
		if( QueryPerformanceFrequency( &frequency ) == 0 )
		{
			pahsc->pahsc_InverseTicksPerUserBuffer = 0.0;
		}
		else
		{
			pahsc->pahsc_InverseTicksPerUserBuffer = past->past_SampleRate /
				( (double)frequency.QuadPart * past->past_FramesPerUserBuffer );
			DBUG(("pahsc_InverseTicksPerUserBuffer = %g\n", pahsc->pahsc_InverseTicksPerUserBuffer ));
		}
	}
	return result;
error:
	PaHost_CloseStream( past );
	return result;
}
Пример #22
0
AudioIOPrefs::AudioIOPrefs(wxWindow * parent):
PrefsPanel(parent)
{
   /* read prefs all at once, then set up the dialog */
   gPrefs->SetPath("/AudioIO");
   mPlayDevice = gPrefs->Read("PlaybackDevice", "");
   mRecDevice = gPrefs->Read("RecordingDevice", "");
   bool recordStereo;
   gPrefs->Read("RecordStereo", &recordStereo, false);
   bool duplex;
   gPrefs->Read("Duplex", &duplex, false);
   gPrefs->SetPath("/");

   topSizer = new wxStaticBoxSizer(
      new wxStaticBox(this,
                      -1,
                     _("Audio I/O Settings")),
      wxVERTICAL);

   //
   // Playback
   //

   wxStaticBoxSizer *playbackSizer =
      new wxStaticBoxSizer(
         new wxStaticBox(this, -1, _("Playback Device")),
            wxVERTICAL);

   wxBoxSizer *pFileSizer = new wxBoxSizer(wxHORIZONTAL);

   int j, k;
   int playIndex = 0;
   int numDevices = 0;

   // Count the number of devices which do output
   for(j=0; j<Pa_CountDevices(); j++) {
      const PaDeviceInfo* info = Pa_GetDeviceInfo(j);
      if (info->maxOutputChannels > 0)
         numDevices++;
   }

   wxString *playNames = new wxString[numDevices];
   k = 0;
   for(j=0; j<Pa_CountDevices(); j++) {
      const PaDeviceInfo* info = Pa_GetDeviceInfo(j);
      if (info->maxOutputChannels > 0) {
         playNames[k] = info->name;
         if (playNames[k] == mPlayDevice)
            playIndex = k;
         k++;
      }
   }

   mPlayChoice = new wxChoice(this, -1, wxDefaultPosition, wxDefaultSize,
                              numDevices, playNames);
   mPlayChoice->SetSelection(playIndex);

   pFileSizer->Add(
      new wxStaticText(this, -1, _("Device:")), 0, 
      wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, GENERIC_CONTROL_BORDER);

   pFileSizer->Add(mPlayChoice, 1, 
      wxGROW|wxALL|wxALIGN_CENTER_VERTICAL, GENERIC_CONTROL_BORDER);

   playbackSizer->Add(pFileSizer, 0,
      wxGROW|wxALL, GENERIC_CONTROL_BORDER);

   topSizer->Add(playbackSizer, 0, wxALL|wxGROW, TOP_LEVEL_BORDER);

   //
   // Recording
   //

   wxStaticBoxSizer *recordingSizer =
      new wxStaticBoxSizer(
         new wxStaticBox(this, -1, _("Recording Device")),
            wxVERTICAL);

   wxBoxSizer *rFileSizer = new wxBoxSizer(wxHORIZONTAL);

   int recIndex = 0;
   numDevices = 0;

   // Count the number of devices which do input
   for(j=0; j<Pa_CountDevices(); j++) {
      const PaDeviceInfo* info = Pa_GetDeviceInfo(j);
      if (info->maxInputChannels > 0)
         numDevices++;
   }

   wxString *recNames = new wxString[numDevices];
   k = 0;
   for(j=0; j<Pa_CountDevices(); j++) {
      const PaDeviceInfo* info = Pa_GetDeviceInfo(j);
      if (info->maxInputChannels > 0) {
         recNames[k] = info->name;
         if (recNames[k] == mRecDevice)
            recIndex = k;
         k++;
      }
   }

   mRecChoice = new wxChoice(this, -1, wxDefaultPosition, wxDefaultSize,
                              numDevices, recNames);
   mRecChoice->SetSelection(recIndex);

   rFileSizer->Add(
      new wxStaticText(this, -1, _("Device:")), 0, 
      wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, GENERIC_CONTROL_BORDER);

   rFileSizer->Add(mRecChoice, 1, 
      wxGROW|wxALL|wxALIGN_CENTER_VERTICAL, GENERIC_CONTROL_BORDER);

   recordingSizer->Add(rFileSizer, 0,
      wxGROW|wxALL, GENERIC_CONTROL_BORDER);

   topSizer->Add(recordingSizer, 0, wxALL|wxGROW, TOP_LEVEL_BORDER);

   mRecordStereo = new wxCheckBox(this, -1, _("Record in Stereo"));
   mRecordStereo->SetValue(recordStereo);
   topSizer->Add(mRecordStereo, 0, wxGROW|wxALL, 2);

   mDuplex = new wxCheckBox(this, -1,
                            _("Play other tracks while recording new one"));
   mDuplex->SetValue(duplex);
   topSizer->Add(mDuplex, 0, wxGROW|wxALL, 2);

   SetAutoLayout(true);
   topSizer->Fit(this);
   topSizer->SetSizeHints(this);
   SetSizer(topSizer);
}
Пример #23
0
static int TestBadOpens( void )
{
    PortAudioStream *stream = NULL;
    PaError result;
    PaQaData myData;
    /* Setup data for synthesis thread. */
    myData.framesLeft = (unsigned long) (SAMPLE_RATE * 100); /* 100 seconds */
    myData.numChannels = 1;
    myData.mode = MODE_OUTPUT;
    HOPEFOR( "No devices specified.",(
                 (result = Pa_OpenStream(
                               &stream,
                               paNoDevice, 0, paFloat32, NULL,
                               paNoDevice, 0, paFloat32, NULL,
                               SAMPLE_RATE, FRAMES_PER_BUFFER, NUM_BUFFERS,
                               paClipOff,
                               QaCallback,
                               &myData )
                 ) == paInvalidDeviceId) );
    HOPEFOR( "Out of range input device specified.",(
                 (result = Pa_OpenStream(
                               &stream,
                               Pa_CountDevices(), 0, paFloat32, NULL,
                               paNoDevice, 0, paFloat32, NULL,
                               SAMPLE_RATE, FRAMES_PER_BUFFER, NUM_BUFFERS,
                               paClipOff,
                               QaCallback,
                               &myData )
                 ) == paInvalidDeviceId) );

    HOPEFOR( "Out of range output device specified.",(
                 (result = Pa_OpenStream(
                               &stream,
                               paNoDevice, 0, paFloat32, NULL,
                               Pa_CountDevices(), 0, paFloat32, NULL,
                               SAMPLE_RATE, FRAMES_PER_BUFFER, NUM_BUFFERS,
                               paClipOff,
                               QaCallback,
                               &myData )
                 ) == paInvalidDeviceId) );
    HOPEFOR( "Zero input channels.",(
                 (result = Pa_OpenStream(
                               &stream,
                               Pa_GetDefaultInputDeviceID(), 0, paFloat32, NULL,
                               paNoDevice, 0, paFloat32, NULL,
                               SAMPLE_RATE, FRAMES_PER_BUFFER, NUM_BUFFERS,
                               paClipOff,
                               QaCallback,
                               &myData )
                 ) == paInvalidChannelCount) );
    HOPEFOR( "Zero output channels.",(
                 (result = Pa_OpenStream(
                               &stream,
                               paNoDevice, 0, paFloat32, NULL,
                               Pa_GetDefaultOutputDeviceID(), 0, paFloat32, NULL,
                               SAMPLE_RATE, FRAMES_PER_BUFFER, NUM_BUFFERS,
                               paClipOff,
                               QaCallback,
                               &myData )
                 ) == paInvalidChannelCount) );
    HOPEFOR( "Nonzero input channels but no device.",(
                 (result = Pa_OpenStream(
                               &stream,
                               Pa_GetDefaultInputDeviceID(), 2, paFloat32, NULL,
                               paNoDevice, 2, paFloat32, NULL,
                               SAMPLE_RATE, FRAMES_PER_BUFFER, NUM_BUFFERS,
                               paClipOff,
                               QaCallback,
                               &myData )
                 ) == paInvalidChannelCount) );

    HOPEFOR( "Nonzero output channels but no device.",(
                 (result = Pa_OpenStream(
                               &stream,
                               paNoDevice, 2, paFloat32, NULL,
                               Pa_GetDefaultOutputDeviceID(), 2, paFloat32, NULL,
                               SAMPLE_RATE, FRAMES_PER_BUFFER, NUM_BUFFERS,
                               paClipOff,
                               QaCallback,
                               &myData )
                 ) == paInvalidChannelCount) );
    HOPEFOR( "NULL stream pointer.",(
                 (result = Pa_OpenStream(
                               NULL,
                               paNoDevice, 0, paFloat32, NULL,
                               Pa_GetDefaultOutputDeviceID(), 2, paFloat32, NULL,
                               SAMPLE_RATE, FRAMES_PER_BUFFER, NUM_BUFFERS,
                               paClipOff,
                               QaCallback,
                               &myData )
                 ) == paBadStreamPtr) );
    HOPEFOR( "Low sample rate.",(
                 (result = Pa_OpenStream(
                               &stream,
                               paNoDevice, 0, paFloat32, NULL,
                               Pa_GetDefaultOutputDeviceID(), 2, paFloat32, NULL,
                               1.0, FRAMES_PER_BUFFER, NUM_BUFFERS,
                               paClipOff,
                               QaCallback,
                               &myData )
                 ) == paInvalidSampleRate) );
    HOPEFOR( "High sample rate.",(
                 (result = Pa_OpenStream(
                               &stream,
                               paNoDevice, 0, paFloat32, NULL,
                               Pa_GetDefaultOutputDeviceID(), 2, paFloat32, NULL,
                               10000000.0, FRAMES_PER_BUFFER, NUM_BUFFERS,
                               paClipOff,
                               QaCallback,
                               &myData )
                 ) == paInvalidSampleRate) );
    HOPEFOR( "NULL callback.",(
                 (result = Pa_OpenStream(
                               &stream,
                               paNoDevice, 0, paFloat32, NULL,
                               Pa_GetDefaultOutputDeviceID(), 2, paFloat32, NULL,
                               SAMPLE_RATE, FRAMES_PER_BUFFER, NUM_BUFFERS,
                               paClipOff,
                               NULL,
                               &myData )
                 ) == paNullCallback) );
    HOPEFOR( "Bad flag.",(
                 (result = Pa_OpenStream(
                               &stream,
                               paNoDevice, 0, paFloat32, NULL,
                               Pa_GetDefaultOutputDeviceID(), 2, paFloat32, NULL,
                               SAMPLE_RATE, FRAMES_PER_BUFFER, NUM_BUFFERS,
                               (1<<3),
                               QaCallback,
                               &myData )
                 ) == paInvalidFlag) );

#if 1 /* FIXME - this is legal for some implementations. */
    HOPEFOR( "Use input device as output device.",(
                 (result = Pa_OpenStream(
                               &stream,
                               paNoDevice, 0, paFloat32, NULL,
                               Pa_GetDefaultInputDeviceID(), 2, paFloat32, NULL,
                               SAMPLE_RATE, FRAMES_PER_BUFFER, NUM_BUFFERS,
                               paClipOff,
                               QaCallback,
                               &myData )
                 ) == paInvalidDeviceId) );

    HOPEFOR( "Use output device as input device.",(
                 (result = Pa_OpenStream(
                               &stream,
                               Pa_GetDefaultOutputDeviceID(), 2, paFloat32, NULL,
                               paNoDevice, 0, paFloat32, NULL,
                               SAMPLE_RATE, FRAMES_PER_BUFFER, NUM_BUFFERS,
                               paClipOff,
                               QaCallback,
                               &myData )
                 ) == paInvalidDeviceId) );
#endif

    if( stream != NULL ) Pa_CloseStream( stream );
    return result;
}
Пример #24
0
bool AudioIO::OpenDevice()
{
   PaError         error;
   int             numPortAudioBuffers;
   int             recDeviceNum;
   int             playDeviceNum;
   PaSampleFormat  paFormat;
   wxString        recDevice;
   wxString        playDevice;

   numPortAudioBuffers = Pa_GetMinNumBuffers(mBufferSize, mRate);

   if (mNumInChannels>0)
      numPortAudioBuffers *= 2;

   recDeviceNum = Pa_GetDefaultInputDeviceID();
   playDeviceNum = Pa_GetDefaultOutputDeviceID();

   recDevice = gPrefs->Read("/AudioIO/RecordingDevice", "");
   playDevice = gPrefs->Read("/AudioIO/PlaybackDevice", "");

   mFormat = (sampleFormat)gPrefs->Read("/AudioIO/SampleFormat", floatSample);

   switch(mFormat) {
   case floatSample:
      paFormat = paFloat32;
      break;
   case int16Sample:
      paFormat = paInt16;
      break;
   default:
      // Debug message only
      printf("Cannot output this sample format using PortAudio\n");
      return false;
   }

   for(int j=0; j<Pa_CountDevices(); j++) {
      const PaDeviceInfo* info = Pa_GetDeviceInfo(j);
      if (info->name == playDevice && info->maxOutputChannels > 0)
         playDeviceNum = j;
      if (info->name == recDevice && info->maxInputChannels > 0)
         recDeviceNum = j;
   }

   if (mNumOutChannels<=0)
      playDeviceNum = paNoDevice;
   if (mNumInChannels<=0)
      recDeviceNum = paNoDevice;

   error = Pa_OpenStream(&mPortStream,
                         recDeviceNum,
                         mNumInChannels,
                         paFormat,
                         NULL, /* inputDriverInfo */
                         playDeviceNum,
                         mNumOutChannels,
                         paFormat,
                         NULL,
                         mRate,
                         (unsigned long)mBufferSize,
                         (unsigned long)numPortAudioBuffers,
                         paClipOff | paDitherOff,
                         audacityAudioCallback,
                         NULL);

   return (mPortStream != NULL && error == paNoError);
}