Audio Redirector, output filter problem

Please post bug reports, feature requests, or any question regarding the DELPHI AREA products here.

Audio Redirector, output filter problem

Postby cozturk » October 7th, 2009, 10:47 am

This is Soft-amplifier and filter project for live signal and speaker output.

Simple code inserted to Wave audio package Redirector demo.
But read and write same buffer data. No filtering. , Additional filters may be available later.

After reading buffer, Output muting. no sound. How is the way to read and write for this buffer?

Code: Select all
procedure TMainForm.RedirectorAudioOutFilter(Sender: TObject;
  const Buffer: Pointer; BufferSize: Cardinal);
var
  ms: tmemorystream;
begin
  ms := tmemorystream.create;
  ms.ReadBuffer(Buffer^, BufferSize);     // problem
  ms.Position:=0;
//  msamp(ms, 2.5);      //  (stream, gain)   Soft amplifier , disabled for test
  ms.Position:=0;
  ms.WriteBuffer(buffer,BufferSize);
  ms.Free;
end;


While debugging, stream read error occurs:
error.JPG
stream read error
error.JPG (16.23 KiB) Viewed 1562 times


Error generated by
Code: Select all
procedure TWaveAudioIO.DoFilter(const Buffer: Pointer; BufferSize: DWORD);
begin
  if Assigned(fOnFilter) and not (csDestroying in ComponentState) then
    fOnFilter(Self, Buffer, BufferSize);
end;
cozturk
Moderator
Moderator
 
Posts: 63
Joined: June 30th, 2005, 5:39 am
Location: Istanbul - Turkiye

Re: Audio Redirector, output filter problem

Postby Kambiz » October 8th, 2009, 3:24 pm

Change this line
Code: Select all
ms.WriteBuffer(buffer,BufferSize);

to this one
Code: Select all
ms.WriteBuffer(buffer^,BufferSize);

A simple mistake! :)
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Re: Audio Redirector, output filter problem

Postby cozturk » October 8th, 2009, 3:42 pm

Thank you Kambiz,

But still same error with this code

Code: Select all
procedure TMainForm.RedirectorAudioOutFilter(Sender: TObject;
  const Buffer: Pointer; BufferSize: Cardinal);
var
  ms: tmemorystream;
begin
  ms := tmemorystream.create;
  ms.ReadBuffer(Buffer^, BufferSize); // problem
  ms.Position := 0;
  //  msamp(ms,1.5);      //
  ms.Position := 0;
  ms.WriteBuffer(buffer^,BufferSize);
  ms.Free;

end;
cozturk
Moderator
Moderator
 
Posts: 63
Joined: June 30th, 2005, 5:39 am
Location: Istanbul - Turkiye

Re: Audio Redirector, output filter problem

Postby Kambiz » October 8th, 2009, 5:20 pm

Because there is still a logical mistake in your code.

Here is the correct code:

Code: Select all
procedure TMainForm.RedirectorAudioOutFilter(Sender: TObject;
  const Buffer: Pointer; BufferSize: Cardinal);
var
  ms: tmemorystream;
begin
  ms := tmemorystream.create;
  ms.WriteBuffer(Buffer^, BufferSize);
  ms.Position := 0;
  //  msamp(ms,1.5);      //
  ms.Position := 0;
  ms.ReadBuffer(buffer^,BufferSize);
  ms.Free;
end;

Did you notice the difference?
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Re: Audio Redirector, output filter problem

Postby cozturk » October 8th, 2009, 6:16 pm

Yes. I see.

WriteBuffer first, ReadBuffer later..

Thanks again.

Kambiz, would you share low pass filter(voice band) or 50-60Hz mains noise filter code for memorystream.?
I need algorithm.
\:D/
cozturk
Moderator
Moderator
 
Posts: 63
Joined: June 30th, 2005, 5:39 am
Location: Istanbul - Turkiye

Re: Audio Redirector, output filter problem

Postby Kambiz » October 9th, 2009, 6:00 am

I've never written those algorithms, otherwise they were already included in the WA package.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm


Return to DELPHI AREA Products

Who is online

Users browsing this forum: No registered users and 2 guests

cron