Author Topic: Recording at half speed?  (Read 197 times)

MikeatBookup

  • Posts: 32
Recording at half speed?
« on: 16 Oct '21 - 02:55 »
My Delphi project seems to record MP3 files at half speed.

It's driving me bonkers as I don't seem to be changing the code.

I can run the same .exe with the same DLLs on Windows 11 and it records MP3 files normally.

When I run the same project on Windows 10 the MP3 files are recorded at half speed.

Code: [Select]
procedure TEbookWindow.StartRecordingAudioBASS;
var
  theErrorCode: Integer;

begin
  // BASS_Init() has already been called at this point.
  // BASS_RecordInit(-1) has already been called at this point.

  fBASS_HRECORD := BASS_RecordStart(44100, 2, 0, @BASSRecordingCallback, nil); // start recording
                                //  44100, 2, 0, @RecordingCallback,     nil
  if (fBASS_HRECORD = 0)
    then
      begin
        theErrorCode := BASS_ErrorGetCode;

        ShowMessage('BASS_RecordStart() failed with error code ' + theErrorCode.ToString);
      end;

  BASS_Encode_MP3_StartFile(fBASS_HRECORD, '', BASS_ENCODE_AUTOFREE or BASS_UNICODE, PChar(TPath.Combine(gPreferences.TemporaryFolder, kMultimediaAudioTemporaryFileName)));

  theErrorCode := BASS_ErrorGetCode;
  if (theErrorCode <> 0)
    then
      begin
        ShowMessage('BASS_Encode_MP3_StartFile() failed with error code ' + theErrorCode.ToString);
      end;
end;

Chris

  • Posts: 1989
Re: Recording at half speed?
« Reply #1 on: 16 Oct '21 - 08:17 »
I think  the Bug is in your ReordingCallback . Is the RecordingCallback needed ? Because you will sending the Recording Data to the Mp3 Encoder.
if yes then you can do it like this
Code: [Select]
fBASS_HRECORD := BASS_RecordStart(44100, 2, 0, nil, nil); // start recording Can you show the Code of your RecordingCallback ?

Code: [Select]
BASS_Encode_MP3_StartFile(fBASS_HRECORD, '', BASS_ENCODE_AUTOFREE or BASS_UNICODE, PChar(TPath.Combine(gPreferences.TemporaryFolder, kMultimediaAudioTemporaryFileName)));should to be
BASS_Encode_MP3_StartFile(fBASS_HRECORD, nil, BASS_ENCODE_AUTOFREE or BASS_UNICODE, PChar(TPath.Combine(gPreferences.TemporaryFolder, kMultimediaAudioTemporaryFileName)));

so that the code will look something like this

Code: [Select]
var
  EbookWindow: TEbookWindow;
  fBass_HRecord:HRecord = 0;
  FBass_Enc:HEncode = 0;
implementation

function TEbookWindow.StartRecordingAudioBASS:boolean;
begin
  fBASS_HRECORD := BASS_RecordStart(44100, 2, 0, nil, nil); // start recording
  if (fBASS_HRECORD <> 0) then
  FBass_Enc :=   BASS_Encode_MP3_StartFile(fBASS_HRECORD, nil, BASS_ENCODE_AUTOFREE or BASS_UNICODE,
      PChar(TPath.Combine(gPreferences.TemporaryFolder, kMultimediaAudioTemporaryFileName)));
  Result := (fBass_HRecord <> 0) and (fBass_Enc <> 0);
end;
« Last Edit: 16 Oct '21 - 10:06 by Chris »

Chris

  • Posts: 1989
Re: Recording at half speed?
« Reply #2 on: 16 Oct '21 - 08:25 »
.

MikeatBookup

  • Posts: 32
Re: Recording at half speed?
« Reply #3 on: 16 Oct '21 - 18:52 »
The code for the callback is quite simple as I am not using it. Replacing the parameter for the callback with nil resulted in a 2K MP3 file with no audio so it seems the callback is necessary.

Code: [Select]

function BASSRecordingCallback(Handle: HRECORD; buffer: Pointer; length: DWORD; user: Pointer): LongBool; stdcall;
begin
  Result := True;
end;


Chris Oakley

  • Posts: 167
Re: Recording at half speed?
« Reply #4 on: 16 Oct '21 - 18:57 »
Not sure if this would help pinpoint the issue but what happens if you change this:
Code: [Select]
BASS_RecordStart(44100, 2, 0, nil, nil);

to something like:

Code: [Select]
BASS_RecordStart(8000, 2, 0, nil, nil);

Does that change the speed in any way?

Just wondering if the device you're recording from may be fixed at a different sample rate.

MikeatBookup

  • Posts: 32
Re: Recording at half speed?
« Reply #5 on: 16 Oct '21 - 20:04 »
That made no difference.

It works correctly on my Windows 11 machine but makes a half speed (twice as long) audio file on my Windows 10 machines.

TDDung

  • Posts: 33
Re: Recording at half speed?
« Reply #6 on: 17 Oct '21 - 19:03 »
This is necessary as True will signal to BassEnc that the current audio data has been processed and its buffer can be clear to accept new incoming audio data.

The code for the callback is quite simple as I am not using it. Replacing the parameter for the callback with nil resulted in a 2K MP3 file with no audio so it seems the callback is necessary.

Code: [Select]

function BASSRecordingCallback(Handle: HRECORD; buffer: Pointer; length: DWORD; user: Pointer): LongBool; stdcall;
begin
  Result := True;
end;


TDDung

  • Posts: 33
Re: Recording at half speed?
« Reply #7 on: 17 Oct '21 - 19:08 »
Did not see the same problem like yours. Both Windows 11 and Windows 10 (used to write the demo) work fine for me (2 different laptops). Processing time may be quite slow on your Windows 10?

My Delphi project seems to record MP3 files at half speed.

It's driving me bonkers as I don't seem to be changing the code.

I can run the same .exe with the same DLLs on Windows 11 and it records MP3 files normally.

When I run the same project on Windows 10 the MP3 files are recorded at half speed.

Code: [Select]
procedure TEbookWindow.StartRecordingAudioBASS;
var
  theErrorCode: Integer;

begin
  // BASS_Init() has already been called at this point.
  // BASS_RecordInit(-1) has already been called at this point.

  fBASS_HRECORD := BASS_RecordStart(44100, 2, 0, @BASSRecordingCallback, nil); // start recording
                                //  44100, 2, 0, @RecordingCallback,     nil
  if (fBASS_HRECORD = 0)
    then
      begin
        theErrorCode := BASS_ErrorGetCode;

        ShowMessage('BASS_RecordStart() failed with error code ' + theErrorCode.ToString);
      end;

  BASS_Encode_MP3_StartFile(fBASS_HRECORD, '', BASS_ENCODE_AUTOFREE or BASS_UNICODE, PChar(TPath.Combine(gPreferences.TemporaryFolder, kMultimediaAudioTemporaryFileName)));

  theErrorCode := BASS_ErrorGetCode;
  if (theErrorCode <> 0)
    then
      begin
        ShowMessage('BASS_Encode_MP3_StartFile() failed with error code ' + theErrorCode.ToString);
      end;
end;

MikeatBookup

  • Posts: 32
Re: Recording at half speed?
« Reply #8 on: 17 Oct '21 - 20:45 »
The half speed recording issue is happening on two different machines. They just happen to be Windows 10 machines.

The Windows 11 machine is a virtual one on an M1 Mac and it works fine.

Even though I can reproduce the issue, there is no error so I don't know what would cause it.

Chris

  • Posts: 1989
Re: Recording at half speed?
« Reply #9 on: 17 Oct '21 - 22:24 »
can you test the Record Demo (from the Demo Package) would be interesting
if the Problem come`s from the Recording Channel or from the Lame  Encoding.

Ian @ un4seen

  • Administrator
  • Posts: 23991
Re: Recording at half speed?
« Reply #10 on: 18 Oct '21 - 14:57 »
To perhaps narrow down what/where the problem is, please see if you can reproduce it with the pre-compiled RECTEST.EXE example from the BASS package (C\BIN folder). If that works fine then also try the pre-compiled RECTEST-ADDONS.EXE example from the BASSenc package (with MP3 output selected).

MikeatBookup

  • Posts: 32
Re: Recording at half speed?
« Reply #11 on: 18 Oct '21 - 16:35 »
Yes! You are on to something.

RECTEST.EXE with the BASS.DLL marked 2.4.16.7 (no other DLLs) records and plays back at half speed on my Windows 10 machine.

To perhaps narrow down what/where the problem is, please see if you can reproduce it with the pre-compiled RECTEST.EXE example from the BASS package (C\BIN folder). If that works fine then also try the pre-compiled RECTEST-ADDONS.EXE example from the BASSenc package (with MP3 output selected).

Chris

  • Posts: 1989
Re: Recording at half speed?
« Reply #12 on: 18 Oct '21 - 16:39 »
fBASS_HRECORD := BASS_RecordStart(44100, 2

I that maybe the same problem as in your "Delphi for MacOS" Thread?
so that the Soundcard doesn`t support Stereo?
Maybe a Driver Problem?

MikeatBookup

  • Posts: 32
Re: Recording at half speed?
« Reply #13 on: 18 Oct '21 - 16:51 »
Tried:

  fBASS_HRECORD := BASS_RecordStart(44100, 1, 0, @BASSRecordingCallback, nil);

This does solve the problem on the first Windows 10 machine. Thank you!

I will try this on the other Windows 10 machine and on the M1 Mac. (Curiously the Windows 11 VM which runs the original BASS_RecordStart(44100, 2...) without an issue is running inside Parallels on that M1 Mac.)

fBASS_HRECORD := BASS_RecordStart(44100, 2

I that maybe the same problem as in your "Delphi for MacOS" Thread?
so that the Soundcard doesn`t support Stereo?
Maybe a Driver Problem?

Chris

  • Posts: 1989
Re: Recording at half speed?
« Reply #14 on: 18 Oct '21 - 17:05 »
For me look like a Driver Thing.
Which Soundcard are on the laptop ?

MikeatBookup

  • Posts: 32
Re: Recording at half speed?
« Reply #15 on: 18 Oct '21 - 17:18 »
I can confirm that the code now works on both Windows 10 machines and on both of the non-M1 Silicon Macs. The other issue with building for native M1 Silicon Macs remains.

Apparently the Macbook and the Windows 11 VM inside the other Mac both simulate stereo recording with mono microphones which is why they worked with the '2' as a parameter.

I don't know how to find information on the Mac laptop's driver or sound card.

For me look like a Driver Thing.
Which Soundcard are on the laptop ?