bugGNU Octave - Bugs: bug #64379, audioplayer creation fails

 
 

bug #64379: audioplayer creation fails

Submitter:  John Donoghue <lostbard>
Submitted:  Mon 03 Jul 2023 07:25:08 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Unexpected Error or Warning
Status:  Fixed Assigned to:  None
Originator Name:  lostbard Open/Closed:  * Closed
Release:  * stable Operating System:  * Any
Fixed Release:  8.3.0 Planned Release:  8.3.0
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Wed 12 Jul 2023 06:26:49 PM UTC, comment #10: 

I ported changes from development back to stable.

Marking bug as Fixed and closing report.

Rik <rik5>
Group administrator
Wed 12 Jul 2023 04:56:58 PM UTC, comment #9: 

Rik, your change seems fine for the stable branch, especially if calling the constructor with a function handle as the first argument never worked previously.

John W. Eaton <jwe>
Group administrator
Wed 12 Jul 2023 04:25:31 PM UTC, comment #8: 

I think the @audioplayer and @audiorecorder classes need an overhaul.  On the development branch I committed this cset (http://hg.savannah.gnu.org/hgweb/octave/rev/7f068048e388) which removes ancient, obsolete code that accepted an input callback function for the constructor.  Matlab doesn't have this calling functionality, and Octave doesn't support it either, except for the fact that it is messing up input validation as shown in this bug report.  This fixes the issue on the dev branch.  The question is whether this should be ported to the stable branch (probably) or whether, instead, we tweak the input validation on the stable branch just to allow an audiorecorder object as the first argument to the audioplayer constructor as John D. suggested in the original bug report.  I'm adding jwe to the CC list for his opinion.

Rik <rik5>
Group administrator
Mon 10 Jul 2023 11:49:45 AM UTC, comment #7: 

Yeah I meant  p = getplayer (a);

So it requires data in recorder object in order to get a player so at least getplayer will return a more meaningful message now.


p = getplayer(a)
error: audioplayer: Y must be non-empty numeric data
error: called from
    audioplayer at line 145 column 7
    getplayer at line 36 column 10


Im not sure why the audioplayer constructor is checking that its not a function handle instead of checking what it should be, but a change for that will fix the other part of the bug report


octave:3> p = audioplayer(a)
error: Invalid call to audioplayer.  Correct usage is:

 -- PLAYER = audioplayer (Y, FS)
 -- PLAYER = audioplayer (Y, FS, NBITS)
 -- PLAYER = audioplayer (Y, FS, NBITS, ID)
 -- PLAYER = audioplayer (RECORDER)
 -- PLAYER = audioplayer (RECORDER, ID)

John Donoghue <lostbard>
Group Member
Mon 10 Jul 2023 06:34:41 AM UTC, comment #6: 

The result for the commands in comment #3 in Matlab R2023a:

>> a = audiorecorder ();
p = getplayer (A);
Unrecognized function or variable 'A'.

Did you mean:
>> p = getplayer (a);
Recorder is empty.


Markus Mützel <mmuetzel>
Group Member
Sun 09 Jul 2023 07:51:46 PM UTC, comment #5: 

Incidentally, I checked in a change on the stable branch to emit an error in audioplayer() when it is called with an empty input.  See http://hg.savannah.gnu.org/hgweb/octave/rev/51f4f59a51dc.

Rik <rik5>
Group administrator
Sun 09 Jul 2023 07:50:23 PM UTC, comment #4: 

I can't test the code in comment #3 because I don't have full access to Matlab.  You might ask on Discourse in the Maintainers area for someone to run this code.  My guess is it fails in the same way as calling audioplayer directly with an empty data input.

Rik <rik5>
Group administrator
Sun 09 Jul 2023 10:46:03 AM UTC, comment #3: 

What does this do in matlab:

a = audiorecorder ();
p = getplayer (A);

I guess if it works in matlab, we could always allocate a silent initial waveform.



John Donoghue <lostbard>
Group Member
Sun 09 Jul 2023 05:22:54 AM UTC, comment #2: 

The second issue, getplayer() failing, does only occur when the data is empty.  I tried this code which works:


A = audiorecorder ();
record (A);
## talk to microphone
stop (A);
p = getplayer (A);


In Matlab, attempting


p = audioplayer ([], 8000)


emits an error that the first argument, Y, must be non-empty.

It seems that Octave should do likewise, rather than emit a strange error about out-of-bound indexing.

Rik <rik5>
Group administrator
Sun 09 Jul 2023 05:05:52 AM UTC, comment #1: 

Any idea why the input validation is trying to weed out callback functions as the first input?  This isn't a documented calling form for either Matlab or Octave.  My first thought is that we should just delete all of this unnecessary code including the comments above the start of the function, the input validation, and the BIST tests.

Rik <rik5>
Group administrator
Mon 03 Jul 2023 07:25:08 PM UTC, original submission:  

Documenttation for audioplayer allows for creation of a audioplayer object using the audiorecorder class however there are two failures.

The first, is that calling audioplayer with the recorder returns a usage rather than the audio player.


> a = audiorecorder;
2> p = audioplayer(a)
error: Invalid call to audioplayer.  Correct usage is:

 -- PLAYER = audioplayer (Y, FS)
 -- PLAYER = audioplayer (Y, FS, NBITS)
 -- PLAYER = audioplayer (Y, FS, NBITS, ID)
 -- PLAYER = audioplayer (RECORDER)
 -- PLAYER = audioplayer (RECORDER, ID)

3>


The issue is that the check for valid arguments does not check if the inputs is a audiorecorder just if its a function handle or char.


  if (nargin < 1 || nargin > 4
      || (nargin < 2 && ! (is_function_handle (varargin{1})
                           || ischar (varargin{1}))))
    print_usage ();
  endif


It should be something like:


  if (nargin < 1 || nargin > 4
      || (nargin < 2 && ! (is_function_handle (varargin{1})
                           || ischar (varargin{1})
                           || isa (varargin{1}, "audiorecorder"))))
    print_usage ();
  endif


The second issue may also occur in matlab ?
When getplayer that is called in audioplayer constructor (or when called independtanly)


octave:3> a = audiorecorder;
octave:4> p = getplayer(a)
error: index (1,_): out of bound 0 (dimensions are 0x1)
error: called from
    audioplayer at line 145 column 19
    getplayer at line 36 column 10
octave:5>


The getplayer function calls audioplayer with the audiodata of the recorder object and samplerate and bits per sample:


  data = getaudiodata (recorder);
  player = audioplayer (data,
                        get (recorder, "SampleRate"),
                        get (recorder, "BitsPerSample"));


According to the documentation data should not be empty, and the documentation also says getplayer returns a audioplayer object populated with the data from the recorder - so the error may also occur in matlab?



John Donoghue <lostbard>
Group Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by rik5
  • -email is unavailable- added by mmuetzel (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by lostbard (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only project members can vote.

     

    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2023-07-12 rik5 StatusIn Progress Fixed
        Open/ClosedOpen Closed
        Fixed ReleaseNone 8.3.0
    2023-07-12 rik5 Carbon-Copy- Added jwe
    2023-07-10 mmuetzel Originator Namelotsbard lostbard
        Planned ReleaseNone 8.3.0
    2023-07-09 rik5 StatusNone In Progress

    Back to the top

    Powered by Savane 3.12