# HG changeset patch # User John W. Eaton # Date 1420182280 18000 # Node ID 4cb4210bd392ca25b5a3a0d9386ce3379f3bbfa6 # Parent a5eb03a7e2a5264ef1090983c0dedb0f357eddfb use C++ style casts in audio code * audiodevinfo.cc, audioread.cc: Use C++ style casts. diff -r a5eb03a7e2a5 -r 4cb4210bd392 libinterp/dldfcn/audiodevinfo.cc --- a/libinterp/dldfcn/audiodevinfo.cc Fri Jan 02 00:59:08 2015 -0500 +++ b/libinterp/dldfcn/audiodevinfo.cc Fri Jan 02 02:04:40 2015 -0500 @@ -523,7 +523,7 @@ const PaStreamCallbackTimeInfo *, PaStreamCallbackFlags, void *data) { - audioplayer *player = (audioplayer *)data; + audioplayer *player = static_cast (data); int big_endian = is_big_endian (); octave_value_list args, retval; args(0) = frames; @@ -556,25 +556,26 @@ { if (player->get_nbits () == 8) { - int8_t *buffer = (int8_t *)output; + int8_t *buffer = static_cast (output); buffer[2 * i] = sound_l.elem (i) * (pow (2.0, 7) - 1); buffer[2 * i + 1] = sound_r.elem (i) * (pow (2.0, 7) - 1); } else if (player->get_nbits () == 16) { - int16_t *buffer = (int16_t *)output; + int16_t *buffer = static_cast (output); buffer[2 * i] = sound_l.elem (i) * (pow (2.0, 15) - 1); buffer[2 * i + 1] = sound_r.elem (i) * (pow (2.0, 15) - 1); } else if (player->get_nbits () == 24) { - uint8_t *buffer = (uint8_t *)output; + uint8_t *buffer = static_cast (output); int32_t sample_l = sound_l.elem (i) * (pow (2.0, 23) - 1); int32_t sample_r = sound_r.elem (i) * (pow (2.0, 23) - 1); sample_l &= 0x00ffffff; sample_r &= 0x00ffffff; - uint8_t *_sample_l = (uint8_t *)&sample_l; - uint8_t *_sample_r = (uint8_t *)&sample_r; + // FIXME: Would a mask work better? + uint8_t *_sample_l = reinterpret_cast (&sample_l); + uint8_t *_sample_r = reinterpret_cast (&sample_r); buffer[i * 6 + 0] = _sample_l[0 + big_endian]; buffer[i * 6 + 1] = _sample_l[1 + big_endian]; buffer[i * 6 + 2] = _sample_l[2 + big_endian]; @@ -591,7 +592,7 @@ const PaStreamCallbackTimeInfo*, PaStreamCallbackFlags, void *data) { - audioplayer *player = (audioplayer *)data; + audioplayer *player = static_cast (data); int big_endian = is_big_endian (); int channels = player->get_channels (); RowVector *sound_l = player->get_left (); @@ -612,25 +613,26 @@ { if (player->get_nbits () == 8) { - int8_t *buffer = (int8_t *)output; + int8_t *buffer = static_cast (output); buffer[k] = sound_l->elem (sample_number) * (pow (2.0, 7) - 1); buffer[k + 1] = sound_r->elem (sample_number) * (pow (2.0, 7) - 1); } else if (player->get_nbits () == 16) { - int16_t *buffer = (int16_t *)output; + int16_t *buffer = static_cast (output); buffer[k] = sound_l->elem (sample_number) * (pow (2.0, 15) - 1); buffer[k + 1] = sound_r->elem (sample_number) * (pow (2.0, 15) - 1); } else if (player->get_nbits () == 24) { - uint8_t *buffer = (uint8_t *)output; + uint8_t *buffer = static_cast (output); int32_t sample_l = sound_l->elem (sample_number) * (pow (2.0, 23) - 1); int32_t sample_r = sound_r->elem (sample_number) * (pow (2.0, 23) - 1); sample_l &= 0x00ffffff; sample_r &= 0x00ffffff; - uint8_t *_sample_l = (uint8_t *)&sample_l; - uint8_t *_sample_r = (uint8_t *)&sample_r; + // FIXME: Would a mask work better? + uint8_t *_sample_l = reinterpret_cast (&sample_l); + uint8_t *_sample_r = reinterpret_cast (&sample_r); buffer[j * 6 + 0] = _sample_l[0 + big_endian]; buffer[j * 6 + 1] = _sample_l[1 + big_endian]; buffer[j * 6 + 2] = _sample_l[2 + big_endian]; @@ -641,19 +643,19 @@ } else if (player->get_type () == INT8) { - int8_t *buffer = (int8_t *)output; + int8_t *buffer = static_cast (output); buffer[k] = sound_l->elem (sample_number); buffer[k + 1] = sound_r->elem (sample_number); } else if (player->get_type () == UINT8) { - uint8_t *buffer = (uint8_t *)output; + uint8_t *buffer = static_cast (output); buffer[k] = sound_l->elem (sample_number); buffer[k + 1] = sound_r->elem (sample_number); } else if (player->get_type () == INT16) { - int16_t *buffer = (int16_t *)output; + int16_t *buffer = static_cast (output); buffer[k] = sound_l->elem (sample_number); buffer[k + 1] = sound_r->elem (sample_number); } @@ -953,9 +955,10 @@ for (int i = start; i < end; i += BUFFER_SIZE) { if (this->octave_callback_function != 0) - octave_play_callback (0, (void *)buffer, BUFFER_SIZE, 0, 0, (void *)this); + octave_play_callback (0, buffer, BUFFER_SIZE, 0, 0, this); else - portaudio_play_callback (0, (void *)buffer, BUFFER_SIZE, 0, 0, (void *)this); + portaudio_play_callback (0, buffer, BUFFER_SIZE, 0, 0, this); + err = Pa_WriteStream (stream, buffer, BUFFER_SIZE); } @@ -986,9 +989,13 @@ PaError err; if (this->octave_callback_function != 0) - err = Pa_OpenStream (&stream, NULL, &(this->output_parameters), this->get_fs (), BUFFER_SIZE, paClipOff, octave_play_callback, (void *)this); + err = Pa_OpenStream (&stream, NULL, &(this->output_parameters), + this->get_fs (), BUFFER_SIZE, paClipOff, + octave_play_callback, this); else - err = Pa_OpenStream (&stream, NULL, &(this->output_parameters), this->get_fs (), BUFFER_SIZE, paClipOff, portaudio_play_callback, (void *)this); + err = Pa_OpenStream (&stream, NULL, &(this->output_parameters), + this->get_fs (), BUFFER_SIZE, paClipOff, + portaudio_play_callback, this); if (err != paNoError) { @@ -1165,14 +1172,14 @@ const PaStreamCallbackTimeInfo *, PaStreamCallbackFlags, void *data) { - audiorecorder *recorder = (audiorecorder *)data; + audiorecorder *recorder = static_cast (data); int channels = recorder->get_channels (); float sample_l, sample_r; Matrix sound; sound.resize (frames, 2); if (recorder->get_nbits () == 8) { - int8_t *input8 = (int8_t *)input; + const int8_t *input8 = static_cast (input); for (int i = 0; i < frames; i++) { sample_l = input8[i * channels] / (pow (2.0, 7) - 1.0); @@ -1183,7 +1190,7 @@ } else if (recorder->get_nbits () == 16) { - int16_t *input16 = (int16_t *)input; + const int16_t *input16 = static_cast (input); for (int i = 0; i < frames; i++) { sample_l = input16[i * channels] / (pow (2.0, 15) - 1.0); @@ -1194,16 +1201,17 @@ } else if (recorder->get_nbits () == 24) { - uint8_t *input24 = (uint8_t *)input; + // FIXME: Is there a better way? + const uint8_t *input24 = static_cast (input); int32_t sample_l32, sample_r32; - uint8_t *_sample_l = (uint8_t *)&sample_l; - uint8_t *_sample_r = (uint8_t *)&sample_r; + uint8_t *_sample_l = reinterpret_cast (&sample_l); + uint8_t *_sample_r = reinterpret_cast (&sample_r); for (int i = 0; i < frames; i++) { for (int j = 0; j < 3; j++) { _sample_l[j] = input24[i * channels * 3 + j]; - _sample_r[j] = input24[i * channels * 3 + (channels - 1) * 3 + j]; + _sample_r[j] = input24[i * channels * 3 + (channels - 1) * 3 + j]; } if (sample_l32 & 0x00800000) sample_l32 |= 0xff000000; @@ -1225,12 +1233,12 @@ const PaStreamCallbackTimeInfo *, PaStreamCallbackFlags, void *data) { - audiorecorder *recorder = (audiorecorder *)data; + audiorecorder *recorder = static_cast (data); int channels = recorder->get_channels (); float sample_l, sample_r; if (recorder->get_nbits () == 8) { - int8_t *input8 = (int8_t *)input; + const int8_t *input8 = static_cast (input); for (int i = 0; i < frames; i++) { sample_l = input8[i * channels] / (pow (2.0, 7) - 1.0); @@ -1240,7 +1248,7 @@ } else if (recorder->get_nbits () == 16) { - int16_t *input16 = (int16_t *)input; + const int16_t *input16 = static_cast (input); for (int i = 0; i < frames; i++) { sample_l = input16[i * channels] / (pow (2.0, 15) - 1.0); @@ -1250,10 +1258,11 @@ } else if (recorder->get_nbits () == 24) { - uint8_t *input24 = (uint8_t *)input; + // FIXME: Is there a better way? + const uint8_t *input24 = static_cast (input); int32_t sample_l32, sample_r32; - uint8_t *_sample_l = (uint8_t *)&sample_l; - uint8_t *_sample_r = (uint8_t *)&sample_r; + uint8_t *_sample_l = reinterpret_cast (&sample_l); + uint8_t *_sample_r = reinterpret_cast (&sample_r); for (int i = 0; i < frames; i++) { for (int j = 0; j < 3; j++) @@ -1501,11 +1510,15 @@ PaError err; if (this->octave_callback_function != 0) { - err = Pa_OpenStream (&stream, &(this->input_parameters), NULL, this->get_fs (), BUFFER_SIZE, paClipOff, octave_record_callback, (void *)this); + err = Pa_OpenStream (&stream, &(this->input_parameters), NULL, + this->get_fs (), BUFFER_SIZE, paClipOff, + octave_record_callback, this); } else { - err = Pa_OpenStream (&stream, &(this->input_parameters), NULL, this->get_fs (), BUFFER_SIZE, paClipOff, portaudio_record_callback, (void *)this); + err = Pa_OpenStream (&stream, &(this->input_parameters), NULL, + this->get_fs (), BUFFER_SIZE, paClipOff, + portaudio_record_callback, this); } if (err != paNoError) { @@ -1530,7 +1543,8 @@ this->right.clear (); PaError err; - err = Pa_OpenStream (&stream, &(this->input_parameters), NULL, this->get_fs (), BUFFER_SIZE, paClipOff, NULL, (void *)this); + err = Pa_OpenStream (&stream, &(this->input_parameters), NULL, + this->get_fs (), BUFFER_SIZE, paClipOff, NULL, this); if (err != paNoError) { error ("audiorecorder: Error opening audio recording stream"); @@ -1548,11 +1562,11 @@ uint8_t buffer[BUFFER_SIZE * 2 * 3]; for (int i = 0; i < frames / BUFFER_SIZE; i++) { - Pa_ReadStream (this->get_stream (), (void *)buffer, BUFFER_SIZE); + Pa_ReadStream (this->get_stream (), buffer, BUFFER_SIZE); if (this->octave_callback_function != 0) - octave_record_callback ((void *)buffer, NULL, BUFFER_SIZE, 0, 0, (void *)this); + octave_record_callback (buffer, NULL, BUFFER_SIZE, 0, 0, this); else - portaudio_record_callback ((void *)buffer, NULL, BUFFER_SIZE, 0, 0, (void *)this); + portaudio_record_callback (buffer, NULL, BUFFER_SIZE, 0, 0, this); } } @@ -1673,6 +1687,16 @@ #endif } +static audiorecorder * +get_recorder (const octave_value& ov) +{ + const octave_base_value& rep = ov.get_rep (); + + octave_base_value *ncrep = const_cast (&rep); + + return dynamic_cast (ncrep); +} + DEFUN_DLD (__recorder_getaudiodata__, args, , "-*- texinfo -*-\n\ @deftypefn {Loadable Function} {@var{data}} __recorder_getaudiodata__ (@var{recorder})\n\ @@ -1681,8 +1705,7 @@ { octave_value retval; #ifdef HAVE_PORTAUDIO - const octave_base_value& rep = args(0).get_rep (); - audiorecorder *recorder = &((audiorecorder &)rep); + audiorecorder *recorder = get_recorder (args(0)); retval = octave_value (recorder->getaudiodata ()); #else error ("portaudio not found on your system and thus audio functionality is not present"); @@ -1701,8 +1724,7 @@ int nargin = args.length (); if (nargin == 1) { - const octave_base_value& rep = args(0).get_rep (); - audiorecorder *recorder = &((audiorecorder &)rep); + audiorecorder *recorder = get_recorder (args(0)); retval = octave_value (recorder->get_channels ()); } #else @@ -1722,8 +1744,7 @@ int nargin = args.length (); if (nargin == 1) { - const octave_base_value& rep = args(0).get_rep (); - audiorecorder *recorder = &((audiorecorder &)rep); + audiorecorder *recorder = get_recorder (args(0)); retval = octave_value (recorder->get_fs ()); } #else @@ -1743,8 +1764,7 @@ int nargin = args.length (); if (nargin == 1) { - const octave_base_value& rep = args(0).get_rep (); - audiorecorder *recorder = &((audiorecorder &)rep); + audiorecorder *recorder = get_recorder (args(0)); retval = octave_value (recorder->get_id ()); } #else @@ -1764,8 +1784,7 @@ int nargin = args.length (); if (nargin == 1) { - const octave_base_value& rep = args(0).get_rep (); - audiorecorder *recorder = &((audiorecorder &)rep); + audiorecorder *recorder = get_recorder (args(0)); retval = octave_value (recorder->get_nbits ()); } #else @@ -1785,8 +1804,7 @@ int nargin = args.length (); if (nargin == 1) { - const octave_base_value& rep = args(0).get_rep (); - audiorecorder *recorder = &((audiorecorder &)rep); + audiorecorder *recorder = get_recorder (args(0)); retval = octave_value (recorder->get_sample_number ()); } #else @@ -1806,8 +1824,7 @@ int nargin = args.length (); if (nargin == 1) { - const octave_base_value& rep = args(0).get_rep (); - audiorecorder *recorder = &((audiorecorder &)rep); + audiorecorder *recorder = get_recorder (args(0)); retval = octave_value (recorder->get_tag ()); } #else @@ -1827,8 +1844,7 @@ int nargin = args.length (); if (nargin == 1) { - const octave_base_value& rep = args(0).get_rep (); - audiorecorder *recorder = &((audiorecorder &)rep); + audiorecorder *recorder = get_recorder (args(0)); retval = octave_value (recorder->get_total_samples ()); } #else @@ -1848,8 +1864,7 @@ int nargin = args.length (); if (nargin == 1) { - const octave_base_value& rep = args(0).get_rep (); - audiorecorder *recorder = &((audiorecorder &)rep); + audiorecorder *recorder = get_recorder (args(0)); retval = recorder->get_userdata (); } #else @@ -1869,8 +1884,7 @@ int nargin = args.length (); if (nargin == 1) { - const octave_base_value& rep = args(0).get_rep (); - audiorecorder *recorder = &((audiorecorder &)rep); + audiorecorder *recorder = get_recorder (args(0)); if (recorder->isrecording ()) return octave_value (1); else @@ -1893,8 +1907,7 @@ int nargin = args.length (); if (nargin == 1) { - const octave_base_value& rep = args(0).get_rep (); - audiorecorder *recorder = &((audiorecorder &)rep); + audiorecorder *recorder = get_recorder (args(0)); recorder->pause (); } #else @@ -1911,8 +1924,7 @@ { octave_value retval; #ifdef HAVE_PORTAUDIO - const octave_base_value& rep = args(0).get_rep (); - audiorecorder *recorder = &((audiorecorder &)rep); + audiorecorder *recorder = get_recorder (args(0)); recorder->recordblocking (args(1).float_value ()); #else error ("portaudio not found on your system and thus audio functionality is not present"); @@ -1929,8 +1941,7 @@ { octave_value retval; #ifdef HAVE_PORTAUDIO - const octave_base_value& rep = args(0).get_rep (); - audiorecorder *recorder = &((audiorecorder &)rep); + audiorecorder *recorder = get_recorder (args(0)); if (args.length () == 1) { recorder->record (); @@ -1961,8 +1972,7 @@ int nargin = args.length (); if (nargin == 1) { - const octave_base_value& rep = args(0).get_rep (); - audiorecorder *recorder = &((audiorecorder &)rep); + audiorecorder *recorder = get_recorder (args(0)); recorder->resume (); } #else @@ -1982,8 +1992,7 @@ int nargin = args.length (); if (nargin == 2) { - const octave_base_value& rep = args(0).get_rep (); - audiorecorder *recorder = &((audiorecorder &)rep); + audiorecorder *recorder = get_recorder (args(0)); recorder->set_fs (args(1).int_value ()); } #else @@ -2003,8 +2012,7 @@ int nargin = args.length (); if (nargin == 2) { - const octave_base_value& rep = args(0).get_rep (); - audiorecorder *recorder = &((audiorecorder &)rep); + audiorecorder *recorder = get_recorder (args(0)); recorder->set_tag (args(1).char_matrix_value ()); } #else @@ -2024,8 +2032,7 @@ int nargin = args.length (); if (nargin == 2) { - const octave_base_value& rep = args(0).get_rep (); - audiorecorder *recorder = &((audiorecorder &)rep); + audiorecorder *recorder = get_recorder (args(0)); recorder->set_userdata (args(1)); } #else @@ -2042,8 +2049,7 @@ { octave_value retval; #ifdef HAVE_PORTAUDIO - const octave_base_value& rep = args(0).get_rep (); - audiorecorder *recorder = &((audiorecorder &)rep); + audiorecorder *recorder = get_recorder (args(0)); recorder->stop (); #else error ("portaudio not found on your system and thus audio functionality is not present"); @@ -2090,6 +2096,16 @@ #endif } +static audioplayer * +get_player (const octave_value& ov) +{ + const octave_base_value& rep = ov.get_rep (); + + octave_base_value *ncrep = const_cast (&rep); + + return dynamic_cast (ncrep); +} + DEFUN_DLD (__player_get_channels__, args, , "-*- texinfo -*-\n\ @deftypefn {Loadable Function} {@var{n} =} __player_get_channels__ (@var{player})\n\ @@ -2101,8 +2117,7 @@ int nargin = args.length (); if (nargin == 1) { - const octave_base_value& rep = args(0).get_rep (); - audioplayer *player = &((audioplayer &)rep); + audioplayer *player = get_player (args(0)); retval = octave_value (player->get_channels ()); } #else @@ -2122,8 +2137,7 @@ int nargin = args.length (); if (nargin == 1) { - const octave_base_value& rep = args(0).get_rep (); - audioplayer *player = &((audioplayer &)rep); + audioplayer *player = get_player (args(0)); retval = octave_value (player->get_fs ()); } #else @@ -2143,8 +2157,7 @@ int nargin = args.length (); if (nargin == 1) { - const octave_base_value& rep = args(0).get_rep (); - audioplayer *player = &((audioplayer &)rep); + audioplayer *player = get_player (args(0)); retval = octave_value (player->get_id ()); } #else @@ -2164,8 +2177,7 @@ int nargin = args.length (); if (nargin == 1) { - const octave_base_value& rep = args(0).get_rep (); - audioplayer *player = &((audioplayer &)rep); + audioplayer *player = get_player (args(0)); retval = octave_value (player->get_nbits ()); } #else @@ -2185,8 +2197,7 @@ int nargin = args.length (); if (nargin == 1) { - const octave_base_value& rep = args(0).get_rep (); - audioplayer *player = &((audioplayer &)rep); + audioplayer *player = get_player (args(0)); retval = octave_value (player->get_sample_number ()); } #else @@ -2206,8 +2217,7 @@ int nargin = args.length (); if (nargin == 1) { - const octave_base_value& rep = args(0).get_rep (); - audioplayer *player = &((audioplayer &)rep); + audioplayer *player = get_player (args(0)); retval = octave_value (player->get_tag ()); } #else @@ -2227,8 +2237,7 @@ int nargin = args.length (); if (nargin == 1) { - const octave_base_value& rep = args(0).get_rep (); - audioplayer *player = &((audioplayer &)rep); + audioplayer *player = get_player (args(0)); retval = octave_value (player->get_total_samples ()); } #else @@ -2248,8 +2257,7 @@ int nargin = args.length (); if (nargin == 1) { - const octave_base_value& rep = args(0).get_rep (); - audioplayer *player = &((audioplayer &)rep); + audioplayer *player = get_player (args(0)); retval = player->get_userdata (); } #else @@ -2269,8 +2277,7 @@ int nargin = args.length (); if (nargin == 1) { - const octave_base_value& rep = args(0).get_rep (); - audioplayer *player = &((audioplayer &)rep); + audioplayer *player = get_player (args(0)); if (player->isplaying ()) return octave_value (1); else @@ -2293,8 +2300,7 @@ int nargin = args.length (); if (nargin == 1) { - const octave_base_value& rep = args(0).get_rep (); - audioplayer *player = &((audioplayer &)rep); + audioplayer *player = get_player (args(0)); player->pause (); } #else @@ -2316,14 +2322,12 @@ int nargin = args.length (); if (nargin == 1) { - const octave_base_value& rep = args(0).get_rep (); - audioplayer *player = &((audioplayer &)rep); + audioplayer *player = get_player (args(0)); player->playblocking (); } else { - const octave_base_value& rep = args(0).get_rep (); - audioplayer *player = &((audioplayer &)rep); + audioplayer *player = get_player (args(0)); if (args(1).is_matrix_type ()) { unsigned int start, end; @@ -2365,14 +2369,12 @@ int nargin = args.length (); if (nargin == 1) { - const octave_base_value& rep = args(0).get_rep (); - audioplayer *player = &((audioplayer &)rep); + audioplayer *player = get_player (args(0)); player->play (); } else { - const octave_base_value& rep = args(0).get_rep (); - audioplayer *player = &((audioplayer &)rep); + audioplayer *player = get_player (args(0)); if (args(1).is_matrix_type ()) { unsigned int start, end; @@ -2412,8 +2414,7 @@ int nargin = args.length (); if (nargin == 1) { - const octave_base_value& rep = args(0).get_rep (); - audioplayer *player = &((audioplayer &)rep); + audioplayer *player = get_player (args(0)); player->resume (); } #else @@ -2433,8 +2434,7 @@ int nargin = args.length (); if (nargin == 2) { - const octave_base_value& rep = args(0).get_rep (); - audioplayer *player = &((audioplayer &)rep); + audioplayer *player = get_player (args(0)); player->set_fs (args(1).int_value ()); } #else @@ -2454,8 +2454,7 @@ int nargin = args.length (); if (nargin == 2) { - const octave_base_value& rep = args(0).get_rep (); - audioplayer *player = &((audioplayer &)rep); + audioplayer *player = get_player (args(0)); player->set_tag (args(1).char_matrix_value ()); } #else @@ -2475,8 +2474,7 @@ int nargin = args.length (); if (nargin == 2) { - const octave_base_value& rep = args(0).get_rep (); - audioplayer *player = &((audioplayer &)rep); + audioplayer *player = get_player (args(0)); player->set_userdata (args(1)); } #else @@ -2496,8 +2494,7 @@ int nargin = args.length (); if (nargin == 1) { - const octave_base_value& rep = args(0).get_rep (); - audioplayer *player = &((audioplayer &)rep); + audioplayer *player = get_player (args (0)); player->stop (); } #else diff -r a5eb03a7e2a5 -r 4cb4210bd392 libinterp/dldfcn/audioread.cc --- a/libinterp/dldfcn/audioread.cc Fri Jan 02 00:59:08 2015 -0500 +++ b/libinterp/dldfcn/audioread.cc Fri Jan 02 02:04:40 2015 -0500 @@ -27,6 +27,8 @@ #include #include +#include "oct-locbuf.h" + #include "defun-dld.h" #include "error.h" #include "gripes.h" @@ -81,7 +83,7 @@ file = sf_open (args(0).string_value ().c_str (), SFM_READ, &info); start = 0; end = info.frames; - float *data = (float *)malloc (sizeof (float) * info.frames * info.channels); + OCTAVE_LOCAL_BUFFER (float, data, info.frames * info.channels); sf_read_float (file, data, info.frames * info.channels); if (args.length () == 2 && !args(1).is_string () || args.length () == 3) { @@ -97,7 +99,7 @@ audio(i - start, channel) = data[i * info.channels + channel]; } } - free (data); + if (args.length () == 2 && args(1).is_string () || args.length () == 3) { std::string type; @@ -206,7 +208,8 @@ Matrix audio = args(1).matrix_value (); SNDFILE *file; SF_INFO info; - float *data = (float *)malloc (audio.rows () * audio.cols () * sizeof (float)); + OCTAVE_LOCAL_BUFFER (float, data, audio.rows () * audio.cols ()); + for (int i = 0; i < audio.cols (); i++) { for (int j = 0; j < audio.rows (); j++) @@ -299,7 +302,9 @@ retval.assign ("NumChannels", info.channels); retval.assign ("SampleRate", info.samplerate); retval.assign ("TotalSamples", info.frames); - retval.assign ("Duration", (float)info.frames / (float)info.samplerate); + double dframes = info.frames; + double drate = info.samplerate; + retval.assign ("Duration", dframes / drate); int bits; if (info.format & SF_FORMAT_PCM_S8)