46 #if defined (HAVE_PORTAUDIO)
48 #include <portaudio.h>
51 bits_to_format (
int bits)
71 @deftypefn {Loadable Function} {@var{devinfo} =} audiodevinfo ()\n\
73 @deftypefnx {Loadable Function} {@var{devs} =} audiodevinfo (@var{io})\n\
74 @deftypefnx {Loadable Function} {@var{name} =} audiodevinfo (@var{io}, @var{id})\n\
75 @deftypefnx {Loadable Function} {@var{id} =} audiodevinfo (@var{io}, @var{name})\n\
76 @deftypefnx {Loadable Function} {@var{id} =} audiodevinfo (@var{io}, @var{rate}, @var{bits}, @var{chans})\n\
78 @deftypefnx {Loadable Function} {@var{supports} =} audiodevinfo (@var{io}, @var{id}, @var{rate}, @var{bits}, @var{chans})\n\
80 Return a structure describing the available audio input and output devices.\n\
82 The @var{devinfo} structure has two fields @qcode{\"input\"} and\n\
83 @qcode{\"output\"}. The value of each field is a structure array with fields\n\
84 @qcode{\"Name\"}, @nospell{\"DriverVersion\"} and @qcode{\"ID\"} describing\n\
87 If the optional argument @var{io} is 1, return information about input\n\
88 devices only. If it is 0, return information about output devices only.\n\
90 If the optional argument @var{id} is provided, return information about\n\
91 the corresponding device.\n\
93 If the optional argument @var{name} is provided, return the id of the\n\
96 Given a sampling rate, bits per sample, and number of channels for an input\n\
97 or output device, return the ID of the first device that supports playback\n\
98 or recording using the specified parameters.\n\
100 If also given a device ID, return true if the device supports playback or\n\
101 recording using those parameters.\n\
106 #ifdef HAVE_PORTAUDIO
108 int nargin = args.
length ();
114 PaError err = Pa_Initialize ();
116 if (err != paNoError)
118 error (
"audiodevinfo: PortAudio initialization failed");
122 int num_devices = Pa_GetDeviceCount ();
126 error (
"audiodevinfo: no audio device found");
131 for (
int i = 0; i < num_devices; i++)
133 const PaDeviceInfo *device_info = Pa_GetDeviceInfo (i);
137 warning (
"Octave:invalid-audio-device",
138 "invalid audio device ID = %d", i);
142 if (device_info->maxInputChannels != 0)
145 if (device_info->maxOutputChannels != 0)
157 for (
int i = 0; i < num_devices; i++)
159 const PaDeviceInfo *device_info = Pa_GetDeviceInfo (i);
163 warning (
"Octave:invalid-audio-device",
164 "invalid audio device ID = %d", i);
168 const PaHostApiInfo *api_info = Pa_GetHostApiInfo (device_info->hostApi);
170 const char *driver = api_info ? api_info->name :
"";
173 sprintf (name,
"%s (%s)", device_info->name, driver);
175 if (device_info->maxInputChannels != 0)
177 input_name(idx_i) = name;
178 input_driver_version(idx_i) = driver;
183 if (device_info->maxOutputChannels != 0)
185 output_name(idx_o) = name;
186 output_driver_version(idx_o) = driver;
187 output_id(idx_o) = i;
193 inputdev.
setfield (
"Name", input_name);
194 inputdev.
setfield (
"DriverVersion", input_driver_version);
196 outputdev.
setfield (
"Name", output_name);
197 outputdev.
setfield (
"DriverVersion", output_driver_version);
198 outputdev.
setfield (
"ID", output_id);
199 devinfo.
setfield (
"input", inputdev);
200 devinfo.
setfield (
"output", outputdev);
207 else if (nargin == 1)
209 if (args(0).int_value () == 0)
211 else if (args(0).int_value () == 1)
215 error (
"audiodevinfo: please specify 0 for output and 1 for input devices");
220 else if (nargin == 2)
224 if (args(1).is_string ())
228 for (
int i = 0; i < numoutput; i++)
230 if (output_name(i).string_value () == args(1).string_value ())
232 retval = output_id(i);
240 for (
int i = 0; i < numinput; i++)
242 if (input_name(i).string_value () == args(1).string_value ())
244 retval = input_id(i);
252 error (
"audiodevinfo: please specify 0 for output and 1 for input devices");
260 for (
int i = 0; i < numoutput; i++)
262 if (output_id(i).int_value () == args(1).int_value ())
264 retval = output_name(i);
272 for (
int i = 0; i < numinput; i++)
274 if (input_id(i).int_value () == args(1).int_value ())
276 retval = input_name(i);
284 error (
"audiodevinfo: please specify 0 for output and 1 for input devices");
289 error (
"audiodevinfo: no device meeting the specified criteria found");
291 else if (nargin == 3)
296 else if (nargin == 4)
298 int io = args(0).int_value ();
299 int rate = args(1).int_value ();
300 int bits = args(2).int_value ();
301 int chans = args(3).int_value ();
303 for (
int i = 0; i < num_devices; i++)
305 PaStreamParameters stream_parameters;
306 stream_parameters.device = i;
307 stream_parameters.channelCount = chans;
308 PaSampleFormat format = bits_to_format (bits);
311 stream_parameters.sampleFormat = format;
314 error (
"audiodevinfo: no such bits per sample format");
318 const PaDeviceInfo *device_info = Pa_GetDeviceInfo (i);
322 warning (
"Octave:invalid-audio-device",
323 "invalid audio device ID = %d", i);
327 stream_parameters.suggestedLatency
328 = device_info->defaultLowInputLatency;
330 stream_parameters.hostApiSpecificStreamInfo = 0;
334 if (device_info->maxOutputChannels < chans)
337 err = Pa_IsFormatSupported (0, &stream_parameters, rate);
339 if (err == paFormatIsSupported)
347 if (device_info->maxInputChannels < chans)
350 err = Pa_IsFormatSupported (&stream_parameters, 0, rate);
351 if (err == paFormatIsSupported)
361 else if (nargin == 5)
364 int id = args(1).int_value ();
365 int rate = args(2).int_value ();
366 int bits = args(3).int_value ();
367 int chans = args(4).int_value ();
368 PaStreamParameters stream_parameters;
369 stream_parameters.device = id;
370 stream_parameters.channelCount = chans;
371 PaSampleFormat format = bits_to_format (bits);
373 stream_parameters.sampleFormat = format;
376 error (
"audiodevinfo: no such bits per sample format");
380 const PaDeviceInfo *device_info = Pa_GetDeviceInfo (
id);
384 error (
"invalid audio device ID = %d",
id);
388 stream_parameters.suggestedLatency
389 = device_info->defaultLowInputLatency;
391 stream_parameters.hostApiSpecificStreamInfo = 0;
394 if (device_info->maxOutputChannels < chans)
399 err = Pa_IsFormatSupported (0, &stream_parameters, rate);
400 if (err == paFormatIsSupported)
408 if (device_info->maxInputChannels < chans)
413 err = Pa_IsFormatSupported (&stream_parameters, 0, rate);
414 if (err == paFormatIsSupported)
422 error (
"audiodevinfo: please specify 0 for output and 1 for input devices");
429 error (
"audiodevinfo: wrong number of arguments");
434 error (
"portaudio not found on your system and thus audio functionality is not present");
477 #ifdef HAVE_PORTAUDIO
479 enum audio_type { TYPE_INT8, TYPE_UINT8, TYPE_UINT16, TYPE_DOUBLE };
488 double player_value (
void)
const {
return 0; }
489 virtual double scalar_value (
bool =
false)
const {
return 0; }
490 void print (std::ostream& os,
bool pr_as_read_syntax =
false)
const;
491 void print_raw (std::ostream& os,
bool pr_as_read_syntax)
const;
502 void set_y (std::string fn);
506 void set_fs (
int fs);
508 void set_nbits (
int nbits);
509 int get_nbits (
void);
510 void set_id (
int id);
512 int get_channels (
void);
513 audio_type get_type (
void);
515 void set_sample_number (
unsigned int sample);
516 unsigned int get_sample_number (
void);
517 unsigned int get_total_samples (
void);
518 void set_end_sample (
unsigned int sample);
519 unsigned int get_end_sample (
void);
520 void reset_end_sample (
void);
525 PaStream *get_stream (
void);
527 void playblocking (
void);
532 bool isplaying (
void);
541 unsigned int sample_number;
542 unsigned int end_sample;
549 PaStreamParameters output_parameters;
558 octave_play_callback (
const void *,
void *output,
unsigned long frames,
559 const PaStreamCallbackTimeInfo *,
560 PaStreamCallbackFlags,
void *data)
562 audioplayer *player =
static_cast<audioplayer *
> (data);
566 error (
"audio player callback function called without player");
571 ovl (static_cast<double> (frames)), 1);
575 error (
"audio player callback function failed");
579 const Matrix sound = retval(0).matrix_value ();
580 int return_status = retval(1).int_value ();
585 error (
"audio player callback function failed");
595 ? sound_l : sound.
column (1));
597 const double *p_l = sound_l.
data ();
598 const double *p_r = sound_r.
data ();
600 switch (player->get_nbits ())
604 static double scale_factor =
std::pow (2.0, 7) - 1.0;
606 int8_t *buffer =
static_cast<int8_t *
> (output);
608 for (
unsigned long i = 0; i < frames; i++)
610 buffer[2*i] = p_l[i] * scale_factor;
611 buffer[2*i+1] = p_r[i] * scale_factor;
618 static double scale_factor =
std::pow (2.0, 15) - 1.0;
620 int16_t *buffer =
static_cast<int16_t *
> (output);
622 for (
unsigned long i = 0; i < frames; i++)
624 buffer[2*i] = p_l[i] * scale_factor;
625 buffer[2*i+1] = p_r[i] * scale_factor;
632 static double scale_factor =
std::pow (2.0, 23) - 1.0;
636 uint8_t *buffer =
static_cast<uint8_t *
> (output);
638 for (
unsigned long i = 0; i < frames; i++)
640 int32_t sample_l = p_l[i];
641 int32_t sample_r = p_r[i];
643 sample_l &= 0x00ffffff;
644 sample_r &= 0x00ffffff;
647 uint8_t *_sample_l =
reinterpret_cast<uint8_t *
> (&sample_l);
648 uint8_t *_sample_r =
reinterpret_cast<uint8_t *
> (&sample_r);
650 unsigned long offset = i * 6;
652 buffer[offset+0] = _sample_l[0+big_endian] * scale_factor;
653 buffer[offset+1] = _sample_l[1+big_endian] * scale_factor;
654 buffer[offset+2] = _sample_l[2+big_endian] * scale_factor;
656 buffer[offset+3] = _sample_r[0+big_endian] * scale_factor;
657 buffer[offset+4] = _sample_r[1+big_endian] * scale_factor;
658 buffer[offset+5] = _sample_r[2+big_endian] * scale_factor;
664 error (
"invalid player bit depth in callback function");
668 return return_status;
672 portaudio_play_callback (
const void *,
void *output,
unsigned long frames,
673 const PaStreamCallbackTimeInfo*,
674 PaStreamCallbackFlags,
void *data)
676 audioplayer *player =
static_cast<audioplayer *
> (data);
680 error (
"audio player callback function called without player");
690 const RowVector sound_l = player->get_left ();
691 const RowVector sound_r = player->get_right ();
693 const double *pl = sound_l.
data ();
694 const double *pr = sound_r.
data ();
696 if (player->get_type () == TYPE_DOUBLE)
698 switch (player->get_nbits ())
702 static double scale_factor =
std::pow (2.0, 7) - 1.0;
704 int8_t *buffer =
static_cast<int8_t *
> (output);
706 for (
unsigned long j = 0; j < frames; j++)
708 unsigned int sample_number = player->get_sample_number ();
710 if (sample_number >= player->get_end_sample ())
713 unsigned long offset = j * 2;
715 buffer[offset+0] = pl[sample_number] * scale_factor;
716 buffer[offset+1] = pr[sample_number] * scale_factor;
718 player->set_sample_number (sample_number + 1);
725 static double scale_factor =
std::pow (2.0, 15) - 1.0;
727 int16_t *buffer =
static_cast<int16_t *
> (output);
729 for (
unsigned long j = 0; j < frames; j++)
731 unsigned int sample_number = player->get_sample_number ();
733 if (sample_number >= player->get_end_sample ())
736 unsigned long offset = j * 2;
738 buffer[offset+0] = pl[sample_number] * scale_factor;
739 buffer[offset+1] = pr[sample_number] * scale_factor;
741 player->set_sample_number (sample_number + 1);
748 static double scale_factor =
std::pow (2.0, 23) - 1.0;
752 uint8_t *buffer =
static_cast<uint8_t *
> (output);
754 for (
unsigned long j = 0; j < frames; j++)
756 unsigned int sample_number = player->get_sample_number ();
758 if (sample_number >= player->get_end_sample ())
761 int32_t sample_l = pl[sample_number] * scale_factor;
762 int32_t sample_r = pr[sample_number] * scale_factor;
764 sample_l &= 0x00ffffff;
765 sample_r &= 0x00ffffff;
768 uint8_t *_sample_l =
reinterpret_cast<uint8_t *
> (&sample_l);
769 uint8_t *_sample_r =
reinterpret_cast<uint8_t *
> (&sample_r);
771 unsigned long offset = j * 6;
773 buffer[offset+0] = _sample_l[0+big_endian];
774 buffer[offset+1] = _sample_l[1+big_endian];
775 buffer[offset+2] = _sample_l[2+big_endian];
777 buffer[offset+3] = _sample_r[0+big_endian];
778 buffer[offset+4] = _sample_r[1+big_endian];
779 buffer[offset+5] = _sample_r[2+big_endian];
781 player->set_sample_number (sample_number + 1);
787 error (
"invalid player bit depth in callback function");
791 else if (player->get_type () == TYPE_INT8)
793 int8_t *buffer =
static_cast<int8_t *
> (output);
795 for (
unsigned long j = 0; j < frames; j++)
797 unsigned int sample_number = player->get_sample_number ();
799 if (sample_number >= player->get_end_sample ())
802 unsigned long offset = j * 2;
804 buffer[offset+0] = pl[sample_number];
805 buffer[offset+1] = pr[sample_number];
807 player->set_sample_number (sample_number + 1);
810 else if (player->get_type () == TYPE_UINT8)
812 uint8_t *buffer =
static_cast<uint8_t *
> (output);
814 for (
unsigned long j = 0; j < frames; j++)
816 unsigned int sample_number = player->get_sample_number ();
818 if (sample_number >= player->get_end_sample ())
821 unsigned long offset = j * 2;
823 buffer[offset+0] = pl[sample_number];
824 buffer[offset+1] = pr[sample_number];
826 player->set_sample_number (sample_number + 1);
829 else if (player->get_type () == TYPE_UINT16)
831 int16_t *buffer =
static_cast<int16_t *
> (output);
833 for (
unsigned long j = 0; j < frames; j++)
835 unsigned int sample_number = player->get_sample_number ();
837 if (sample_number >= player->get_end_sample ())
840 unsigned long offset = j * 2;
842 buffer[offset+0] = pl[sample_number];
843 buffer[offset+1] = pr[sample_number];
845 player->set_sample_number (sample_number + 1);
853 safe_audioplayer_stop (audioplayer *player)
858 audioplayer::audioplayer (
void)
859 : octave_callback_function (0),
860 id (-1), fs (0), nbits (16), channels (0), sample_number (0),
861 end_sample (-1), tag (
""), y (), userdata (
Matrix ()),
862 left (), right (), stream (0), output_parameters (),
type ()
865 audioplayer::~audioplayer (
void)
869 warning (
"Octave:audio-interrupt",
870 "interrupting playing audioplayer");
876 audioplayer::print (std::ostream& os,
bool pr_as_read_syntax)
const
878 print_raw (os, pr_as_read_syntax);
883 audioplayer::print_raw (std::ostream& os,
bool)
const
889 audioplayer::init_fn (
void)
891 if (Pa_Initialize () != paNoError)
893 error (
"audioplayer: initialization error!");
897 if (Pa_GetDeviceCount () < 1)
899 error (
"audioplayer: no audio devices found or available!");
903 int device = get_id ();
906 device = Pa_GetDefaultOutputDevice ();
908 output_parameters.device = device;
909 output_parameters.channelCount = 2;
910 output_parameters.sampleFormat = bits_to_format (get_nbits ());
912 const PaDeviceInfo *device_info = Pa_GetDeviceInfo (device);
915 warning (
"Octave:invalid-default-audio-device",
916 "invalid default audio device ID = %d", device);
918 output_parameters.suggestedLatency
919 = device_info ? device_info->defaultHighOutputLatency : -1;
921 output_parameters.hostApiSpecificStreamInfo = 0;
925 audioplayer::init (
void)
933 if (Pa_Initialize () != paNoError)
935 error (
"audioplayer: initialization error!");
939 if (Pa_GetDeviceCount () < 1)
941 error (
"audioplayer: no audio devices found or available!");
945 int device = get_id ();
948 device = Pa_GetDefaultOutputDevice ();
950 output_parameters.device = device;
951 output_parameters.channelCount = 2;
953 if (
type == TYPE_DOUBLE)
954 output_parameters.sampleFormat = bits_to_format (get_nbits ());
955 else if (
type == TYPE_INT8)
956 output_parameters.sampleFormat = paInt8;
957 else if (
type == TYPE_UINT8)
958 output_parameters.sampleFormat = paUInt8;
959 else if (
type == TYPE_UINT16)
960 output_parameters.sampleFormat = paInt16;
962 const PaDeviceInfo *device_info = Pa_GetDeviceInfo (device);
965 warning (
"Octave:invalid-default-audio-device",
966 "invalid default audio device ID = %d", device);
968 output_parameters.suggestedLatency
969 = device_info ? device_info->defaultHighOutputLatency : -1;
971 output_parameters.hostApiSpecificStreamInfo = 0;
991 channels = y.
rows ();
1003 octave_callback_function = fn;
1005 reset_end_sample ();
1009 audioplayer::get_y (
void)
1015 audioplayer::get_left (
void)
const
1021 audioplayer::get_right (
void)
const
1023 return channels == 1 ?
left : right;
1027 audioplayer::set_fs (
int fs_arg)
1033 audioplayer::get_fs (
void)
1039 audioplayer::set_nbits (
int nbits_arg)
1045 audioplayer::get_nbits (
void)
1051 audioplayer::set_id (
int id_arg)
1057 audioplayer::get_id (
void)
1063 audioplayer::get_channels (
void)
1069 audioplayer::get_type (
void)
1075 audioplayer::set_sample_number (
unsigned int sample_number_arg)
1077 sample_number = sample_number_arg;
1081 audioplayer::get_sample_number (
void)
1083 return sample_number;
1087 audioplayer::get_total_samples (
void)
1089 return left.length ();
1093 audioplayer::set_end_sample (
unsigned int end_sample_arg)
1095 end_sample = end_sample_arg;
1099 audioplayer::get_end_sample (
void)
1105 audioplayer::reset_end_sample (
void)
1107 set_end_sample (
left.length ());
1111 audioplayer::set_tag (
const charMatrix& tag_arg)
1117 audioplayer::get_tag (
void)
1123 audioplayer::set_userdata (
const octave_value& userdata_arg)
1125 userdata = userdata_arg;
1129 audioplayer::get_userdata (
void)
1135 audioplayer::playblocking (
void)
1140 const unsigned int buffer_size = get_fs () / 20;
1144 err = Pa_OpenStream (&stream, 0, &(output_parameters), get_fs (),
1145 buffer_size, paClipOff, 0, 0);
1146 if (err != paNoError)
1148 error (
"audioplayer: unable to open audio playback stream");
1152 err = Pa_StartStream (stream);
1153 if (err != paNoError)
1155 error (
"audioplayer: unable to start start audio playback stream");
1159 unsigned int start, end;
1160 start = get_sample_number ();
1161 end = get_end_sample ();
1165 frame.
add_fcn (safe_audioplayer_stop,
this);
1167 for (
unsigned int i = start; i < end; i += buffer_size)
1170 if (octave_callback_function != 0)
1171 octave_play_callback (0, buffer, buffer_size, 0, 0,
this);
1173 portaudio_play_callback (0, buffer, buffer_size, 0, 0,
this);
1175 err = Pa_WriteStream (stream, buffer, buffer_size);
1180 audioplayer::play (
void)
1185 const unsigned int buffer_size = get_fs () / 20;
1188 if (octave_callback_function != 0)
1189 err = Pa_OpenStream (&stream, 0, &(output_parameters),
1190 get_fs (), buffer_size, paClipOff,
1191 octave_play_callback,
this);
1193 err = Pa_OpenStream (&stream, 0, &(output_parameters),
1194 get_fs (), buffer_size, paClipOff,
1195 portaudio_play_callback,
this);
1197 if (err != paNoError)
1199 error (
"audioplayer: failed to open audio playback stream");
1203 err = Pa_StartStream (stream);
1204 if (err != paNoError)
1206 error (
"audioplayer: failed to start audio playback stream");
1212 audioplayer::pause (
void)
1214 if (get_stream () == 0)
1218 err = Pa_StopStream (stream);
1219 if (err != paNoError)
1221 error (
"audiorecorder: failed to stop audio recording stream");
1227 audioplayer::resume (
void)
1229 if (get_stream () == 0)
1233 err = Pa_StartStream (stream);
1234 if (err != paNoError)
1236 error (
"audiorecorder: failed to start audio recording stream");
1242 audioplayer::get_stream (
void)
1248 audioplayer::stop (
void)
1250 if (get_stream () == 0)
1254 set_sample_number (0);
1255 reset_end_sample ();
1256 if (! Pa_IsStreamStopped (get_stream ()))
1258 err = Pa_AbortStream (get_stream ());
1259 if (err != paNoError)
1261 error (
"audioplayer: failed to stop audio playback stream");
1266 err = Pa_CloseStream (get_stream ());
1267 if (err != paNoError)
1269 error (
"audioplayer: failed to close audio playback stream");
1277 audioplayer::isplaying (
void)
1279 if (get_stream () == 0)
1283 err = Pa_IsStreamActive (stream);
1284 if (err != 0 && err != 1)
1286 error (
"audiorecorder: checking stream activity status failed");
1296 audiorecorder (
void);
1297 ~audiorecorder (
void);
1300 double player_value (
void)
const {
return 0; }
1301 virtual double scalar_value (
bool =
false)
const {
return 0; }
1302 void print (std::ostream& os,
bool pr_as_read_syntax =
false)
const;
1303 void print_raw (std::ostream& os,
bool pr_as_read_syntax)
const;
1307 bool is_defined (
void)
const {
return true; }
1311 void set_fs (
int fs);
1313 void set_nbits (
int nbits);
1314 int get_nbits (
void);
1315 void set_id (
int id);
1317 void set_channels (
int channels);
1318 int get_channels (
void);
1319 audio_type get_type (
void);
1321 void set_sample_number (
unsigned int sample);
1322 unsigned int get_sample_number (
void);
1323 unsigned int get_total_samples (
void);
1324 void set_end_sample (
unsigned int sample);
1325 unsigned int get_end_sample (
void);
1326 void reset_end_sample (
void);
1331 PaStream *get_stream (
void);
1334 audioplayer *getplayer (
void);
1335 bool isrecording (
void);
1336 audioplayer play (
void);
1338 void recordblocking (
float seconds);
1342 void append (
float sample_l,
float sample_r);
1351 unsigned int sample_number;
1352 unsigned int end_sample;
1356 std::vector<float>
left;
1357 std::vector<float> right;
1359 PaStreamParameters input_parameters;
1368 octave_record_callback (
const void *
input,
void *,
unsigned long frames,
1369 const PaStreamCallbackTimeInfo *,
1370 PaStreamCallbackFlags,
void *data)
1372 audiorecorder *recorder =
static_cast<audiorecorder *
> (data);
1376 error (
"audio recorder callback function called without player");
1380 int channels = recorder->get_channels ();
1382 Matrix sound (frames, 2);
1383 sound.
resize (frames, 2);
1385 if (recorder->get_nbits () == 8)
1387 static double scale_factor =
std::pow (2.0, 7) - 1.0;
1389 const int8_t *input8 =
static_cast<const int8_t *
> (
input);
1391 for (
unsigned long i = 0; i < frames; i++)
1393 float sample_l = input8[i*channels] / scale_factor;
1394 float sample_r = input8[i*channels + (channels - 1)] / scale_factor;
1396 sound(i,0) = sample_l;
1397 sound(i,1) = sample_r;
1400 else if (recorder->get_nbits () == 16)
1402 static double scale_factor =
std::pow (2.0, 15) - 1.0;
1404 const int16_t *input16 =
static_cast<const int16_t *
> (
input);
1406 for (
unsigned long i = 0; i < frames; i++)
1408 float sample_l = input16[i*channels] / scale_factor;
1409 float sample_r = input16[i*channels + (channels - 1)] / scale_factor;
1411 sound(i,0) = sample_l;
1412 sound(i,1) = sample_r;
1415 else if (recorder->get_nbits () == 24)
1417 static double scale_factor =
std::pow (2.0, 23);
1420 const uint8_t *input24 =
static_cast<const uint8_t *
> (
input);
1422 int32_t sample_l32 = 0, sample_r32 = 0;
1424 uint8_t *sample_l =
reinterpret_cast<uint8_t *
> (&sample_l32);
1425 uint8_t *sample_r =
reinterpret_cast<uint8_t *
> (&sample_r32);
1427 for (
unsigned long i = 0; i < frames; i++)
1429 for (
int j = 0; j < 3; j++)
1431 sample_l[j] = input24[i*channels*3 + j];
1432 sample_r[j] = input24[i*channels*3 + (channels - 1)*3 + j];
1435 if (sample_l32 & 0x00800000)
1436 sample_l32 |= 0xff000000;
1438 if (sample_r32 & 0x00800000)
1439 sample_r32 |= 0xff000000;
1441 sound(i,0) = sample_l32 / scale_factor;
1442 sound(i,1) = sample_r32 / scale_factor;
1447 =
feval (recorder->octave_callback_function,
ovl (sound), 1);
1449 return retval(0).int_value ();
1453 portaudio_record_callback (
const void *input,
void *,
unsigned long frames,
1454 const PaStreamCallbackTimeInfo *,
1455 PaStreamCallbackFlags,
void *data)
1457 audiorecorder *recorder =
static_cast<audiorecorder *
> (data);
1461 error (
"audio recorder callback function called without player");
1465 int channels = recorder->get_channels ();
1467 if (recorder->get_nbits () == 8)
1469 static float scale_factor =
std::pow (2.0
f, 7) - 1.0f;
1471 const int8_t *input8 =
static_cast<const int8_t *
> (
input);
1473 for (
unsigned long i = 0; i < frames; i++)
1475 float sample_l = input8[i*channels] / scale_factor;
1476 float sample_r = input8[i*channels + (channels - 1)] / scale_factor;
1478 recorder->append (sample_l, sample_r);
1481 else if (recorder->get_nbits () == 16)
1483 static float scale_factor =
std::pow (2.0
f, 15) - 1.0f;
1485 const int16_t *input16 =
static_cast<const int16_t *
> (
input);
1487 for (
unsigned long i = 0; i < frames; i++)
1489 float sample_l = input16[i*channels] / scale_factor;
1490 float sample_r = input16[i*channels + (channels - 1)] / scale_factor;
1492 recorder->append (sample_l, sample_r);
1495 else if (recorder->get_nbits () == 24)
1497 static float scale_factor =
std::pow (2.0
f, 23);
1500 const uint8_t *input24 =
static_cast<const uint8_t *
> (
input);
1502 int32_t sample_l32 = 0, sample_r32 = 0;
1504 uint8_t *sample_l =
reinterpret_cast<uint8_t *
> (&sample_l32);
1505 uint8_t *sample_r =
reinterpret_cast<uint8_t *
> (&sample_r32);
1507 for (
unsigned long i = 0; i < frames; i++)
1509 for (
int j = 0; j < 3; j++)
1511 sample_l[j] = input24[i*channels*3 + j];
1512 sample_r[j] = input24[i*channels*3 + (channels - 1)*3 + j];
1515 if (sample_l32 & 0x00800000)
1516 sample_l32 |= 0xff000000;
1518 if (sample_r32 & 0x00800000)
1519 sample_r32 |= 0xff000000;
1521 recorder->append (sample_l32 / scale_factor,
1522 sample_r32 / scale_factor);
1526 if (recorder->get_sample_number () >= recorder->get_end_sample ())
1533 safe_audiorecorder_stop (audiorecorder *recorder)
1538 audiorecorder::audiorecorder (
void)
1539 : octave_callback_function (0),
1540 id (-1), fs (44100), nbits (16), channels (2), sample_number (0),
1541 end_sample (-1), tag (
""), y (), userdata (
Matrix ()),
1542 left (), right (), stream (0), input_parameters (),
type ()
1545 audiorecorder::~audiorecorder (
void)
1549 warning (
"Octave:audio-interrupt",
1550 "interrupting recording audiorecorder");
1556 audiorecorder::print (std::ostream& os,
bool pr_as_read_syntax)
const
1558 print_raw (os, pr_as_read_syntax);
1563 audiorecorder::print_raw (std::ostream& os,
bool)
const
1569 audiorecorder::init (
void)
1571 if (Pa_Initialize () != paNoError)
1573 error (
"audiorecorder: initialization error!");
1577 if (Pa_GetDeviceCount () < 1)
1579 error (
"audiorecorder: no audio devices found or available!");
1583 int device = get_id ();
1586 device = Pa_GetDefaultInputDevice ();
1588 input_parameters.device = device;
1589 input_parameters.channelCount = get_channels ();
1590 input_parameters.sampleFormat = bits_to_format (get_nbits ());
1592 const PaDeviceInfo *device_info = Pa_GetDeviceInfo (device);
1595 warning (
"Octave:invalid-default-audio-device",
1596 "invalid default audio device ID = %d", device);
1598 input_parameters.suggestedLatency
1599 = device_info ? device_info->defaultHighInputLatency : -1;
1601 input_parameters.hostApiSpecificStreamInfo = 0;
1605 audiorecorder::set_fs (
int fs_arg)
1611 audiorecorder::get_fs (
void)
1617 audiorecorder::set_nbits (
int nbits_arg)
1623 audiorecorder::get_nbits (
void)
1629 audiorecorder::set_id (
int id_arg)
1635 audiorecorder::get_id (
void)
1641 audiorecorder::set_channels (
int channels_arg)
1643 assert (channels_arg == 1 || channels_arg == 2);
1644 channels = channels_arg;
1648 audiorecorder::get_channels (
void)
1654 audiorecorder::get_type (
void)
1660 audiorecorder::set_sample_number (
unsigned int sample_number_arg)
1662 sample_number = sample_number_arg;
1666 audiorecorder::get_sample_number (
void)
1668 return sample_number;
1672 audiorecorder::get_total_samples (
void)
1674 return left.size ();
1678 audiorecorder::set_end_sample (
unsigned int end_sample_arg)
1680 end_sample = end_sample_arg;
1684 audiorecorder::get_end_sample (
void)
1690 audiorecorder::reset_end_sample (
void)
1692 set_end_sample (
left.size ());
1696 audiorecorder::set_tag (
const charMatrix& tag_arg)
1702 audiorecorder::get_tag (
void)
1708 audiorecorder::set_userdata (
const octave_value& userdata_arg)
1710 userdata = userdata_arg;
1714 audiorecorder::get_userdata (
void)
1720 audiorecorder::getaudiodata (
void)
1724 for (
unsigned int i = 0; i <
left.size (); i++)
1726 audio(0,i) =
left[i];
1727 audio(1,i) = right[i];
1734 audiorecorder::getplayer (
void)
1736 audioplayer *player =
new audioplayer ();
1738 player->set_y (getaudiodata ());
1739 player->set_fs (get_fs ());
1740 player->set_nbits (get_nbits ());
1747 audiorecorder::isrecording (
void)
1749 if (get_stream () == 0)
1753 err = Pa_IsStreamActive (stream);
1754 if (err != 0 && err != 1)
1756 error (
"audiorecorder: checking stream activity status failed");
1764 audiorecorder::record (
void)
1772 const unsigned int buffer_size = get_fs () / 20;
1775 if (octave_callback_function != 0)
1777 err = Pa_OpenStream (&stream, &(input_parameters), 0,
1778 get_fs (), buffer_size, paClipOff,
1779 octave_record_callback,
this);
1783 err = Pa_OpenStream (&stream, &(input_parameters), 0,
1784 get_fs (), buffer_size, paClipOff,
1785 portaudio_record_callback,
this);
1787 if (err != paNoError)
1789 error (
"audiorecorder: unable to open audio recording stream");
1792 err = Pa_StartStream (stream);
1793 if (err != paNoError)
1795 error (
"audiorecorder: unable to start audio recording stream");
1801 audiorecorder::recordblocking (
float seconds)
1809 const unsigned int buffer_size = get_fs () / 20;
1813 err = Pa_OpenStream (&stream, &(input_parameters), 0,
1814 get_fs (), buffer_size, paClipOff, 0,
this);
1815 if (err != paNoError)
1817 error (
"audiorecorder: unable to open audio recording stream");
1821 err = Pa_StartStream (stream);
1822 if (err != paNoError)
1824 error (
"audiorecorder: unable to start audio recording stream");
1828 unsigned int frames = seconds * get_fs ();
1832 frame.
add_fcn (safe_audiorecorder_stop,
this);
1834 for (
unsigned int i = 0; i < frames; i += buffer_size)
1837 Pa_ReadStream (get_stream (), buffer, buffer_size);
1839 if (octave_callback_function != 0)
1840 octave_record_callback (buffer, 0, buffer_size, 0, 0,
this);
1842 portaudio_record_callback (buffer, 0, buffer_size, 0, 0,
this);
1847 audiorecorder::pause (
void)
1849 if (get_stream () == 0)
1853 err = Pa_StopStream (stream);
1854 if (err != paNoError)
1856 error (
"audiorecorder: unable to stop audio recording stream");
1862 audiorecorder::resume (
void)
1864 if (get_stream () == 0)
1868 err = Pa_StartStream (stream);
1869 if (err != paNoError)
1871 error (
"audiorecorder: unable to start audio recording stream");
1877 audiorecorder::stop (
void)
1879 if (get_stream () == 0)
1883 if (! Pa_IsStreamStopped (get_stream ()))
1885 err = Pa_AbortStream (get_stream ());
1886 if (err != paNoError)
1888 error (
"audioplayer: unable to stop audio playback stream");
1893 err = Pa_CloseStream (stream);
1894 if (err != paNoError)
1896 error (
"audiorecorder: unable to close audio recording stream");
1900 set_sample_number (0);
1901 reset_end_sample ();
1906 audiorecorder::append (
float sample_l,
float sample_r)
1908 left.push_back (sample_l);
1909 right.push_back (sample_r);
1910 set_sample_number (get_sample_number () + 1);
1914 audiorecorder::get_stream (
void)
1921 DEFUN_DLD (__recorder_audiorecorder__, args, ,
1923 @deftypefn {Loadable Function} {@var{recorder} =} __recorder_audiorecorder__ (@var{fs}, @var{nbits}, @var{channels})\n\
1924 @deftypefnx {Loadable Function} {@var{recorder} =} __recorder_audiorecorder__ (@var{fs}, @var{nbits}, @var{channels}, @var{id})\n\
1925 @deftypefnx {Loadable Function} {@var{recorder} =} __recorder_audiorecorder__ (@var{fcn}, @dots{})\n\
1926 Undocumented internal function.\n\
1931 #ifdef HAVE_PORTAUDIO
1933 int nargin = args.
length ();
1935 audiorecorder* recorder =
new audiorecorder ();
1941 bool is_function = (args(0).is_string () || args(0).is_function_handle ()
1942 || args(0).is_inline_function ());
1946 error (
"audioplayer: callbacks not yet implemented");
1954 switch (nargin - offset)
1957 recorder->set_fs (args(0 + offset).int_value ());
1958 recorder->set_nbits (args(1 + offset).int_value ());
1959 recorder->set_channels (args(2 + offset).int_value ());
1963 recorder->set_fs (args(0 + offset).int_value ());
1964 recorder->set_nbits (args(1 + offset).int_value ());
1965 recorder->set_channels (args(2 + offset).int_value ());
1966 recorder->set_id (args(3 + offset).int_value ());
1976 error (
"portaudio not found on your system and thus audio functionality is not present");
1983 #ifdef HAVE_PORTAUDIO
1985 static audiorecorder *
1992 return dynamic_cast<audiorecorder *
> (ncrep);
1997 DEFUN_DLD (__recorder_getaudiodata__, args, ,
1999 @deftypefn {Loadable Function} {@var{data}} __recorder_getaudiodata__ (@var{recorder})\n\
2000 Undocumented internal function.\n\
2005 #ifdef HAVE_PORTAUDIO
2007 audiorecorder *recorder = get_recorder (args(0));
2015 retval = recorder->getaudiodata ();
2019 error (
"portaudio not found on your system and thus audio functionality is not present");
2026 DEFUN_DLD (__recorder_get_channels__, args, ,
2028 @deftypefn {Loadable Function} {@var{n} =} __recorder_get_channels__ (@var{recorder})\n\
2029 Undocumented internal function.\n\
2034 #ifdef HAVE_PORTAUDIO
2036 if (args.length () == 1)
2038 audiorecorder *recorder = get_recorder (args(0));
2046 retval = recorder->get_channels ();
2051 error (
"portaudio not found on your system and thus audio functionality is not present");
2060 @deftypefn {Loadable Function} {@var{fs} =} __recorder_get_fs__ (@var{recorder})\n\
2061 Undocumented internal function.\n\
2066 #ifdef HAVE_PORTAUDIO
2068 if (args.length () == 1)
2070 audiorecorder *recorder = get_recorder (args(0));
2078 retval = recorder->get_fs ();
2083 error (
"portaudio not found on your system and thus audio functionality is not present");
2092 @deftypefn {Loadable Function} {@var{id} =} __recorder_get_id__ (@var{recorder})\n\
2093 Undocumented internal function.\n\
2098 #ifdef HAVE_PORTAUDIO
2100 if (args.length () == 1)
2102 audiorecorder *recorder = get_recorder (args(0));
2110 retval = recorder->get_id ();
2115 error (
"portaudio not found on your system and thus audio functionality is not present");
2122 DEFUN_DLD (__recorder_get_nbits__, args, ,
2124 @deftypefn {Loadable Function} {@var{nbits} =} __recorder_get_nbits__ (@var{recorder})\n\
2125 Undocumented internal function.\n\
2130 #ifdef HAVE_PORTAUDIO
2132 if (args.length () == 1)
2134 audiorecorder *recorder = get_recorder (args(0));
2142 retval = recorder->get_nbits ();
2147 error (
"portaudio not found on your system and thus audio functionality is not present");
2154 DEFUN_DLD (__recorder_get_sample_number__, args, ,
2156 @deftypefn {Loadable Function} {@var{n} =} __recorder_get_sample_number__ (@var{recorder})\n\
2157 Undocumented internal function.\n\
2162 #ifdef HAVE_PORTAUDIO
2164 if (args.length () == 1)
2166 audiorecorder *recorder = get_recorder (args(0));
2174 retval = recorder->get_sample_number ();
2179 error (
"portaudio not found on your system and thus audio functionality is not present");
2186 DEFUN_DLD (__recorder_get_tag__, args, ,
2188 @deftypefn {Loadable Function} {@var{tag} =} __recorder_get_tag__ (@var{recorder})\n\
2189 Undocumented internal function.\n\
2194 #ifdef HAVE_PORTAUDIO
2196 if (args.length () == 1)
2198 audiorecorder *recorder = get_recorder (args(0));
2206 retval = recorder->get_tag ();
2211 error (
"portaudio not found on your system and thus audio functionality is not present");
2218 DEFUN_DLD (__recorder_get_total_samples__, args, ,
2220 @deftypefn {Loadable Function} {@var{n} =} __recorder_get_total_samples__ (@var{recorder})\n\
2221 Undocumented internal function.\n\
2226 #ifdef HAVE_PORTAUDIO
2228 if (args.length () == 1)
2230 audiorecorder *recorder = get_recorder (args(0));
2238 retval = recorder->get_total_samples ();
2243 error (
"portaudio not found on your system and thus audio functionality is not present");
2250 DEFUN_DLD (__recorder_get_userdata__, args, ,
2252 @deftypefn {Loadable Function} {@var{data} =} __recorder_get_userdata__ (@var{recorder})\n\
2253 Undocumented internal function.\n\
2258 #ifdef HAVE_PORTAUDIO
2260 if (args.length () == 1)
2262 audiorecorder *recorder = get_recorder (args(0));
2270 retval = recorder->get_userdata ();
2275 error (
"portaudio not found on your system and thus audio functionality is not present");
2282 DEFUN_DLD (__recorder_isrecording__, args, ,
2284 @deftypefn {Loadable Function} {} __recorder_isrecording__ (@var{recorder})\n\
2285 Undocumented internal function.\n\
2290 #ifdef HAVE_PORTAUDIO
2292 if (args.length () == 1)
2294 audiorecorder *recorder = get_recorder (args(0));
2302 retval = recorder->isrecording () ?
true :
false;
2307 error (
"portaudio not found on your system and thus audio functionality is not present");
2316 @deftypefn {Loadable Function} {} __recorder_pause__ (@var{recorder})\n\
2317 Undocumented internal function.\n\
2322 #ifdef HAVE_PORTAUDIO
2324 if (args.length () == 1)
2326 audiorecorder *recorder = get_recorder (args(0));
2339 error (
"portaudio not found on your system and thus audio functionality is not present");
2346 DEFUN_DLD (__recorder_recordblocking__, args, ,
2348 @deftypefn {Loadable Function} {} __recorder_recordblocking__ (@var{recorder}, @var{seconds})\n\
2349 Undocumented internal function.\n\
2354 #ifdef HAVE_PORTAUDIO
2356 audiorecorder *recorder = get_recorder (args(0));
2364 recorder->recordblocking (args(1).float_value ());
2368 error (
"portaudio not found on your system and thus audio functionality is not present");
2377 @deftypefn {Loadable Function} {} __recorder_record__ (@var{recorder})\n\
2378 @deftypefnx {Loadable Function} {} __recorder_record__ (@var{recorder}, @var{seconds})\n\
2379 Undocumented internal function.\n\
2384 #ifdef HAVE_PORTAUDIO
2386 audiorecorder *recorder = get_recorder (args(0));
2394 if (args.length () == 1)
2395 recorder->record ();
2396 else if (args.length () == 2)
2398 recorder->set_end_sample (args(1).int_value () * recorder->get_fs ());
2399 recorder->record ();
2402 error (
"audiorecorder: wrong number of arguments passed to record");
2406 error (
"portaudio not found on your system and thus audio functionality is not present");
2415 @deftypefn {Loadable Function} {} __recorder_resume__ (@var{recorder})\n\
2416 Undocumented internal function.\n\
2421 #ifdef HAVE_PORTAUDIO
2423 if (args.length () == 1)
2425 audiorecorder *recorder = get_recorder (args(0));
2433 recorder->resume ();
2438 error (
"portaudio not found on your system and thus audio functionality is not present");
2447 @deftypefn {Loadable Function} {} __recorder_set_fs__ (@var{recorder}, @var{fs})\n\
2448 Undocumented internal function.\n\
2453 #ifdef HAVE_PORTAUDIO
2455 if (args.length () == 2)
2457 audiorecorder *recorder = get_recorder (args(0));
2465 recorder->set_fs (args(1).int_value ());
2470 error (
"portaudio not found on your system and thus audio functionality is not present");
2477 DEFUN_DLD (__recorder_set_tag__, args, ,
2479 @deftypefn {Loadable Function} {} __recorder_set_tag__ (@var{recorder}, @var{tag})\n\
2480 Undocumented internal function.\n\
2485 #ifdef HAVE_PORTAUDIO
2487 if (args.length () == 2)
2489 audiorecorder *recorder = get_recorder (args(0));
2497 recorder->set_tag (args(1).char_matrix_value ());
2502 error (
"portaudio not found on your system and thus audio functionality is not present");
2509 DEFUN_DLD (__recorder_set_userdata__, args, ,
2511 @deftypefn {Loadable Function} {} __recorder_set_userdata__ (@var{recorder}, @var{data})\n\
2512 Undocumented internal function.\n\
2517 #ifdef HAVE_PORTAUDIO
2519 if (args.length () == 2)
2521 audiorecorder *recorder = get_recorder (args(0));
2529 recorder->set_userdata (args(1));
2534 error (
"portaudio not found on your system and thus audio functionality is not present");
2543 @deftypefn {Loadable Function} {} __recorder_stop__ (@var{recorder})\n\
2544 Undocumented internal function.\n\
2549 #ifdef HAVE_PORTAUDIO
2551 audiorecorder *recorder = get_recorder (args(0));
2563 error (
"portaudio not found on your system and thus audio functionality is not present");
2570 DEFUN_DLD (__player_audioplayer__, args, ,
2572 @deftypefn {Loadable Function} {@var{player} =} __player_audioplayer__ (@var{y}, @var{fs})\n\
2573 @deftypefnx {Loadable Function} {@var{player} =} __player_audioplayer__ (@var{y}, @var{fs}, @var{nbits})\n\
2574 @deftypefnx {Loadable Function} {@var{player} =} __player_audioplayer__ (@var{y}, @var{fs}, @var{nbits}, @var{id})\n\
2575 Undocumented internal function.\n\
2580 #ifdef HAVE_PORTAUDIO
2582 int nargin = args.
length ();
2584 if (nargin < 2 || nargin > 4)
2590 audioplayer* recorder =
new audioplayer ();
2598 bool is_function = (args(0).is_string () || args(0).is_function_handle ()
2599 || args(0).is_inline_function ());
2603 error (
"audioplayer: callbacks not yet implemented");
2609 recorder->set_y (args(0));
2611 recorder->set_fs (args(1).int_value ());
2616 recorder->set_nbits (args(2).int_value ());
2620 recorder->set_nbits (args(2).int_value ());
2621 recorder->set_id (args(3).int_value ());
2626 recorder->init_fn ();
2634 error (
"portaudio not found on your system and thus audio functionality is not present");
2641 #ifdef HAVE_PORTAUDIO
2643 static audioplayer *
2650 return dynamic_cast<audioplayer *
> (ncrep);
2655 DEFUN_DLD (__player_get_channels__, args, ,
2657 @deftypefn {Loadable Function} {@var{n} =} __player_get_channels__ (@var{player})\n\
2658 Undocumented internal function.\n\
2663 #ifdef HAVE_PORTAUDIO
2665 if (args.length () == 1)
2667 audioplayer *player = get_player (args(0));
2675 retval = player->get_channels ();
2680 error (
"portaudio not found on your system and thus audio functionality is not present");
2689 @deftypefn {Loadable Function} {@var{fs} =} __player_get_fs__ (@var{player})\n\
2690 Undocumented internal function.\n\
2695 #ifdef HAVE_PORTAUDIO
2697 if (args.length () == 1)
2699 audioplayer *player = get_player (args(0));
2707 retval = player->get_fs ();
2712 error (
"portaudio not found on your system and thus audio functionality is not present");
2721 @deftypefn {Loadable Function} {@var{id} =} __player_get_id__ (@var{player})\n\
2722 Undocumented internal function.\n\
2727 #ifdef HAVE_PORTAUDIO
2729 if (args.length () == 1)
2731 audioplayer *player = get_player (args(0));
2739 retval = player->get_id ();
2744 error (
"portaudio not found on your system and thus audio functionality is not present");
2751 DEFUN_DLD (__player_get_nbits__, args, ,
2753 @deftypefn {Loadable Function} {@var{nbits} =} __player_get_nbits__ (@var{player})\n\
2754 Undocumented internal function.\n\
2759 #ifdef HAVE_PORTAUDIO
2761 if (args.length () == 1)
2763 audioplayer *player = get_player (args(0));
2771 retval = player->get_nbits ();
2776 error (
"portaudio not found on your system and thus audio functionality is not present");
2783 DEFUN_DLD (__player_get_sample_number__, args, ,
2785 @deftypefn {Loadable Function} {@var{n} =} __player_get_sample_number__ (@var{player})\n\
2786 Undocumented internal function.\n\
2791 #ifdef HAVE_PORTAUDIO
2793 if (args.length () == 1)
2795 audioplayer *player = get_player (args(0));
2803 retval = player->get_sample_number ();
2808 error (
"portaudio not found on your system and thus audio functionality is not present");
2817 @deftypefn {Loadable Function} {@var{tag} =} __player_get_tag__ (@var{player})\n\
2818 Undocumented internal function.\n\
2823 #ifdef HAVE_PORTAUDIO
2825 if (args.length () == 1)
2827 audioplayer *player = get_player (args(0));
2835 retval = player->get_tag ();
2840 error (
"portaudio not found on your system and thus audio functionality is not present");
2847 DEFUN_DLD (__player_get_total_samples__, args, ,
2849 @deftypefn {Loadable Function} {@var{n} =} __player_get_total_samples__ (@var{player})\n\
2850 Undocumented internal function.\n\
2855 #ifdef HAVE_PORTAUDIO
2857 if (args.length () == 1)
2859 audioplayer *player = get_player (args(0));
2867 retval = player->get_total_samples ();
2872 error (
"portaudio not found on your system and thus audio functionality is not present");
2879 DEFUN_DLD (__player_get_userdata__, args, ,
2881 @deftypefn {Loadable Function} {@var{data} =} __player_get_userdata__ (@var{player})\n\
2882 Undocumented internal function.\n\
2887 #ifdef HAVE_PORTAUDIO
2889 if (args.length () == 1)
2891 audioplayer *player = get_player (args(0));
2899 retval = player->get_userdata ();
2904 error (
"portaudio not found on your system and thus audio functionality is not present");
2911 DEFUN_DLD (__player_isplaying__, args, ,
2913 @deftypefn {Loadable Function} {} __player_isplaying__ (@var{player})\n\
2914 Undocumented internal function.\n\
2919 #ifdef HAVE_PORTAUDIO
2921 if (args.length () == 1)
2923 audioplayer *player = get_player (args(0));
2931 retval = player->isplaying () ?
true :
false;
2936 error (
"portaudio not found on your system and thus audio functionality is not present");
2945 @deftypefn {Loadable Function} {} __player_pause__ (@var{player})\n\
2946 Undocumented internal function.\n\
2951 #ifdef HAVE_PORTAUDIO
2953 if (args.length () == 1)
2955 audioplayer *player = get_player (args(0));
2968 error (
"portaudio not found on your system and thus audio functionality is not present");
2975 DEFUN_DLD (__player_playblocking__, args, ,
2977 @deftypefn {Loadable Function} {} __player_playblocking__ (@var{player})\n\
2978 @deftypefnx {Loadable Function} {} __player_playblocking__ (@var{player}, @var{start})\n\
2979 @deftypefnx {Loadable Function} {} __player_playblocking__ (@var{player}, [@var{start}, @var{end}])\n\
2980 Undocumented internal function.\n\
2985 #ifdef HAVE_PORTAUDIO
2987 audioplayer *player = get_player (args(0));
2995 if (args.length () == 1)
2996 player->playblocking ();
2999 if (args(1).is_matrix_type ())
3001 RowVector range = args(1).row_vector_value ();
3003 unsigned int start = range.
elem (0) - 1;
3004 unsigned int end = range.
elem (1) - 1;
3006 if (start > player->get_total_samples ()
3007 || start > end || end > player->get_total_samples ())
3009 error (
"audioplayer: invalid range specified for playback");
3013 player->set_sample_number (start);
3014 player->set_end_sample (end);
3018 unsigned int start = args(1).int_value () - 1;
3020 if (start > player->get_total_samples ())
3022 error (
"audioplayer: invalid range specified for playback");
3026 player->set_sample_number (start);
3029 player->playblocking ();
3034 error (
"portaudio not found on your system and thus audio functionality is not present");
3043 @deftypefn {Loadable Function} {} __player_play__ (@var{player})\n\
3044 @deftypefnx {Loadable Function} {} __player_play__ (@var{player}, @var{start})\n\
3045 @deftypefnx {Loadable Function} {} __player_play__ (@var{player}, [@var{start}, @var{end}])\n\
3046 Undocumented internal function.\n\
3051 #ifdef HAVE_PORTAUDIO
3053 if (args.length () == 1)
3055 audioplayer *player = get_player (args(0));
3067 audioplayer *player = get_player (args(0));
3069 if (args(1).is_matrix_type ())
3071 RowVector range = args(1).row_vector_value ();
3073 unsigned int start = range.
elem (0) - 1;
3074 unsigned int end = range.
elem (1) - 1;
3076 if (start > player->get_total_samples ()
3077 || start > end || end > player->get_total_samples ())
3079 error (
"audioplayer: invalid range specified for playback");
3083 player->set_sample_number (start);
3084 player->set_end_sample (end);
3088 unsigned int start = args(1).int_value () - 1;
3090 if (start > player->get_total_samples ())
3092 error (
"audioplayer: invalid range specified for playback");
3096 player->set_sample_number (start);
3104 error (
"portaudio not found on your system and thus audio functionality is not present");
3113 @deftypefn {Loadable Function} {} __player_resume__ (@var{player})\n\
3114 Undocumented internal function.\n\
3119 #ifdef HAVE_PORTAUDIO
3121 if (args.length () == 1)
3123 audioplayer *player = get_player (args(0));
3136 error (
"portaudio not found on your system and thus audio functionality is not present");
3145 @deftypefn {Loadable Function} {} __player_set_fs__ (@var{player}, @var{fs})\n\
3146 Undocumented internal function.\n\
3151 #ifdef HAVE_PORTAUDIO
3153 if (args.length () == 2)
3155 audioplayer *player = get_player (args(0));
3163 player->set_fs (args(1).int_value ());
3168 error (
"portaudio not found on your system and thus audio functionality is not present");
3177 @deftypefn {Loadable Function} {} __player_set_tag__ (@var{player}, @var{tag})\n\
3178 Undocumented internal function.\n\
3183 #ifdef HAVE_PORTAUDIO
3185 if (args.length () == 2)
3187 audioplayer *player = get_player (args(0));
3195 player->set_tag (args(1).char_matrix_value ());
3200 error (
"portaudio not found on your system and thus audio functionality is not present");
3207 DEFUN_DLD (__player_set_userdata__, args, ,
3209 @deftypefn {Loadable Function} {} __player_set_userdata__ (@var{player}, @var{data})\n\
3210 Undocumented internal function.\n\
3215 #ifdef HAVE_PORTAUDIO
3217 if (args.length () == 2)
3219 audioplayer *player = get_player (args(0));
3227 player->set_userdata (args(1));
3232 error (
"portaudio not found on your system and thus audio functionality is not present");
3241 @deftypefn {Loadable Function} {} __player_stop__ (@var{player})\n\
3242 Undocumented internal function.\n\
3247 #ifdef HAVE_PORTAUDIO
3249 if (args.length () == 1)
3251 audioplayer *player = get_player (args (0));
3264 error (
"portaudio not found on your system and thus audio functionality is not present");
void resize(octave_idx_type nr, octave_idx_type nc, double rfv=0)
OCTINTERP_API void print_usage(void)
octave_idx_type length(void) const
int int_value(bool req_int=false, bool frc_str_conv=false) const
virtual double scalar_value(bool frc_str_conv=false) const
void error(const char *fmt,...)
bool is_int8_type(void) const
octave_value_list feval(const std::string &name, const octave_value_list &args, int nargout)
void setfield(const std::string &key, const octave_value &val)
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
T & elem(octave_idx_type n)
octave_idx_type rows(void) const
virtual void print(std::ostream &os, bool pr_as_read_syntax=false)
#define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
F77_RET_T const double const double * f
void add_fcn(void(*fcn)(void))
const T * data(void) const
octave_int< T > pow(const octave_int< T > &a, const octave_int< T > &b)
Matrix transpose(void) const
virtual bool print_as_scalar(void) const
static bool words_big_endian(void)
octave_idx_type length(void) const
Matrix matrix_value(bool frc_str_conv=false) const
virtual bool is_defined(void) const
void setfield(const std::string &key, const Cell &val)
bool is_int16_type(void) const
void warning(const char *fmt,...)
virtual bool is_constant(void) const
octave_value_list ovl(const octave_value &a0)
bool is_uint8_type(void) const
const octave_base_value & get_rep(void) const
ColumnVector column(octave_idx_type i) const
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
static int input(yyscan_t yyscanner)
virtual void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
#define DEFUN_DLD(name, args_name, nargout_name, doc)
octave_idx_type columns(void) const