serbod / acs

Audio Components Suite for Lazarus/Delphi
63 stars 21 forks source link

Access Violation Exception raised on TStdAudioOut.Init (only on Linux, but no in Windows) #23

Open wilco2009 opened 2 years ago

wilco2009 commented 2 years ago

Hi! I have a program using your library, working right on Windows, but in Linux the sound does not want to start.

My program is a zxspectrum emulator, and I have using a TAcsMemoryIn as destination of the emulator sound, and it is connected to a TAcsAudioOut.

I have used the following code to setup the buffers:

  ACSEar.DataBuffer :=@speaker_buffer;
  ACSEar.DataSize := bufsize;                         // bufsize = 180

And I start the sound in another point of the code with:

AudioOut.Run();

I have inserting some code to investigate, and I have found an Access Violation en the following point:

  procedure TAcsOutThread.Execute();
 var
   //DoneThread: TAcsVerySmallThread;
   ParentComponent: TAcsCustomOutput;
   Res: Boolean;
 begin
   ParentComponent:=(Parent as TAcsCustomOutput);
   // init
   try
     writeln('TAcsOutThread.Execute()');
     ParentComponent.Init();
   except
     on E: Exception do
     begin
       if Assigned(Self.HandleException) then Self.HandleException(E);             // <- here return an Access Violation exception
       writeln('TAcsOutThread.Execute() - Exception ', E.Message);       
       Terminate();
     end;
   end;

However in the "ParentComponent.Init();" all seems to be working rigth.

procedure TAcsCustomOutput.Init();
var
  //TmpInput: TAcsCustomInput;
  TmpPrefetchMode: TAcsPrefetchMode;
begin
  writeln('TAcsCustomOutput.Init() - 0');
  if not Assigned(FInput) then
    raise EAcsException.Create(strInputNotAssigned);
  writeln('TAcsCustomOutput.Init() - 1');
  SetBufferSize(FBufferSize); // set default buffer size
  writeln('TAcsCustomOutput.Init() - 2');
  if Assigned(FInput) then FInput.Init();
  writeln('TAcsCustomOutput.Init() - 3');

  // calculate prefetch mode
  TmpPrefetchMode:=FPrefetchMode;
  writeln('TAcsCustomOutput.Init() - 4');
  { TODO: get prefetch mode from filters chain }
  {
  if TmpPrefetchMode = pmAuto then
  begin
    // get prefetch mode from input
    TmpInput:=Self.Input;
    while Assigned(TmpInput) or (TmpPrefetchMode = pmAuto) do
    begin
      TmpPrefetchMode:=TmpInput.PrefetchMode;
      TmpInput:=TmpInput.Input;
    end;
  end;
  }
  if TmpPrefetchMode = pmAuto then TmpPrefetchMode:=pmFetch1_4;
  writeln('TAcsCustomOutput.Init() - 5');

  // calculate prefetch size
  FPrefetchSize:=0;
  case TmpPrefetchMode of
    pmFetch3_4: FPrefetchSize:=(BufferSize div 4) * 3;
    pmFetch1_2: FPrefetchSize:=(BufferSize div 2);
    pmFetch1_4: FPrefetchSize:=(BufferSize div 4);
    pmFetch1_8: FPrefetchSize:=(BufferSize div 8);
  end;
  writeln('TAcsCustomOutput.Init() - 6');
end;

Do you know what i could be doing bad?

If you need you can download the entire code of my program on my github: https://github.com/wilco2009/Alvatrum

thank you in advance.

serbod commented 2 years ago

Are you put cthreads unit in project's uses?

https://wiki.lazarus.freepascal.org/Multithreaded_Application_Tutorial

On Wed, Dec 22, 2021, 00:45 wilco2009 @.***> wrote:

Hi! I have a program using your library, working right on Windows, but in Linux the sound does not want to start.

My program is a zxspectrum emulator, and I have using a TAcsMemoryIn as destination of the emulator sound, and it is connected to a TAcsAudioOut.

I have used the following code to setup the buffers:

ACSEar.DataBuffer @.***_buffer; ACSEar.DataSize := bufsize; // bufsize = 180

And I start the sound in another point of the code with:

AudioOut.Run();

I have inserting some code to investigate, and I have found an Access Violation en the following point:

procedure TAcsOutThread.Execute(); var //DoneThread: TAcsVerySmallThread; ParentComponent: TAcsCustomOutput; Res: Boolean; begin ParentComponent:=(Parent as TAcsCustomOutput); // init try writeln('TAcsOutThread.Execute()'); ParentComponent.Init(); except on E: Exception do begin if Assigned(Self.HandleException) then Self.HandleException(E); // <- here return an Access Violation exception writeln('TAcsOutThread.Execute() - Exception ', E.Message); Terminate(); end; end;

However in the "ParentComponent.Init();" all seems to be working rigth.

procedure TAcsCustomOutput.Init(); var //TmpInput: TAcsCustomInput; TmpPrefetchMode: TAcsPrefetchMode; begin writeln('TAcsCustomOutput.Init() - 0'); if not Assigned(FInput) then raise EAcsException.Create(strInputNotAssigned); writeln('TAcsCustomOutput.Init() - 1'); SetBufferSize(FBufferSize); // set default buffer size writeln('TAcsCustomOutput.Init() - 2'); if Assigned(FInput) then FInput.Init(); writeln('TAcsCustomOutput.Init() - 3');

// calculate prefetch mode TmpPrefetchMode:=FPrefetchMode; writeln('TAcsCustomOutput.Init() - 4'); { TODO: get prefetch mode from filters chain } { if TmpPrefetchMode = pmAuto then begin // get prefetch mode from input TmpInput:=Self.Input; while Assigned(TmpInput) or (TmpPrefetchMode = pmAuto) do begin TmpPrefetchMode:=TmpInput.PrefetchMode; TmpInput:=TmpInput.Input; end; end; } if TmpPrefetchMode = pmAuto then TmpPrefetchMode:=pmFetch1_4; writeln('TAcsCustomOutput.Init() - 5');

// calculate prefetch size FPrefetchSize:=0; case TmpPrefetchMode of pmFetch3_4: FPrefetchSize:=(BufferSize div 4) * 3; pmFetch1_2: FPrefetchSize:=(BufferSize div 2); pmFetch1_4: FPrefetchSize:=(BufferSize div 4); pmFetch1_8: FPrefetchSize:=(BufferSize div 8); end; writeln('TAcsCustomOutput.Init() - 6'); end;

Do you know what i could be doing bad?

If you need you can download the entire code of my program on my github: https://github.com/wilco2009/Alvatrum

thank you in advance.

— Reply to this email directly, view it on GitHub https://github.com/serbod/acs/issues/23, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACXM37OVI34XZTQLRQTKK4DUSDYPJANCNFSM5KREKEHQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you are subscribed to this thread.Message ID: @.***>

wilco2009 commented 2 years ago

Thanks for your reply! Yes I am using it in the lpr file: `program Alvatrum;

{$mode objfpc}{$H+} { $AppType CONSOLE}

uses {$IFDEF UNIX}{$IFDEF UseCThreads} cthreads, {$ENDIF}{$ENDIF} Interfaces, // this includes the LCL widgetset Forms, etpackage, lazcolorpalette, laz_acs_lib, pascalscript, main, Z80, Z80ops, Z80Globals, z80bitops, Z80bitops_ixiy, roms, Screen, fastbitmap, Z80Tools, exops, spectrum, TAP, Global, hardware, FileFormats, cassette, bas2tap, bin2tap;

{$R *.res}

begin RequireDerivedFormResource:=True; Application.Initialize; Application.ExtendedKeysSupport:= true; Application.CreateForm(TSpecEmu, SpecEmu); Application.Run; end. ` In the personalized options section I have added '-dUseCThreads'.

regards

wilco2009 commented 2 years ago

Do you have any example working in Linux to take as reference? thanks in advance

EDIT: I mean an example using TACSMemoryIn

serbod commented 2 years ago

I do not have native linux for long time. Only virtual machine. Try console player demo for example, it very simple.

If you can write ZX Spectrum emulator, you may be proficient in low-level debugging. I will accept your fixes and suggestions.

On Thu, Dec 23, 2021, 00:31 wilco2009 @.***> wrote:

Do you have any example working in Linux to take as reference? thanks in advance

— Reply to this email directly, view it on GitHub https://github.com/serbod/acs/issues/23#issuecomment-999892529, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACXM37JBVEDYCAXY7X4HGC3USI7S7ANCNFSM5KREKEHQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>