Mercurial > octave
annotate libinterp/dldfcn/audiodevinfo.cc @ 19511:19f75d156ffe
don't include oct.h in Octave source files
* audiodevinfo.cc, audioread.cc: Don't include oct.h.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 02 Jan 2015 00:47:25 -0500 |
parents | 99522db5b911 |
children | a5eb03a7e2a5 |
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; } | |
440 virtual double scalar_value (bool frc_str_conv = false) const { return 0; } | |
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 | |
522 octave_play_callback (const void *input, void *output, | |
523 unsigned long frames, | |
524 const PaStreamCallbackTimeInfo *time, | |
525 PaStreamCallbackFlags status, | |
526 void *data) | |
527 { | |
528 audioplayer *player = (audioplayer *)data; | |
529 int big_endian = is_big_endian (); | |
530 octave_value_list args, retval; | |
531 args(0) = frames; | |
532 retval = feval (player->octave_callback_function, args, 1); | |
533 RowVector sound_l, sound_r; | |
534 Matrix sound = retval(0).matrix_value (); | |
535 int return_status = retval(1).int_value (); | |
536 sound_l.resize (frames); | |
537 sound_r.resize (frames); | |
538 if (sound.cols () == 1) | |
539 { | |
540 for (int i = 0; i < frames; i++) | |
541 { | |
542 sound_l(i) = sound(i, 0); | |
543 sound_r(i) = sound(i, 0); | |
544 } | |
545 } | |
546 else if (sound.cols () == 2) | |
547 { | |
548 for (int i = 0; i < frames; i++) | |
549 { | |
550 sound_l(i) = sound(i, 0); | |
551 sound_r(i) = sound(i, 1); | |
552 } | |
553 } | |
554 else | |
555 return paAbort; | |
556 | |
557 for (int i = 0; i < frames; i++) | |
558 { | |
559 if (player->get_nbits () == 8) | |
560 { | |
561 int8_t *buffer = (int8_t *)output; | |
562 buffer[2 * i] = sound_l.elem (i) * (pow (2.0, 7) - 1); | |
563 buffer[2 * i + 1] = sound_r.elem (i) * (pow (2.0, 7) - 1); | |
564 } | |
565 else if (player->get_nbits () == 16) | |
566 { | |
567 int16_t *buffer = (int16_t *)output; | |
568 buffer[2 * i] = sound_l.elem (i) * (pow (2.0, 15) - 1); | |
569 buffer[2 * i + 1] = sound_r.elem (i) * (pow (2.0, 15) - 1); | |
570 } | |
571 else if (player->get_nbits () == 24) | |
572 { | |
573 uint8_t *buffer = (uint8_t *)output; | |
574 int32_t sample_l = sound_l.elem (i) * (pow (2.0, 23) - 1); | |
575 int32_t sample_r = sound_r.elem (i) * (pow (2.0, 23) - 1); | |
576 sample_l &= 0x00ffffff; | |
577 sample_r &= 0x00ffffff; | |
578 uint8_t *_sample_l = (uint8_t *)&sample_l; | |
579 uint8_t *_sample_r = (uint8_t *)&sample_r; | |
580 buffer[i * 6 + 0] = _sample_l[0 + big_endian]; | |
581 buffer[i * 6 + 1] = _sample_l[1 + big_endian]; | |
582 buffer[i * 6 + 2] = _sample_l[2 + big_endian]; | |
583 buffer[i * 6 + 3] = _sample_r[0 + big_endian]; | |
584 buffer[i * 6 + 4] = _sample_r[1 + big_endian]; | |
585 buffer[i * 6 + 5] = _sample_r[2 + big_endian]; | |
586 } | |
587 } | |
588 return return_status; | |
589 } | |
590 | |
591 static int | |
592 portaudio_play_callback (const void *input, void *output, | |
593 unsigned long frames, | |
594 const PaStreamCallbackTimeInfo* time, | |
595 PaStreamCallbackFlags status, | |
596 void *data) | |
597 { | |
598 audioplayer *player = (audioplayer *)data; | |
599 int big_endian = is_big_endian (); | |
600 int channels = player->get_channels (); | |
601 RowVector *sound_l = player->get_left (); | |
602 RowVector *sound_r; | |
603 | |
604 if (channels > 1) | |
605 sound_r = player->get_right (); | |
606 else | |
607 sound_r = sound_l; | |
608 | |
609 for (int j = 0, k = 0; j < frames; j++, k += 2) | |
610 { | |
611 unsigned int sample_number = player->get_sample_number (); | |
612 if (sample_number > player->get_end_sample ()) | |
613 return paAbort; | |
614 | |
615 if (player->get_type () == DOUBLE) | |
616 { | |
617 if (player->get_nbits () == 8) | |
618 { | |
619 int8_t *buffer = (int8_t *)output; | |
620 buffer[k] = sound_l->elem (sample_number) * (pow (2.0, 7) - 1); | |
621 buffer[k + 1] = sound_r->elem (sample_number) * (pow (2.0, 7) - 1); | |
622 } | |
623 else if (player->get_nbits () == 16) | |
624 { | |
625 int16_t *buffer = (int16_t *)output; | |
626 buffer[k] = sound_l->elem (sample_number) * (pow (2.0, 15) - 1); | |
627 buffer[k + 1] = sound_r->elem (sample_number) * (pow (2.0, 15) - 1); | |
628 } | |
629 else if (player->get_nbits () == 24) | |
630 { | |
631 uint8_t *buffer = (uint8_t *)output; | |
632 int32_t sample_l = sound_l->elem (sample_number) * (pow (2.0, 23) - 1); | |
633 int32_t sample_r = sound_r->elem (sample_number) * (pow (2.0, 23) - 1); | |
634 sample_l &= 0x00ffffff; | |
635 sample_r &= 0x00ffffff; | |
636 uint8_t *_sample_l = (uint8_t *)&sample_l; | |
637 uint8_t *_sample_r = (uint8_t *)&sample_r; | |
638 buffer[j * 6 + 0] = _sample_l[0 + big_endian]; | |
639 buffer[j * 6 + 1] = _sample_l[1 + big_endian]; | |
640 buffer[j * 6 + 2] = _sample_l[2 + big_endian]; | |
641 buffer[j * 6 + 3] = _sample_r[0 + big_endian]; | |
642 buffer[j * 6 + 4] = _sample_r[1 + big_endian]; | |
643 buffer[j * 6 + 5] = _sample_r[2 + big_endian]; | |
644 } | |
645 } | |
646 else if (player->get_type () == INT8) | |
647 { | |
648 int8_t *buffer = (int8_t *)output; | |
649 buffer[k] = sound_l->elem (sample_number); | |
650 buffer[k + 1] = sound_r->elem (sample_number); | |
651 } | |
652 else if (player->get_type () == UINT8) | |
653 { | |
654 uint8_t *buffer = (uint8_t *)output; | |
655 buffer[k] = sound_l->elem (sample_number); | |
656 buffer[k + 1] = sound_r->elem (sample_number); | |
657 } | |
658 else if (player->get_type () == INT16) | |
659 { | |
660 int16_t *buffer = (int16_t *)output; | |
661 buffer[k] = sound_l->elem (sample_number); | |
662 buffer[k + 1] = sound_r->elem (sample_number); | |
663 } | |
664 player->set_sample_number (sample_number + 1); | |
665 } | |
666 return paContinue; | |
667 } | |
668 | |
669 audioplayer::audioplayer (void) | |
670 { | |
671 this->nbits = 16; | |
672 this->id = -1; | |
673 this->sample_number = 0; | |
674 this->tag = charMatrix (""); | |
675 Matrix userdata; | |
676 this->userdata = octave_value (userdata); | |
677 this->stream = 0; | |
678 this->octave_callback_function = 0; | |
679 } | |
680 | |
681 void | |
682 audioplayer::print (std::ostream& os, bool pr_as_read_syntax) const | |
683 { | |
684 print_raw (os, pr_as_read_syntax); | |
685 newline (os); | |
686 } | |
687 | |
688 void | |
689 audioplayer::print_raw (std::ostream& os, bool pr_as_read_syntax) const | |
690 { | |
691 os << 0; | |
692 } | |
693 | |
694 void | |
695 audioplayer::init_fn (void) | |
696 { | |
697 PaError err; | |
698 int device; | |
699 | |
700 err = Pa_Initialize (); | |
701 if (err != paNoError) | |
702 { | |
703 error ("audioplayer: Initialization error!"); | |
704 return; | |
705 } | |
706 | |
707 int numDevices = Pa_GetDeviceCount (); | |
708 if (numDevices < 0) | |
709 { | |
710 error ("audioplayer: No audio devices found!"); | |
711 return; | |
712 } | |
713 | |
714 if (this->get_id () == -1) | |
715 device = Pa_GetDefaultOutputDevice (); | |
716 else | |
717 device = this->get_id (); | |
718 | |
719 output_parameters.device = device; | |
720 output_parameters.channelCount = 2; | |
721 output_parameters.sampleFormat = bits_to_format (this->get_nbits ()); | |
722 output_parameters.suggestedLatency = Pa_GetDeviceInfo (device)->defaultHighOutputLatency; | |
723 output_parameters.hostApiSpecificStreamInfo = NULL; | |
724 } | |
725 | |
726 void | |
727 audioplayer::init (void) | |
728 { | |
729 PaError err; | |
730 int channels = this->y.rows (); | |
731 RowVector *sound_l = this->get_left (); | |
732 int device; | |
733 | |
734 err = Pa_Initialize (); | |
735 if (err != paNoError) | |
736 { | |
737 error ("audioplayer: Initialization error!"); | |
738 return; | |
739 } | |
740 | |
741 int numDevices = Pa_GetDeviceCount (); | |
742 if (numDevices < 0) | |
743 { | |
744 error ("audioplayer: No audio devices found!"); | |
745 return; | |
746 } | |
747 | |
748 if (this->get_id () == -1) | |
749 device = Pa_GetDefaultOutputDevice (); | |
750 else | |
751 device = this->get_id (); | |
752 | |
753 output_parameters.device = device; | |
754 output_parameters.channelCount = 2; | |
755 | |
756 if (this->type == DOUBLE) | |
757 output_parameters.sampleFormat = bits_to_format (this->get_nbits ()); | |
758 else if (this->type == INT8) | |
759 output_parameters.sampleFormat = paInt8; | |
760 else if (this->type == UINT8) | |
761 output_parameters.sampleFormat = paUInt8; | |
762 else if (this->type == INT16) | |
763 output_parameters.sampleFormat = paInt16; | |
764 | |
765 output_parameters.suggestedLatency = Pa_GetDeviceInfo (device)->defaultHighOutputLatency; | |
766 output_parameters.hostApiSpecificStreamInfo = NULL; | |
767 } | |
768 | |
769 void | |
770 audioplayer::set_y (octave_value y) | |
771 { | |
772 if (y.is_int8_type ()) | |
773 this->type = INT8; | |
774 else if (y.is_uint8_type ()) | |
775 this->type = UINT8; | |
776 else if (y.is_int16_type ()) | |
777 this->type = INT16; | |
778 else | |
779 this->type = DOUBLE; | |
780 | |
781 this->y = y.matrix_value (); | |
782 if (this->y.rows () > 2) | |
783 this->y = this->y.transpose (); | |
784 | |
785 this->channels = this->y.rows (); | |
786 this->left = this->y.row (0); | |
787 if (this->channels == 2) | |
788 this->right = this->y.row (1); | |
789 | |
790 this->reset_end_sample (); | |
791 } | |
792 | |
793 void | |
794 audioplayer::set_y (octave_function *fn) | |
795 { | |
796 this->octave_callback_function = fn; | |
797 this->channels = 2; | |
798 this->reset_end_sample (); | |
799 } | |
800 | |
801 Matrix& | |
802 audioplayer::get_y (void) | |
803 { | |
804 return this->y; | |
805 } | |
806 | |
807 RowVector * | |
808 audioplayer::get_left (void) | |
809 { | |
810 return &(this->left); | |
811 } | |
812 | |
813 RowVector * | |
814 audioplayer::get_right (void) | |
815 { | |
816 return &(this->right); | |
817 } | |
818 | |
819 void | |
820 audioplayer::set_fs (int fs) | |
821 { | |
822 this->fs = fs; | |
823 } | |
824 | |
825 int | |
826 audioplayer::get_fs (void) | |
827 { | |
828 return this->fs; | |
829 } | |
830 | |
831 void | |
832 audioplayer::set_nbits (int nbits) | |
833 { | |
834 this->nbits = nbits; | |
835 } | |
836 | |
837 int | |
838 audioplayer::get_nbits (void) | |
839 { | |
840 return this->nbits; | |
841 } | |
842 | |
843 void | |
844 audioplayer::set_id (int id) | |
845 { | |
846 this->id = id; | |
847 } | |
848 | |
849 int | |
850 audioplayer::get_id (void) | |
851 { | |
852 return this->id; | |
853 } | |
854 | |
855 int | |
856 audioplayer::get_channels (void) | |
857 { | |
858 return this->channels; | |
859 } | |
860 | |
861 audio_type | |
862 audioplayer::get_type (void) | |
863 { | |
864 return this->type; | |
865 } | |
866 | |
867 void | |
868 audioplayer::set_sample_number (unsigned int sample_number) | |
869 { | |
870 this->sample_number = sample_number; | |
871 } | |
872 | |
873 unsigned int | |
874 audioplayer::get_sample_number (void) | |
875 { | |
876 return this->sample_number; | |
877 } | |
878 | |
879 unsigned int | |
880 audioplayer::get_total_samples (void) | |
881 { | |
882 return this->left.length (); | |
883 } | |
884 | |
885 void | |
886 audioplayer::set_end_sample (unsigned int end_sample) | |
887 { | |
888 this->end_sample = end_sample; | |
889 } | |
890 | |
891 unsigned int | |
892 audioplayer::get_end_sample (void) | |
893 { | |
894 return this->end_sample; | |
895 } | |
896 | |
897 void | |
898 audioplayer::reset_end_sample (void) | |
899 { | |
900 this->set_end_sample (this->left.length ()); | |
901 } | |
902 | |
903 void | |
904 audioplayer::set_tag (charMatrix tag) | |
905 { | |
906 this->tag = tag; | |
907 } | |
908 | |
909 charMatrix | |
910 audioplayer::get_tag (void) | |
911 { | |
912 return this->tag; | |
913 } | |
914 | |
915 void | |
916 audioplayer::set_userdata (octave_value userdata) | |
917 { | |
918 this->userdata = userdata; | |
919 } | |
920 | |
921 octave_value | |
922 audioplayer::get_userdata (void) | |
923 { | |
924 return this->userdata; | |
925 } | |
926 | |
927 void | |
928 audioplayer::playblocking (void) | |
929 { | |
930 if (this->get_stream ()) | |
931 this->stop (); | |
932 | |
933 PaError err; | |
934 uint32_t buffer[BUFFER_SIZE * 2]; | |
935 err = Pa_OpenStream (&stream, NULL, &(this->output_parameters), this->get_fs (), BUFFER_SIZE, paClipOff, NULL, NULL); | |
936 if (err != paNoError) | |
937 { | |
938 error ("audioplayer: Error opening audio playback stream"); | |
939 return; | |
940 } | |
941 | |
942 err = Pa_StartStream (stream); | |
943 if (err != paNoError) | |
944 { | |
945 error ("audioplayer: Error starting audio playback stream"); | |
946 return; | |
947 } | |
948 | |
949 unsigned int start, end; | |
950 start = this->get_sample_number (); | |
951 end = this->get_end_sample (); | |
952 for (int i = start; i < end; i += BUFFER_SIZE) | |
953 { | |
954 if (this->octave_callback_function != 0) | |
955 octave_play_callback (0, (void *)buffer, BUFFER_SIZE, 0, 0, (void *)this); | |
956 else | |
957 portaudio_play_callback (0, (void *)buffer, BUFFER_SIZE, 0, 0, (void *)this); | |
958 err = Pa_WriteStream (stream, buffer, BUFFER_SIZE); | |
959 } | |
960 | |
961 err = Pa_StopStream (stream); | |
962 if (err != paNoError) | |
963 { | |
964 error ("audioplayer: Error stoping audio playback stream"); | |
965 return; | |
966 } | |
967 | |
968 err = Pa_CloseStream (stream); | |
969 if (err != paNoError) | |
970 { | |
971 error ("audioplayer: Error closing audio playback stream"); | |
972 return; | |
973 } | |
974 | |
975 stream = 0; | |
976 this->set_sample_number (0); | |
977 this->reset_end_sample (); | |
978 } | |
979 | |
980 void | |
981 audioplayer::play (void) | |
982 { | |
983 if (this->get_stream ()) | |
984 this->stop (); | |
985 | |
986 PaError err; | |
987 if (this->octave_callback_function != 0) | |
988 err = Pa_OpenStream (&stream, NULL, &(this->output_parameters), this->get_fs (), BUFFER_SIZE, paClipOff, octave_play_callback, (void *)this); | |
989 else | |
990 err = Pa_OpenStream (&stream, NULL, &(this->output_parameters), this->get_fs (), BUFFER_SIZE, paClipOff, portaudio_play_callback, (void *)this); | |
991 | |
992 if (err != paNoError) | |
993 { | |
994 error ("audioplayer: Error opening audio playback stream"); | |
995 return; | |
996 } | |
997 | |
998 err = Pa_StartStream (stream); | |
999 if (err != paNoError) | |
1000 { | |
1001 error ("audioplayer: Error starting audio playback stream"); | |
1002 return; | |
1003 } | |
1004 } | |
1005 | |
1006 void | |
1007 audioplayer::pause (void) | |
1008 { | |
1009 if (this->get_stream () == 0) | |
1010 return; | |
1011 | |
1012 PaError err; | |
1013 err = Pa_StopStream (stream); | |
1014 if (err != paNoError) | |
1015 { | |
1016 error ("audiorecorder: Error stoping audio recording stream"); | |
1017 return; | |
1018 } | |
1019 } | |
1020 | |
1021 void | |
1022 audioplayer::resume (void) | |
1023 { | |
1024 if (this->get_stream () == 0) | |
1025 return; | |
1026 | |
1027 PaError err; | |
1028 err = Pa_StartStream (stream); | |
1029 if (err != paNoError) | |
1030 { | |
1031 error ("audiorecorder: Error starting audio recording stream"); | |
1032 return; | |
1033 } | |
1034 } | |
1035 | |
1036 PaStream * | |
1037 audioplayer::get_stream (void) | |
1038 { | |
1039 return this->stream; | |
1040 } | |
1041 | |
1042 void | |
1043 audioplayer::stop (void) | |
1044 { | |
1045 if (this->get_stream () == 0) | |
1046 return; | |
1047 | |
1048 PaError err; | |
1049 this->set_sample_number (0); | |
1050 this->reset_end_sample (); | |
1051 if (not Pa_IsStreamStopped (this->get_stream ())) | |
1052 { | |
1053 err = Pa_AbortStream (this->get_stream ()); | |
1054 if (err != paNoError) | |
1055 { | |
1056 error ("audioplayer: Error stopping audio playback stream"); | |
1057 return; | |
1058 } | |
1059 } | |
1060 | |
1061 err = Pa_CloseStream (this->get_stream ()); | |
1062 if (err != paNoError) | |
1063 { | |
1064 error ("audioplayer: Error closing audio playback stream"); | |
1065 return; | |
1066 } | |
1067 | |
1068 stream = 0; | |
1069 } | |
1070 | |
1071 bool | |
1072 audioplayer::isplaying (void) | |
1073 { | |
1074 if (this->get_stream () == 0) | |
1075 return false; | |
1076 | |
1077 PaError err; | |
1078 err = Pa_IsStreamActive (stream); | |
1079 if (err != 0 and err != 1) | |
1080 { | |
1081 error ("audiorecorder: Error checking stream activity status"); | |
1082 return false; | |
1083 } | |
1084 | |
1085 return (err == 1); | |
1086 } | |
1087 | |
1088 class audiorecorder : public octave_base_value | |
1089 { | |
1090 public: | |
1091 audiorecorder (void); | |
1092 ~audiorecorder (void) {}; | |
1093 | |
1094 // Overloaded base functions | |
1095 double player_value (void) const { return 0; } | |
1096 virtual double scalar_value (bool frc_str_conv = false) const { return 0; } | |
1097 void print (std::ostream& os, bool pr_as_read_syntax = false) const; | |
1098 void print_raw (std::ostream& os, bool pr_as_read_syntax) const; | |
1099 | |
1100 // Properties | |
1101 bool is_constant (void) const { return true; } | |
1102 bool is_defined (void) const { return true; } | |
1103 bool print_as_scalar (void) const { return true; } | |
1104 | |
1105 void init (void); | |
1106 void set_fs (int fs); | |
1107 int get_fs (void); | |
1108 void set_nbits (int nbits); | |
1109 int get_nbits (void); | |
1110 void set_id (int id); | |
1111 int get_id (void); | |
1112 void set_channels (int channels); | |
1113 int get_channels (void); | |
1114 audio_type get_type (void); | |
1115 | |
1116 void set_sample_number (unsigned int sample); | |
1117 unsigned int get_sample_number (void); | |
1118 unsigned int get_total_samples (void); | |
1119 void set_end_sample (unsigned int sample); | |
1120 unsigned int get_end_sample (void); | |
1121 void reset_end_sample (void); | |
1122 void set_tag (charMatrix tag); | |
1123 charMatrix get_tag (void); | |
1124 void set_userdata (octave_value userdata); | |
1125 octave_value get_userdata (void); | |
1126 PaStream *get_stream (void); | |
1127 octave_function *octave_callback_function; | |
1128 | |
1129 octave_value getaudiodata (void); | |
1130 audioplayer *getplayer (void); | |
1131 bool isrecording (void); | |
1132 audioplayer play (void); | |
1133 void record (void); | |
1134 void recordblocking (float seconds); | |
1135 void pause (void); | |
1136 void resume (void); | |
1137 void stop (void); | |
1138 void append (float sample_l, float sample_r); | |
1139 | |
1140 private: | |
1141 Matrix y; | |
1142 std::vector<float> left; | |
1143 std::vector<float> right; | |
1144 charMatrix tag; | |
1145 octave_value userdata; | |
1146 int channels; | |
1147 int fs; | |
1148 int nbits; | |
1149 int id; | |
1150 unsigned int sample_number; | |
1151 unsigned int end_sample; | |
1152 PaStream *stream; | |
1153 PaStreamParameters input_parameters; | |
1154 audio_type type; | |
1155 DECLARE_OCTAVE_ALLOCATOR | |
1156 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA | |
1157 }; | |
1158 | |
1159 DEFINE_OCTAVE_ALLOCATOR (audiorecorder); | |
1160 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (audiorecorder, "audiorecorder", "audiorecorder"); | |
1161 | |
1162 static int | |
1163 octave_record_callback (const void *input, void *output, | |
1164 unsigned long frames, | |
1165 const PaStreamCallbackTimeInfo* time, | |
1166 PaStreamCallbackFlags status, | |
1167 void *data) | |
1168 { | |
1169 audiorecorder *recorder = (audiorecorder *)data; | |
1170 int channels = recorder->get_channels (); | |
1171 float sample_l, sample_r; | |
1172 Matrix sound; | |
1173 sound.resize (frames, 2); | |
1174 if (recorder->get_nbits () == 8) | |
1175 { | |
1176 int8_t *input8 = (int8_t *)input; | |
1177 for (int i = 0; i < frames; i++) | |
1178 { | |
1179 sample_l = input8[i * channels] / (pow (2.0, 7) - 1.0); | |
1180 sample_r = input8[i * channels + (channels - 1)] / (pow (2.0, 7) - 1.0); | |
1181 sound(i, 0) = sample_l; | |
1182 sound(i, 1) = sample_r; | |
1183 } | |
1184 } | |
1185 else if (recorder->get_nbits () == 16) | |
1186 { | |
1187 int16_t *input16 = (int16_t *)input; | |
1188 for (int i = 0; i < frames; i++) | |
1189 { | |
1190 sample_l = input16[i * channels] / (pow (2.0, 15) - 1.0); | |
1191 sample_r = input16[i * channels + (channels - 1)] / (pow (2.0, 15) - 1.0); | |
1192 sound(i, 0) = sample_l; | |
1193 sound(i, 1) = sample_r; | |
1194 } | |
1195 } | |
1196 else if (recorder->get_nbits () == 24) | |
1197 { | |
1198 uint8_t *input24 = (uint8_t *)input; | |
1199 int32_t sample_l32, sample_r32; | |
1200 uint8_t *_sample_l = (uint8_t *)&sample_l; | |
1201 uint8_t *_sample_r = (uint8_t *)&sample_r; | |
1202 for (int i = 0; i < frames; i++) | |
1203 { | |
1204 for (int j = 0; j < 3; j++) | |
1205 { | |
1206 _sample_l[j] = input24[i * channels * 3 + j]; | |
1207 _sample_r[j] = input24[i * channels * 3 + (channels - 1) * 3 + j]; | |
1208 } | |
1209 if (sample_l32 & 0x00800000) | |
1210 sample_l32 |= 0xff000000; | |
1211 if (sample_r32 & 0x00800000) | |
1212 sample_r32 |= 0xff000000; | |
1213 sound(i, 0) = sample_l32 / pow (2.0, 23); | |
1214 sound(i, 1) = sample_r32 / pow (2.0, 23); | |
1215 } | |
1216 } | |
1217 | |
1218 octave_value_list args, retval; | |
1219 args(0) = sound; | |
1220 retval = feval (recorder->octave_callback_function, args, 1); | |
1221 return retval(0).int_value (); | |
1222 } | |
1223 | |
1224 static int | |
1225 portaudio_record_callback (const void *input, void *output, | |
1226 unsigned long frames, | |
1227 const PaStreamCallbackTimeInfo* time, | |
1228 PaStreamCallbackFlags status, | |
1229 void *data) | |
1230 { | |
1231 audiorecorder *recorder = (audiorecorder *)data; | |
1232 int channels = recorder->get_channels (); | |
1233 float sample_l, sample_r; | |
1234 if (recorder->get_nbits () == 8) | |
1235 { | |
1236 int8_t *input8 = (int8_t *)input; | |
1237 for (int i = 0; i < frames; i++) | |
1238 { | |
1239 sample_l = input8[i * channels] / (pow (2.0, 7) - 1.0); | |
1240 sample_r = input8[i * channels + (channels - 1)] / (pow (2.0, 7) - 1.0); | |
1241 recorder->append (sample_l, sample_r); | |
1242 } | |
1243 } | |
1244 else if (recorder->get_nbits () == 16) | |
1245 { | |
1246 int16_t *input16 = (int16_t *)input; | |
1247 for (int i = 0; i < frames; i++) | |
1248 { | |
1249 sample_l = input16[i * channels] / (pow (2.0, 15) - 1.0); | |
1250 sample_r = input16[i * channels + (channels - 1)] / (pow (2.0, 15) - 1.0); | |
1251 recorder->append (sample_l, sample_r); | |
1252 } | |
1253 } | |
1254 else if (recorder->get_nbits () == 24) | |
1255 { | |
1256 uint8_t *input24 = (uint8_t *)input; | |
1257 int32_t sample_l32, sample_r32; | |
1258 uint8_t *_sample_l = (uint8_t *)&sample_l; | |
1259 uint8_t *_sample_r = (uint8_t *)&sample_r; | |
1260 for (int i = 0; i < frames; i++) | |
1261 { | |
1262 for (int j = 0; j < 3; j++) | |
1263 { | |
1264 _sample_l[j] = input24[i * channels * 3 + j]; | |
1265 _sample_r[j] = input24[i * channels * 3 + (channels - 1) * 3 + j]; | |
1266 } | |
1267 if (sample_l32 & 0x00800000) | |
1268 sample_l32 |= 0xff000000; | |
1269 if (sample_r32 & 0x00800000) | |
1270 sample_r32 |= 0xff000000; | |
1271 recorder->append (sample_l32 / pow (2.0, 23), sample_r32 / pow (2.0, 23)); | |
1272 } | |
1273 } | |
1274 | |
1275 if (recorder->get_sample_number () > recorder->get_end_sample ()) | |
1276 return paComplete; | |
1277 | |
1278 return paContinue; | |
1279 } | |
1280 | |
1281 audiorecorder::audiorecorder (void) | |
1282 { | |
1283 this->id = -1; | |
1284 this->sample_number = 0; | |
1285 this->channels = 1; | |
1286 this->tag = charMatrix (""); | |
1287 Matrix userdata; | |
1288 this->userdata = octave_value (userdata); | |
1289 this->stream = 0; | |
1290 this->end_sample = -1; | |
1291 this->set_fs (44100); | |
1292 this->set_nbits (16); | |
1293 this->set_channels (2); | |
1294 this->octave_callback_function = 0; | |
1295 } | |
1296 | |
1297 void | |
1298 audiorecorder::print (std::ostream& os, bool pr_as_read_syntax) const | |
1299 { | |
1300 print_raw (os, pr_as_read_syntax); | |
1301 newline (os); | |
1302 } | |
1303 | |
1304 void | |
1305 audiorecorder::print_raw (std::ostream& os, bool pr_as_read_syntax) const | |
1306 { | |
1307 os << 0; | |
1308 } | |
1309 | |
1310 void | |
1311 audiorecorder::init (void) | |
1312 { | |
1313 PaError err; | |
1314 int device; | |
1315 err = Pa_Initialize (); | |
1316 if (err != paNoError) | |
1317 { | |
1318 error ("audiorecorder: Initialization error!"); | |
1319 return; | |
1320 } | |
1321 | |
1322 int numDevices = Pa_GetDeviceCount (); | |
1323 if (numDevices < 0) | |
1324 { | |
1325 error ("audiorecorder: No audio devices found!"); | |
1326 return; | |
1327 } | |
1328 | |
1329 if (this->get_id () == -1) | |
1330 device = Pa_GetDefaultInputDevice (); | |
1331 else | |
1332 device = this->get_id (); | |
1333 | |
1334 this->input_parameters.device = device; | |
1335 this->input_parameters.channelCount = this->get_channels (); | |
1336 this->input_parameters.sampleFormat = bits_to_format (this->get_nbits ()); | |
1337 this->input_parameters.suggestedLatency = Pa_GetDeviceInfo (device)->defaultHighInputLatency; | |
1338 this->input_parameters.hostApiSpecificStreamInfo = NULL; | |
1339 } | |
1340 | |
1341 void | |
1342 audiorecorder::set_fs (int fs) | |
1343 { | |
1344 this->fs = fs; | |
1345 } | |
1346 | |
1347 int | |
1348 audiorecorder::get_fs (void) | |
1349 { | |
1350 return this->fs; | |
1351 } | |
1352 | |
1353 void | |
1354 audiorecorder::set_nbits (int nbits) | |
1355 { | |
1356 this->nbits = nbits; | |
1357 } | |
1358 | |
1359 int | |
1360 audiorecorder::get_nbits (void) | |
1361 { | |
1362 return this->nbits; | |
1363 } | |
1364 | |
1365 void | |
1366 audiorecorder::set_id (int id) | |
1367 { | |
1368 this->id = id; | |
1369 } | |
1370 | |
1371 int | |
1372 audiorecorder::get_id (void) | |
1373 { | |
1374 return this->id; | |
1375 } | |
1376 | |
1377 void | |
1378 audiorecorder::set_channels (int channels) | |
1379 { | |
1380 assert (channels == 1 or channels == 2); | |
1381 this->channels = channels; | |
1382 } | |
1383 | |
1384 int | |
1385 audiorecorder::get_channels (void) | |
1386 { | |
1387 return this->channels; | |
1388 } | |
1389 | |
1390 audio_type | |
1391 audiorecorder::get_type (void) | |
1392 { | |
1393 return this->type; | |
1394 } | |
1395 | |
1396 void | |
1397 audiorecorder::set_sample_number (unsigned int sample_number) | |
1398 { | |
1399 this->sample_number = sample_number; | |
1400 } | |
1401 | |
1402 unsigned int | |
1403 audiorecorder::get_sample_number (void) | |
1404 { | |
1405 return this->sample_number; | |
1406 } | |
1407 | |
1408 unsigned int | |
1409 audiorecorder::get_total_samples (void) | |
1410 { | |
1411 return this->left.size (); | |
1412 } | |
1413 | |
1414 void | |
1415 audiorecorder::set_end_sample (unsigned int end_sample) | |
1416 { | |
1417 this->end_sample = end_sample; | |
1418 } | |
1419 | |
1420 unsigned int | |
1421 audiorecorder::get_end_sample (void) | |
1422 { | |
1423 return this->end_sample; | |
1424 } | |
1425 | |
1426 void | |
1427 audiorecorder::reset_end_sample (void) | |
1428 { | |
1429 this->set_end_sample (this->left.size ()); | |
1430 } | |
1431 | |
1432 void | |
1433 audiorecorder::set_tag (charMatrix tag) | |
1434 { | |
1435 this->tag = tag; | |
1436 } | |
1437 | |
1438 charMatrix | |
1439 audiorecorder::get_tag (void) | |
1440 { | |
1441 return this->tag; | |
1442 } | |
1443 | |
1444 void | |
1445 audiorecorder::set_userdata (octave_value userdata) | |
1446 { | |
1447 this->userdata = userdata; | |
1448 } | |
1449 | |
1450 octave_value | |
1451 audiorecorder::get_userdata (void) | |
1452 { | |
1453 return this->userdata; | |
1454 } | |
1455 | |
1456 octave_value | |
1457 audiorecorder::getaudiodata (void) | |
1458 { | |
1459 Matrix audio (2, this->left.size ()); | |
1460 for (int i = 0; i < this->left.size (); i++) | |
1461 { | |
1462 audio(0, i) = this->left[i]; | |
1463 audio(1, i) = this->right[i]; | |
1464 } | |
1465 return octave_value (audio); | |
1466 } | |
1467 | |
1468 audioplayer * | |
1469 audiorecorder::getplayer (void) | |
1470 { | |
1471 audioplayer *player = new audioplayer (); | |
1472 player->set_y (this->getaudiodata ()); | |
1473 player->set_fs (this->get_fs ()); | |
1474 player->set_nbits (this->get_nbits ()); | |
1475 player->init (); | |
1476 return player; | |
1477 } | |
1478 | |
1479 bool | |
1480 audiorecorder::isrecording (void) | |
1481 { | |
1482 if (this->get_stream () == 0) | |
1483 return false; | |
1484 | |
1485 PaError err; | |
1486 err = Pa_IsStreamActive (stream); | |
1487 if (err != 0 and err != 1) | |
1488 { | |
1489 error ("audiorecorder: Error checking stream activity status"); | |
1490 return false; | |
1491 } | |
1492 | |
1493 return (err == 1); | |
1494 } | |
1495 | |
1496 void | |
1497 audiorecorder::record (void) | |
1498 { | |
1499 if (this->get_stream ()) | |
1500 this->stop (); | |
1501 | |
1502 this->left.clear (); | |
1503 this->right.clear (); | |
1504 PaError err; | |
1505 if (this->octave_callback_function != 0) | |
1506 { | |
1507 err = Pa_OpenStream (&stream, &(this->input_parameters), NULL, this->get_fs (), BUFFER_SIZE, paClipOff, octave_record_callback, (void *)this); | |
1508 } | |
1509 else | |
1510 { | |
1511 err = Pa_OpenStream (&stream, &(this->input_parameters), NULL, this->get_fs (), BUFFER_SIZE, paClipOff, portaudio_record_callback, (void *)this); | |
1512 } | |
1513 if (err != paNoError) | |
1514 { | |
1515 error ("audiorecorder: Error opening audio recording stream"); | |
1516 return; | |
1517 } | |
1518 err = Pa_StartStream (stream); | |
1519 if (err != paNoError) | |
1520 { | |
1521 error ("audiorecorder: Error starting audio recording stream"); | |
1522 return; | |
1523 } | |
1524 } | |
1525 | |
1526 void | |
1527 audiorecorder::recordblocking (float seconds) | |
1528 { | |
1529 if (this->get_stream ()) | |
1530 this->stop (); | |
1531 | |
1532 this->left.clear (); | |
1533 this->right.clear (); | |
1534 | |
1535 PaError err; | |
1536 err = Pa_OpenStream (&stream, &(this->input_parameters), NULL, this->get_fs (), BUFFER_SIZE, paClipOff, NULL, (void *)this); | |
1537 if (err != paNoError) | |
1538 { | |
1539 error ("audiorecorder: Error opening audio recording stream"); | |
1540 return; | |
1541 } | |
1542 | |
1543 err = Pa_StartStream (stream); | |
1544 if (err != paNoError) | |
1545 { | |
1546 error ("audiorecorder: Error starting audio recording stream"); | |
1547 return; | |
1548 } | |
1549 | |
1550 unsigned int frames = seconds * this->get_fs (); | |
1551 uint8_t buffer[BUFFER_SIZE * 2 * 3]; | |
1552 for (int i = 0; i < frames / BUFFER_SIZE; i++) | |
1553 { | |
1554 Pa_ReadStream (this->get_stream (), (void *)buffer, BUFFER_SIZE); | |
1555 if (this->octave_callback_function != 0) | |
1556 octave_record_callback ((void *)buffer, NULL, BUFFER_SIZE, 0, 0, (void *)this); | |
1557 else | |
1558 portaudio_record_callback ((void *)buffer, NULL, BUFFER_SIZE, 0, 0, (void *)this); | |
1559 } | |
1560 } | |
1561 | |
1562 void | |
1563 audiorecorder::pause (void) | |
1564 { | |
1565 if (this->get_stream () == 0) | |
1566 return; | |
1567 | |
1568 PaError err; | |
1569 err = Pa_StopStream (stream); | |
1570 if (err != paNoError) | |
1571 { | |
1572 error ("audiorecorder: Error stoping audio recording stream"); | |
1573 return; | |
1574 } | |
1575 } | |
1576 | |
1577 void | |
1578 audiorecorder::resume (void) | |
1579 { | |
1580 if (this->get_stream () == 0) | |
1581 return; | |
1582 | |
1583 PaError err; | |
1584 err = Pa_StartStream (stream); | |
1585 if (err != paNoError) | |
1586 { | |
1587 error ("audiorecorder: Error starting audio recording stream"); | |
1588 return; | |
1589 } | |
1590 } | |
1591 | |
1592 void | |
1593 audiorecorder::stop (void) | |
1594 { | |
1595 if (this->get_stream () == 0) | |
1596 return; | |
1597 | |
1598 PaError err; | |
1599 if (not Pa_IsStreamStopped (this->get_stream ())) | |
1600 { | |
1601 err = Pa_AbortStream (this->get_stream ()); | |
1602 if (err != paNoError) | |
1603 { | |
1604 error ("audioplayer: Error stopping audio playback stream"); | |
1605 return; | |
1606 } | |
1607 } | |
1608 | |
1609 err = Pa_CloseStream (stream); | |
1610 if (err != paNoError) | |
1611 { | |
1612 error ("audiorecorder: Error closing audio recording stream"); | |
1613 return; | |
1614 } | |
1615 | |
1616 this->set_sample_number (0); | |
1617 this->reset_end_sample (); | |
1618 stream = 0; | |
1619 } | |
1620 | |
1621 void | |
1622 audiorecorder::append (float sample_l, float sample_r) | |
1623 { | |
1624 this->left.push_back (sample_l); | |
1625 this->right.push_back (sample_r); | |
1626 this->set_sample_number (this->get_sample_number () + 1); | |
1627 } | |
1628 | |
1629 PaStream * | |
1630 audiorecorder::get_stream (void) | |
1631 { | |
1632 return this->stream; | |
1633 } | |
1634 | |
1635 DEFUN_DLD (__recorder_audiorecorder__, args, , | |
1636 "-*- texinfo -*-\n\ | |
1637 @deftypefn {Loadable Function} {@var{recorder} =} __recorder_audiorecorder__ (@var{fs}, @var{nbits}, @var{channels})\n\ | |
1638 @deftypefnx {Loadable Function} {@var{recorder} =} __recorder_audiorecorder__ (@var{fs}, @var{nbits}, @var{channels}, @var{id})\n\ | |
1639 @deftypefnx {Loadable Function} {@var{recorder} =} __recorder_audiorecorder__ (@var{fcn}, @dots{})\n\ | |
1640 Undocumented internal function.\n\ | |
1641 @end deftypefn") | |
1642 { | |
1643 #ifdef HAVE_PORTAUDIO | |
1644 int nargin = args.length (); | |
1645 audiorecorder* retval = new audiorecorder (); | |
1646 int offset = 0; | |
1647 if (nargin > 0) | |
1648 { | |
1649 bool is_function = args(0).is_string () || args(0).is_function_handle () || args(0).is_inline_function (); | |
1650 if (is_function) | |
1651 { | |
1652 retval->octave_callback_function = args(0).function_value (); | |
1653 offset = 1; | |
1654 } | |
1655 } | |
1656 switch (nargin - offset) | |
1657 { | |
1658 case 3: | |
1659 retval->set_fs (args(0 + offset).int_value ()); | |
1660 retval->set_nbits (args(1 + offset).int_value ()); | |
1661 retval->set_channels (args(2 + offset).int_value ()); | |
1662 break; | |
1663 case 4: | |
1664 retval->set_fs (args(0 + offset).int_value ()); | |
1665 retval->set_nbits (args(1 + offset).int_value ()); | |
1666 retval->set_channels (args(2 + offset).int_value ()); | |
1667 retval->set_id (args(3 + offset).int_value ()); | |
1668 break; | |
1669 } | |
1670 retval->init (); | |
1671 return octave_value (retval); | |
1672 #else | |
1673 octave_value retval; | |
1674 error ("portaudio not found on your system and thus audio functionality is not present"); | |
1675 return retval; | |
1676 #endif | |
1677 } | |
1678 | |
1679 DEFUN_DLD (__recorder_getaudiodata__, args, , | |
1680 "-*- texinfo -*-\n\ | |
1681 @deftypefn {Loadable Function} {@var{data}} __recorder_getaudiodata__ (@var{recorder})\n\ | |
1682 Undocumented internal function.\n\ | |
1683 @end deftypefn") | |
1684 { | |
1685 octave_value retval; | |
1686 #ifdef HAVE_PORTAUDIO | |
1687 const octave_base_value& rep = args(0).get_rep (); | |
1688 audiorecorder *recorder = &((audiorecorder &)rep); | |
1689 retval = octave_value (recorder->getaudiodata ()); | |
1690 #else | |
1691 error ("portaudio not found on your system and thus audio functionality is not present"); | |
1692 #endif | |
1693 return retval; | |
1694 } | |
1695 | |
1696 DEFUN_DLD (__recorder_get_channels__, args, , | |
1697 "-*- texinfo -*-\n\ | |
1698 @deftypefn {Loadable Function} {@var{n} =} __recorder_get_channels__ (@var{recorder})\n\ | |
1699 Undocumented internal function.\n\ | |
1700 @end deftypefn") | |
1701 { | |
1702 octave_value retval; | |
1703 #ifdef HAVE_PORTAUDIO | |
1704 int nargin = args.length (); | |
1705 if (nargin == 1) | |
1706 { | |
1707 const octave_base_value& rep = args(0).get_rep (); | |
1708 audiorecorder *recorder = &((audiorecorder &)rep); | |
1709 retval = octave_value (recorder->get_channels ()); | |
1710 } | |
1711 #else | |
1712 error ("portaudio not found on your system and thus audio functionality is not present"); | |
1713 #endif | |
1714 return retval; | |
1715 } | |
1716 | |
1717 DEFUN_DLD (__recorder_get_fs__, args, , | |
1718 "-*- texinfo -*-\n\ | |
1719 @deftypefn {Loadable Function} {@var{fs} =} __recorder_get_fs__ (@var{recorder})\n\ | |
1720 Undocumented internal function.\n\ | |
1721 @end deftypefn") | |
1722 { | |
1723 octave_value retval; | |
1724 #ifdef HAVE_PORTAUDIO | |
1725 int nargin = args.length (); | |
1726 if (nargin == 1) | |
1727 { | |
1728 const octave_base_value& rep = args(0).get_rep (); | |
1729 audiorecorder *recorder = &((audiorecorder &)rep); | |
1730 retval = octave_value (recorder->get_fs ()); | |
1731 } | |
1732 #else | |
1733 error ("portaudio not found on your system and thus audio functionality is not present"); | |
1734 #endif | |
1735 return retval; | |
1736 } | |
1737 | |
1738 DEFUN_DLD (__recorder_get_id__, args, , | |
1739 "-*- texinfo -*-\n\ | |
1740 @deftypefn {Loadable Function} {@var{id} =} __recorder_get_id__ (@var{recorder})\n\ | |
1741 Undocumented internal function.\n\ | |
1742 @end deftypefn") | |
1743 { | |
1744 octave_value retval; | |
1745 #ifdef HAVE_PORTAUDIO | |
1746 int nargin = args.length (); | |
1747 if (nargin == 1) | |
1748 { | |
1749 const octave_base_value& rep = args(0).get_rep (); | |
1750 audiorecorder *recorder = &((audiorecorder &)rep); | |
1751 retval = octave_value (recorder->get_id ()); | |
1752 } | |
1753 #else | |
1754 error ("portaudio not found on your system and thus audio functionality is not present"); | |
1755 #endif | |
1756 return retval; | |
1757 } | |
1758 | |
1759 DEFUN_DLD (__recorder_get_nbits__, args, , | |
1760 "-*- texinfo -*-\n\ | |
1761 @deftypefn {Loadable Function} {@var{nbits} =} __recorder_get_nbits__ (@var{recorder})\n\ | |
1762 Undocumented internal function.\n\ | |
1763 @end deftypefn") | |
1764 { | |
1765 octave_value retval; | |
1766 #ifdef HAVE_PORTAUDIO | |
1767 int nargin = args.length (); | |
1768 if (nargin == 1) | |
1769 { | |
1770 const octave_base_value& rep = args(0).get_rep (); | |
1771 audiorecorder *recorder = &((audiorecorder &)rep); | |
1772 retval = octave_value (recorder->get_nbits ()); | |
1773 } | |
1774 #else | |
1775 error ("portaudio not found on your system and thus audio functionality is not present"); | |
1776 #endif | |
1777 return retval; | |
1778 } | |
1779 | |
1780 DEFUN_DLD (__recorder_get_sample_number__, args, , | |
1781 "-*- texinfo -*-\n\ | |
1782 @deftypefn {Loadable Function} {@var{n} =} __recorder_get_sample_number__ (@var{recorder})\n\ | |
1783 Undocumented internal function.\n\ | |
1784 @end deftypefn") | |
1785 { | |
1786 octave_value retval; | |
1787 #ifdef HAVE_PORTAUDIO | |
1788 int nargin = args.length (); | |
1789 if (nargin == 1) | |
1790 { | |
1791 const octave_base_value& rep = args(0).get_rep (); | |
1792 audiorecorder *recorder = &((audiorecorder &)rep); | |
1793 retval = octave_value (recorder->get_sample_number ()); | |
1794 } | |
1795 #else | |
1796 error ("portaudio not found on your system and thus audio functionality is not present"); | |
1797 #endif | |
1798 return retval; | |
1799 } | |
1800 | |
1801 DEFUN_DLD (__recorder_get_tag__, args, , | |
1802 "-*- texinfo -*-\n\ | |
1803 @deftypefn {Loadable Function} {@var{tag} =} __recorder_get_tag__ (@var{recorder})\n\ | |
1804 Undocumented internal function.\n\ | |
1805 @end deftypefn") | |
1806 { | |
1807 octave_value retval; | |
1808 #ifdef HAVE_PORTAUDIO | |
1809 int nargin = args.length (); | |
1810 if (nargin == 1) | |
1811 { | |
1812 const octave_base_value& rep = args(0).get_rep (); | |
1813 audiorecorder *recorder = &((audiorecorder &)rep); | |
1814 retval = octave_value (recorder->get_tag ()); | |
1815 } | |
1816 #else | |
1817 error ("portaudio not found on your system and thus audio functionality is not present"); | |
1818 #endif | |
1819 return retval; | |
1820 } | |
1821 | |
1822 DEFUN_DLD (__recorder_get_total_samples__, args, , | |
1823 "-*- texinfo -*-\n\ | |
1824 @deftypefn {Loadable Function} {@var{n} =} __recorder_get_total_samples__ (@var{recorder})\n\ | |
1825 Undocumented internal function.\n\ | |
1826 @end deftypefn") | |
1827 { | |
1828 octave_value retval; | |
1829 #ifdef HAVE_PORTAUDIO | |
1830 int nargin = args.length (); | |
1831 if (nargin == 1) | |
1832 { | |
1833 const octave_base_value& rep = args(0).get_rep (); | |
1834 audiorecorder *recorder = &((audiorecorder &)rep); | |
1835 retval = octave_value (recorder->get_total_samples ()); | |
1836 } | |
1837 #else | |
1838 error ("portaudio not found on your system and thus audio functionality is not present"); | |
1839 #endif | |
1840 return retval; | |
1841 } | |
1842 | |
1843 DEFUN_DLD (__recorder_get_userdata__, args, , | |
1844 "-*- texinfo -*-\n\ | |
1845 @deftypefn {Loadable Function} {@var{data} =} __recorder_get_userdata__ (@var{recorder})\n\ | |
1846 Undocumented internal function.\n\ | |
1847 @end deftypefn") | |
1848 { | |
1849 octave_value retval; | |
1850 #ifdef HAVE_PORTAUDIO | |
1851 int nargin = args.length (); | |
1852 if (nargin == 1) | |
1853 { | |
1854 const octave_base_value& rep = args(0).get_rep (); | |
1855 audiorecorder *recorder = &((audiorecorder &)rep); | |
1856 retval = recorder->get_userdata (); | |
1857 } | |
1858 #else | |
1859 error ("portaudio not found on your system and thus audio functionality is not present"); | |
1860 #endif | |
1861 return retval; | |
1862 } | |
1863 | |
1864 DEFUN_DLD (__recorder_isrecording__, args, , | |
1865 "-*- texinfo -*-\n\ | |
1866 @deftypefn {Loadable Function} {} __recorder_isrecording__ (@var{recorder})\n\ | |
1867 Undocumented internal function.\n\ | |
1868 @end deftypefn") | |
1869 { | |
1870 octave_value retval; | |
1871 #ifdef HAVE_PORTAUDIO | |
1872 int nargin = args.length (); | |
1873 if (nargin == 1) | |
1874 { | |
1875 const octave_base_value& rep = args(0).get_rep (); | |
1876 audiorecorder *recorder = &((audiorecorder &)rep); | |
1877 if (recorder->isrecording ()) | |
1878 return octave_value (1); | |
1879 else | |
1880 return octave_value (0); | |
1881 } | |
1882 #else | |
1883 error ("portaudio not found on your system and thus audio functionality is not present"); | |
1884 #endif | |
1885 return retval; | |
1886 } | |
1887 | |
1888 DEFUN_DLD (__recorder_pause__, args, , | |
1889 "-*- texinfo -*-\n\ | |
1890 @deftypefn {Loadable Function} {} __recorder_pause__ (@var{recorder})\n\ | |
1891 Undocumented internal function.\n\ | |
1892 @end deftypefn") | |
1893 { | |
1894 octave_value retval; | |
1895 #ifdef HAVE_PORTAUDIO | |
1896 int nargin = args.length (); | |
1897 if (nargin == 1) | |
1898 { | |
1899 const octave_base_value& rep = args(0).get_rep (); | |
1900 audiorecorder *recorder = &((audiorecorder &)rep); | |
1901 recorder->pause (); | |
1902 } | |
1903 #else | |
1904 error ("portaudio not found on your system and thus audio functionality is not present"); | |
1905 #endif | |
1906 return retval; | |
1907 } | |
1908 | |
1909 DEFUN_DLD (__recorder_recordblocking__, args, , | |
1910 "-*- texinfo -*-\n\ | |
1911 @deftypefn {Loadable Function} {} __recorder_recordblocking__ (@var{recorder}, @var{seconds})\n\ | |
1912 Undocumented internal function.\n\ | |
1913 @end deftypefn") | |
1914 { | |
1915 octave_value retval; | |
1916 #ifdef HAVE_PORTAUDIO | |
1917 const octave_base_value& rep = args(0).get_rep (); | |
1918 audiorecorder *recorder = &((audiorecorder &)rep); | |
1919 recorder->recordblocking (args(1).float_value ()); | |
1920 #else | |
1921 error ("portaudio not found on your system and thus audio functionality is not present"); | |
1922 #endif | |
1923 return retval; | |
1924 } | |
1925 | |
1926 DEFUN_DLD (__recorder_record__, args, , | |
1927 "-*- texinfo -*-\n\ | |
1928 @deftypefn {Loadable Function} {} __recorder_record__ (@var{recorder})\n\ | |
1929 @deftypefnx {Loadable Function} {} __recorder_record__ (@var{recorder}, @var{seconds})\n\ | |
1930 Undocumented internal function.\n\ | |
1931 @end deftypefn") | |
1932 { | |
1933 octave_value retval; | |
1934 #ifdef HAVE_PORTAUDIO | |
1935 const octave_base_value& rep = args(0).get_rep (); | |
1936 audiorecorder *recorder = &((audiorecorder &)rep); | |
1937 if (args.length () == 1) | |
1938 { | |
1939 recorder->record (); | |
1940 } | |
1941 else if (args.length () == 2) | |
1942 { | |
1943 recorder->set_end_sample (args(1).int_value () * recorder->get_fs ()); | |
1944 recorder->record (); | |
1945 } | |
1946 else | |
1947 { | |
1948 error ("audiorecorder: wrong number of arguments passed to record"); | |
1949 } | |
1950 #else | |
1951 error ("portaudio not found on your system and thus audio functionality is not present"); | |
1952 #endif | |
1953 return retval; | |
1954 } | |
1955 | |
1956 DEFUN_DLD (__recorder_resume__, args, , | |
1957 "-*- texinfo -*-\n\ | |
1958 @deftypefn {Loadable Function} {} __recorder_resume__ (@var{recorder})\n\ | |
1959 Undocumented internal function.\n\ | |
1960 @end deftypefn") | |
1961 { | |
1962 octave_value retval; | |
1963 #ifdef HAVE_PORTAUDIO | |
1964 int nargin = args.length (); | |
1965 if (nargin == 1) | |
1966 { | |
1967 const octave_base_value& rep = args(0).get_rep (); | |
1968 audiorecorder *recorder = &((audiorecorder &)rep); | |
1969 recorder->resume (); | |
1970 } | |
1971 #else | |
1972 error ("portaudio not found on your system and thus audio functionality is not present"); | |
1973 #endif | |
1974 return retval; | |
1975 } | |
1976 | |
1977 DEFUN_DLD (__recorder_set_fs__, args, , | |
1978 "-*- texinfo -*-\n\ | |
1979 @deftypefn {Loadable Function} {} __recorder_set_fs__ (@var{recorder}, @var{fs})\n\ | |
1980 Undocumented internal function.\n\ | |
1981 @end deftypefn") | |
1982 { | |
1983 octave_value retval; | |
1984 #ifdef HAVE_PORTAUDIO | |
1985 int nargin = args.length (); | |
1986 if (nargin == 2) | |
1987 { | |
1988 const octave_base_value& rep = args(0).get_rep (); | |
1989 audiorecorder *recorder = &((audiorecorder &)rep); | |
1990 recorder->set_fs (args(1).int_value ()); | |
1991 } | |
1992 #else | |
1993 error ("portaudio not found on your system and thus audio functionality is not present"); | |
1994 #endif | |
1995 return retval; | |
1996 } | |
1997 | |
1998 DEFUN_DLD (__recorder_set_tag__, args, , | |
1999 "-*- texinfo -*-\n\ | |
2000 @deftypefn {Loadable Function} {} __recorder_set_tag__ (@var{recorder}, @var{tag})\n\ | |
2001 Undocumented internal function.\n\ | |
2002 @end deftypefn") | |
2003 { | |
2004 octave_value retval; | |
2005 #ifdef HAVE_PORTAUDIO | |
2006 int nargin = args.length (); | |
2007 if (nargin == 2) | |
2008 { | |
2009 const octave_base_value& rep = args(0).get_rep (); | |
2010 audiorecorder *recorder = &((audiorecorder &)rep); | |
2011 recorder->set_tag (args(1).char_matrix_value ()); | |
2012 } | |
2013 #else | |
2014 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2015 #endif | |
2016 return retval; | |
2017 } | |
2018 | |
2019 DEFUN_DLD (__recorder_set_userdata__, args, , | |
2020 "-*- texinfo -*-\n\ | |
2021 @deftypefn {Loadable Function} {} __recorder_set_userdata__ (@var{recorder}, @var{data})\n\ | |
2022 Undocumented internal function.\n\ | |
2023 @end deftypefn") | |
2024 { | |
2025 octave_value retval; | |
2026 #ifdef HAVE_PORTAUDIO | |
2027 int nargin = args.length (); | |
2028 if (nargin == 2) | |
2029 { | |
2030 const octave_base_value& rep = args(0).get_rep (); | |
2031 audiorecorder *recorder = &((audiorecorder &)rep); | |
2032 recorder->set_userdata (args(1)); | |
2033 } | |
2034 #else | |
2035 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2036 #endif | |
2037 return retval; | |
2038 } | |
2039 | |
2040 DEFUN_DLD (__recorder_stop__, args, , | |
2041 "-*- texinfo -*-\n\ | |
2042 @deftypefn {Loadable Function} {} __recorder_stop__ (@var{recorder})\n\ | |
2043 Undocumented internal function.\n\ | |
2044 @end deftypefn") | |
2045 { | |
2046 octave_value retval; | |
2047 #ifdef HAVE_PORTAUDIO | |
2048 const octave_base_value& rep = args(0).get_rep (); | |
2049 audiorecorder *recorder = &((audiorecorder &)rep); | |
2050 recorder->stop (); | |
2051 #else | |
2052 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2053 #endif | |
2054 return retval; | |
2055 } | |
2056 | |
2057 DEFUN_DLD (__player_audioplayer__, args, , | |
2058 "-*- texinfo -*-\n\ | |
2059 @deftypefn {Loadable Function} {@var{player} =} __player_audioplayer__ (@var{y}, @var{fs})\n\ | |
2060 @deftypefnx {Loadable Function} {@var{player} =} __player_audioplayer__ (@var{y}, @var{fs}, @var{nbits})\n\ | |
2061 @deftypefnx {Loadable Function} {@var{player} =} __player_audioplayer__ (@var{y}, @var{fs}, @var{nbits}, @var{id})\n\ | |
2062 Undocumented internal function.\n\ | |
2063 @end deftypefn") | |
2064 { | |
2065 #ifdef HAVE_PORTAUDIO | |
2066 int nargin = args.length (); | |
2067 audioplayer* retval = new audioplayer (); | |
2068 bool is_function = args(0).is_string () || args(0).is_function_handle () || args(0).is_inline_function (); | |
2069 if (is_function) | |
2070 retval->set_y (args(0).function_value ()); | |
2071 else | |
2072 retval->set_y (args(0)); | |
2073 retval->set_fs (args(1).int_value ()); | |
2074 switch (nargin) | |
2075 { | |
2076 case 3: | |
2077 retval->set_nbits (args(2).int_value ()); | |
2078 break; | |
2079 case 4: | |
2080 retval->set_nbits (args(2).int_value ()); | |
2081 retval->set_id (args(3).int_value ()); | |
2082 break; | |
2083 } | |
2084 if (is_function) | |
2085 retval->init_fn (); | |
2086 else | |
2087 retval->init (); | |
2088 return octave_value (retval); | |
2089 #else | |
2090 octave_value retval; | |
2091 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2092 return retval; | |
2093 #endif | |
2094 } | |
2095 | |
2096 DEFUN_DLD (__player_get_channels__, args, , | |
2097 "-*- texinfo -*-\n\ | |
2098 @deftypefn {Loadable Function} {@var{n} =} __player_get_channels__ (@var{player})\n\ | |
2099 Undocumented internal function.\n\ | |
2100 @end deftypefn") | |
2101 { | |
2102 octave_value retval; | |
2103 #ifdef HAVE_PORTAUDIO | |
2104 int nargin = args.length (); | |
2105 if (nargin == 1) | |
2106 { | |
2107 const octave_base_value& rep = args(0).get_rep (); | |
2108 audioplayer *player = &((audioplayer &)rep); | |
2109 retval = octave_value (player->get_channels ()); | |
2110 } | |
2111 #else | |
2112 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2113 #endif | |
2114 return retval; | |
2115 } | |
2116 | |
2117 DEFUN_DLD (__player_get_fs__, args, , | |
2118 "-*- texinfo -*-\n\ | |
2119 @deftypefn {Loadable Function} {@var{fs} =} __player_get_fs__ (@var{player})\n\ | |
2120 Undocumented internal function.\n\ | |
2121 @end deftypefn") | |
2122 { | |
2123 octave_value retval; | |
2124 #ifdef HAVE_PORTAUDIO | |
2125 int nargin = args.length (); | |
2126 if (nargin == 1) | |
2127 { | |
2128 const octave_base_value& rep = args(0).get_rep (); | |
2129 audioplayer *player = &((audioplayer &)rep); | |
2130 retval = octave_value (player->get_fs ()); | |
2131 } | |
2132 #else | |
2133 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2134 #endif | |
2135 return retval; | |
2136 } | |
2137 | |
2138 DEFUN_DLD (__player_get_id__, args, , | |
2139 "-*- texinfo -*-\n\ | |
2140 @deftypefn {Loadable Function} {@var{id} =} __player_get_id__ (@var{player})\n\ | |
2141 Undocumented internal function.\n\ | |
2142 @end deftypefn") | |
2143 { | |
2144 octave_value retval; | |
2145 #ifdef HAVE_PORTAUDIO | |
2146 int nargin = args.length (); | |
2147 if (nargin == 1) | |
2148 { | |
2149 const octave_base_value& rep = args(0).get_rep (); | |
2150 audioplayer *player = &((audioplayer &)rep); | |
2151 retval = octave_value (player->get_id ()); | |
2152 } | |
2153 #else | |
2154 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2155 #endif | |
2156 return retval; | |
2157 } | |
2158 | |
2159 DEFUN_DLD (__player_get_nbits__, args, , | |
2160 "-*- texinfo -*-\n\ | |
2161 @deftypefn {Loadable Function} {@var{nbits} =} __player_get_nbits__ (@var{player})\n\ | |
2162 Undocumented internal function.\n\ | |
2163 @end deftypefn") | |
2164 { | |
2165 octave_value retval; | |
2166 #ifdef HAVE_PORTAUDIO | |
2167 int nargin = args.length (); | |
2168 if (nargin == 1) | |
2169 { | |
2170 const octave_base_value& rep = args(0).get_rep (); | |
2171 audioplayer *player = &((audioplayer &)rep); | |
2172 retval = octave_value (player->get_nbits ()); | |
2173 } | |
2174 #else | |
2175 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2176 #endif | |
2177 return retval; | |
2178 } | |
2179 | |
2180 DEFUN_DLD (__player_get_sample_number__, args, , | |
2181 "-*- texinfo -*-\n\ | |
2182 @deftypefn {Loadable Function} {@var{n} =} __player_get_sample_number__ (@var{player})\n\ | |
2183 Undocumented internal function.\n\ | |
2184 @end deftypefn") | |
2185 { | |
2186 octave_value retval; | |
2187 #ifdef HAVE_PORTAUDIO | |
2188 int nargin = args.length (); | |
2189 if (nargin == 1) | |
2190 { | |
2191 const octave_base_value& rep = args(0).get_rep (); | |
2192 audioplayer *player = &((audioplayer &)rep); | |
2193 retval = octave_value (player->get_sample_number ()); | |
2194 } | |
2195 #else | |
2196 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2197 #endif | |
2198 return retval; | |
2199 } | |
2200 | |
2201 DEFUN_DLD (__player_get_tag__, args, , | |
2202 "-*- texinfo -*-\n\ | |
2203 @deftypefn {Loadable Function} {@var{tag} =} __player_get_tag__ (@var{player})\n\ | |
2204 Undocumented internal function.\n\ | |
2205 @end deftypefn") | |
2206 { | |
2207 octave_value retval; | |
2208 #ifdef HAVE_PORTAUDIO | |
2209 int nargin = args.length (); | |
2210 if (nargin == 1) | |
2211 { | |
2212 const octave_base_value& rep = args(0).get_rep (); | |
2213 audioplayer *player = &((audioplayer &)rep); | |
2214 retval = octave_value (player->get_tag ()); | |
2215 } | |
2216 #else | |
2217 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2218 #endif | |
2219 return retval; | |
2220 } | |
2221 | |
2222 DEFUN_DLD (__player_get_total_samples__, args, , | |
2223 "-*- texinfo -*-\n\ | |
2224 @deftypefn {Loadable Function} {@var{n} =} __player_get_total_samples__ (@var{player})\n\ | |
2225 Undocumented internal function.\n\ | |
2226 @end deftypefn") | |
2227 { | |
2228 octave_value retval; | |
2229 #ifdef HAVE_PORTAUDIO | |
2230 int nargin = args.length (); | |
2231 if (nargin == 1) | |
2232 { | |
2233 const octave_base_value& rep = args(0).get_rep (); | |
2234 audioplayer *player = &((audioplayer &)rep); | |
2235 retval = octave_value (player->get_total_samples ()); | |
2236 } | |
2237 #else | |
2238 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2239 #endif | |
2240 return retval; | |
2241 } | |
2242 | |
2243 DEFUN_DLD (__player_get_userdata__, args, , | |
2244 "-*- texinfo -*-\n\ | |
2245 @deftypefn {Loadable Function} {@var{data} =} __player_get_userdata__ (@var{player})\n\ | |
2246 Undocumented internal function.\n\ | |
2247 @end deftypefn") | |
2248 { | |
2249 octave_value retval; | |
2250 #ifdef HAVE_PORTAUDIO | |
2251 int nargin = args.length (); | |
2252 if (nargin == 1) | |
2253 { | |
2254 const octave_base_value& rep = args(0).get_rep (); | |
2255 audioplayer *player = &((audioplayer &)rep); | |
2256 retval = player->get_userdata (); | |
2257 } | |
2258 #else | |
2259 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2260 #endif | |
2261 return retval; | |
2262 } | |
2263 | |
2264 DEFUN_DLD (__player_isplaying__, args, , | |
2265 "-*- texinfo -*-\n\ | |
2266 @deftypefn {Loadable Function} {} __player_isplaying__ (@var{player})\n\ | |
2267 Undocumented internal function.\n\ | |
2268 @end deftypefn") | |
2269 { | |
2270 octave_value retval; | |
2271 #ifdef HAVE_PORTAUDIO | |
2272 int nargin = args.length (); | |
2273 if (nargin == 1) | |
2274 { | |
2275 const octave_base_value& rep = args(0).get_rep (); | |
2276 audioplayer *player = &((audioplayer &)rep); | |
2277 if (player->isplaying ()) | |
2278 return octave_value (1); | |
2279 else | |
2280 return octave_value (0); | |
2281 } | |
2282 #else | |
2283 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2284 #endif | |
2285 return retval; | |
2286 } | |
2287 | |
2288 DEFUN_DLD (__player_pause__, args, , | |
2289 "-*- texinfo -*-\n\ | |
2290 @deftypefn {Loadable Function} {} __player_pause__ (@var{player})\n\ | |
2291 Undocumented internal function.\n\ | |
2292 @end deftypefn") | |
2293 { | |
2294 octave_value retval; | |
2295 #ifdef HAVE_PORTAUDIO | |
2296 int nargin = args.length (); | |
2297 if (nargin == 1) | |
2298 { | |
2299 const octave_base_value& rep = args(0).get_rep (); | |
2300 audioplayer *player = &((audioplayer &)rep); | |
2301 player->pause (); | |
2302 } | |
2303 #else | |
2304 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2305 #endif | |
2306 return retval; | |
2307 } | |
2308 | |
2309 DEFUN_DLD (__player_playblocking__, args, , | |
2310 "-*- texinfo -*-\n\ | |
2311 @deftypefn {Loadable Function} {} __player_playblocking__ (@var{player})\n\ | |
2312 @deftypefnx {Loadable Function} {} __player_playblocking__ (@var{player}, @var{start})\n\ | |
2313 @deftypefnx {Loadable Function} {} __player_playblocking__ (@var{player}, [@var{start}, @var{end}])\n\ | |
2314 Undocumented internal function.\n\ | |
2315 @end deftypefn") | |
2316 { | |
2317 octave_value retval; | |
2318 #ifdef HAVE_PORTAUDIO | |
2319 int nargin = args.length (); | |
2320 if (nargin == 1) | |
2321 { | |
2322 const octave_base_value& rep = args(0).get_rep (); | |
2323 audioplayer *player = &((audioplayer &)rep); | |
2324 player->playblocking (); | |
2325 } | |
2326 else | |
2327 { | |
2328 const octave_base_value& rep = args(0).get_rep (); | |
2329 audioplayer *player = &((audioplayer &)rep); | |
2330 if (args(1).is_matrix_type ()) | |
2331 { | |
2332 unsigned int start, end; | |
2333 RowVector range = args(1).row_vector_value (); | |
2334 start = range.elem (0) - 1; | |
2335 end = range.elem (1) - 1; | |
2336 if (start < 0 or start > player->get_total_samples () or | |
2337 start > end or end < 0 or end > player->get_total_samples ()) | |
2338 error ("audioplayer: invalid range specified for playback"); | |
2339 player->set_sample_number (start); | |
2340 player->set_end_sample (end); | |
2341 } | |
2342 else | |
2343 { | |
2344 unsigned int start; | |
2345 start = args(1).int_value () - 1; | |
2346 if (start < 0 or start > player->get_total_samples ()) | |
2347 error ("audioplayer: invalid range specified for playback"); | |
2348 player->set_sample_number (start); | |
2349 } | |
2350 player->playblocking (); | |
2351 } | |
2352 #else | |
2353 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2354 #endif | |
2355 return retval; | |
2356 } | |
2357 | |
2358 DEFUN_DLD (__player_play__, args, , | |
2359 "-*- texinfo -*-\n\ | |
2360 @deftypefn {Loadable Function} {} __player_play__ (@var{player})\n\ | |
2361 @deftypefnx {Loadable Function} {} __player_play__ (@var{player}, @var{start})\n\ | |
2362 @deftypefnx {Loadable Function} {} __player_play__ (@var{player}, [@var{start}, @var{end}])\n\ | |
2363 Undocumented internal function.\n\ | |
2364 @end deftypefn") | |
2365 { | |
2366 octave_value retval; | |
2367 #ifdef HAVE_PORTAUDIO | |
2368 int nargin = args.length (); | |
2369 if (nargin == 1) | |
2370 { | |
2371 const octave_base_value& rep = args(0).get_rep (); | |
2372 audioplayer *player = &((audioplayer &)rep); | |
2373 player->play (); | |
2374 } | |
2375 else | |
2376 { | |
2377 const octave_base_value& rep = args(0).get_rep (); | |
2378 audioplayer *player = &((audioplayer &)rep); | |
2379 if (args(1).is_matrix_type ()) | |
2380 { | |
2381 unsigned int start, end; | |
2382 RowVector range = args(1).row_vector_value (); | |
2383 start = range.elem (0) - 1; | |
2384 end = range.elem (1) - 1; | |
2385 if (start < 0 or start > player->get_total_samples () or | |
2386 start > end or end < 0 or end > player->get_total_samples ()) | |
2387 error ("audioplayer: invalid range specified for playback"); | |
2388 player->set_sample_number (start); | |
2389 player->set_end_sample (end); | |
2390 } | |
2391 else | |
2392 { | |
2393 unsigned int start; | |
2394 start = args(1).int_value () - 1; | |
2395 if (start < 0 or start > player->get_total_samples ()) | |
2396 error ("audioplayer: invalid range specified for playback"); | |
2397 player->set_sample_number (start); | |
2398 } | |
2399 player->play (); | |
2400 } | |
2401 #else | |
2402 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2403 #endif | |
2404 return retval; | |
2405 } | |
2406 | |
2407 DEFUN_DLD (__player_resume__, args, , | |
2408 "-*- texinfo -*-\n\ | |
2409 @deftypefn {Loadable Function} {} __player_resume__ (@var{player})\n\ | |
2410 Undocumented internal function.\n\ | |
2411 @end deftypefn") | |
2412 { | |
2413 octave_value retval; | |
2414 #ifdef HAVE_PORTAUDIO | |
2415 int nargin = args.length (); | |
2416 if (nargin == 1) | |
2417 { | |
2418 const octave_base_value& rep = args(0).get_rep (); | |
2419 audioplayer *player = &((audioplayer &)rep); | |
2420 player->resume (); | |
2421 } | |
2422 #else | |
2423 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2424 #endif | |
2425 return retval; | |
2426 } | |
2427 | |
2428 DEFUN_DLD (__player_set_fs__, args, , | |
2429 "-*- texinfo -*-\n\ | |
2430 @deftypefn {Loadable Function} {} __player_set_fs__ (@var{player}, @var{fs})\n\ | |
2431 Undocumented internal function.\n\ | |
2432 @end deftypefn") | |
2433 { | |
2434 octave_value retval; | |
2435 #ifdef HAVE_PORTAUDIO | |
2436 int nargin = args.length (); | |
2437 if (nargin == 2) | |
2438 { | |
2439 const octave_base_value& rep = args(0).get_rep (); | |
2440 audioplayer *player = &((audioplayer &)rep); | |
2441 player->set_fs (args(1).int_value ()); | |
2442 } | |
2443 #else | |
2444 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2445 #endif | |
2446 return retval; | |
2447 } | |
2448 | |
2449 DEFUN_DLD (__player_set_tag__, args, , | |
2450 "-*- texinfo -*-\n\ | |
2451 @deftypefn {Loadable Function} {} __player_set_tag__ (@var{player}, @var{tag})\n\ | |
2452 Undocumented internal function.\n\ | |
2453 @end deftypefn") | |
2454 { | |
2455 octave_value retval; | |
2456 #ifdef HAVE_PORTAUDIO | |
2457 int nargin = args.length (); | |
2458 if (nargin == 2) | |
2459 { | |
2460 const octave_base_value& rep = args(0).get_rep (); | |
2461 audioplayer *player = &((audioplayer &)rep); | |
2462 player->set_tag (args(1).char_matrix_value ()); | |
2463 } | |
2464 #else | |
2465 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2466 #endif | |
2467 return retval; | |
2468 } | |
2469 | |
2470 DEFUN_DLD (__player_set_userdata__, args, , | |
2471 "-*- texinfo -*-\n\ | |
2472 @deftypefn {Loadable Function} {} __player_set_userdata__ (@var{player}, @var{data})\n\ | |
2473 Undocumented internal function.\n\ | |
2474 @end deftypefn") | |
2475 { | |
2476 octave_value retval; | |
2477 #ifdef HAVE_PORTAUDIO | |
2478 int nargin = args.length (); | |
2479 if (nargin == 2) | |
2480 { | |
2481 const octave_base_value& rep = args(0).get_rep (); | |
2482 audioplayer *player = &((audioplayer &)rep); | |
2483 player->set_userdata (args(1)); | |
2484 } | |
2485 #else | |
2486 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2487 #endif | |
2488 return retval; | |
2489 } | |
2490 | |
2491 DEFUN_DLD (__player_stop__, args, , | |
2492 "-*- texinfo -*-\n\ | |
2493 @deftypefn {Loadable Function} {} __player_stop__ (@var{player})\n\ | |
2494 Undocumented internal function.\n\ | |
2495 @end deftypefn") | |
2496 { | |
2497 octave_value retval; | |
2498 #ifdef HAVE_PORTAUDIO | |
2499 int nargin = args.length (); | |
2500 if (nargin == 1) | |
2501 { | |
2502 const octave_base_value& rep = args(0).get_rep (); | |
2503 audioplayer *player = &((audioplayer &)rep); | |
2504 player->stop (); | |
2505 } | |
2506 #else | |
2507 error ("portaudio not found on your system and thus audio functionality is not present"); | |
2508 #endif | |
2509 return retval; | |
2510 } |