Author Topic: Delphi for MacOS  (Read 162 times)

MikeatBookup

  • Posts: 32
Delphi for MacOS
« on: 16 Oct '21 - 20:16 »
Delphi 11

I'm getting error code 6 when calling BASS_RecordStart() while targeting MacOS.

The microphone works with the VoiceMemos app on the Mac.

The BASS help file doesn't show the values of the error constants, and the Delphi wrapper I'm using doesn't show them either (or I may be misunderstanding which ones apply to BASS_RecordStart).

Code: [Select]
function RecordingCallback(Handle: HRECORD; buffer: Pointer; length: DWORD; user: Pointer): boolean; stdcall;
begin
  Result := True;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  theErrorCode: Integer;

begin
  Button2.Enabled:= False;

  if not BASS_RecordInit(-1) then
    ShowMessage('Cannot start default recording device!')
  else
  begin
    Channel:= BASS_RecordStart(44100, 2, 0, @RecordingCallback, nil);
    if Channel = 0
      then
        begin
          theErrorCode := BASS_ErrorGetCode;
          ShowMessage('Couldn''t start recording! Error is ' + theErrorCode.ToString)
        end
    else
    begin
      BASS_Encode_MP3_StartFile(Channel, '', BASS_ENCODE_AUTOFREE or BASS_UNICODE, PChar(FilePath + 'MP3Rec.mp3'));
      Button3.Enabled:= True;
    end;
  end;
end;

Chris

  • Posts: 1989
Re: Delphi for MacOS
« Reply #1 on: 16 Oct '21 - 22:36 »
The Bass_Error Values are in the front of the Bass.pas .

MikeatBookup

  • Posts: 32
Re: Delphi for MacOS
« Reply #2 on: 16 Oct '21 - 22:47 »
Ah, then error code 6 is "unsupported sample format."

How would I get around that?


Chris

  • Posts: 1989
Re: Delphi for MacOS
« Reply #3 on: 17 Oct '21 - 12:32 »
The error comes from the Lame Encoder.
"BASS_ERROR_FORMAT   The channel's sample format is not supported by the encoder"

is that the same Device as in the other Post ?
if yes i thing a good start it to list which SampleFormats the Device/Sound will supportet.
so something like

Code: [Select]
var r_info : BASS_RECORDINFO;

   Bass_RecordGetInfo(r_info);

if ( r_info.formats and WAVE_FORMAT_4S16 > 0) then.......// will support 44.1   kHz, Stereo, 16-bit
else
........

by the way which Device ? Realtec ?

and by the way
Code: [Select]
BASS_Encode_MP3_StartFile(Channel, '', BASS_ENCODE_AUTOFREE or BASS_UNICODE, PChar(FilePath + 'MP3Rec.mp3'));
must be
BASS_Encode_MP3_StartFile(Channel, nil, BASS_ENCODE_AUTOFREE or BASS_UNICODE, PChar(FilePath + 'MP3Rec.mp3'));

'' is not the same as nil (or in other Dev Languages NULL)
« Last Edit: 17 Oct '21 - 19:14 by Chris »

MikeatBookup

  • Posts: 32
Re: Delphi for MacOS
« Reply #4 on: 17 Oct '21 - 16:04 »
The use of '' in lieu of nil is from code borrowed from TDDung's Github contribution.

This is unrelated to the other post. This is a new issue, targeting MacOS. (The project also records and plays back that MP3 file on an iPad which amazes me!)

The project works successfully and plays back the MP3 file on a Mac 10.15.7 Catalina.

The project gives error code 6 when calling BASS_RecordStart() on a Mac 11.4 Big Sur M1.

I will add the r_info.formats checking code you suggested and post the results here. I assume from the code that it is always recording to WAV format even on a Mac?

MikeatBookup

  • Posts: 32
Re: Delphi for MacOS
« Reply #5 on: 17 Oct '21 - 16:41 »
Both the Mac that works and the Mac that fails while reporting error code 6 say "No to WAVE_FORMAT_4S16".

Code: [Select]
var
  r_info: BASS_RECORDINFO;
begin
  if not Bass_RecordGetInfo(r_info)
    then
      begin
        ShowMessage('Bass_RecordGetInfo failed.');
        Exit;
      end;

  if (r_info.formats and WAVE_FORMAT_4S16 > 0)
    then ShowMessage ('Yes to WAVE_FORMAT_4S16')
    else ShowMessage ('No to WAVE_FORMAT_4S16');
end;

Bass_RecordGetInfo() does fail if recording hasn't been started.

TDDung

  • Posts: 33
Re: Delphi for MacOS
« Reply #6 on: 17 Oct '21 - 18:59 »
Not completely sure (Has been a year ago) but I remember that on MacOS The Bass_RecordInit(-1) may need to be replaced by Bass_RecordInit(0) instead. You could try.

Delphi 11

I'm getting error code 6 when calling BASS_RecordStart() while targeting MacOS.

The microphone works with the VoiceMemos app on the Mac.

The BASS help file doesn't show the values of the error constants, and the Delphi wrapper I'm using doesn't show them either (or I may be misunderstanding which ones apply to BASS_RecordStart).

Code: [Select]
function RecordingCallback(Handle: HRECORD; buffer: Pointer; length: DWORD; user: Pointer): boolean; stdcall;
begin
  Result := True;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  theErrorCode: Integer;

begin
  Button2.Enabled:= False;

  if not BASS_RecordInit(-1) then
    ShowMessage('Cannot start default recording device!')
  else
  begin
    Channel:= BASS_RecordStart(44100, 2, 0, @RecordingCallback, nil);
    if Channel = 0
      then
        begin
          theErrorCode := BASS_ErrorGetCode;
          ShowMessage('Couldn''t start recording! Error is ' + theErrorCode.ToString)
        end
    else
    begin
      BASS_Encode_MP3_StartFile(Channel, '', BASS_ENCODE_AUTOFREE or BASS_UNICODE, PChar(FilePath + 'MP3Rec.mp3'));
      Button3.Enabled:= True;
    end;
  end;
end;

Ian @ un4seen

  • Administrator
  • Posts: 23997
Re: Delphi for MacOS
« Reply #7 on: 18 Oct '21 - 14:58 »
I'm getting error code 6 when calling BASS_RecordStart() while targeting MacOS.

It may be that the recording device only supports mono. Try setting the BASS_RecordStart "chans" parameter to 1 and see if you still get the error then.

Note the WAVE_FORMAT_XXX flags aren't used on macOS, but you can check the high 8 bits for the maximum number of channels, like this:

Code: [Select]
int chans = info.formats >> 24;

MikeatBookup

  • Posts: 32
Re: Delphi for MacOS
« Reply #8 on: 18 Oct '21 - 16:25 »
I tried that. No joy.

Calling BASS_RecordInit(0) still worked on the Catalina Mac and still reported error code 6 on the Big Sur M1 Mac.

Not completely sure (Has been a year ago) but I remember that on MacOS The Bass_RecordInit(-1) may need to be replaced by Bass_RecordInit(0) instead. You could try.

MikeatBookup

  • Posts: 32
Re: Delphi for MacOS
« Reply #9 on: 18 Oct '21 - 17:23 »
This was indeed fixed by switching to '1' for the parameter in BASS_RecortStart(). Thank you!

Apparently the issue was masked by the Mac laptop simulating stereo recording with its mono mic.

This also fixed the issue with half speed recording of MP3 files on the two Windows 10 machines using a mono mic.

I'm getting error code 6 when calling BASS_RecordStart() while targeting MacOS.

It may be that the recording device only supports mono. Try setting the BASS_RecordStart "chans" parameter to 1 and see if you still get the error then.