Imported Upstream version 3.0
[debian/gnuradio] / gr-audio-portaudio / src / gri_portaudio.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2006 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  * 
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include <gri_portaudio.h>
28 #include <portaudio.h>
29 #include <string.h>
30
31
32 PaDeviceIndex
33 gri_pa_find_device_by_name(const char *name)
34 {
35   int   i;
36   int   numDevices;
37   const PaDeviceInfo *pdi;
38   int   len = strlen( name );
39   PaDeviceIndex result = paNoDevice;
40   numDevices = Pa_GetDeviceCount();
41   for( i=0; i<numDevices; i++ )
42   {
43     pdi = Pa_GetDeviceInfo( i );
44     if( strncmp( name, pdi->name, len ) == 0 )
45     {
46       result = i;
47       break;
48     }
49   }
50   return result;
51 }
52
53
54 void
55 gri_print_devices()
56 {
57   int     numDevices, defaultDisplayed, myDevice=0;
58   const   PaDeviceInfo *deviceInfo;
59
60   numDevices = Pa_GetDeviceCount();
61   if (numDevices < 0)
62     return;
63
64   printf("Number of devices found = %d\n", numDevices);
65
66   for (int i=0; i < numDevices; i++ ) {
67     deviceInfo = Pa_GetDeviceInfo( i );
68     printf( "--------------------------------------- device #%d\n", i );
69     /* Mark global and API specific default devices */
70     defaultDisplayed = 0;
71     if( i == Pa_GetDefaultInputDevice() )
72       {
73         myDevice = i;
74         printf( "[ Default Input" );
75         defaultDisplayed = 1;
76       }
77     else if( i == Pa_GetHostApiInfo( deviceInfo->hostApi )->defaultInputDevice )
78       {
79         const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo( deviceInfo->hostApi );
80         printf( "[ Default %s Input", hostInfo->name );
81         defaultDisplayed = 1;
82       }
83         
84     if( i == Pa_GetDefaultOutputDevice() )
85       {
86         printf( (defaultDisplayed ? "," : "[") );
87         printf( " Default Output" );
88         defaultDisplayed = 1;
89       }
90     else if( i == Pa_GetHostApiInfo( deviceInfo->hostApi )->defaultOutputDevice )
91       {
92         const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo( deviceInfo->hostApi );
93         printf( (defaultDisplayed ? "," : "[") );                
94         printf( " Default %s Output", hostInfo->name );
95         defaultDisplayed = 1;
96       }
97     if( defaultDisplayed )
98       printf( " ]\n" );
99
100     /* print device info fields */
101     printf( "Name                        = %s\n", deviceInfo->name );
102     printf( "Host API                    = %s\n",  Pa_GetHostApiInfo( deviceInfo->hostApi )->name );
103     printf( "Max inputs = %d", deviceInfo->maxInputChannels  );
104     printf( ", Max outputs = %d\n", deviceInfo->maxOutputChannels  );
105
106     printf( "Default low input latency   = %8.3f\n", deviceInfo->defaultLowInputLatency  );
107     printf( "Default low output latency  = %8.3f\n", deviceInfo->defaultLowOutputLatency  );
108     printf( "Default high input latency  = %8.3f\n", deviceInfo->defaultHighInputLatency  );
109     printf( "Default high output latency = %8.3f\n", deviceInfo->defaultHighOutputLatency  );
110   }
111 }