Best way to loop a sound

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Best way to loop a sound

fauri
Hi!

Is there a preferred way to loop a sound in UOS? The only method I know is "uos_EndProc", but I can't use it, due to a error: Incompatible type for arg no. 2: Got "<address of procedure;Register>", expected "<procedure variable type of procedure of object;Register>".

Thanks for now!
Reply | Threaded
Open this post in threaded view
|

Re: Best way to loop a sound

fredvs
Administrator
> The only method I know is "uos_EndProc", but I can't use it, due to a error: Incompatible type for arg no. 2:

Did you try the demo MorseTL ? It uses uos_EndProc.
What code are you using (could you show it ?)

EndProc is a procedure to execute when the player stop.

But you may also use DSP procedure inside the main loop.

Something like this:
...
uos_InputSetPositionEnable(PlayerIndex1, InputIndex1, 1);
uos_InputAddDSP(PlayerIndex1, InputIndex1, nil, @LoopIt, nil, nil);

And LoopIt function will be something like:

function LoopIt(Data: TuosF_Data; fft: TuosF_FFT): TDArFloat;
  begin
    if uos_InputPosition(PlayerIndex, InputIndex) > uos_InputLength(PlayerIndex, InputIndex) - whenmuststart
 then dosomething;
  end;
Reply | Threaded
Open this post in threaded view
|

Re: Best way to loop a sound

fauri
This post was updated on .
> Did you try the demo MorseTL ? It uses uos_EndProc.

Yeap, and it worked here. But I realized what's wrong, and it's not a UOS fault.

From what I understand, a procedure can be referenced with a "@" symbol only if that routine is inside a class. But I'm using UOS functions in a separate unit (with no classes), and it's impossible to point to any procedure there.

Solution? I had to create another procedure in the main form. And this routine calls back again another one, which has all code I need, including "uos_EndProc" calling the procedure on main form.

Some like that:

unit Sound;
...

procedure play_sound;
   ...
   uos_EndProc(0, @main_play);
   ...

--------------------------------------

unit UMain;
...

procedure TForm1.main_play;
   ...
   play_sound;
   ...

Reply | Threaded
Open this post in threaded view
|

Re: Best way to loop a sound

fredvs
Administrator
Hello.

Did you use the fpc object mode ?

(adding this after program myprogram:)

{$mode objfpc}{$H+}

Fre;D
Reply | Threaded
Open this post in threaded view
|

Re: Best way to loop a sound

fauri
This line already exists (after unit Sound) since I created it. Still, didn't work when I use "@" for a procedure in the same unit.
Reply | Threaded
Open this post in threaded view
|

Re: Best way to loop a sound

fredvs
Administrator
> This line already exists (after unit Sound) since I created it. Still, didn't work when I use "@" for a procedure in the same unit.

Hum, very strange, in MorseTL, unit main_mt.pas does not need a "@" to associate a procedure.

Fre;D
Reply | Threaded
Open this post in threaded view
|

Re: Best way to loop a sound

fauri
This line was extracted from unit main_mt.pas:

>   if length(Memo1.text) > i then  uos_EndProc(player, @CreateMorsePlayer);

It uses "@", as you see. And, because "uos_EndProc" is pointing a TForm1 procedure, it works. The problem is that FPC don't accept calls with "@" inside a unit without a object associed. And I don't why.
Reply | Threaded
Open this post in threaded view
|

Re: Best way to loop a sound

fredvs
Administrator
> t uses "@", as you see.

Oops, I have to buy new glasses (and go to bed).
Yes, sorry, you are totally right.

Fre;D
Reply | Threaded
Open this post in threaded view
|

Re: Best way to loop a sound

fredvs
Administrator
In reply to this post by fauri
> The problem is that FPC don't accept calls with "@" inside a unit without a object associed.

I think that it has something to do with the declared mode.

Did you try with ?:
{$mode delphi}{$H+}

But that way, maybe, uos will have problem.

Fre;D
Reply | Threaded
Open this post in threaded view
|

Re: Best way to loop a sound

fauri
With "{$mode delphi}{$H+}", it works without "@", but only if the procedure informed into uos_EndProc belongs to a object (in this case, TForm1 from main unit). Still remains the same.

Anyway, I think it's not a UOS problem, but a FPC limitation.
Reply | Threaded
Open this post in threaded view
|

Re: Best way to loop a sound

fredvs
Administrator
> Anyway, I think it's not a UOS problem, but a FPC limitation.

OK, I go to sleep then.

Thanks and good night.

Fre;D