summaryrefslogtreecommitdiff
path: root/gr-audio-portaudio/src/gri_portaudio.cc
blob: faa472337de026480508531042ea535ebbf5e1cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* -*- c++ -*- */
/*
 * Copyright 2006 Free Software Foundation, Inc.
 * 
 * This file is part of GNU Radio
 * 
 * GNU Radio is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3, or (at your option)
 * any later version.
 * 
 * GNU Radio is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with GNU Radio; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street,
 * Boston, MA 02110-1301, USA.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <gri_portaudio.h>
#include <portaudio.h>
#include <string.h>


PaDeviceIndex
gri_pa_find_device_by_name(const char *name)
{
  int   i;
  int   numDevices;
  const PaDeviceInfo *pdi;
  int   len = strlen( name );
  PaDeviceIndex result = paNoDevice;
  numDevices = Pa_GetDeviceCount();
  for( i=0; i<numDevices; i++ )
  {
    pdi = Pa_GetDeviceInfo( i );
    if( strncmp( name, pdi->name, len ) == 0 )
    {
      result = i;
      break;
    }
  }
  return result;
}


void
gri_print_devices()
{
  int     numDevices, defaultDisplayed, myDevice=0;
  const   PaDeviceInfo *deviceInfo;

  numDevices = Pa_GetDeviceCount();
  if (numDevices < 0)
    return;

  printf("Number of devices found = %d\n", numDevices);

  for (int i=0; i < numDevices; i++ ) {
    deviceInfo = Pa_GetDeviceInfo( i );
    printf( "--------------------------------------- device #%d\n", i );
    /* Mark global and API specific default devices */
    defaultDisplayed = 0;
    if( i == Pa_GetDefaultInputDevice() )
      {
	myDevice = i;
	printf( "[ Default Input" );
	defaultDisplayed = 1;
      }
    else if( i == Pa_GetHostApiInfo( deviceInfo->hostApi )->defaultInputDevice )
      {
	const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo( deviceInfo->hostApi );
	printf( "[ Default %s Input", hostInfo->name );
	defaultDisplayed = 1;
      }
        
    if( i == Pa_GetDefaultOutputDevice() )
      {
	printf( (defaultDisplayed ? "," : "[") );
	printf( " Default Output" );
	defaultDisplayed = 1;
      }
    else if( i == Pa_GetHostApiInfo( deviceInfo->hostApi )->defaultOutputDevice )
      {
	const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo( deviceInfo->hostApi );
	printf( (defaultDisplayed ? "," : "[") );                
	printf( " Default %s Output", hostInfo->name );
	defaultDisplayed = 1;
      }
    if( defaultDisplayed )
      printf( " ]\n" );

    /* print device info fields */
    printf( "Name                        = %s\n", deviceInfo->name );
    printf( "Host API                    = %s\n",  Pa_GetHostApiInfo( deviceInfo->hostApi )->name );
    printf( "Max inputs = %d", deviceInfo->maxInputChannels  );
    printf( ", Max outputs = %d\n", deviceInfo->maxOutputChannels  );

    printf( "Default low input latency   = %8.3f\n", deviceInfo->defaultLowInputLatency  );
    printf( "Default low output latency  = %8.3f\n", deviceInfo->defaultLowOutputLatency  );
    printf( "Default high input latency  = %8.3f\n", deviceInfo->defaultHighInputLatency  );
    printf( "Default high output latency = %8.3f\n", deviceInfo->defaultHighOutputLatency  );
  }
}