Mercurial > octave-antonio
annotate libinterp/dldfcn/audiodevinfo.cc @ 19512:a5eb03a7e2a5
eliminate unused variable and parameter warnings
* audiodevinfo.cc, audioread.cc: Eliminate unused variable and
parameter warnings.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 02 Jan 2015 00:59:08 -0500 |
parents | 19f75d156ffe |
children | 4cb4210bd392 |
rev | line source |
---|---|
19500
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19498
diff
changeset
|
1 /* |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19498
diff
changeset
|
2 |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19498
diff
changeset
|
3 Copyright (C) 2013 Vytautas JanĨauskas |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19498
diff
changeset
|
4 |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19498
diff
changeset
|
5 This file is part of Octave. |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19498
diff
changeset
|
6 |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19498
diff
changeset
|
7 Octave is free software; you can redistribute it and/or modify it |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19498
diff
changeset
|
8 under the terms of the GNU General Public License as published by the |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19498
diff
changeset
|
9 Free Software Foundation; either version 3 of the License, or (at your |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19498
diff
changeset
|
10 option) any later version. |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19498
diff
changeset
|
11 |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19498
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19498
diff
changeset
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19498
diff
changeset
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19498
diff
changeset
|
15 for more details. |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19498
diff
changeset
|
16 |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19498
diff
changeset
|
17 You should have received a copy of the GNU General Public License |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19498
diff
changeset
|
18 along with Octave; see the file COPYING. If not, see |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19498
diff
changeset
|
19 <http://www.gnu.org/licenses/>. |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19498
diff
changeset
|
20 |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19498
diff
changeset
|
21 */ |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19498
diff
changeset
|
22 |
19501
1f551d169db2
Include config.h in audio project source files
Mike Miller <mtmiller@ieee.org>
parents:
19500
diff
changeset
|
23 #ifdef HAVE_CONFIG_H |
1f551d169db2
Include config.h in audio project source files
Mike Miller <mtmiller@ieee.org>
parents:
19500
diff
changeset
|
24 #include <config.h> |
1f551d169db2
Include config.h in audio project source files
Mike Miller <mtmiller@ieee.org>
parents:
19500
diff
changeset
|
25 #endif |
1f551d169db2
Include config.h in audio project source files
Mike Miller <mtmiller@ieee.org>
parents:
19500
diff
changeset
|
26 |
19510 | 27 // <cstdint> requires c++11 |
28 #include <stdint.h> | |
29 | |
30 #include <string> | |
31 #include <vector> | |
32 | |
19511
19f75d156ffe
don't include oct.h in Octave source files
John W. Eaton <jwe@octave.org>
parents:
19510
diff
changeset
|
33 #include "defun-dld.h" |
19f75d156ffe
don't include oct.h in Octave source files
John W. Eaton <jwe@octave.org>
parents:
19510
diff
changeset
|
34 #include "error.h" |
19f75d156ffe
don't include oct.h in Octave source files
John W. Eaton <jwe@octave.org>
parents:
19510
diff
changeset
|
35 #include "gripes.h" |
19f75d156ffe
don't include oct.h in Octave source files
John W. Eaton <jwe@octave.org>
parents:
19510
diff
changeset
|
36 #include "oct-obj.h" |
19510 | 37 #include "ov.h" |
19511
19f75d156ffe
don't include oct.h in Octave source files
John W. Eaton <jwe@octave.org>
parents:
19510
diff
changeset
|
38 #include "ov-int32.h" |
19472
c2031ad6dbe7
Fix octave header includes in audiodevinfo
Vytautas Jančauskas <unaudio@gmail.com>
parents:
19469
diff
changeset
|
39 #include "ov-struct.h" |
19510 | 40 #include "parse.h" |
41 | |
42 #if defined (HAVE_PORTAUDIO) | |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
43 #include <portaudio.h> |
19510 | 44 #endif |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
45 |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
46 PaSampleFormat |
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
47 bits_to_format (int bits) |
19473
2e174b5e7703
Fix audiodevinfo, audioinfo, audioread and audiowrite build process
Vytautas Jančauskas <unaudio@gmail.com>
parents:
19472
diff
changeset
|
48 { |
2e174b5e7703
Fix audiodevinfo, audioinfo, audioread and audiowrite build process
Vytautas Jančauskas <unaudio@gmail.com>
parents:
19472
diff
changeset
|
49 if (bits == 8) |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
50 return paInt8; |
19473
2e174b5e7703
Fix audiodevinfo, audioinfo, audioread and audiowrite build process
Vytautas Jančauskas <unaudio@gmail.com>
parents:
19472
diff
changeset
|
51 else if (bits == 16) |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
52 return paInt16; |
19473
2e174b5e7703
Fix audiodevinfo, audioinfo, audioread and audiowrite build process
Vytautas Jančauskas <unaudio@gmail.com>
parents:
19472
diff
changeset
|
53 else if (bits == 24) |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
54 return paInt24; |
19473
2e174b5e7703
Fix audiodevinfo, audioinfo, audioread and audiowrite build process
Vytautas Jančauskas <unaudio@gmail.com>
parents:
19472
diff
changeset
|
55 else if (bits == 32) |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
56 return paInt32; |
19473
2e174b5e7703
Fix audiodevinfo, audioinfo, audioread and audiowrite build process
Vytautas Jančauskas <unaudio@gmail.com>
parents:
19472
diff
changeset
|
57 else if (bits == -1) |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
58 return paFloat32; |
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
59 else |
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
60 return 0; |
19473
2e174b5e7703
Fix audiodevinfo, audioinfo, audioread and audiowrite build process
Vytautas Jančauskas <unaudio@gmail.com>
parents:
19472
diff
changeset
|
61 } |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
62 |
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
63 DEFUN_DLD (audiodevinfo, args, , |
19505
ce02743b6f2a
Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19503
diff
changeset
|
64 "-*- texinfo -*-\n\ |
ce02743b6f2a
Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19503
diff
changeset
|
65 @deftypefn {Loadable Function} {@var{devinfo} =} audiodevinfo ()\n\ |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
66 \n\ |
19505
ce02743b6f2a
Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19503
diff
changeset
|
67 Returns a structure with two fields called \"input\" and \"output\".\n\ |
ce02743b6f2a
Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19503
diff
changeset
|
68 Each structure contains an array of structures with three fields called\n\ |
ce02743b6f2a
Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19503
diff
changeset
|
69 \"Name\", \"DriverVersion\" and \"ID\". Each structure contains information\n\ |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
70 about a PortAudio device.\n\ |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
71 \n\ |
19498
0ac6a4e7369b
change docstrings in audio defundld cc files to work with new texinfo
Vytautas Jančauskas <unaudio@gmail.com>
parents:
19483
diff
changeset
|
72 @end deftypefn\n\ |
0ac6a4e7369b
change docstrings in audio defundld cc files to work with new texinfo
Vytautas Jančauskas <unaudio@gmail.com>
parents:
19483
diff
changeset
|
73 \n\ |
19505
ce02743b6f2a
Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19503
diff
changeset
|
74 @deftypefn {Loadable Function} {@var{devs} =} audiodevinfo (@var{io})\n\ |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
75 \n\ |
19505
ce02743b6f2a
Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19503
diff
changeset
|
76 Returns the number of input or output devices available. Set @var{io} to 1\n\ |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
77 for input devices and to 0 for output devices.\n\ |
19498
0ac6a4e7369b
change docstrings in audio defundld cc files to work with new texinfo
Vytautas Jančauskas <unaudio@gmail.com>
parents:
19483
diff
changeset
|
78 @end deftypefn\n\ |
0ac6a4e7369b
change docstrings in audio defundld cc files to work with new texinfo
Vytautas Jančauskas <unaudio@gmail.com>
parents:
19483
diff
changeset
|
79 \n\ |
19505
ce02743b6f2a
Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19503
diff
changeset
|
80 @deftypefn {Loadable Function} {@var{name} =} audiodevinfo (@var{io}, @var{id})\n\ |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
81 \n\ |
19505
ce02743b6f2a
Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19503
diff
changeset
|
82 Returns the name of a device specified by numerical @var{id}. Set @var{io}\n\ |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
83 to 1 for input devices and to 0 for output devices.\n\ |
19498
0ac6a4e7369b
change docstrings in audio defundld cc files to work with new texinfo
Vytautas Jančauskas <unaudio@gmail.com>
parents:
19483
diff
changeset
|
84 @end deftypefn\n\ |
0ac6a4e7369b
change docstrings in audio defundld cc files to work with new texinfo
Vytautas Jančauskas <unaudio@gmail.com>
parents:
19483
diff
changeset
|
85 \n\ |
19505
ce02743b6f2a
Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19503
diff
changeset
|
86 @deftypefn {Loadable Function} {@var{id} =} audiodevinfo (@var{io}, @var{name})\n\ |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
87 \n\ |
19505
ce02743b6f2a
Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19503
diff
changeset
|
88 Returns the id of a device specified by name. Set @var{io}\n\ |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
89 to 1 for input devices and to 0 for output devices.\n\ |
19498
0ac6a4e7369b
change docstrings in audio defundld cc files to work with new texinfo
Vytautas Jančauskas <unaudio@gmail.com>
parents:
19483
diff
changeset
|
90 @end deftypefn\n\ |
0ac6a4e7369b
change docstrings in audio defundld cc files to work with new texinfo
Vytautas Jančauskas <unaudio@gmail.com>
parents:
19483
diff
changeset
|
91 \n\ |
19505
ce02743b6f2a
Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19503
diff
changeset
|
92 @deftypefn {Loadable Function} {@var{id} =} audiodevinfo (@var{io}, @var{rate}, @var{bits}, @var{chans})\n\ |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
93 \n\ |
19505
ce02743b6f2a
Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19503
diff
changeset
|
94 Returns the id of the first device that supports playback or recording\n\ |
ce02743b6f2a
Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19503
diff
changeset
|
95 using the specified sampling rate (@var{rate}), bits per sample (@var{bits})\n\ |
ce02743b6f2a
Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19503
diff
changeset
|
96 and number of channels (@var{chans}). Set @var{io} to 1 for input devices\n\ |
ce02743b6f2a
Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19503
diff
changeset
|
97 and to 0 for output devices.\n\ |
19498
0ac6a4e7369b
change docstrings in audio defundld cc files to work with new texinfo
Vytautas Jančauskas <unaudio@gmail.com>
parents:
19483
diff
changeset
|
98 @end deftypefn\n\ |
0ac6a4e7369b
change docstrings in audio defundld cc files to work with new texinfo
Vytautas Jančauskas <unaudio@gmail.com>
parents:
19483
diff
changeset
|
99 \n\ |
19505
ce02743b6f2a
Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19503
diff
changeset
|
100 @deftypefn {Loadable Function} {@var{supports} =} audiodevinfo (@var{io}, @var{id}, @var{rate}, @var{bits}, @var{chans})\n\ |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
101 \n\ |
19505
ce02743b6f2a
Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19503
diff
changeset
|
102 Returns 1 if the device bearing @var{id} supports specified sampling rate\n\ |
ce02743b6f2a
Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19503
diff
changeset
|
103 (@var{rate}), bits per sample (@var{bits}) and number of channels (@var{chans}).\n\ |
ce02743b6f2a
Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19503
diff
changeset
|
104 Returns 0 otherwise. Set @var{io} to 1 for input devices and to 0 for output\n\ |
ce02743b6f2a
Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19503
diff
changeset
|
105 devices.\n\ |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
106 @end deftypefn") |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
107 { |
19483
abde714a4f88
let audiodevinfo be built even when PortAudio is not present
Vytautas Jančauskas <unaudio@gmail.com>
parents:
19473
diff
changeset
|
108 octave_value retval; |
abde714a4f88
let audiodevinfo be built even when PortAudio is not present
Vytautas Jančauskas <unaudio@gmail.com>
parents:
19473
diff
changeset
|
109 #ifdef HAVE_PORTAUDIO |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
110 int nargin = args.length (); |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
111 PaError err; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
112 octave_scalar_map devinfo; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
113 octave_value_list input; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
114 octave_value_list output; |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
115 |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
116 err = Pa_Initialize (); |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
117 if (err != paNoError) |
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
118 { |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
119 error ("audiodevinfo: cannot initialize PortAudio"); |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
120 return retval; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
121 } |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
122 |
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
123 int num_devices = Pa_GetDeviceCount (); |
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
124 if (num_devices < 0) |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
125 { |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
126 error ("audiodevinfo: no audio device found"); |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
127 return retval; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
128 } |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
129 |
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
130 octave_idx_type numinput = 0, numoutput = 0; |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
131 for (int i = 0; i < num_devices; i++) |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
132 { |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
133 const PaDeviceInfo *device_info = Pa_GetDeviceInfo (i); |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
134 if (device_info->maxInputChannels != 0) |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
135 numinput++; |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
136 if (device_info->maxOutputChannels != 0) |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
137 numoutput++; |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
138 } |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
139 |
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
140 Cell input_name (dim_vector (1, numinput)); |
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
141 Cell input_driver_version (dim_vector (1, numinput)); |
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
142 Cell input_id (dim_vector (1, numinput)); |
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
143 Cell output_name (dim_vector (1, numoutput)); |
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
144 Cell output_driver_version (dim_vector (1, numoutput)); |
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
145 Cell output_id (dim_vector (1, numoutput)); |
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
146 |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
147 octave_idx_type idx_i = 0, idx_o = 0; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
148 for (int i = 0; i < num_devices; i++) |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
149 { |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
150 const PaDeviceInfo *device_info = Pa_GetDeviceInfo (i); |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
151 const char *driver; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
152 char name[128]; |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
153 driver = Pa_GetHostApiInfo (device_info->hostApi)->name; |
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
154 sprintf (name, "%s (%s)", device_info->name, driver); |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
155 |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
156 if (device_info->maxInputChannels != 0) |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
157 { |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
158 input_name(idx_i) = name; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
159 input_driver_version(idx_i) = driver; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
160 input_id(idx_i) = i; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
161 idx_i++; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
162 } |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
163 |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
164 if (device_info->maxOutputChannels != 0) |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
165 { |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
166 output_name(idx_o) = name; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
167 output_driver_version(idx_o) = driver; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
168 output_id(idx_o) = i; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
169 idx_o++; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
170 } |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
171 } |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
172 |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
173 octave_map inputdev, outputdev; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
174 inputdev.setfield ("Name", input_name); |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
175 inputdev.setfield ("DriverVersion", input_driver_version); |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
176 inputdev.setfield ("ID", input_id); |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
177 outputdev.setfield ("Name", output_name); |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
178 outputdev.setfield ("DriverVersion", output_driver_version); |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
179 outputdev.setfield ("ID", output_id); |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
180 devinfo.setfield ("input", inputdev); |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
181 devinfo.setfield ("output", outputdev); |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
182 |
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
183 // Return information about input and output audio devices and |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
184 // their properties. |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
185 if (nargin == 0) |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
186 retval = devinfo; |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
187 // Return the number of input or output devices |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
188 else if (nargin == 1) |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
189 { |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
190 if (args(0).int_value () == 0) |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
191 retval = octave_value (numoutput); |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
192 else if (args(0).int_value () == 1) |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
193 retval = octave_value (numinput); |
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
194 else |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
195 { |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
196 error ("audiodevinfo: please specify 0 for output and 1 for input devices"); |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
197 return retval; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
198 } |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
199 } |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
200 // Return device name when given id or id when given device name. |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
201 else if (nargin == 2) |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
202 { |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
203 bool found = false; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
204 int outin = args(0).int_value (); |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
205 if (args(1).is_string ()) |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
206 { |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
207 if (outin == 0) |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
208 { |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
209 for (int i = 0; i < numoutput; i++) |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
210 { |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
211 if (output_name(i).string_value () == args(1).string_value ()) |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
212 { |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
213 retval = output_id(i); |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
214 found = true; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
215 break; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
216 } |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
217 } |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
218 } |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
219 else if (outin == 1) |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
220 { |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
221 for (int i = 0; i < numinput; i++) |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
222 { |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
223 if (input_name(i).string_value () == args(1).string_value ()) |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
224 { |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
225 retval = input_id(i); |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
226 found = true; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
227 break; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
228 } |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
229 } |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
230 } |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
231 else |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
232 { |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
233 error ("audiodevinfo: please specify 0 for output and 1 for input devices"); |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
234 return retval; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
235 } |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
236 } |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
237 else |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
238 { |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
239 if (outin == 0) |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
240 { |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
241 for (int i = 0; i < numoutput; i++) |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
242 { |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
243 if (output_id(i).int_value () == args(1).int_value ()) |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
244 { |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
245 retval = output_name(i); |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
246 found = true; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
247 break; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
248 } |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
249 } |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
250 } |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
251 else if (outin == 1) |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
252 { |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
253 for (int i = 0; i < numinput; i++) |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
254 { |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
255 if (input_id(i).int_value () == args(1).int_value ()) |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
256 { |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
257 retval = input_name(i); |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
258 found = true; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
259 break; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
260 } |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
261 } |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
262 } |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
263 else |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
264 { |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
265 error ("audiodevinfo: please specify 0 for output and 1 for input devices"); |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
266 return retval; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
267 } |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
268 } |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
269 if (not found) |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
270 error ("audiodevinfo: no device meeting the specified criteria found"); |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
271 } |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
272 else if (nargin == 3) |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
273 { |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
274 // |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
275 } |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
276 // Return the id of the first device meeting specified criteria. |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
277 else if (nargin == 4) |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
278 { |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
279 int io = args(0).int_value (); |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
280 int rate = args(1).int_value (); |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
281 int bits = args(2).int_value (); |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
282 int chans = args(3).int_value (); |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
283 for (int i = 0; i < num_devices; i++) |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
284 { |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
285 PaStreamParameters stream_parameters; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
286 stream_parameters.device = i; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
287 stream_parameters.channelCount = chans; |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
288 PaSampleFormat format = bits_to_format (bits); |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
289 if (format != 0) |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
290 stream_parameters.sampleFormat = format; |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
291 else |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
292 { |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
293 error ("audiodevinfo: no such bits per sample format"); |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
294 return retval; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
295 } |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
296 stream_parameters.suggestedLatency = |
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
297 Pa_GetDeviceInfo (i)->defaultLowInputLatency; |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
298 stream_parameters.hostApiSpecificStreamInfo = NULL; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
299 if (io == 0) |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
300 { |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
301 if (Pa_GetDeviceInfo (i)->maxOutputChannels < chans) |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
302 continue; |
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
303 |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
304 err = Pa_IsFormatSupported (NULL, &stream_parameters, rate); |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
305 if (err == paFormatIsSupported) |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
306 { |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
307 retval = i; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
308 return retval; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
309 } |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
310 } |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
311 else if (io == 1) |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
312 { |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
313 if (Pa_GetDeviceInfo (i)->maxInputChannels < chans) |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
314 continue; |
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
315 |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
316 err = Pa_IsFormatSupported (&stream_parameters, NULL, rate); |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
317 if (err == paFormatIsSupported) |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
318 { |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
319 retval = i; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
320 return retval; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
321 } |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
322 } |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
323 } |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
324 retval = -1; |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
325 } |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
326 // Check if given device supports specified playback or recording modes. |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
327 else if (nargin == 5) |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
328 { |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
329 int io = args(0).int_value (); |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
330 int id = args(1).int_value (); |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
331 int rate = args(2).int_value (); |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
332 int bits = args(3).int_value (); |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
333 int chans = args(4).int_value (); |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
334 PaStreamParameters stream_parameters; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
335 stream_parameters.device = id; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
336 stream_parameters.channelCount = chans; |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
337 PaSampleFormat format = bits_to_format (bits); |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
338 if (format != 0) |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
339 stream_parameters.sampleFormat = format; |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
340 else |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
341 { |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
342 error ("audiodevinfo: no such bits per sample format"); |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
343 return retval; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
344 } |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
345 stream_parameters.suggestedLatency = |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
346 Pa_GetDeviceInfo (id)->defaultLowInputLatency; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
347 stream_parameters.hostApiSpecificStreamInfo = NULL; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
348 if (io == 0) |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
349 { |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
350 if (Pa_GetDeviceInfo (id)->maxOutputChannels < chans) |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
351 { |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
352 retval = 0; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
353 return retval; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
354 } |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
355 err = Pa_IsFormatSupported (NULL, &stream_parameters, rate); |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
356 if (err == paFormatIsSupported) |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
357 { |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
358 retval = 1; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
359 return retval; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
360 } |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
361 } |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
362 else if (io == 1) |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
363 { |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
364 if (Pa_GetDeviceInfo (id)->maxInputChannels < chans) |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
365 { |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
366 retval = 0; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
367 return retval; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
368 } |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
369 err = Pa_IsFormatSupported (&stream_parameters, NULL, rate); |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
370 if (err == paFormatIsSupported) |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
371 { |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
372 retval = 1; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
373 return retval; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
374 } |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
375 } |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
376 else |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
377 { |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
378 error ("audiodevinfo: please specify 0 for output and 1 for input devices"); |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
379 return retval; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
380 } |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
381 retval = 0; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
382 } |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
383 else |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
384 { |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
385 error ("audiodevinfo: wrong number of arguments"); |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
386 return retval; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
387 } |
19483
abde714a4f88
let audiodevinfo be built even when PortAudio is not present
Vytautas Jančauskas <unaudio@gmail.com>
parents:
19473
diff
changeset
|
388 #else |
abde714a4f88
let audiodevinfo be built even when PortAudio is not present
Vytautas Jančauskas <unaudio@gmail.com>
parents:
19473
diff
changeset
|
389 error ("portaudio not found on your system and thus audio functionality is not present"); |
abde714a4f88
let audiodevinfo be built even when PortAudio is not present
Vytautas Jančauskas <unaudio@gmail.com>
parents:
19473
diff
changeset
|
390 #endif |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
391 return retval; |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
392 } |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
393 |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
394 /* |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
395 %!test |
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
396 %! devinfo = audiodevinfo; |
19509 | 397 %! assert (rows (devinfo.input), 1); |
398 %! assert (rows (devinfo.output), 1); | |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
399 |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
400 %!test |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
401 %! devinfo = audiodevinfo; |
19509 | 402 %! nout = audiodevinfo (0); |
403 %! nin = audiodevinfo (1); | |
404 %! assert (columns (devinfo.output), nout); | |
405 %! assert (columns (devinfo.input), nin); | |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
406 |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
407 %!test |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
408 %! devinfo = audiodevinfo; |
19509 | 409 %! nout = audiodevinfo (0); |
410 %! nin = audiodevinfo (1); | |
411 %! for i = 1:nout, | |
412 %! assert (devinfo.output(i).Name, audiodevinfo (0, devinfo.output(i).ID)) | |
413 %! endfor | |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
414 %! for i=1:nin, |
19509 | 415 %! assert (devinfo.input(i).Name, audiodevinfo (1, devinfo.input(i).ID)) |
416 %! endfor | |
19469
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
417 |
ea5c156aa804
audiodevinfo.cc: new file
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
418 %!test |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19501
diff
changeset
|
419 %! devinfo = audiodevinfo; |
19509 | 420 %! nout = audiodevinfo (0); |
421 %! nin = audiodevinfo (1); | |
422 %! for i = 1:nout, | |
423 %! assert (devinfo.output(i).ID, audiodevinfo (0, devinfo.output(i).Name)) | |
424 %! endfor | |
425 %! for i = 1:nin, | |
426 %! assert (devinfo.input(i).ID, audiodevinfo (1, devinfo.input(i).Name)) | |
427 %! endfor | |
19500
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19498
diff
changeset
|
428 */ |
19510 | 429 |
430 enum audio_type { INT8, UINT8, INT16, DOUBLE }; | |
431 | |
432 class audioplayer : public octave_base_value | |
433 { | |
434 public: | |
435 audioplayer (void); | |
436 ~audioplayer (void) {}; | |
437 | |
438 // Overloaded base functions | |
439 double player_value (void) const { return 0; } | |
19512
a5eb03a7e2a5
eliminate unused variable and parameter warnings
John W. Eaton <jwe@octave.org>
parents:
19511
diff
changeset
|
440 virtual double scalar_value (bool = false) const { return 0; } |
19510 | 441 void print (std::ostream& os, bool pr_as_read_syntax = false) const; |
442 void print_raw (std::ostream& os, bool pr_as_read_syntax) const; | |
443 | |
444 // Properties | |
445 bool is_constant (void) const { return true; } | |
446 bool is_defined (void) const { return true; } | |
447 bool print_as_scalar (void) const { return true; } | |
448 | |
449 void init (void); | |
450 void init_fn (void); | |
451 void set_y (octave_value y); | |
452 void set_y (octave_function *fn); | |
453 void set_y (std::string fn); | |
454 Matrix& get_y (void); | |
455 RowVector *get_left (void); | |
456 RowVector *get_right (void); | |
457 void set_fs (int fs); | |
458 int get_fs (void); | |
459 void set_nbits (int nbits); | |
460 int get_nbits (void); | |
461 void set_id (int id); | |
462 int get_id (void); | |
463 int get_channels (void); | |
464 audio_type get_type (void); | |
465 | |
466 void set_sample_number (unsigned int sample); | |
467 unsigned int get_sample_number (void); | |
468 unsigned int get_total_samples (void); | |
469 void set_end_sample (unsigned int sample); | |
470 unsigned int get_end_sample (void); | |
471 void reset_end_sample (void); | |
472 void set_tag (charMatrix tag); | |
473 charMatrix get_tag (void); | |
474 void set_userdata (octave_value userdata); | |
475 octave_value get_userdata (void); | |
476 PaStream *get_stream (void); | |
477 octave_function *octave_callback_function; | |
478 | |
479 void playblocking (void); | |
480 void play (void); | |
481 void pause (void); | |
482 void resume (void); | |
483 void stop (void); | |
484 bool isplaying (void); | |
485 | |
486 private: | |
487 Matrix y; | |
488 RowVector left; | |
489 RowVector right; | |
490 charMatrix tag; | |
491 octave_value userdata; | |
492 int channels; | |
493 int fs; | |
494 int nbits; | |
495 int id; | |
496 unsigned int sample_number; | |
497 unsigned int end_sample; | |
498 PaStream *stream; | |
499 PaStreamParameters output_parameters; | |
500 audio_type type; | |
501 DECLARE_OCTAVE_ALLOCATOR | |
502 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA | |
503 }; | |
504 | |
505 #define BUFFER_SIZE 512 | |
506 | |
507 DEFINE_OCTAVE_ALLOCATOR (audioplayer); | |
508 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (audioplayer, "audioplayer", "audioplayer"); | |
509 | |
510 int | |
511 is_big_endian (void) | |
512 { | |
513 union | |
514 { | |
515 uint32_t i; | |
516 char c[4]; | |
517 } bint = { 0x01020304 }; | |
518 return bint.c[0] == 1; | |
519 } | |
520 | |
521 static int | |
19512
a5eb03a7e2a5
eliminate unused variable and parameter warnings
John W. Eaton <jwe@octave.org>
parents:
19511
diff
changeset
|
522 octave_play_callback (const void *, void *output, unsigned long frames, |
a5eb03a7e2a5
eliminate unused variable and parameter warnings
John W. Eaton <jwe@octave.org>
parents:
19511
diff
changeset
|
523 const PaStreamCallbackTimeInfo *, |
a5eb03a7e2a5
eliminate unused variable and parameter warnings
John W. Eaton <jwe@octave.org>
parents:
19511
diff
changeset
|
524 PaStreamCallbackFlags, void *data) |
19510 | 525 { |
526 audioplayer *player = (audioplayer *)data; | |
527 int big_endian = is_big_endian (); | |
528 octave_value_list args, retval; | |
529 args(0) = frames; | |
530 retval = feval (player->octave_callback_function, args, 1); | |
531 RowVector sound_l, sound_r; | |
532 Matrix sound = retval(0).matrix_value (); | |
533 int return_status = retval(1).int_value (); | |
534 sound_l.resize (frames); | |
535 sound_r.resize (frames); | |
536 if (sound.cols () == 1) | |
537 { | |
538 for (int i = 0; i < frames; i++) | |
539 { | |
540 sound_l(i) = sound(i, 0); | |
541 sound_r(i) = sound(i, 0); | |
542 } | |
543 } | |
544 else if (sound.cols () == 2) | |
545 { | |
546 for (int i = 0; i < frames; i++) | |
547 { | |
548 sound_l(i) = sound(i, 0); | |
549 sound_r(i) = sound(i, 1); | |
550 } | |
551 } | |
552 else | |
553 return paAbort; | |
554 | |
555 for (int i = 0; i < frames; i++) | |
556 { | |
557 if (player->get_nbits () == 8) | |
558 { | |
559 int8_t *buffer = (int8_t *)output; | |
560 buffer[2 * i] = sound_l.elem (i) * (pow (2.0, 7) - 1); | |
561 buffer[2 * i + 1] = sound_r.elem (i) * (pow (2.0, 7) - 1); | |
562 } | |
563 else if (player->get_nbits () == 16) | |
564 { | |
565 int16_t *buffer = (int16_t *)output; | |
566 buffer[2 * i] = sound_l.elem (i) * (pow (2.0, 15) - 1); | |
567 buffer[2 * i + 1] = sound_r.elem (i) * (pow (2.0, 15) - 1); | |
568 } | |
569 else if (player->get_nbits () == 24) | |
570 { | |
571 uint8_t *buffer = (uint8_t *)output; | |
572 int32_t sample_l = sound_l.elem (i) * (pow (2.0, 23) - 1); | |
573 int32_t sample_r = sound_r.elem (i) * (pow (2.0, 23) - 1); | |
574 sample_l &= 0x00ffffff; | |
575 sample_r &= 0x00ffffff; | |
576 uint8_t *_sample_l = (uint8_t *)&sample_l; | |
577 uint8_t *_sample_r = (uint8_t *)&sample_r; | |
578 buffer[i * 6 + 0] = _sample_l[0 + big_endian]; | |
579 buffer[i * 6 + 1] = _sample_l[1 + big_endian]; | |
580 buffer[i * 6 + 2] = _sample_l[2 + big_endian]; | |
581 buffer[i * 6 + 3] = _sample_r[0 + big_endian]; | |
582 buffer[i * 6 + 4] = _sample_r[1 + big_endian]; | |
583 buffer[i * 6 + 5] = _sample_r[2 + big_endian]; | |
584 } | |
585 } | |
586 return return_status; | |
587 } | |
588 | |
589 static int | |
19512
a5eb03a7e2a5
eliminate unused variable and parameter warnings
John W. Eaton <jwe@octave.org>
parents:
19511
diff
changeset
|
590 portaudio_play_callback (const void *, void *output, unsigned long frames, |
a5eb03a7e2a5
eliminate unused variable and parameter warnings
John W. Eaton <jwe@octave.org>
parents:
19511
diff
changeset
|
591 const PaStreamCallbackTimeInfo*, |
a5eb03a7e2a5
eliminate unused variable and parameter warnings
John W. Eaton <jwe@octave.org>
parents:
19511
diff
changeset
|
592 PaStreamCallbackFlags, void *data) |
19510 | 593 { |
594 audioplayer *player = (audioplayer *)data; | |
595 int big_endian = is_big_endian (); | |
596 int channels = player->get_channels (); | |
597 RowVector *sound_l = player->get_left (); | |
598 RowVector *sound_r; | |
599 | |
600 if (channels > 1) | |
601 sound_r = player->get_right (); | |
602 else | |
603 sound_r = sound_l; | |
604 | |
605 for (int j = 0, k = 0; j < frames; j++, k += 2) | |
606 { | |
607 unsigned int sample_number = player->get_sample_number (); | |
608 if (sample_number > player->get_end_sample ()) | |
609 return paAbort; | |
610 | |
611 if (player->get_type () == DOUBLE) | |
612 { | |
613 if (player->get_nbits () == 8) | |
614 { | |
615 int8_t *buffer = (int8_t *)output; | |
616 buffer[k] = sound_l->elem (sample_number) * (pow (2.0, 7) - 1); | |
617 buffer[k + 1] = sound_r->elem (sample_number) * (pow (2.0, 7) - 1); | |
618 } | |
619 else if (player->get_nbits () == 16) | |
620 { | |
621 int16_t *buffer = (int16_t *)output; | |
622 buffer[k] = sound_l->elem (sample_number) * (pow (2.0, 15) - 1); | |
623 buffer[k + 1] = sound_r->elem (sample_number) * (pow (2.0, 15) - 1); | |
624 } | |
625 else if (player->get_nbits () == 24) | |
626 { | |
627 uint8_t *buffer = (uint8_t *)output; | |
628 int32_t sample_l = sound_l->elem (sample_number) * (pow (2.0, 23) - 1); | |
629 int32_t sample_r = sound_r->elem (sample_number) * (pow (2.0, 23) - 1); | |
630 sample_l &= 0x00ffffff; | |
631 sample_r &= 0x00ffffff; | |
632 uint8_t *_sample_l = (uint8_t *)&sample_l; | |
633 uint8_t *_sample_r = (uint8_t *)&sample_r; | |
634 buffer[j * 6 + 0] = _sample_l[0 + big_endian]; | |
635 buffer[j * 6 + 1] = _sample_l[1 + big_endian]; | |
636 buffer[j * 6 + 2] = _sample_l[2 + big_endian]; | |
637 buffer[j * 6 + 3] = _sample_r[0 + big_endian]; | |
638 buffer[j * 6 + 4] = _sample_r[1 + big_endian]; | |
639 buffer[j * 6 + 5] = _sample_r[2 + big_endian]; | |
640 } | |
641 } | |
642 else if (player->get_type () == INT8) | |
643 { | |
644 int8_t *buffer = (int8_t *)output; | |
645 buffer[k] = sound_l->elem (sample_number); | |
646 buffer[k + 1] = sound_r->elem (sample_number); | |
647 } | |
648 else if (player->get_type () == UINT8) | |
649 { | |
650 uint8_t *buffer = (uint8_t *)output; | |
651 buffer[k] = sound_l->elem (sample_number); | |
652 buffer[k + 1] = sound_r->elem (sample_number); | |
653 } | |
654 else if (player->get_type () == INT16) | |
655 { | |
656 int16_t *buffer = (int16_t *)output; | |
657 buffer[k] = sound_l->elem (sample_number); | |
658 buffer[k + 1] = sound_r->elem (sample_number); | |
659 } | |
660 player->set_sample_number (sample_number + 1); | |
661 } | |
662 return paContinue; | |
663 } | |
664 | |
665 audioplayer::audioplayer (void) | |
666 { | |
667 this->nbits = 16; | |
668 this->id = -1; | |
669 this->sample_number = 0; | |
670 this->tag = charMatrix (""); | |
671 Matrix userdata; | |
672 this->userdata = octave_value (userdata); | |
673 this->stream = 0; | |
674 this->octave_callback_function = 0; | |
675 } | |
676 | |
677 void | |
678 audioplayer::print (std::ostream& os, bool pr_as_read_syntax) const | |
679 { | |
680 print_raw (os, pr_as_read_syntax); | |
681 newline (os); | |
682 } | |
683 | |
684 void | |
19512
a5eb03a7e2a5
eliminate unused variable and parameter warnings
John W. Eaton <jwe@octave.org>
parents:
19511
diff
changeset
|
685 audioplayer::print_raw (std::ostream& os, bool) const |
19510 | 686 { |
687 os << 0; | |
688 } | |
689 | |
690 void | |
691 audioplayer::init_fn (void) | |
692 { | |
693 PaError err; | |
694 int device; | |
695 | |
696 err = Pa_Initialize (); | |
697 if (err != paNoError) | |
698 { | |
699 error ("audioplayer: Initialization error!"); | |
700 return; | |
701 } | |
702 | |
703 int numDevices = Pa_GetDeviceCount (); | |
704 if (numDevices < 0) | |
705 { | |
706 error ("audioplayer: No audio devices found!"); | |
707 return; | |
708 } | |
709 | |
710 if (this->get_id () == -1) | |
711 device = Pa_GetDefaultOutputDevice (); | |
712 else | |
713 device = this->get_id (); | |
714 | |
715 output_parameters.device = device; | |
716 output_parameters.channelCount = 2; | |
717 output_parameters.sampleFormat = bits_to_format (this->get_nbits ()); | |
718 output_parameters.suggestedLatency = Pa_GetDeviceInfo (device)->defaultHighOutputLatency; | |
719 output_parameters.hostApiSpecificStreamInfo = NULL; | |
720 } | |
721 | |
722 void | |
723 audioplayer::init (void) | |
724 { | |
725 PaError err; | |
19512
a5eb03a7e2a5
eliminate unused variable and parameter warnings
John W. Eaton <jwe@octave.org>
parents:
19511
diff
changeset
|
726 |
a5eb03a7e2a5
eliminate unused variable and parameter warnings
John W. Eaton <jwe@octave.org>
parents:
19511
diff
changeset
|
727 // Both of these variables are unused. Should they be |
a5eb03a7e2a5
eliminate unused variable and parameter warnings
John W. Eaton <jwe@octave.org>
parents:
19511
diff
changeset
|
728 // eliminated or is something not yet implemented? |
a5eb03a7e2a5
eliminate unused variable and parameter warnings
John W. Eaton <jwe@octave.org>
parents:
19511
diff
changeset
|
729 // |
a5eb03a7e2a5
eliminate unused variable and parameter warnings
John W. Eaton <jwe@octave.org>
parents:
19511
diff
changeset
|
730 // int channels = this->y.rows (); |
a5eb03a7e2a5
eliminate unused variable and parameter warnings
John W. Eaton <jwe@octave.org>
parents:
19511
diff
changeset
|
731 // RowVector *sound_l = this->get_left (); |
a5eb03a7e2a5
eliminate unused variable and parameter warnings
John W. Eaton <jwe@octave.org>
parents:
19511
diff
changeset
|
732 |
19510 | 733 int device; |
734 | |
735 err = Pa_Initialize (); | |
736 if (err != paNoError) | |
737 { | |
738 error ("audioplayer: Initialization error!"); | |
739 return; | |
740 } | |
741 | |
742 int numDevices = Pa_GetDeviceCount (); | |
743 if (numDevices < 0) | |
744 { | |
745 error ("audioplayer: No audio devices found!"); | |
746 return; | |
747 } | |
748 | |
749 if (this->get_id () == -1) | |
750 device = Pa_GetDefaultOutputDevice (); | |
751 else | |
752 device = this->get_id (); | |
753 | |
754 output_parameters.device = device; | |
755 output_parameters.channelCount = 2; | |
756 | |
757 if (this->type == DOUBLE) | |
758 output_parameters.sampleFormat = bits_to_format (this->get_nbits ()); | |
759 else if (this->type == INT8) | |
760 output_parameters.sampleFormat = paInt8; | |
761 else if (this->type == UINT8) | |
762 output_parameters.sampleFormat = paUInt8; | |
763 else if (this->type == INT16) | |
764 output_parameters.sampleFormat = paInt16; | |
765 | |
766 output_parameters.suggestedLatency = Pa_GetDeviceInfo (device)->defaultHighOutputLatency; | |
767 output_parameters.hostApiSpecificStreamInfo = NULL; | |
768 } | |
769 | |
770 void | |
771 audioplayer::set_y (octave_value y) | |
772 { | |
773 if (y.is_int8_type ()) | |
774 this->type = INT8; | |
775 else if (y.is_uint8_type ()) | |
776 this->type = UINT8; | |
777 else if (y.is_int16_type ()) | |
778 this->type = INT16; | |
779 else | |
780 this->type = DOUBLE; | |
781 | |
782 this->y = y.matrix_value (); | |
783 if (this->y.rows () > 2) | |
784 this->y = this->y.transpose (); | |
785 | |
786 this->channels = this->y.rows (); | |
787 this->left = this->y.row (0); | |
788 if (this->channels == 2) | |
789 this->right = this->y.row (1); | |
790 | |
791 this->reset_end_sample (); | |
792 } | |
793 | |
794 void | |
795 audioplayer::set_y (octave_function *fn) | |
796 { | |
797 this->octave_callback_function = fn; | |
798 this->channels = 2; | |
799 this->reset_end_sample (); | |
800 } | |
801 | |
802 Matrix& | |
803 audioplayer::get_y (void) | |
804 { | |
805 return this->y; | |
806 } | |
807 | |
808 RowVector * | |
809 audioplayer::get_left (void) | |
810 { | |
811 return &(this->left); | |
812 } | |
813 | |
814 RowVector * | |
815 audioplayer::get_right (void) | |
816 { | |
817 return &(this->right); | |
818 } | |
819 | |
820 void | |
821 audioplayer::set_fs (int fs) | |
822 { | |
823 this->fs = fs; | |
824 } | |
825 | |
826 int | |
827 audioplayer::get_fs (void) | |
828 { | |
829 return this->fs; | |
830 } | |
831 | |
832 void | |
833 audioplayer::set_nbits (int nbits) | |
834 { | |
835 this->nbits = nbits; | |
836 } | |
837 | |
838 int | |
839 audioplayer::get_nbits (void) | |
840 { | |
841 return this->nbits; | |
842 } | |
843 | |
844 void | |
845 audioplayer::set_id (int id) | |
846 { | |
847 this->id = id; | |
848 } | |
849 | |
850 int | |
851 audioplayer::get_id (void) | |
852 { | |
853 return this->id; | |
854 } | |
855 | |
856 int | |
857 audioplayer::get_channels (void) | |
858 { | |
859 return this->channels; | |
860 } | |
861 | |
862 audio_type | |
863 audioplayer::get_type (void) | |
864 { | |
865 return this->type; | |
866 } | |
867 | |
868 void | |
869 audioplayer::set_sample_number (unsigned int sample_number) | |
870 { | |
871 this->sample_number = sample_number; | |
872 } | |
873 | |
874 unsigned int | |
875 audioplayer::get_sample_number (void) | |
876 { | |
877 return this->sample_number; | |
878 } | |
879 | |
880 unsigned int | |
881 audioplayer::get_total_samples (void) | |
882 { | |
883 return this->left.length (); | |
884 } | |
885 | |
886 void | |
887 audioplayer::set_end_sample (unsigned int end_sample) | |
888 { | |
889 this->end_sample = end_sample; | |
890 } | |
891 | |
892 unsigned int | |
893 audioplayer::get_end_sample (void) | |
894 { | |
895 return this->end_sample; | |
896 } | |
897 | |
898 void | |
899 audioplayer::reset_end_sample (void) | |
900 { | |
901 this->set_end_sample (this->left.length ()); | |
902 } | |
903 | |
904 void | |
905 audioplayer::set_tag (charMatrix tag) | |
906 { | |
907 this->tag = tag; | |
908 } | |
909 | |
910 charMatrix | |
911 audioplayer::get_tag (void) | |
912 { | |
913 return this->tag; | |
914 } | |
915 | |
916 void | |
917 audioplayer::set_userdata (octave_value userdata) | |
918 { | |
919 this->userdata = userdata; | |
920 } | |
921 | |
922 octave_value | |
923 audioplayer::get_userdata (void) | |
924 { | |
925 return this->userdata; | |
926 } | |
927 | |
928 void | |
929 audioplayer::playblocking (void) | |
930 { | |
931 if (this->get_stream ()) | |
932 this->stop (); | |
933 | |
934 PaError err; | |
935 uint32_t buffer[BUFFER_SIZE * 2]; | |
936 err = Pa_OpenStream (&stream, NULL, &(this->output_parameters), this->get_fs (), BUFFER_SIZE, paClipOff, NULL, NULL); | |
937 if (err != paNoError) | |
938 { | |
939 error ("audioplayer: Error opening audio playback stream"); | |
940 return; | |
941 } | |
942 | |
943 err = Pa_StartStream (stream); | |
944 if (err != paNoError) | |
945 { | |
946 error ("audioplayer: Error starting audio playback stream"); | |
947 return; | |
948 } | |
949 | |
950 unsigned int start, end; | |
951 start = this->get_sample_number (); | |
952 end = this->get_end_sample (); | |
953 for (int i = start; i < end; i += BUFFER_SIZE) | |
954 { | |
955 if (this->octave_callback_function != 0) | |
956 octave_play_callback (0, (void *)buffer, BUFFER_SIZE, 0, 0, (void *)this); | |
957 else | |
958 portaudio_play_callback (0, (void *)buffer, BUFFER_SIZE, 0, 0, (void *)this); | |
959 err = Pa_WriteStream (stream, buffer, BUFFER_SIZE); | |
960 } | |
961 | |
962 err = Pa_StopStream (stream); | |
963 if (err != paNoError) | |
964 { | |
965 error ("audioplayer: Error stoping audio playback stream"); | |
966 return; | |
967 } | |
968 | |
969 err = Pa_CloseStream (stream); | |
970 if (err != paNoError) | |
971 { | |
972 error ("audioplayer: Error closing audio playback stream"); | |
973 return; | |
974 } | |
975 | |
976 stream = 0; | |
977 this->set_sample_number (0); | |
978 this->reset_end_sample (); | |
979 } | |
980 | |
981 void | |
982 audioplayer::play (void) | |
983 { | |
984 if (this->get_stream ()) | |
985 this->stop (); | |
986 | |
987 PaError err; | |
988 if (this->octave_callback_function != 0) | |
989 err = Pa_OpenStream (&stream, NULL, &(this->output_parameters), this->get_fs (), BUFFER_SIZE, paClipOff, octave_play_callback, (void *)this); | |
990 else | |
991 err = Pa_OpenStream (&stream, NULL, &(this->output_parameters), this->get_fs (), BUFFER_SIZE, paClipOff, portaudio_play_callback, (void *)this); | |
992 | |
993 if (err != paNoError) | |
994 { | |
995 error ("audioplayer: Error opening audio playback stream"); | |
996 return; | |
997 } | |
998 | |
999 err = Pa_StartStream (stream); | |
1000 if (err != paNoError) | |
1001 { | |
1002 error ("audioplayer: Error starting audio playback stream"); | |
1003 return; | |
1004 } | |
1005 } | |
1006 | |
1007 void | |
1008 audioplayer::pause (void) | |
1009 { | |
1010 if (this->get_stream () == 0) | |
1011 return; | |
1012 | |
1013 PaError err; | |
1014 err = Pa_StopStream (stream); | |
1015 if (err != paNoError) | |
1016 { | |
1017 error ("audiorecorder: Error stoping audio recording stream"); | |
1018 return; | |
1019 } | |
1020 } | |
1021 | |
1022 void | |
1023 audioplayer::resume (void) | |
1024 { | |
1025 if (this->get_stream () == 0) | |
1026 return; | |
1027 | |
1028 PaError err; | |
1029 err = Pa_StartStream (stream); | |
1030 if (err != paNoError) | |
1031 { | |
1032 error ("audiorecorder: Error starting audio recording stream"); | |
1033 return; | |
1034 } | |
1035 } | |
1036 | |
1037 PaStream * | |
1038 audioplayer::get_stream (void) | |
1039 { | |
1040 return this->stream; | |
1041 } | |
1042 | |
1043 void | |
1044 audioplayer::stop (void) | |
1045 { | |
1046 if (this->get_stream () == 0) | |
1047 return; | |
1048 | |
1049 PaError err; | |
1050 this->set_sample_number (0); | |
1051 this->reset_end_sample (); | |
1052 if (not Pa_IsStreamStopped (this->get_stream ())) | |
1053 { | |
1054 err = Pa_AbortStream (this->get_stream ()); | |
1055 if (err != paNoError) | |
1056 { | |
1057 error ("audioplayer: Error stopping audio playback stream"); | |
1058 return; | |
1059 } | |
1060 } | |
1061 | |
1062 err = Pa_CloseStream (this->get_stream ()); | |
1063 if (err != paNoError) | |
1064 { | |
1065 error ("audioplayer: Error closing audio playback stream"); | |
1066 return; | |
1067 } | |
1068 | |
1069 stream = 0; | |
1070 } | |
1071 | |
1072 bool | |
1073 audioplayer::isplaying (void) | |
1074 { | |
1075 if (this->get_stream () == 0) | |
1076 return false; | |
1077 | |
1078 PaError err; | |
1079 err = Pa_IsStreamActive (stream); | |
1080 if (err != 0 and err != 1) | |
1081 { | |
1082 error ("audiorecorder: Error checking stream activity status"); | |
1083 return false; | |
1084 } | |
1085 | |
1086 return (err == 1); | |
1087 } | |
1088 | |
1089 class audiorecorder : public octave_base_value | |
1090 { | |
1091 public: | |
1092 audiorecorder (void); | |
1093 ~audiorecorder (void) {}; | |
1094 | |
1095 // Overloaded base functions | |
1096 double player_value (void) const { return 0; } | |
19512
a5eb03a7e2a5
eliminate unused variable and parameter warnings
John W. Eaton <jwe@octave.org>
parents:
19511
diff
changeset
|
1097 virtual double scalar_value (bool = false) const { return 0; } |
19510 | 1098 void print (std::ostream& os, bool pr_as_read_syntax = false) const; |
1099 void print_raw (std::ostream& os, bool pr_as_read_syntax) const; | |
1100 | |
1101 // Properties | |
1102 bool is_constant (void) const { return true; } | |
1103 bool is_defined (void) const { return true; } | |
1104 bool print_as_scalar (void) const { return true; } | |
1105 | |
1106 void init (void); | |
1107 void set_fs (int fs); | |
1108 int get_fs (void); | |
1109 void set_nbits (int nbits); | |
1110 int get_nbits (void); | |
1111 void set_id (int id); | |
1112 int get_id (void); | |
1113 void set_channels (int channels); | |
1114 int get_channels (void); | |
1115 audio_type get_type (void); | |
1116 | |
1117 void set_sample_number (unsigned int sample); | |
1118 unsigned int get_sample_number (void); | |
1119 unsigned int get_total_samples (void); | |
1120 void set_end_sample (unsigned int sample); | |
1121 unsigned int get_end_sample (void); | |
1122 void reset_end_sample (void); | |
1123 void set_tag (charMatrix tag); | |
1124 charMatrix get_tag (void); | |
1125 void set_userdata (octave_value userdata); | |
1126 octave_value get_userdata (void); | |
1127 PaStream *get_stream (void); | |
1128 octave_function *octave_callback_function; | |
1129 | |
1130 octave_value getaudiodata (void); | |
1131 audioplayer *getplayer (void); | |
1132 bool isrecording (void); | |
1133 audioplayer play (void); | |
1134 void record (void); | |
1135 void recordblocking (float seconds); | |
1136 void pause (void); | |
1137 void resume (void); | |
1138 void stop (void); | |
1139 void append (float sample_l, float sample_r); | |
1140 | |
1141 private: | |
1142 Matrix y; | |
1143 std::vector<float> left; | |
1144 std::vector<float> right; | |
1145 charMatrix tag; | |
1146 octave_value userdata; | |
1147 int channels; | |
1148 int fs; | |
1149 int nbits; | |
1150 int id; | |
1151 unsigned int sample_number; | |
1152 unsigned int end_sample; | |
1153 PaStream *stream; | |
1154 PaStreamParameters input_parameters; | |
1155 audio_type type; | |
1156 DECLARE_OCTAVE_ALLOCATOR | |
1157 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA | |
1158 }; | |
1159 | |
1160 DEFINE_OCTAVE_ALLOCATOR (audiorecorder); | |
1161 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (audiorecorder, "audiorecorder", "audiorecorder"); | |
1162 | |
1163 static int | |
19512
a5eb03a7e2a5
eliminate unused variable and parameter warnings
John W. Eaton <jwe@octave.org>
parents:
19511
diff
changeset
|
1164 octave_record_callback (const void *input, void *, unsigned long frames, |
a5eb03a7e2a5
eliminate unused variable and parameter warnings
John W. Eaton <jwe@octave.org>
parents:
19511
diff
changeset
|
1165 const PaStreamCallbackTimeInfo *, |
a5eb03a7e2a5
eliminate unused variable and parameter warnings
John W. Eaton <jwe@octave.org>
parents:
19511
diff
changeset
|
1166 PaStreamCallbackFlags, void *data) |
19510 | 1167 { |
1168 audiorecorder *recorder = (audiorecorder *)data; | |
1169 int channels = recorder->get_channels (); | |
1170 float sample_l, sample_r; | |
1171 Matrix sound; | |
1172 sound.resize (frames, 2); | |
1173 if (recorder->get_nbits () == 8) | |
1174 { | |
1175 int8_t *input8 = (int8_t *)input; | |
1176 for (int i = 0; i < frames; i++) | |
1177 { | |
1178 sample_l = input8[i * channels] / (pow (2.0, 7) - 1.0); | |
1179 sample_r = input8[i * channels + (channels - 1)] / (pow (2.0, 7) - 1.0); | |
1180 sound(i, 0) = sample_l; | |
1181 sound(i, 1) = sample_r; | |
1182 } | |
1183 } | |
1184 else if (recorder->get_nbits () == 16) | |
1185 { | |
1186 int16_t *input16 = (int16_t *)input; | |
1187 for (int i = 0; i < frames; i++) | |
1188 { | |
1189 sample_l = input16[i * channels] / (pow (2.0, 15) - 1.0); | |
1190 sample_r = input16[i * channels + (channels - 1)] / (pow (2.0, 15) - 1.0); | |
1191 sound(i, 0) = sample_l; | |
1192 sound(i, 1) = sample_r; | |
1193 } | |
1194 } | |
1195 else if (recorder->get_nbits () == 24) | |
1196 { | |
1197 uint8_t *input24 = (uint8_t *)input; | |
1198 int32_t sample_l32, sample_r32; | |
1199 uint8_t *_sample_l = (uint8_t *)&sample_l; | |
1200 uint8_t *_sample_r = (uint8_t *)&sample_r; | |
1201 for (int i = 0; i < frames; i++) | |
1202 { | |
1203 for (int j = 0; j < 3; j++) | |
1204 { | |
1205 _sample_l[j] = input24[i * channels * 3 + j]; | |
1206 _sample_r[j] = input24[i * channels * 3 + (channels - 1) * 3 + j]; | |
1207 } | |
1208 if (sample_l32 & 0x00800000) | |
1209 sample_l32 |= 0xff000000; | |
1210 if (sample_r32 & 0x00800000) | |
1211 sample_r32 |= 0xff000000; | |
1212 sound(i, 0) = sample_l32 / pow (2.0, 23); | |
1213 sound(i, 1) = sample_r32 / pow (2.0, 23); | |
1214 } | |
1215 } | |
1216 | |
1217 octave_value_list args, retval; | |
1218 args(0) = sound; | |
1219 retval = feval (recorder->octave_callback_function, args, 1); | |
1220 return retval(0).int_value (); | |
1221 } | |
1222 | |
1223 static int | |
19512
a5eb03a7e2a5
eliminate unused variable and parameter warnings
John W. Eaton <jwe@octave.org>
parents:
19511
diff
changeset
|
1224 portaudio_record_callback (const void *input, void *, unsigned long frames, |
a5eb03a7e2a5
eliminate unused variable and parameter warnings
John W. Eaton <jwe@octave.org>
parents:
19511
diff
changeset
|
1225 const PaStreamCallbackTimeInfo *, |
a5eb03a7e2a5
eliminate unused variable and parameter warnings
John W. Eaton <jwe@octave.org>
parents:
19511
diff
changeset
|
1226 PaStreamCallbackFlags, void *data) |
19510 | 1227 { |
1228 audiorecorder *recorder = (audiorecorder *)data; | |
1229 int channels = recorder->get_channels (); | |
1230 float sample_l, sample_r; | |
1231 if (recorder->get_nbits () == 8) | |
1232 { | |
1233 int8_t *input8 = (int8_t *)input; | |
1234 for (int i = 0; i < frames; i++) | |
1235 { | |
1236 sample_l = input8[i * channels] / (pow (2.0, 7) - 1.0); | |
1237 sample_r = input8[i * channels + (channels - 1)] / (pow (2.0, 7) - 1.0); | |
1238 recorder->append (sample_l, sample_r); | |
1239 } | |
1240 } | |
1241 else if (recorder->get_nbits () == 16) | |
1242 { | |
1243 int16_t *input16 = (int16_t *)input; | |
1244 for (int i = 0; i < frames; i++) | |
1245 { | |
1246 sample_l = input16[i * channels] / (pow (2.0, 15) - 1.0); | |
1247 sample_r = input16[i * channels + (channels - 1)] / (pow (2.0, 15) - 1.0); | |
1248 recorder->append (sample_l, sample_r); | |
1249 } | |
1250 } | |
1251 else if (recorder->get_nbits () == 24) | |
1252 { | |
1253 uint8_t *input24 = (uint8_t *)input; | |
1254 int32_t sample_l32, sample_r32; | |
1255 uint8_t *_sample_l = (uint8_t *)&sample_l; | |
1256 uint8_t *_sample_r = (uint8_t *)&sample_r; | |
1257 for (int i = 0; i < frames; i++) | |
1258 { | |
1259 for (int j = 0; j < 3; j++) | |
1260 { | |
1261 _sample_l[j] = input24[i * channels * 3 + j]; | |
1262 _sample_r[j] = input24[i * channels * 3 + (channels - 1) * 3 + j]; | |
1263 } | |
1264 if (sample_l32 & 0x00800000) | |
1265 sample_l32 |= 0xff000000; | |
1266 if (sample_r32 & 0x00800000) | |
1267 sample_r32 |= 0xff000000; | |
1268 recorder->append (sample_l32 / pow (2.0, 23), sample_r32 / pow (2.0, 23)); | |
1269 } | |
1270 } | |
1271 | |
1272 if (recorder->get_sample_number () > recorder->get_end_sample ()) | |
1273 return paComplete; | |
1274 | |
1275 return paContinue; | |
1276 } | |
1277 | |
1278 audiorecorder::audiorecorder (void) | |
1279 { | |
1280 this->id = -1; | |
1281 this->sample_number = 0; | |
1282 this->channels = 1; | |
1283 this->tag = charMatrix (""); | |
1284 Matrix userdata; | |
1285 this->userdata = octave_value (userdata); | |
1286 this->stream = 0; | |
1287 this->end_sample = -1; | |
1288 this->set_fs (44100); | |
1289 this->set_nbits (16); | |
1290 this->set_channels (2); | |
1291 this->octave_callback_function = 0; | |
1292 } | |
1293 | |
1294 void | |
1295 audiorecorder::print (std::ostream& os, bool pr_as_read_syntax) const | |
1296 { | |
1297 print_raw (os, pr_as_read_syntax); | |
1298 newline (os); | |
1299 } | |
1300 | |
1301 void | |
19512
a5eb03a7e2a5
eliminate unused variable and parameter warnings
John W. Eaton <jwe@octave.org>
parents:
19511
diff
changeset
|
1302 audiorecorder::print_raw (std::ostream& os, bool) const |
19510 | 1303 { |
1304 os << 0; | |
1305 } | |
1306 | |
1307 void | |
1308 audiorecorder::init (void) | |
1309 { | |
1310 PaError err; | |
1311 int device; | |
1312 err = Pa_Initialize (); | |
1313 if (err != paNoError) | |
1314 { | |
1315 error ("audiorecorder: Initialization error!"); | |
1316 return; | |
1317 } | |
1318 | |
1319 int numDevices = Pa_GetDeviceCount (); | |
1320 if (numDevices < 0) | |
1321 { | |
1322 error ("audiorecorder: No audio devices found!"); | |
1323 return; | |
1324 } | |
1325 | |
1326 if (this->get_id () == -1) | |
1327 device = Pa_GetDefaultInputDevice (); | |
1328 else | |
1329 device = this->get_id (); | |
1330 | |
1331 this->input_parameters.device = device; | |
1332 this->input_parameters.channelCount = this->get_channels (); | |
1333 this->input_parameters.sampleFormat = bits_to_format (this->get_nbits ()); | |
1334 this->input_parameters.suggestedLatency = Pa_GetDeviceInfo (device)->defaultHighInputLatency; | |
1335 this->input_parameters.hostApiSpecificStreamInfo = NULL; | |
1336 } | |
1337 | |
1338 void | |
1339 audiorecorder::set_fs (int fs) | |
1340 { | |
1341 this->fs = fs; | |
1342 } | |
1343 | |
1344 int | |
1345 audiorecorder::get_fs (void) | |
1346 { | |
1347 return this->fs; | |
1348 } | |
1349 | |
1350 void | |
1351 audiorecorder::set_nbits (int nbits) | |
1352 { | |
1353 this->nbits = nbits; | |
1354 } | |
1355 | |
1356 int | |
1357 audiorecorder::get_nbits (void) | |
1358 { | |
1359 return this->nbits; | |
1360 } | |
1361 | |
1362 void | |
1363 audiorecorder::set_id (int id) | |
1364 { | |
1365 this->id = id; | |
1366 } | |
1367 | |
1368 int | |
1369 audiorecorder::get_id (void) | |
1370 { | |
1371 return this->id; | |
1372 } | |
1373 | |
1374 void | |
1375 audiorecorder::set_channels (int channels) | |
1376 { | |
1377 assert (channels == 1 or channels == 2); | |
1378 this->channels = channels; | |
1379 } | |
1380 | |
1381 int | |
1382 audiorecorder::get_channels (void) | |
1383 { | |
1384 return this->channels; | |
1385 } | |
1386 | |
1387 audio_type | |
1388 audiorecorder::get_type (void) | |
1389 { | |
1390 return this->type; | |
1391 } | |
1392 | |
1393 void | |
1394 audiorecorder::set_sample_number (unsigned int sample_number) | |
1395 { | |
1396 this->sample_number = sample_number; | |
1397 } | |
1398 | |
1399 unsigned int | |
1400 audiorecorder::get_sample_number (void) | |
1401 { | |
1402 return this->sample_number; | |
1403 } | |
1404 | |
1405 unsigned int | |
1406 audiorecorder::get_total_samples (void) | |
1407 { | |
1408 return this->left.size (); | |
1409 } | |
1410 | |
1411 void | |
1412 audiorecorder::set_end_sample (unsigned int end_sample) | |
1413 { | |
1414 this->end_sample = end_sample; | |
1415 } | |
1416 | |
1417 unsigned int | |
1418 audiorecorder::get_end_sample (void) | |
1419 { | |
1420 return this->end_sample; | |
1421 } | |
1422 | |
1423 void | |
1424 audiorecorder::reset_end_sample (void) | |
1425 { | |
1426 this->set_end_sample (this->left.size ()); | |
1427 } | |
1428 | |
1429 void | |
1430 audiorecorder::set_tag (charMatrix tag) | |
1431 { | |
1432 this->tag = tag; | |
1433 } | |
1434 | |
1435 charMatrix | |
1436 audiorecorder::get_tag (void) | |
1437 { | |
1438 return this->tag; | |
1439 } | |
1440 | |
1441 void | |
1442 audiorecorder::set_userdata (octave_value userdata) | |
1443 { | |
1444 this->userdata = userdata; | |
1445 } | |
1446 | |
1447 octave_value | |
1448 audiorecorder::get_userdata (void) | |
1449 { | |
1450 return this->userdata; | |
1451 } | |
1452 | |
1453 octave_value | |
1454 audiorecorder::getaudiodata (void) | |
1455 { | |
1456 Matrix audio (2, this->left.size ()); | |
1457 for (int i = 0; i < this->left.size (); i++) | |
1458 { | |
1459 audio(0, i) = this->left[i]; | |
1460 audio(1, i) = this->right[i]; | |
1461 } | |
1462 return octave_value (audio); | |
1463 } | |
1464 | |
1465 audioplayer * | |
1466 audiorecorder::getplayer (void) | |
1467 { | |
1468 audioplayer *player = new audioplayer (); | |
1469 player->set_y (this->getaudiodata ()); | |
1470 player->set_fs (this->get_fs ()); | |
1471 player->set_nbits (this->get_nbits ()); | |
1472 player->init (); | |
1473 return player; | |
1474 } | |
1475 | |
1476 bool | |
1477 audiorecorder::isrecording (void) | |
1478 { | |
1479 if (this->get_stream () == 0) | |
1480 return false; | |
1481 | |
1482 PaError err; | |
1483 err = Pa_IsStreamActive (stream); | |
1484 if (err != 0 and err != 1) | |
1485 { | |
1486 error ("audiorecorder: Error checking stream activity status"); | |
1487 return false; | |
1488 } | |
1489 | |
1490 return (err == 1); | |
1491 } | |
1492 | |
1493 void | |
1494 audiorecorder::record (void) | |
1495 { | |
1496 if (this->get_stream ()) | |
1497 this->stop (); | |
1498 | |
1499 this->left.clear (); | |
1500 this->right.clear (); | |
1501 PaError err; | |
1502 if (this->octave_callback_function != 0) | |
1503 { | |
1504 err = Pa_OpenStream (&stream, &(this->input_parameters), NULL, this->get_fs (), BUFFER_SIZE, paClipOff, octave_record_callback, (void *)this); | |
1505 } | |
1506 else | |
1507 { | |
1508 err = Pa_OpenStream (&stream, &(this->input_parameters), NULL, this->get_fs (), BUFFER_SIZE, paClipOff, portaudio_record_callback, (void *)this); | |
1509 } | |
1510 if (err != paNoError) | |
1511 { | |
1512 error ("audiorecorder: Error opening audio recording stream"); | |
1513 return; | |
1514 } | |
1515 err = Pa_StartStream (stream); | |
1516 if (err != paNoError) | |
1517 { | |
1518 error ("audiorecorder: Error starting audio recording stream"); | |
1519 return; | |
1520 } | |
1521 } | |
1522 | |
1523 void | |
1524 audiorecorder::recordblocking (float seconds) | |
1525 { | |
1526 if (this->get_stream ()) | |
1527 this->stop (); | |
1528 | |
1529 this->left.clear (); | |
1530 this->right.clear (); | |
1531 | |
1532 PaError err; | |
1533 err = Pa_OpenStream (&stream, &(this->input_parameters), NULL, this->get_fs (), BUFFER_SIZE, paClipOff, NULL, (void *)this); | |
1534 if (err != paNoError) | |
1535 { | |
1536 error ("audiorecorder: Error opening audio recording stream"); | |
1537 return; | |
1538 } | |
1539 | |
1540 err = Pa_StartStream (stream); | |
1541 if (err != paNoError) | |
1542 { | |
1543 error ("audiorecorder: Error starting audio recording stream"); | |
1544 return; | |
1545 } | |
1546 | |
1547 unsigned int frames = seconds * this->get_fs (); | |
1548 uint8_t buffer[BUFFER_SIZE * 2 * 3]; | |
1549 for (int i = 0; i < frames / BUFFER_SIZE; i++) | |
1550 { | |
1551 Pa_ReadStream (this->get_stream (), (void *)buffer, BUFFER_SIZE); | |
1552 if (this->octave_callback_function != 0) | |
1553 octave_record_callback ((void *)buffer, NULL, BUFFER_SIZE, 0, 0, (void *)this); | |
1554 else | |
1555 portaudio_record_callback ((void *)buffer, NULL, BUFFER_SIZE, 0, 0, (void *)this); | |
1556 } | |
1557 } | |
1558 | |
1559 void | |
1560 audiorecorder::pause (void) | |
1561 { | |
1562 if (this->get_stream () == 0) | |
1563 return; | |
1564 | |
1565 PaError err; | |
1566 err = Pa_StopStream (stream); | |
1567 if (err != paNoError) | |
1568 { | |
1569 error ("audiorecorder: Error stoping audio recording stream"); | |
1570 return; | |
1571 } | |
1572 } | |
1573 | |
1574 void | |
1575 audiorecorder::resume (void) | |
1576 { | |
1577 if (this->get_stream () == 0) | |
1578 return; | |
1579 | |
1580 PaError err; | |
1581 err = Pa_StartStream (stream); | |
1582 if (err != paNoError) | |
1583 { | |
1584 error ("audiorecorder: Error starting audio recording stream"); | |
1585 return; | |
1586 } | |
1587 } | |
1588 | |
1589 void | |
1590 audiorecorder::stop (void) | |
1591 { | |
1592 if (this->get_stream () == 0) | |
1593 return; | |
1594 | |
1595 PaError err; | |
1596 if (not Pa_IsStreamStopped (this->get_stream ())) | |
1597 { | |
1598 err = Pa_AbortStream (this->get_stream ()); | |
1599 if (err != paNoError) | |
1600 { | |
1601 error ("audioplayer: Error stopping audio playback stream"); | |
1602 return; | |
1603 } | |
1604 } | |
1605 | |
1606 err = Pa_CloseStream (stream); | |
1607 if (err != paNoError) | |
1608 { | |
1609 error ("audiorecorder: Error closing audio recording stream"); | |
1610 return; | |
1611 } | |
1612 | |
1613 this->set_sample_number (0); | |
1614 this->reset_end_sample (); | |
1615 stream = 0; | |
1616 } | |
1617 | |
1618 void | |
1619 audiorecorder::append (float sample_l, float sample_r) | |
1620 { | |
1621 this->left.push_back (sample_l); | |
1622 this->right.push_back (sample_r); | |
1623 this->set_sample_number (this->get_sample_number () + 1); | |
1624 } | |
1625 | |
1626 PaStream * | |
1627 audiorecorder::get_stream (void) | |
1628 { | |
1629 return this->stream; | |
1630 } | |
1631 | |
1632 DEFUN_DLD (__recorder_audiorecorder__, args, , | |
1633 "-*- texinfo -*-\n\ | |
1634 @deftypefn {Loadable Function} {@var{recorder} =} __recorder_audiorecorder__ (@var{fs}, @var{nbits}, @var{channels})\n\ | |
1635 @deftypefnx {Loadable Function} {@var{recorder} =} __recorder_audiorecorder__ (@var{fs}, @var{nbits}, @var{channels}, @var{id})\n\ | |
1636 @deftypefnx {Loadable Function} {@var{recorder} =} __recorder_audiorecorder__ (@var{fcn}, @dots{})\n\ | |
1637 Undocumented internal function.\n\ | |
1638 @end deftypefn") | |
1639 { | |
1640 #ifdef HAVE_PORTAUDIO | |
1641 int nargin = args.length (); | |
1642 audiorecorder* retval = new audiorecorder (); | |
1643 int offset = 0; | |
1644 if (nargin > 0) | |
1645 { | |
1646 bool is_function = args(0).is_string () || args(0).is_function_handle () || args(0).is_inline_function (); | |
1647 if (is_function) | |
1648 { | |
1649 retval->octave_callback_function = args(0).function_value (); | |
1650 offset = 1; | |
1651 } | |
1652 } | |
1653 switch (nargin - offset) | |
1654 { | |
1655 case 3: | |
1656 retval->set_fs (args(0 + offset).int_value ()); | |
1657 retval->set_nbits (args(1 + offset).int_value ()); | |
1658 retval->set_channels (args(2 + offset).int_value ()); | |
1659 break; | |
1660 case 4: | |
1661 retval->set_fs (args(0 + offset).int_value ()); | |
1662 retval->set_nbits (args(1 + offset).int_value ()); | |
1663 retval->set_channels (args(2 + offset).int_value ()); | |
1664 retval->set_id (args(3 + offset).int_value ()); | |
1665 break; | |
1666 } | |
1667 retval->init (); | |
1668 return octave_value (retval); | |
1669 #else | |
1670 octave_value retval; | |
1671 error ("portaudio not found on your system and thus audio functionality is not present"); | |
1672 return retval; | |
1673 #endif | |
1674 } | |
1675 | |
1676 DEFUN_DLD (__recorder_getaudiodata__, args, , | |
1677 "-*- texinfo -*-\n\ | |
1678 @deftypefn {Loadable Function} {@var{data}} __recorder_getaudiodata__ (@var{recorder})\n\ | |
1679 Undocumented internal function.\n\ | |
1680 @end deftypefn") | |
1681 { | |
1682 octave_value retval; | |
1683 #ifdef HAVE_PORTAUDIO | |
1684 const octave_base_value& rep = args(0).get_rep (); | |
1685 audiorecorder *recorder = &((audiorecorder &)rep); | |
1686 retval = octave_value (recorder->getaudiodata ()); | |
1687 #else | |
1688 error ("portaudio not found on your system and thus audio functionality is not present"); | |
1689 #endif | |
1690 return retval; | |
1691 } | |
1692 | |
1693 DEFUN_DLD (__recorder_get_channels__, args, , | |
1694 "-*- texinfo -*-\n\ | |
1695 @deftypefn {Loadable Function} {@var{n} =} __recorder_get_channels__ (@var{recorder})\n\ | |
1696 Undocumented internal function.\n\ | |
1697 @end deftypefn") | |
1698 { | |
1699 octave_value retval; | |
1700 #ifdef HAVE_PORTAUDIO | |
1701 int nargin = args.length (); | |
1702 if (nargin == 1) | |
1703 { | |
1704 const octave_base_value& rep = args(0).get_rep (); | |
1705 audiorecorder *recorder = &((audiorecorder &)rep); | |
1706 retval = octave_value (recorder->get_channels ()); | |
1707 } | |
1708 #else | |
1709 error ("portaudio not found on your system and thus audio functionality is not present"); | |
1710 #endif | |
1711 return retval; | |
1712 } | |
1713 | |
1714 DEFUN_DLD (__recorder_get_fs__, args, , | |
1715 "-*- texinfo -*-\n\ | |
1716 @deftypefn {Loadable Function} {@var{fs} =} __recorder_get_fs__ (@var{recorder})\n\ | |
1717 Undocumented internal function.\n\ | |
1718 @end deftypefn") | |
1719 { | |
1720 octave_value retval; | |
1721 #ifdef HAVE_PORTAUDIO | |
1722 int nargin = args.length (); | |
1723 if (nargin == 1) | |
1724 { | |
1725 const octave_base_value& rep = args(0).get_rep (); | |
1726 audiorecorder *recorder = &((audiorecorder &)rep); | |
1727 retval = octave_value (recorder->get_fs ()); | |
1728 } | |
1729 #else | |
1730 error ("portaudio not found on your system and thus audio functionality is not present"); | |
1731 #endif | |
1732 return retval; | |
1733 } | |
1734 | |
1735 DEFUN_DLD (__recorder_get_id__, args, , | |
1736 "-*- texinfo -*-\n\ | |
1737 @deftypefn {Loadable Function} {@var{id} =} __recorder_get_id__ (@var{recorder})\n\ | |
1738 Undocumented internal function.\n\ | |
1739 @end deftypefn") | |
1740 { | |
1741 octave_value retval; | |
1742 #ifdef HAVE_PORTAUDIO | |
1743 int nargin = args.length (); | |
1744 if (nargin == 1) | |
1745 { | |
1746 const octave_base_value& rep = args(0).get_rep (); | |
1747 audiorecorder *recorder = &((audiorecorder &)rep); | |
1748 retval = octave_value (recorder->get_id ()); | |
1749 } | |
1750 #else | |
1751 error ("portaudio not found on your system and thus audio functionality is not present"); | |
1752 #endif | |
1753 return retval; | |
1754 } | |
1755 | |
1756 DEFUN_DLD (__recorder_get_nbits__, args, , | |
1757 "-*- texinfo -*-\n\ | |
1758 @deftypefn {Loadable Function} {@var{nbits} =} __recorder_get_nbits__ (@var{recorder})\n\ | |
1759 Undocumented internal function.\n\ | |
1760 @end deftypefn") | |
1761 { | |
1762 octave_value retval; | |
1763 #ifdef HAVE_PORTAUDIO | |
1764 int nargin = args.length (); | |
1765 if (nargin == 1) | |
1766 { | |
1767 const octave_base_value& rep = args(0).get_rep (); | |
1768 audiorecorder *recorder = &((audiorecorder &)rep); | |
1769 retval = octave_value (recorder->get_nbits ()); | |
1770 } | |
1771 #else | |
1772 error ("portaudio not found on your system and thus audio functionality is not present"); | |
1773 #endif | |
1774 return retval; | |
1775 } | |
1776 | |
1777 DEFUN_DLD (__recorder_get_sample_number__, args, , | |
1778 "-*- texinfo -*-\n\ | |
1779 @deftypefn {Loadable Function} {@var{n} =} __recorder_get_sample_number__ (@var{recorder})\n\ | |
1780 Undocumented internal function.\n\ | |
1781 @end deftypefn") | |
1782 { | |
1783 octave_value retval; | |
1784 #ifdef HAVE_PORTAUDIO | |
1785 int nargin = args.length (); | |
1786 if (nargin == 1) | |
1787 { | |
1788 const octave_base_value& rep = args(0).get_rep (); | |
1789 audiorecorder *recorder = &((audiorecorder &)rep); | |
1790 retval = octave_value (recorder->get_sample_number ()); | |
1791 } | |
1792 #else | |
1793 error ("portaudio not found on your system and thus audio functionality is not present"); | |
1794 #endif | |
1795 return retval; | |
1796 } | |
1797 | |
1798 DEFUN_DLD (__recorder_get_tag__, args, , | |
1799 "-*- texinfo -*-\n\ | |
1800 @deftypefn {Loadable Function} {@var{tag} =} __recorder_get_tag__ (@var{recorder})\n\ | |
1801 Undocumented internal function.\n\ | |
1802 @end deftypefn") | |
1803 { | |
1804 octave_value retval; | |
1805 #ifdef HAVE_PORTAUDIO | |
1806 int nargin = args.length (); | |
1807 if (nargin == 1) | |
1808 { | |
1809 const octave_base_value& rep = args(0).get_rep (); | |
1810 audiorecorder *recorder = &((audiorecorder &)rep); | |
1811 retval = octave_value (recorder->get_tag ()); | |
1812 } | |
1813 #else | |
1814 error ("portaudio not found on your system and thus audio functionality is not present"); | |
1815 #endif | |
1816 return retval; | |
1817 } | |
1818 | |
1819 DEFUN_DLD (__recorder_get_total_samples__, args, , | |
1820 "-*- texinfo -*-\n\ | |
1821 @deftypefn {Loadable Function} {@var{n} =} __recorder_get_total_samples__ (@var{recorder})\n\ | |
1822 Undocumented internal function.\n\ | |
1823 @end deftypefn") | |
1824 { | |
1825 octave_value retval; | |
1826 #ifdef HAVE_PORTAUDIO | |
1827 int nargin = args.length (); | |
1828 if (nargin == 1) | |
1829 { | |
1830 const octave_base_value& rep = args(0).get_rep (); | |
1831 audiorecorder *recorder = &((audiorecorder &)rep); | |
1832 retval = octave_value (recorder->get_total_samples ()); | |
1833 } | |
1834 #else | |
1835 error ("portaudio not found on your system and thus audio functionality is not present"); | |
1836 #endif | |
1837 return retval; | |
1838 } | |
1839 | |
1840 DEFUN_DLD (__recorder_get_userdata__, args, , | |
1841 "-*- texinfo -*-\n\ | |
1842 @deftypefn {Loadable Function} {@var{data} =} __recorder_get_userdata__ (@var{recorder})\n\ | |
1843 Undocumented internal function.\n\ | |
1844 @end deftypefn") | |
1845 { | |
1846 octave_value retval; | |
1847 #ifdef HAVE_PORTAUDIO | |
1848 int nargin = args.length (); | |
1849 if (nargin == 1) | |
1850 { | |
1851 const octave_base_value& rep = args(0).get_rep (); | |
1852 audiorecorder *recorder = &((audiorecorder &)rep); | |
1853 retval = recorder->get_userdata (); | |
1854 } | |
1855 #else | |
1856 error ("portaudio not found on your system and thus audio functionality is not present"); | |
1857 #endif | |
1858 return retval; | |
1859 } | |
1860 | |
1861 DEFUN_DLD (__recorder_isrecording__, args, , | |
1862 "-*- texinfo -*-\n\ | |
1863 @deftypefn {Loadable Function} {} __recorder_isrecording__ (@var{recorder})\n\ | |
1864 Undocumented internal function.\n\ | |
1865 @end deftypefn") | |
1866 { | |
1867 octave_value retval; | |
1868 #ifdef HAVE_PORTAUDIO | |
1869 int nargin = args.length (); | |
1870 if (nargin == 1) | |
1871 { | |
1872 const octave_base_value& rep = args(0).get_rep (); | |
1873 audiorecorder *recorder = &((audiorecorder &)rep); | |
1874 if (recorder->isrecording ()) | |
1875 return octave_value (1); | |
1876 else | |
1877 return octave_value (0); | |
1878 } | |
1879 #else | |
1880 error ("portaudio not found on your system and thus audio functionality is not present"); | |
1881 #endif | |
1882 return retval; | |
1883 } | |
1884 | |
1885 DEFUN_DLD (__recorder_pause__, args, , | |
1886 "-*- texinfo -*-\n\ | |
1887 @deftypefn {Loadable Function} {} __recorder_pause__ (@var{recorder})\n\ | |
1888 Undocumented internal function.\n\ | |
1889 @end deftypefn") | |
1890 { | |
1891 octave_value retval; | |
1892 #ifdef HAVE_PORTAUDIO | |
1893 int nargin = args.length (); | |
1894 if (nargin == 1) | |
1895 { | |
1896 const octave_base_value& rep = args(0).get_rep (); | |
1897 audiorecorder *recorder = &((audiorecorder &)rep); | |
1898 recorder->pause (); | |
1899 } | |
1900 #else | |
1901 error ("portaudio not found on your system and thus audio functionality is not present"); | |
1902 #endif | |
1903 return retval; | |
1904 } | |
1905 | |
1906 DEFUN_DLD (__recorder_recordblocking__, args, , | |
1907 "-*- texinfo -*-\n\ | |
1908 @deftypefn {Loadable Function} {} __recorder_recordblocking__ (@var{recorder}, @var{seconds})\n\ | |
1909 Undocumented internal function.\n\ | |
1910 @end deftypefn") | |
1911 { | |
1912 octave_value retval; | |
1913 #ifdef HAVE_PORTAUDIO | |
1914 const octave_base_value& rep = args(0).get_rep (); | |
1915 audiorecorder *recorder = &((audiorecorder &)rep); | |
1916 recorder->recordblocking (args(1).float_value ()); | |
1917 #else | |
1918 error ("portaudio not found on your system and thus audio functionality is not present"); | |
1919 #endif | |
1920 return retval; | |
1921 } | |
1922 | |
1923 DEFUN_DLD (__recorder_record__, args, , | |
1924 "-*- texinfo -*-\n\ | |
1925 @deftypefn {Loadable Function} {} __recorder_record__ (@var{recorder})\n\ | |
1926 @deftypefnx {Loadable Function} {} __recorder_record__ (@var{recorder}, @var{seconds})\n\ | |
1927 Undocumented internal function.\n\ | |
1928 @end deftypefn") | |
1929 { | |
1930 octave_value retval; | |
1931 #ifdef HAVE_PORTAUDIO | |
1932 const octave_base_value& rep = args(0).get_rep (); | |
1933 audiorecorder *recorder = &((audiorecorder &)rep); | |
1934 if (args.length () == 1) | |
1935 { | |
1936 recorder->record (); | |
1937 } | |
1938 else if (args.length () == 2) | |
1939 { | |
1940 recorder->set_end_sample (args(1).int_value () * recorder->get_fs ()); | |
1941 recorder->record (); | |
1942 } | |
1943 else | |
1944 { | |
1945 error ("audiorecorder: wrong number of arguments passed to record"); | |
1946 } | |
1947 #else | |
1948 error ("portaudio not found on your system and thus audio functionality is not present"); | |
1949 #endif | |
1950 return retval; | |
1951 } | |
1952 | |
1953 DEFUN_DLD (__recorder_resume__, args, , | |
1954 "-*- texinfo -*-\n\ | |
1955 @deftypefn {Loadable Function} {} __recorder_resume__ (@var{recorder})\n\ | |
1956 Undocumented internal function.\n\ | |
1957 @end deftypefn") | |
1958 { | |
1959 octave_value retval; | |
1960 #ifdef HAVE_PORTAUDIO | |
1961 int nargin = args.length (); | |
1962 if (nargin == 1) | |
1963 { | |
1964 const octave_base_value& rep = args(0).get_rep (); | |
1965 audiorecorder *recorder = &((audiorecorder &)rep); | |
1966 recorder->resume (); | |
1967 } | |
1968 #else | |
1969 error ("portaudio not found on your system and thus audio functionality is not present"); | |
1970 #endif | |
1971 return retval; | |
1972 } | |
1973 | |
1974 DEFUN_DLD (__recorder_set_fs__, args, , | |
1975 "-*- texinfo -*-\n\ | |
1976 @deftypefn {Loadable Function} {} __recorder_set_fs__ (@var{recorder}, @var{fs})\n\ | |
1977 Undocumented internal function.\n\ | |
1978 @end deftypefn") | |
1979 { | |
1980 octave_value retval; | |
1981 #ifdef HAVE_PORTAUDIO | |
1982 int nargin = args.length (); | |
1983 if (nargin == 2) | |
1984 { | |
1985 const octave_base_value& rep = args(0).get_rep (); | |
1986 audiorecorder *recorder = &((audiorecorder &)rep); | |
1987 recorder->set_fs (args(1).int_value ()); | |
1988 } | |
1989 #else | |
1990 error ("portaudio not found on your system and thus audio functionality is not present"); | |
1991 #endif | |
1992 return retval; | |
1993 } | |
1994 | |
1995 DEFUN_DLD (__recorder_set_tag__, args, , | |
1996 "-*- texinfo -*-\n\ | |
1997 @deftypefn {Loadable Function} {} __recorder_set_tag__ (@var{recorder}, @var{tag})\n\ | |
1998 Undocumented internal function.\n\ | |
1999 @end deftypefn") | |
2000 { | |
2001 octave_value retval; | |
2002 #ifdef HAVE_PORTAUDIO | |
2003 int nargin = args.length (); | |
2004 if (nargin == 2) | |
2005 { | |
2006 const octave_base_value& rep = args(0).get_rep (); | |
2007 audiorecorder *recorder = &((audiorecorder &)rep); | |
2008 recorder->set_tag (args(1).char_matrix_value ()); | |
2009 } | |
2010 #else | |
2011 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2012 #endif | |
2013 return retval; | |
2014 } | |
2015 | |
2016 DEFUN_DLD (__recorder_set_userdata__, args, , | |
2017 "-*- texinfo -*-\n\ | |
2018 @deftypefn {Loadable Function} {} __recorder_set_userdata__ (@var{recorder}, @var{data})\n\ | |
2019 Undocumented internal function.\n\ | |
2020 @end deftypefn") | |
2021 { | |
2022 octave_value retval; | |
2023 #ifdef HAVE_PORTAUDIO | |
2024 int nargin = args.length (); | |
2025 if (nargin == 2) | |
2026 { | |
2027 const octave_base_value& rep = args(0).get_rep (); | |
2028 audiorecorder *recorder = &((audiorecorder &)rep); | |
2029 recorder->set_userdata (args(1)); | |
2030 } | |
2031 #else | |
2032 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2033 #endif | |
2034 return retval; | |
2035 } | |
2036 | |
2037 DEFUN_DLD (__recorder_stop__, args, , | |
2038 "-*- texinfo -*-\n\ | |
2039 @deftypefn {Loadable Function} {} __recorder_stop__ (@var{recorder})\n\ | |
2040 Undocumented internal function.\n\ | |
2041 @end deftypefn") | |
2042 { | |
2043 octave_value retval; | |
2044 #ifdef HAVE_PORTAUDIO | |
2045 const octave_base_value& rep = args(0).get_rep (); | |
2046 audiorecorder *recorder = &((audiorecorder &)rep); | |
2047 recorder->stop (); | |
2048 #else | |
2049 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2050 #endif | |
2051 return retval; | |
2052 } | |
2053 | |
2054 DEFUN_DLD (__player_audioplayer__, args, , | |
2055 "-*- texinfo -*-\n\ | |
2056 @deftypefn {Loadable Function} {@var{player} =} __player_audioplayer__ (@var{y}, @var{fs})\n\ | |
2057 @deftypefnx {Loadable Function} {@var{player} =} __player_audioplayer__ (@var{y}, @var{fs}, @var{nbits})\n\ | |
2058 @deftypefnx {Loadable Function} {@var{player} =} __player_audioplayer__ (@var{y}, @var{fs}, @var{nbits}, @var{id})\n\ | |
2059 Undocumented internal function.\n\ | |
2060 @end deftypefn") | |
2061 { | |
2062 #ifdef HAVE_PORTAUDIO | |
2063 int nargin = args.length (); | |
2064 audioplayer* retval = new audioplayer (); | |
2065 bool is_function = args(0).is_string () || args(0).is_function_handle () || args(0).is_inline_function (); | |
2066 if (is_function) | |
2067 retval->set_y (args(0).function_value ()); | |
2068 else | |
2069 retval->set_y (args(0)); | |
2070 retval->set_fs (args(1).int_value ()); | |
2071 switch (nargin) | |
2072 { | |
2073 case 3: | |
2074 retval->set_nbits (args(2).int_value ()); | |
2075 break; | |
2076 case 4: | |
2077 retval->set_nbits (args(2).int_value ()); | |
2078 retval->set_id (args(3).int_value ()); | |
2079 break; | |
2080 } | |
2081 if (is_function) | |
2082 retval->init_fn (); | |
2083 else | |
2084 retval->init (); | |
2085 return octave_value (retval); | |
2086 #else | |
2087 octave_value retval; | |
2088 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2089 return retval; | |
2090 #endif | |
2091 } | |
2092 | |
2093 DEFUN_DLD (__player_get_channels__, args, , | |
2094 "-*- texinfo -*-\n\ | |
2095 @deftypefn {Loadable Function} {@var{n} =} __player_get_channels__ (@var{player})\n\ | |
2096 Undocumented internal function.\n\ | |
2097 @end deftypefn") | |
2098 { | |
2099 octave_value retval; | |
2100 #ifdef HAVE_PORTAUDIO | |
2101 int nargin = args.length (); | |
2102 if (nargin == 1) | |
2103 { | |
2104 const octave_base_value& rep = args(0).get_rep (); | |
2105 audioplayer *player = &((audioplayer &)rep); | |
2106 retval = octave_value (player->get_channels ()); | |
2107 } | |
2108 #else | |
2109 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2110 #endif | |
2111 return retval; | |
2112 } | |
2113 | |
2114 DEFUN_DLD (__player_get_fs__, args, , | |
2115 "-*- texinfo -*-\n\ | |
2116 @deftypefn {Loadable Function} {@var{fs} =} __player_get_fs__ (@var{player})\n\ | |
2117 Undocumented internal function.\n\ | |
2118 @end deftypefn") | |
2119 { | |
2120 octave_value retval; | |
2121 #ifdef HAVE_PORTAUDIO | |
2122 int nargin = args.length (); | |
2123 if (nargin == 1) | |
2124 { | |
2125 const octave_base_value& rep = args(0).get_rep (); | |
2126 audioplayer *player = &((audioplayer &)rep); | |
2127 retval = octave_value (player->get_fs ()); | |
2128 } | |
2129 #else | |
2130 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2131 #endif | |
2132 return retval; | |
2133 } | |
2134 | |
2135 DEFUN_DLD (__player_get_id__, args, , | |
2136 "-*- texinfo -*-\n\ | |
2137 @deftypefn {Loadable Function} {@var{id} =} __player_get_id__ (@var{player})\n\ | |
2138 Undocumented internal function.\n\ | |
2139 @end deftypefn") | |
2140 { | |
2141 octave_value retval; | |
2142 #ifdef HAVE_PORTAUDIO | |
2143 int nargin = args.length (); | |
2144 if (nargin == 1) | |
2145 { | |
2146 const octave_base_value& rep = args(0).get_rep (); | |
2147 audioplayer *player = &((audioplayer &)rep); | |
2148 retval = octave_value (player->get_id ()); | |
2149 } | |
2150 #else | |
2151 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2152 #endif | |
2153 return retval; | |
2154 } | |
2155 | |
2156 DEFUN_DLD (__player_get_nbits__, args, , | |
2157 "-*- texinfo -*-\n\ | |
2158 @deftypefn {Loadable Function} {@var{nbits} =} __player_get_nbits__ (@var{player})\n\ | |
2159 Undocumented internal function.\n\ | |
2160 @end deftypefn") | |
2161 { | |
2162 octave_value retval; | |
2163 #ifdef HAVE_PORTAUDIO | |
2164 int nargin = args.length (); | |
2165 if (nargin == 1) | |
2166 { | |
2167 const octave_base_value& rep = args(0).get_rep (); | |
2168 audioplayer *player = &((audioplayer &)rep); | |
2169 retval = octave_value (player->get_nbits ()); | |
2170 } | |
2171 #else | |
2172 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2173 #endif | |
2174 return retval; | |
2175 } | |
2176 | |
2177 DEFUN_DLD (__player_get_sample_number__, args, , | |
2178 "-*- texinfo -*-\n\ | |
2179 @deftypefn {Loadable Function} {@var{n} =} __player_get_sample_number__ (@var{player})\n\ | |
2180 Undocumented internal function.\n\ | |
2181 @end deftypefn") | |
2182 { | |
2183 octave_value retval; | |
2184 #ifdef HAVE_PORTAUDIO | |
2185 int nargin = args.length (); | |
2186 if (nargin == 1) | |
2187 { | |
2188 const octave_base_value& rep = args(0).get_rep (); | |
2189 audioplayer *player = &((audioplayer &)rep); | |
2190 retval = octave_value (player->get_sample_number ()); | |
2191 } | |
2192 #else | |
2193 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2194 #endif | |
2195 return retval; | |
2196 } | |
2197 | |
2198 DEFUN_DLD (__player_get_tag__, args, , | |
2199 "-*- texinfo -*-\n\ | |
2200 @deftypefn {Loadable Function} {@var{tag} =} __player_get_tag__ (@var{player})\n\ | |
2201 Undocumented internal function.\n\ | |
2202 @end deftypefn") | |
2203 { | |
2204 octave_value retval; | |
2205 #ifdef HAVE_PORTAUDIO | |
2206 int nargin = args.length (); | |
2207 if (nargin == 1) | |
2208 { | |
2209 const octave_base_value& rep = args(0).get_rep (); | |
2210 audioplayer *player = &((audioplayer &)rep); | |
2211 retval = octave_value (player->get_tag ()); | |
2212 } | |
2213 #else | |
2214 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2215 #endif | |
2216 return retval; | |
2217 } | |
2218 | |
2219 DEFUN_DLD (__player_get_total_samples__, args, , | |
2220 "-*- texinfo -*-\n\ | |
2221 @deftypefn {Loadable Function} {@var{n} =} __player_get_total_samples__ (@var{player})\n\ | |
2222 Undocumented internal function.\n\ | |
2223 @end deftypefn") | |
2224 { | |
2225 octave_value retval; | |
2226 #ifdef HAVE_PORTAUDIO | |
2227 int nargin = args.length (); | |
2228 if (nargin == 1) | |
2229 { | |
2230 const octave_base_value& rep = args(0).get_rep (); | |
2231 audioplayer *player = &((audioplayer &)rep); | |
2232 retval = octave_value (player->get_total_samples ()); | |
2233 } | |
2234 #else | |
2235 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2236 #endif | |
2237 return retval; | |
2238 } | |
2239 | |
2240 DEFUN_DLD (__player_get_userdata__, args, , | |
2241 "-*- texinfo -*-\n\ | |
2242 @deftypefn {Loadable Function} {@var{data} =} __player_get_userdata__ (@var{player})\n\ | |
2243 Undocumented internal function.\n\ | |
2244 @end deftypefn") | |
2245 { | |
2246 octave_value retval; | |
2247 #ifdef HAVE_PORTAUDIO | |
2248 int nargin = args.length (); | |
2249 if (nargin == 1) | |
2250 { | |
2251 const octave_base_value& rep = args(0).get_rep (); | |
2252 audioplayer *player = &((audioplayer &)rep); | |
2253 retval = player->get_userdata (); | |
2254 } | |
2255 #else | |
2256 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2257 #endif | |
2258 return retval; | |
2259 } | |
2260 | |
2261 DEFUN_DLD (__player_isplaying__, args, , | |
2262 "-*- texinfo -*-\n\ | |
2263 @deftypefn {Loadable Function} {} __player_isplaying__ (@var{player})\n\ | |
2264 Undocumented internal function.\n\ | |
2265 @end deftypefn") | |
2266 { | |
2267 octave_value retval; | |
2268 #ifdef HAVE_PORTAUDIO | |
2269 int nargin = args.length (); | |
2270 if (nargin == 1) | |
2271 { | |
2272 const octave_base_value& rep = args(0).get_rep (); | |
2273 audioplayer *player = &((audioplayer &)rep); | |
2274 if (player->isplaying ()) | |
2275 return octave_value (1); | |
2276 else | |
2277 return octave_value (0); | |
2278 } | |
2279 #else | |
2280 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2281 #endif | |
2282 return retval; | |
2283 } | |
2284 | |
2285 DEFUN_DLD (__player_pause__, args, , | |
2286 "-*- texinfo -*-\n\ | |
2287 @deftypefn {Loadable Function} {} __player_pause__ (@var{player})\n\ | |
2288 Undocumented internal function.\n\ | |
2289 @end deftypefn") | |
2290 { | |
2291 octave_value retval; | |
2292 #ifdef HAVE_PORTAUDIO | |
2293 int nargin = args.length (); | |
2294 if (nargin == 1) | |
2295 { | |
2296 const octave_base_value& rep = args(0).get_rep (); | |
2297 audioplayer *player = &((audioplayer &)rep); | |
2298 player->pause (); | |
2299 } | |
2300 #else | |
2301 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2302 #endif | |
2303 return retval; | |
2304 } | |
2305 | |
2306 DEFUN_DLD (__player_playblocking__, args, , | |
2307 "-*- texinfo -*-\n\ | |
2308 @deftypefn {Loadable Function} {} __player_playblocking__ (@var{player})\n\ | |
2309 @deftypefnx {Loadable Function} {} __player_playblocking__ (@var{player}, @var{start})\n\ | |
2310 @deftypefnx {Loadable Function} {} __player_playblocking__ (@var{player}, [@var{start}, @var{end}])\n\ | |
2311 Undocumented internal function.\n\ | |
2312 @end deftypefn") | |
2313 { | |
2314 octave_value retval; | |
2315 #ifdef HAVE_PORTAUDIO | |
2316 int nargin = args.length (); | |
2317 if (nargin == 1) | |
2318 { | |
2319 const octave_base_value& rep = args(0).get_rep (); | |
2320 audioplayer *player = &((audioplayer &)rep); | |
2321 player->playblocking (); | |
2322 } | |
2323 else | |
2324 { | |
2325 const octave_base_value& rep = args(0).get_rep (); | |
2326 audioplayer *player = &((audioplayer &)rep); | |
2327 if (args(1).is_matrix_type ()) | |
2328 { | |
2329 unsigned int start, end; | |
2330 RowVector range = args(1).row_vector_value (); | |
2331 start = range.elem (0) - 1; | |
2332 end = range.elem (1) - 1; | |
2333 if (start < 0 or start > player->get_total_samples () or | |
2334 start > end or end < 0 or end > player->get_total_samples ()) | |
2335 error ("audioplayer: invalid range specified for playback"); | |
2336 player->set_sample_number (start); | |
2337 player->set_end_sample (end); | |
2338 } | |
2339 else | |
2340 { | |
2341 unsigned int start; | |
2342 start = args(1).int_value () - 1; | |
2343 if (start < 0 or start > player->get_total_samples ()) | |
2344 error ("audioplayer: invalid range specified for playback"); | |
2345 player->set_sample_number (start); | |
2346 } | |
2347 player->playblocking (); | |
2348 } | |
2349 #else | |
2350 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2351 #endif | |
2352 return retval; | |
2353 } | |
2354 | |
2355 DEFUN_DLD (__player_play__, args, , | |
2356 "-*- texinfo -*-\n\ | |
2357 @deftypefn {Loadable Function} {} __player_play__ (@var{player})\n\ | |
2358 @deftypefnx {Loadable Function} {} __player_play__ (@var{player}, @var{start})\n\ | |
2359 @deftypefnx {Loadable Function} {} __player_play__ (@var{player}, [@var{start}, @var{end}])\n\ | |
2360 Undocumented internal function.\n\ | |
2361 @end deftypefn") | |
2362 { | |
2363 octave_value retval; | |
2364 #ifdef HAVE_PORTAUDIO | |
2365 int nargin = args.length (); | |
2366 if (nargin == 1) | |
2367 { | |
2368 const octave_base_value& rep = args(0).get_rep (); | |
2369 audioplayer *player = &((audioplayer &)rep); | |
2370 player->play (); | |
2371 } | |
2372 else | |
2373 { | |
2374 const octave_base_value& rep = args(0).get_rep (); | |
2375 audioplayer *player = &((audioplayer &)rep); | |
2376 if (args(1).is_matrix_type ()) | |
2377 { | |
2378 unsigned int start, end; | |
2379 RowVector range = args(1).row_vector_value (); | |
2380 start = range.elem (0) - 1; | |
2381 end = range.elem (1) - 1; | |
2382 if (start < 0 or start > player->get_total_samples () or | |
2383 start > end or end < 0 or end > player->get_total_samples ()) | |
2384 error ("audioplayer: invalid range specified for playback"); | |
2385 player->set_sample_number (start); | |
2386 player->set_end_sample (end); | |
2387 } | |
2388 else | |
2389 { | |
2390 unsigned int start; | |
2391 start = args(1).int_value () - 1; | |
2392 if (start < 0 or start > player->get_total_samples ()) | |
2393 error ("audioplayer: invalid range specified for playback"); | |
2394 player->set_sample_number (start); | |
2395 } | |
2396 player->play (); | |
2397 } | |
2398 #else | |
2399 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2400 #endif | |
2401 return retval; | |
2402 } | |
2403 | |
2404 DEFUN_DLD (__player_resume__, args, , | |
2405 "-*- texinfo -*-\n\ | |
2406 @deftypefn {Loadable Function} {} __player_resume__ (@var{player})\n\ | |
2407 Undocumented internal function.\n\ | |
2408 @end deftypefn") | |
2409 { | |
2410 octave_value retval; | |
2411 #ifdef HAVE_PORTAUDIO | |
2412 int nargin = args.length (); | |
2413 if (nargin == 1) | |
2414 { | |
2415 const octave_base_value& rep = args(0).get_rep (); | |
2416 audioplayer *player = &((audioplayer &)rep); | |
2417 player->resume (); | |
2418 } | |
2419 #else | |
2420 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2421 #endif | |
2422 return retval; | |
2423 } | |
2424 | |
2425 DEFUN_DLD (__player_set_fs__, args, , | |
2426 "-*- texinfo -*-\n\ | |
2427 @deftypefn {Loadable Function} {} __player_set_fs__ (@var{player}, @var{fs})\n\ | |
2428 Undocumented internal function.\n\ | |
2429 @end deftypefn") | |
2430 { | |
2431 octave_value retval; | |
2432 #ifdef HAVE_PORTAUDIO | |
2433 int nargin = args.length (); | |
2434 if (nargin == 2) | |
2435 { | |
2436 const octave_base_value& rep = args(0).get_rep (); | |
2437 audioplayer *player = &((audioplayer &)rep); | |
2438 player->set_fs (args(1).int_value ()); | |
2439 } | |
2440 #else | |
2441 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2442 #endif | |
2443 return retval; | |
2444 } | |
2445 | |
2446 DEFUN_DLD (__player_set_tag__, args, , | |
2447 "-*- texinfo -*-\n\ | |
2448 @deftypefn {Loadable Function} {} __player_set_tag__ (@var{player}, @var{tag})\n\ | |
2449 Undocumented internal function.\n\ | |
2450 @end deftypefn") | |
2451 { | |
2452 octave_value retval; | |
2453 #ifdef HAVE_PORTAUDIO | |
2454 int nargin = args.length (); | |
2455 if (nargin == 2) | |
2456 { | |
2457 const octave_base_value& rep = args(0).get_rep (); | |
2458 audioplayer *player = &((audioplayer &)rep); | |
2459 player->set_tag (args(1).char_matrix_value ()); | |
2460 } | |
2461 #else | |
2462 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2463 #endif | |
2464 return retval; | |
2465 } | |
2466 | |
2467 DEFUN_DLD (__player_set_userdata__, args, , | |
2468 "-*- texinfo -*-\n\ | |
2469 @deftypefn {Loadable Function} {} __player_set_userdata__ (@var{player}, @var{data})\n\ | |
2470 Undocumented internal function.\n\ | |
2471 @end deftypefn") | |
2472 { | |
2473 octave_value retval; | |
2474 #ifdef HAVE_PORTAUDIO | |
2475 int nargin = args.length (); | |
2476 if (nargin == 2) | |
2477 { | |
2478 const octave_base_value& rep = args(0).get_rep (); | |
2479 audioplayer *player = &((audioplayer &)rep); | |
2480 player->set_userdata (args(1)); | |
2481 } | |
2482 #else | |
2483 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2484 #endif | |
2485 return retval; | |
2486 } | |
2487 | |
2488 DEFUN_DLD (__player_stop__, args, , | |
2489 "-*- texinfo -*-\n\ | |
2490 @deftypefn {Loadable Function} {} __player_stop__ (@var{player})\n\ | |
2491 Undocumented internal function.\n\ | |
2492 @end deftypefn") | |
2493 { | |
2494 octave_value retval; | |
2495 #ifdef HAVE_PORTAUDIO | |
2496 int nargin = args.length (); | |
2497 if (nargin == 1) | |
2498 { | |
2499 const octave_base_value& rep = args(0).get_rep (); | |
2500 audioplayer *player = &((audioplayer &)rep); | |
2501 player->stop (); | |
2502 } | |
2503 #else | |
2504 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2505 #endif | |
2506 return retval; | |
2507 } |