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