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