Mercurial > octave-nkf
comparison libinterp/dldfcn/audiodevinfo.cc @ 19607:2aaf6077eb3c
avoid dereferencing null pointers in audio functions
* audiodevinfo.cc: Check values returned from portaudio functions to
avoid dereferencing null pointers.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 13 Jan 2015 22:33:02 -0500 |
parents | 72304a4e010a |
children | 47d778e6a518 |
comparison
equal
deleted
inserted
replaced
19605:72304a4e010a | 19607:2aaf6077eb3c |
---|---|
126 octave_idx_type numinput = 0, numoutput = 0; | 126 octave_idx_type numinput = 0, numoutput = 0; |
127 for (int i = 0; i < num_devices; i++) | 127 for (int i = 0; i < num_devices; i++) |
128 { | 128 { |
129 const PaDeviceInfo *device_info = Pa_GetDeviceInfo (i); | 129 const PaDeviceInfo *device_info = Pa_GetDeviceInfo (i); |
130 | 130 |
131 if (! device_info) | |
132 { | |
133 warning ("Octave:invalid-audio-device", | |
134 "invalid audio device ID = %d", i); | |
135 continue; | |
136 } | |
137 | |
131 if (device_info->maxInputChannels != 0) | 138 if (device_info->maxInputChannels != 0) |
132 numinput++; | 139 numinput++; |
133 | 140 |
134 if (device_info->maxOutputChannels != 0) | 141 if (device_info->maxOutputChannels != 0) |
135 numoutput++; | 142 numoutput++; |
144 | 151 |
145 octave_idx_type idx_i = 0, idx_o = 0; | 152 octave_idx_type idx_i = 0, idx_o = 0; |
146 for (int i = 0; i < num_devices; i++) | 153 for (int i = 0; i < num_devices; i++) |
147 { | 154 { |
148 const PaDeviceInfo *device_info = Pa_GetDeviceInfo (i); | 155 const PaDeviceInfo *device_info = Pa_GetDeviceInfo (i); |
149 const char *driver; | 156 |
157 if (! device_info) | |
158 { | |
159 warning ("Octave:invalid-audio-device", | |
160 "invalid audio device ID = %d", i); | |
161 continue; | |
162 } | |
163 | |
164 const PaHostApiInfo *api_info = Pa_GetHostApiInfo (device_info->hostApi); | |
165 | |
166 const char *driver = api_info ? api_info->name : ""; | |
167 | |
150 char name[128]; | 168 char name[128]; |
151 driver = Pa_GetHostApiInfo (device_info->hostApi)->name; | |
152 sprintf (name, "%s (%s)", device_info->name, driver); | 169 sprintf (name, "%s (%s)", device_info->name, driver); |
153 | 170 |
154 if (device_info->maxInputChannels != 0) | 171 if (device_info->maxInputChannels != 0) |
155 { | 172 { |
156 input_name(idx_i) = name; | 173 input_name(idx_i) = name; |
292 { | 309 { |
293 error ("audiodevinfo: no such bits per sample format"); | 310 error ("audiodevinfo: no such bits per sample format"); |
294 return retval; | 311 return retval; |
295 } | 312 } |
296 | 313 |
314 const PaDeviceInfo *device_info = Pa_GetDeviceInfo (i); | |
315 | |
316 if (! device_info) | |
317 { | |
318 warning ("Octave:invalid-audio-device", | |
319 "invalid audio device ID = %d", i); | |
320 continue; | |
321 } | |
322 | |
297 stream_parameters.suggestedLatency | 323 stream_parameters.suggestedLatency |
298 = Pa_GetDeviceInfo (i)->defaultLowInputLatency; | 324 = device_info->defaultLowInputLatency; |
325 | |
299 stream_parameters.hostApiSpecificStreamInfo = 0; | 326 stream_parameters.hostApiSpecificStreamInfo = 0; |
300 | 327 |
301 if (io == 0) | 328 if (io == 0) |
302 { | 329 { |
303 if (Pa_GetDeviceInfo (i)->maxOutputChannels < chans) | 330 if (device_info->maxOutputChannels < chans) |
304 continue; | 331 continue; |
305 | 332 |
306 err = Pa_IsFormatSupported (0, &stream_parameters, rate); | 333 err = Pa_IsFormatSupported (0, &stream_parameters, rate); |
307 | 334 |
308 if (err == paFormatIsSupported) | 335 if (err == paFormatIsSupported) |
311 return retval; | 338 return retval; |
312 } | 339 } |
313 } | 340 } |
314 else if (io == 1) | 341 else if (io == 1) |
315 { | 342 { |
316 if (Pa_GetDeviceInfo (i)->maxInputChannels < chans) | 343 if (device_info->maxInputChannels < chans) |
317 continue; | 344 continue; |
318 | 345 |
319 err = Pa_IsFormatSupported (&stream_parameters, 0, rate); | 346 err = Pa_IsFormatSupported (&stream_parameters, 0, rate); |
320 if (err == paFormatIsSupported) | 347 if (err == paFormatIsSupported) |
321 { | 348 { |
343 else | 370 else |
344 { | 371 { |
345 error ("audiodevinfo: no such bits per sample format"); | 372 error ("audiodevinfo: no such bits per sample format"); |
346 return retval; | 373 return retval; |
347 } | 374 } |
348 stream_parameters.suggestedLatency = | 375 |
349 Pa_GetDeviceInfo (id)->defaultLowInputLatency; | 376 const PaDeviceInfo *device_info = Pa_GetDeviceInfo (id); |
377 | |
378 if (! device_info) | |
379 { | |
380 error ("invalid audio device ID = %d", id); | |
381 return retval; | |
382 } | |
383 | |
384 stream_parameters.suggestedLatency | |
385 = device_info->defaultLowInputLatency; | |
386 | |
350 stream_parameters.hostApiSpecificStreamInfo = 0; | 387 stream_parameters.hostApiSpecificStreamInfo = 0; |
351 if (io == 0) | 388 if (io == 0) |
352 { | 389 { |
353 if (Pa_GetDeviceInfo (id)->maxOutputChannels < chans) | 390 if (device_info->maxOutputChannels < chans) |
354 { | 391 { |
355 retval = 0; | 392 retval = 0; |
356 return retval; | 393 return retval; |
357 } | 394 } |
358 err = Pa_IsFormatSupported (0, &stream_parameters, rate); | 395 err = Pa_IsFormatSupported (0, &stream_parameters, rate); |
362 return retval; | 399 return retval; |
363 } | 400 } |
364 } | 401 } |
365 else if (io == 1) | 402 else if (io == 1) |
366 { | 403 { |
367 if (Pa_GetDeviceInfo (id)->maxInputChannels < chans) | 404 if (device_info->maxInputChannels < chans) |
368 { | 405 { |
369 retval = 0; | 406 retval = 0; |
370 return retval; | 407 return retval; |
371 } | 408 } |
372 err = Pa_IsFormatSupported (&stream_parameters, 0, rate); | 409 err = Pa_IsFormatSupported (&stream_parameters, 0, rate); |
862 device = Pa_GetDefaultOutputDevice (); | 899 device = Pa_GetDefaultOutputDevice (); |
863 | 900 |
864 output_parameters.device = device; | 901 output_parameters.device = device; |
865 output_parameters.channelCount = 2; | 902 output_parameters.channelCount = 2; |
866 output_parameters.sampleFormat = bits_to_format (get_nbits ()); | 903 output_parameters.sampleFormat = bits_to_format (get_nbits ()); |
867 output_parameters.suggestedLatency = | 904 |
868 Pa_GetDeviceInfo (device)->defaultHighOutputLatency; | 905 const PaDeviceInfo *device_info = Pa_GetDeviceInfo (device); |
906 | |
907 if (! device_info) | |
908 warning ("Octave:invalid-default-audio-device", | |
909 "invalid default audio device ID = %d", device); | |
910 | |
911 output_parameters.suggestedLatency | |
912 = device_info ? device_info->defaultHighOutputLatency : -1; | |
913 | |
869 output_parameters.hostApiSpecificStreamInfo = 0; | 914 output_parameters.hostApiSpecificStreamInfo = 0; |
870 } | 915 } |
871 | 916 |
872 void | 917 void |
873 audioplayer::init (void) | 918 audioplayer::init (void) |
905 else if (type == TYPE_UINT8) | 950 else if (type == TYPE_UINT8) |
906 output_parameters.sampleFormat = paUInt8; | 951 output_parameters.sampleFormat = paUInt8; |
907 else if (type == TYPE_UINT16) | 952 else if (type == TYPE_UINT16) |
908 output_parameters.sampleFormat = paInt16; | 953 output_parameters.sampleFormat = paInt16; |
909 | 954 |
910 output_parameters.suggestedLatency = | 955 const PaDeviceInfo *device_info = Pa_GetDeviceInfo (device); |
911 Pa_GetDeviceInfo (device)->defaultHighOutputLatency; | 956 |
957 if (! device_info) | |
958 warning ("Octave:invalid-default-audio-device", | |
959 "invalid default audio device ID = %d", device); | |
960 | |
961 output_parameters.suggestedLatency | |
962 = device_info ? device_info->defaultHighOutputLatency : -1; | |
963 | |
912 output_parameters.hostApiSpecificStreamInfo = 0; | 964 output_parameters.hostApiSpecificStreamInfo = 0; |
913 } | 965 } |
914 | 966 |
915 void | 967 void |
916 audioplayer::set_y (const octave_value& y_arg) | 968 audioplayer::set_y (const octave_value& y_arg) |
1319 octave_record_callback (const void *input, void *, unsigned long frames, | 1371 octave_record_callback (const void *input, void *, unsigned long frames, |
1320 const PaStreamCallbackTimeInfo *, | 1372 const PaStreamCallbackTimeInfo *, |
1321 PaStreamCallbackFlags, void *data) | 1373 PaStreamCallbackFlags, void *data) |
1322 { | 1374 { |
1323 audiorecorder *recorder = static_cast<audiorecorder *> (data); | 1375 audiorecorder *recorder = static_cast<audiorecorder *> (data); |
1376 | |
1377 if (! recorder) | |
1378 { | |
1379 error ("audio recorder callback function called without player"); | |
1380 return paAbort; | |
1381 } | |
1382 | |
1324 int channels = recorder->get_channels (); | 1383 int channels = recorder->get_channels (); |
1325 | 1384 |
1326 Matrix sound (frames, 2); | 1385 Matrix sound (frames, 2); |
1327 sound.resize (frames, 2); | 1386 sound.resize (frames, 2); |
1328 | 1387 |
1397 portaudio_record_callback (const void *input, void *, unsigned long frames, | 1456 portaudio_record_callback (const void *input, void *, unsigned long frames, |
1398 const PaStreamCallbackTimeInfo *, | 1457 const PaStreamCallbackTimeInfo *, |
1399 PaStreamCallbackFlags, void *data) | 1458 PaStreamCallbackFlags, void *data) |
1400 { | 1459 { |
1401 audiorecorder *recorder = static_cast<audiorecorder *> (data); | 1460 audiorecorder *recorder = static_cast<audiorecorder *> (data); |
1461 | |
1462 if (! recorder) | |
1463 { | |
1464 error ("audio recorder callback function called without player"); | |
1465 return paAbort; | |
1466 } | |
1402 | 1467 |
1403 int channels = recorder->get_channels (); | 1468 int channels = recorder->get_channels (); |
1404 | 1469 |
1405 if (recorder->get_nbits () == 8) | 1470 if (recorder->get_nbits () == 8) |
1406 { | 1471 { |
1508 device = Pa_GetDefaultInputDevice (); | 1573 device = Pa_GetDefaultInputDevice (); |
1509 | 1574 |
1510 input_parameters.device = device; | 1575 input_parameters.device = device; |
1511 input_parameters.channelCount = get_channels (); | 1576 input_parameters.channelCount = get_channels (); |
1512 input_parameters.sampleFormat = bits_to_format (get_nbits ()); | 1577 input_parameters.sampleFormat = bits_to_format (get_nbits ()); |
1513 input_parameters.suggestedLatency = | 1578 |
1514 Pa_GetDeviceInfo (device)->defaultHighInputLatency; | 1579 const PaDeviceInfo *device_info = Pa_GetDeviceInfo (device); |
1580 | |
1581 if (! device_info) | |
1582 warning ("Octave:invalid-default-audio-device", | |
1583 "invalid default audio device ID = %d", device); | |
1584 | |
1585 input_parameters.suggestedLatency | |
1586 = device_info ? device_info->defaultHighInputLatency : -1; | |
1587 | |
1515 input_parameters.hostApiSpecificStreamInfo = 0; | 1588 input_parameters.hostApiSpecificStreamInfo = 0; |
1516 } | 1589 } |
1517 | 1590 |
1518 void | 1591 void |
1519 audiorecorder::set_fs (int fs_arg) | 1592 audiorecorder::set_fs (int fs_arg) |
1905 octave_value retval; | 1978 octave_value retval; |
1906 | 1979 |
1907 #ifdef HAVE_PORTAUDIO | 1980 #ifdef HAVE_PORTAUDIO |
1908 | 1981 |
1909 audiorecorder *recorder = get_recorder (args(0)); | 1982 audiorecorder *recorder = get_recorder (args(0)); |
1983 | |
1984 if (! recorder) | |
1985 { | |
1986 print_usage (); | |
1987 return retval; | |
1988 } | |
1989 | |
1910 retval = recorder->getaudiodata (); | 1990 retval = recorder->getaudiodata (); |
1911 | 1991 |
1912 #else | 1992 #else |
1913 | 1993 |
1914 error ("portaudio not found on your system and thus audio functionality is not present"); | 1994 error ("portaudio not found on your system and thus audio functionality is not present"); |
1929 #ifdef HAVE_PORTAUDIO | 2009 #ifdef HAVE_PORTAUDIO |
1930 | 2010 |
1931 if (args.length () == 1) | 2011 if (args.length () == 1) |
1932 { | 2012 { |
1933 audiorecorder *recorder = get_recorder (args(0)); | 2013 audiorecorder *recorder = get_recorder (args(0)); |
2014 | |
2015 if (! recorder) | |
2016 { | |
2017 print_usage (); | |
2018 return retval; | |
2019 } | |
2020 | |
1934 retval = recorder->get_channels (); | 2021 retval = recorder->get_channels (); |
1935 } | 2022 } |
1936 | 2023 |
1937 #else | 2024 #else |
1938 | 2025 |
1954 #ifdef HAVE_PORTAUDIO | 2041 #ifdef HAVE_PORTAUDIO |
1955 | 2042 |
1956 if (args.length () == 1) | 2043 if (args.length () == 1) |
1957 { | 2044 { |
1958 audiorecorder *recorder = get_recorder (args(0)); | 2045 audiorecorder *recorder = get_recorder (args(0)); |
2046 | |
2047 if (! recorder) | |
2048 { | |
2049 print_usage (); | |
2050 return retval; | |
2051 } | |
2052 | |
1959 retval = recorder->get_fs (); | 2053 retval = recorder->get_fs (); |
1960 } | 2054 } |
1961 | 2055 |
1962 #else | 2056 #else |
1963 | 2057 |
1979 #ifdef HAVE_PORTAUDIO | 2073 #ifdef HAVE_PORTAUDIO |
1980 | 2074 |
1981 if (args.length () == 1) | 2075 if (args.length () == 1) |
1982 { | 2076 { |
1983 audiorecorder *recorder = get_recorder (args(0)); | 2077 audiorecorder *recorder = get_recorder (args(0)); |
2078 | |
2079 if (! recorder) | |
2080 { | |
2081 print_usage (); | |
2082 return retval; | |
2083 } | |
2084 | |
1984 retval = recorder->get_id (); | 2085 retval = recorder->get_id (); |
1985 } | 2086 } |
1986 | 2087 |
1987 #else | 2088 #else |
1988 | 2089 |
2004 #ifdef HAVE_PORTAUDIO | 2105 #ifdef HAVE_PORTAUDIO |
2005 | 2106 |
2006 if (args.length () == 1) | 2107 if (args.length () == 1) |
2007 { | 2108 { |
2008 audiorecorder *recorder = get_recorder (args(0)); | 2109 audiorecorder *recorder = get_recorder (args(0)); |
2110 | |
2111 if (! recorder) | |
2112 { | |
2113 print_usage (); | |
2114 return retval; | |
2115 } | |
2116 | |
2009 retval = recorder->get_nbits (); | 2117 retval = recorder->get_nbits (); |
2010 } | 2118 } |
2011 | 2119 |
2012 #else | 2120 #else |
2013 | 2121 |
2029 #ifdef HAVE_PORTAUDIO | 2137 #ifdef HAVE_PORTAUDIO |
2030 | 2138 |
2031 if (args.length () == 1) | 2139 if (args.length () == 1) |
2032 { | 2140 { |
2033 audiorecorder *recorder = get_recorder (args(0)); | 2141 audiorecorder *recorder = get_recorder (args(0)); |
2142 | |
2143 if (! recorder) | |
2144 { | |
2145 print_usage (); | |
2146 return retval; | |
2147 } | |
2148 | |
2034 retval = recorder->get_sample_number (); | 2149 retval = recorder->get_sample_number (); |
2035 } | 2150 } |
2036 | 2151 |
2037 #else | 2152 #else |
2038 | 2153 |
2054 #ifdef HAVE_PORTAUDIO | 2169 #ifdef HAVE_PORTAUDIO |
2055 | 2170 |
2056 if (args.length () == 1) | 2171 if (args.length () == 1) |
2057 { | 2172 { |
2058 audiorecorder *recorder = get_recorder (args(0)); | 2173 audiorecorder *recorder = get_recorder (args(0)); |
2174 | |
2175 if (! recorder) | |
2176 { | |
2177 print_usage (); | |
2178 return retval; | |
2179 } | |
2180 | |
2059 retval = recorder->get_tag (); | 2181 retval = recorder->get_tag (); |
2060 } | 2182 } |
2061 | 2183 |
2062 #else | 2184 #else |
2063 | 2185 |
2079 #ifdef HAVE_PORTAUDIO | 2201 #ifdef HAVE_PORTAUDIO |
2080 | 2202 |
2081 if (args.length () == 1) | 2203 if (args.length () == 1) |
2082 { | 2204 { |
2083 audiorecorder *recorder = get_recorder (args(0)); | 2205 audiorecorder *recorder = get_recorder (args(0)); |
2206 | |
2207 if (! recorder) | |
2208 { | |
2209 print_usage (); | |
2210 return retval; | |
2211 } | |
2212 | |
2084 retval = recorder->get_total_samples (); | 2213 retval = recorder->get_total_samples (); |
2085 } | 2214 } |
2086 | 2215 |
2087 #else | 2216 #else |
2088 | 2217 |
2104 #ifdef HAVE_PORTAUDIO | 2233 #ifdef HAVE_PORTAUDIO |
2105 | 2234 |
2106 if (args.length () == 1) | 2235 if (args.length () == 1) |
2107 { | 2236 { |
2108 audiorecorder *recorder = get_recorder (args(0)); | 2237 audiorecorder *recorder = get_recorder (args(0)); |
2238 | |
2239 if (! recorder) | |
2240 { | |
2241 print_usage (); | |
2242 return retval; | |
2243 } | |
2244 | |
2109 retval = recorder->get_userdata (); | 2245 retval = recorder->get_userdata (); |
2110 } | 2246 } |
2111 | 2247 |
2112 #else | 2248 #else |
2113 | 2249 |
2129 #ifdef HAVE_PORTAUDIO | 2265 #ifdef HAVE_PORTAUDIO |
2130 | 2266 |
2131 if (args.length () == 1) | 2267 if (args.length () == 1) |
2132 { | 2268 { |
2133 audiorecorder *recorder = get_recorder (args(0)); | 2269 audiorecorder *recorder = get_recorder (args(0)); |
2270 | |
2271 if (! recorder) | |
2272 { | |
2273 print_usage (); | |
2274 return retval; | |
2275 } | |
2276 | |
2134 retval = recorder->isrecording () ? true : false; | 2277 retval = recorder->isrecording () ? true : false; |
2135 } | 2278 } |
2136 | 2279 |
2137 #else | 2280 #else |
2138 | 2281 |
2154 #ifdef HAVE_PORTAUDIO | 2297 #ifdef HAVE_PORTAUDIO |
2155 | 2298 |
2156 if (args.length () == 1) | 2299 if (args.length () == 1) |
2157 { | 2300 { |
2158 audiorecorder *recorder = get_recorder (args(0)); | 2301 audiorecorder *recorder = get_recorder (args(0)); |
2302 | |
2303 if (! recorder) | |
2304 { | |
2305 print_usage (); | |
2306 return retval; | |
2307 } | |
2308 | |
2159 recorder->pause (); | 2309 recorder->pause (); |
2160 } | 2310 } |
2161 | 2311 |
2162 #else | 2312 #else |
2163 | 2313 |
2177 octave_value retval; | 2327 octave_value retval; |
2178 | 2328 |
2179 #ifdef HAVE_PORTAUDIO | 2329 #ifdef HAVE_PORTAUDIO |
2180 | 2330 |
2181 audiorecorder *recorder = get_recorder (args(0)); | 2331 audiorecorder *recorder = get_recorder (args(0)); |
2332 | |
2333 if (! recorder) | |
2334 { | |
2335 print_usage (); | |
2336 return retval; | |
2337 } | |
2338 | |
2182 recorder->recordblocking (args(1).float_value ()); | 2339 recorder->recordblocking (args(1).float_value ()); |
2183 | 2340 |
2184 #else | 2341 #else |
2185 | 2342 |
2186 error ("portaudio not found on your system and thus audio functionality is not present"); | 2343 error ("portaudio not found on your system and thus audio functionality is not present"); |
2200 octave_value retval; | 2357 octave_value retval; |
2201 | 2358 |
2202 #ifdef HAVE_PORTAUDIO | 2359 #ifdef HAVE_PORTAUDIO |
2203 | 2360 |
2204 audiorecorder *recorder = get_recorder (args(0)); | 2361 audiorecorder *recorder = get_recorder (args(0)); |
2362 | |
2363 if (! recorder) | |
2364 { | |
2365 print_usage (); | |
2366 return retval; | |
2367 } | |
2205 | 2368 |
2206 if (args.length () == 1) | 2369 if (args.length () == 1) |
2207 recorder->record (); | 2370 recorder->record (); |
2208 else if (args.length () == 2) | 2371 else if (args.length () == 2) |
2209 { | 2372 { |
2233 #ifdef HAVE_PORTAUDIO | 2396 #ifdef HAVE_PORTAUDIO |
2234 | 2397 |
2235 if (args.length () == 1) | 2398 if (args.length () == 1) |
2236 { | 2399 { |
2237 audiorecorder *recorder = get_recorder (args(0)); | 2400 audiorecorder *recorder = get_recorder (args(0)); |
2401 | |
2402 if (! recorder) | |
2403 { | |
2404 print_usage (); | |
2405 return retval; | |
2406 } | |
2407 | |
2238 recorder->resume (); | 2408 recorder->resume (); |
2239 } | 2409 } |
2240 | 2410 |
2241 #else | 2411 #else |
2242 | 2412 |
2258 #ifdef HAVE_PORTAUDIO | 2428 #ifdef HAVE_PORTAUDIO |
2259 | 2429 |
2260 if (args.length () == 2) | 2430 if (args.length () == 2) |
2261 { | 2431 { |
2262 audiorecorder *recorder = get_recorder (args(0)); | 2432 audiorecorder *recorder = get_recorder (args(0)); |
2433 | |
2434 if (! recorder) | |
2435 { | |
2436 print_usage (); | |
2437 return retval; | |
2438 } | |
2439 | |
2263 recorder->set_fs (args(1).int_value ()); | 2440 recorder->set_fs (args(1).int_value ()); |
2264 } | 2441 } |
2265 | 2442 |
2266 #else | 2443 #else |
2267 | 2444 |
2283 #ifdef HAVE_PORTAUDIO | 2460 #ifdef HAVE_PORTAUDIO |
2284 | 2461 |
2285 if (args.length () == 2) | 2462 if (args.length () == 2) |
2286 { | 2463 { |
2287 audiorecorder *recorder = get_recorder (args(0)); | 2464 audiorecorder *recorder = get_recorder (args(0)); |
2465 | |
2466 if (! recorder) | |
2467 { | |
2468 print_usage (); | |
2469 return retval; | |
2470 } | |
2471 | |
2288 recorder->set_tag (args(1).char_matrix_value ()); | 2472 recorder->set_tag (args(1).char_matrix_value ()); |
2289 } | 2473 } |
2290 | 2474 |
2291 #else | 2475 #else |
2292 | 2476 |
2308 #ifdef HAVE_PORTAUDIO | 2492 #ifdef HAVE_PORTAUDIO |
2309 | 2493 |
2310 if (args.length () == 2) | 2494 if (args.length () == 2) |
2311 { | 2495 { |
2312 audiorecorder *recorder = get_recorder (args(0)); | 2496 audiorecorder *recorder = get_recorder (args(0)); |
2497 | |
2498 if (! recorder) | |
2499 { | |
2500 print_usage (); | |
2501 return retval; | |
2502 } | |
2503 | |
2313 recorder->set_userdata (args(1)); | 2504 recorder->set_userdata (args(1)); |
2314 } | 2505 } |
2315 | 2506 |
2316 #else | 2507 #else |
2317 | 2508 |
2331 octave_value retval; | 2522 octave_value retval; |
2332 | 2523 |
2333 #ifdef HAVE_PORTAUDIO | 2524 #ifdef HAVE_PORTAUDIO |
2334 | 2525 |
2335 audiorecorder *recorder = get_recorder (args(0)); | 2526 audiorecorder *recorder = get_recorder (args(0)); |
2527 | |
2528 if (! recorder) | |
2529 { | |
2530 print_usage (); | |
2531 return retval; | |
2532 } | |
2533 | |
2336 recorder->stop (); | 2534 recorder->stop (); |
2337 | 2535 |
2338 #else | 2536 #else |
2339 | 2537 |
2340 error ("portaudio not found on your system and thus audio functionality is not present"); | 2538 error ("portaudio not found on your system and thus audio functionality is not present"); |
2363 print_usage (); | 2561 print_usage (); |
2364 return retval; | 2562 return retval; |
2365 } | 2563 } |
2366 | 2564 |
2367 audioplayer* recorder = new audioplayer (); | 2565 audioplayer* recorder = new audioplayer (); |
2566 | |
2567 if (! recorder) | |
2568 { | |
2569 print_usage (); | |
2570 return retval; | |
2571 } | |
2368 | 2572 |
2369 bool is_function = args(0).is_string () || args(0).is_function_handle () | 2573 bool is_function = args(0).is_string () || args(0).is_function_handle () |
2370 || args(0).is_inline_function (); | 2574 || args(0).is_inline_function (); |
2371 | 2575 |
2372 if (is_function) | 2576 if (is_function) |
2434 #ifdef HAVE_PORTAUDIO | 2638 #ifdef HAVE_PORTAUDIO |
2435 | 2639 |
2436 if (args.length () == 1) | 2640 if (args.length () == 1) |
2437 { | 2641 { |
2438 audioplayer *player = get_player (args(0)); | 2642 audioplayer *player = get_player (args(0)); |
2643 | |
2644 if (! player) | |
2645 { | |
2646 print_usage (); | |
2647 return retval; | |
2648 } | |
2649 | |
2439 retval = player->get_channels (); | 2650 retval = player->get_channels (); |
2440 } | 2651 } |
2441 | 2652 |
2442 #else | 2653 #else |
2443 | 2654 |
2459 #ifdef HAVE_PORTAUDIO | 2670 #ifdef HAVE_PORTAUDIO |
2460 | 2671 |
2461 if (args.length () == 1) | 2672 if (args.length () == 1) |
2462 { | 2673 { |
2463 audioplayer *player = get_player (args(0)); | 2674 audioplayer *player = get_player (args(0)); |
2675 | |
2676 if (! player) | |
2677 { | |
2678 print_usage (); | |
2679 return retval; | |
2680 } | |
2681 | |
2464 retval = player->get_fs (); | 2682 retval = player->get_fs (); |
2465 } | 2683 } |
2466 | 2684 |
2467 #else | 2685 #else |
2468 | 2686 |
2484 #ifdef HAVE_PORTAUDIO | 2702 #ifdef HAVE_PORTAUDIO |
2485 | 2703 |
2486 if (args.length () == 1) | 2704 if (args.length () == 1) |
2487 { | 2705 { |
2488 audioplayer *player = get_player (args(0)); | 2706 audioplayer *player = get_player (args(0)); |
2707 | |
2708 if (! player) | |
2709 { | |
2710 print_usage (); | |
2711 return retval; | |
2712 } | |
2713 | |
2489 retval = player->get_id (); | 2714 retval = player->get_id (); |
2490 } | 2715 } |
2491 | 2716 |
2492 #else | 2717 #else |
2493 | 2718 |
2509 #ifdef HAVE_PORTAUDIO | 2734 #ifdef HAVE_PORTAUDIO |
2510 | 2735 |
2511 if (args.length () == 1) | 2736 if (args.length () == 1) |
2512 { | 2737 { |
2513 audioplayer *player = get_player (args(0)); | 2738 audioplayer *player = get_player (args(0)); |
2739 | |
2740 if (! player) | |
2741 { | |
2742 print_usage (); | |
2743 return retval; | |
2744 } | |
2745 | |
2514 retval = player->get_nbits (); | 2746 retval = player->get_nbits (); |
2515 } | 2747 } |
2516 | 2748 |
2517 #else | 2749 #else |
2518 | 2750 |
2534 #ifdef HAVE_PORTAUDIO | 2766 #ifdef HAVE_PORTAUDIO |
2535 | 2767 |
2536 if (args.length () == 1) | 2768 if (args.length () == 1) |
2537 { | 2769 { |
2538 audioplayer *player = get_player (args(0)); | 2770 audioplayer *player = get_player (args(0)); |
2771 | |
2772 if (! player) | |
2773 { | |
2774 print_usage (); | |
2775 return retval; | |
2776 } | |
2777 | |
2539 retval = player->get_sample_number (); | 2778 retval = player->get_sample_number (); |
2540 } | 2779 } |
2541 | 2780 |
2542 #else | 2781 #else |
2543 | 2782 |
2559 #ifdef HAVE_PORTAUDIO | 2798 #ifdef HAVE_PORTAUDIO |
2560 | 2799 |
2561 if (args.length () == 1) | 2800 if (args.length () == 1) |
2562 { | 2801 { |
2563 audioplayer *player = get_player (args(0)); | 2802 audioplayer *player = get_player (args(0)); |
2803 | |
2804 if (! player) | |
2805 { | |
2806 print_usage (); | |
2807 return retval; | |
2808 } | |
2809 | |
2564 retval = player->get_tag (); | 2810 retval = player->get_tag (); |
2565 } | 2811 } |
2566 | 2812 |
2567 #else | 2813 #else |
2568 | 2814 |
2584 #ifdef HAVE_PORTAUDIO | 2830 #ifdef HAVE_PORTAUDIO |
2585 | 2831 |
2586 if (args.length () == 1) | 2832 if (args.length () == 1) |
2587 { | 2833 { |
2588 audioplayer *player = get_player (args(0)); | 2834 audioplayer *player = get_player (args(0)); |
2835 | |
2836 if (! player) | |
2837 { | |
2838 print_usage (); | |
2839 return retval; | |
2840 } | |
2841 | |
2589 retval = player->get_total_samples (); | 2842 retval = player->get_total_samples (); |
2590 } | 2843 } |
2591 | 2844 |
2592 #else | 2845 #else |
2593 | 2846 |
2609 #ifdef HAVE_PORTAUDIO | 2862 #ifdef HAVE_PORTAUDIO |
2610 | 2863 |
2611 if (args.length () == 1) | 2864 if (args.length () == 1) |
2612 { | 2865 { |
2613 audioplayer *player = get_player (args(0)); | 2866 audioplayer *player = get_player (args(0)); |
2867 | |
2868 if (! player) | |
2869 { | |
2870 print_usage (); | |
2871 return retval; | |
2872 } | |
2873 | |
2614 retval = player->get_userdata (); | 2874 retval = player->get_userdata (); |
2615 } | 2875 } |
2616 | 2876 |
2617 #else | 2877 #else |
2618 | 2878 |
2634 #ifdef HAVE_PORTAUDIO | 2894 #ifdef HAVE_PORTAUDIO |
2635 | 2895 |
2636 if (args.length () == 1) | 2896 if (args.length () == 1) |
2637 { | 2897 { |
2638 audioplayer *player = get_player (args(0)); | 2898 audioplayer *player = get_player (args(0)); |
2899 | |
2900 if (! player) | |
2901 { | |
2902 print_usage (); | |
2903 return retval; | |
2904 } | |
2905 | |
2639 retval = player->isplaying () ? true : false; | 2906 retval = player->isplaying () ? true : false; |
2640 } | 2907 } |
2641 | 2908 |
2642 #else | 2909 #else |
2643 | 2910 |
2659 #ifdef HAVE_PORTAUDIO | 2926 #ifdef HAVE_PORTAUDIO |
2660 | 2927 |
2661 if (args.length () == 1) | 2928 if (args.length () == 1) |
2662 { | 2929 { |
2663 audioplayer *player = get_player (args(0)); | 2930 audioplayer *player = get_player (args(0)); |
2931 | |
2932 if (! player) | |
2933 { | |
2934 print_usage (); | |
2935 return retval; | |
2936 } | |
2937 | |
2664 player->pause (); | 2938 player->pause (); |
2665 } | 2939 } |
2666 | 2940 |
2667 #else | 2941 #else |
2668 | 2942 |
2683 { | 2957 { |
2684 octave_value retval; | 2958 octave_value retval; |
2685 | 2959 |
2686 #ifdef HAVE_PORTAUDIO | 2960 #ifdef HAVE_PORTAUDIO |
2687 | 2961 |
2962 audioplayer *player = get_player (args(0)); | |
2963 | |
2964 if (! player) | |
2965 { | |
2966 print_usage (); | |
2967 return retval; | |
2968 } | |
2969 | |
2688 if (args.length () == 1) | 2970 if (args.length () == 1) |
2689 { | 2971 player->playblocking (); |
2690 audioplayer *player = get_player (args(0)); | |
2691 player->playblocking (); | |
2692 } | |
2693 else | 2972 else |
2694 { | 2973 { |
2695 audioplayer *player = get_player (args(0)); | |
2696 if (args(1).is_matrix_type ()) | 2974 if (args(1).is_matrix_type ()) |
2697 { | 2975 { |
2698 RowVector range = args(1).row_vector_value (); | 2976 RowVector range = args(1).row_vector_value (); |
2699 | 2977 |
2700 unsigned int start = range.elem (0) - 1; | 2978 unsigned int start = range.elem (0) - 1; |
2748 #ifdef HAVE_PORTAUDIO | 3026 #ifdef HAVE_PORTAUDIO |
2749 | 3027 |
2750 if (args.length () == 1) | 3028 if (args.length () == 1) |
2751 { | 3029 { |
2752 audioplayer *player = get_player (args(0)); | 3030 audioplayer *player = get_player (args(0)); |
3031 | |
3032 if (! player) | |
3033 { | |
3034 print_usage (); | |
3035 return retval; | |
3036 } | |
3037 | |
2753 player->play (); | 3038 player->play (); |
2754 } | 3039 } |
2755 else | 3040 else |
2756 { | 3041 { |
2757 audioplayer *player = get_player (args(0)); | 3042 audioplayer *player = get_player (args(0)); |
2809 #ifdef HAVE_PORTAUDIO | 3094 #ifdef HAVE_PORTAUDIO |
2810 | 3095 |
2811 if (args.length () == 1) | 3096 if (args.length () == 1) |
2812 { | 3097 { |
2813 audioplayer *player = get_player (args(0)); | 3098 audioplayer *player = get_player (args(0)); |
3099 | |
3100 if (! player) | |
3101 { | |
3102 print_usage (); | |
3103 return retval; | |
3104 } | |
3105 | |
2814 player->resume (); | 3106 player->resume (); |
2815 } | 3107 } |
2816 | 3108 |
2817 #else | 3109 #else |
2818 | 3110 |
2834 #ifdef HAVE_PORTAUDIO | 3126 #ifdef HAVE_PORTAUDIO |
2835 | 3127 |
2836 if (args.length () == 2) | 3128 if (args.length () == 2) |
2837 { | 3129 { |
2838 audioplayer *player = get_player (args(0)); | 3130 audioplayer *player = get_player (args(0)); |
3131 | |
3132 if (! player) | |
3133 { | |
3134 print_usage (); | |
3135 return retval; | |
3136 } | |
3137 | |
2839 player->set_fs (args(1).int_value ()); | 3138 player->set_fs (args(1).int_value ()); |
2840 } | 3139 } |
2841 | 3140 |
2842 #else | 3141 #else |
2843 | 3142 |
2859 #ifdef HAVE_PORTAUDIO | 3158 #ifdef HAVE_PORTAUDIO |
2860 | 3159 |
2861 if (args.length () == 2) | 3160 if (args.length () == 2) |
2862 { | 3161 { |
2863 audioplayer *player = get_player (args(0)); | 3162 audioplayer *player = get_player (args(0)); |
3163 | |
3164 if (! player) | |
3165 { | |
3166 print_usage (); | |
3167 return retval; | |
3168 } | |
3169 | |
2864 player->set_tag (args(1).char_matrix_value ()); | 3170 player->set_tag (args(1).char_matrix_value ()); |
2865 } | 3171 } |
2866 | 3172 |
2867 #else | 3173 #else |
2868 | 3174 |
2884 #ifdef HAVE_PORTAUDIO | 3190 #ifdef HAVE_PORTAUDIO |
2885 | 3191 |
2886 if (args.length () == 2) | 3192 if (args.length () == 2) |
2887 { | 3193 { |
2888 audioplayer *player = get_player (args(0)); | 3194 audioplayer *player = get_player (args(0)); |
3195 | |
3196 if (! player) | |
3197 { | |
3198 print_usage (); | |
3199 return retval; | |
3200 } | |
3201 | |
2889 player->set_userdata (args(1)); | 3202 player->set_userdata (args(1)); |
2890 } | 3203 } |
2891 | 3204 |
2892 #else | 3205 #else |
2893 | 3206 |
2909 #ifdef HAVE_PORTAUDIO | 3222 #ifdef HAVE_PORTAUDIO |
2910 | 3223 |
2911 if (args.length () == 1) | 3224 if (args.length () == 1) |
2912 { | 3225 { |
2913 audioplayer *player = get_player (args (0)); | 3226 audioplayer *player = get_player (args (0)); |
3227 | |
3228 if (! player) | |
3229 { | |
3230 print_usage (); | |
3231 return retval; | |
3232 } | |
3233 | |
2914 player->stop (); | 3234 player->stop (); |
2915 } | 3235 } |
2916 | 3236 |
2917 #else | 3237 #else |
2918 | 3238 |