19 Jun '13 - 11:38 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Reply  |  Print  
Author Topic: Make AGC  (Read 3725 times)
MrTDelphi
Posts: 111


« on: 10 Nov '04 - 13:53 »
Reply with quoteQuote

For ALL
What different COMPRESSOR with AGC
and How Make AGC..?
how give ideal value for it?

Thanks A lot
Best,  LuQ
Logged
Chris
Posts: 1507


« Reply #1 on: 10 Nov '04 - 16:16 »
Reply with quoteQuote

Hi...
1.) Compressor
a Compressor will Limit a High Volume
and it will push a low Volume...(and will give Low Volume a better Dynamic)
So you AudioFile will have a more sono stereophonic  Sound...
Thats the same way how every UKW Radiostation will working
2.) AGC (Automatic Gain Control)
this Effekt will try to give on every AudioFile the same Volume
So if you will have a AudioFile the have a bad Volume (Example you will have a AudioFile what will have the highest Volume - 20 DB)
with the Volume of 0 DB

The Best way is to combine both Effects

Compressor for the Dynamic, and AGC for the AutoVolume

Compressor is a FX Effekt..
if you want a AGC-Effekt you can Find it in JOBnik! Bass_FX Dll (DSP Effekt BASS_FX_DSPFX_DAMP)
Greets Chris
Logged
MrTDelphi
Posts: 111


« Reply #2 on: 13 Nov '04 - 06:58 »
Reply with quoteQuote

Hi Chris..

I get/found a C code for normalise like this

Quote
The C code was

Here's a simple dynamic amplification DSP...
#define amptarget 30000 // target level
#define ampquiet 800 // quiet level
#define amprate 0.02f // amp adjustment rate

typedef struct {
    float gain; // amplification level
    int delay; // delay before increasing level
    int count; // count of sequential samples below target level
    int high; // the highest in that period
    int quiet; // count of sequential samples below quiet level
} AUTOAMPSTUFF;

void CALLBACK autoamp(HDSP handle, DWORD channel, void *buffer, DWORD length, AUTOAMPSTUFF *amp)
{
    short *data=(short*)buffer;
    DWORD c;
    for (c=0;c<length/2;c++) {
          int s=(int)(data[c]*amp->gain); // amplify sample
          int sa=abs(s);
          if (abs(data[c])<ampquiet)
                amp->quiet++; // sample is below quiet level
          else
                amp->quiet=0;
          if (sa<amptarget) { // amplified level is below target
                if (sa>amp->high) amp->high=sa;
                amp->count++;
                if (amp->count==amp->delay) { // been below target for a while
                      if (amp->quiet>amp->delay)
                            // it's quiet, go back towards normal level
                            amp->gain+=10*amprate*(1-amp->gain);
                      else
                            amp->gain+=amprate*amptarget/amp->high; // increase amp
                      amp->high=amp->count=0; // reset counts
                }
          } else { // amplified level is above target
                if (s<-32768) s=-32768;
                else if (s>32767) s=32767;
                amp->gain-=2*amprate*sa/amptarget; // decrease amp
                amp->high=amp->count=0;
          }
          data[c]=(short)s; // replace original sample with amplified version
    }
}

...

AUTOAMPSTUFF amp;

amp.gain=1;
amp.delay=BASS_ChannelSeconds2Bytes(handle,1)/2;
amp.count=amp.high=amp.quiet=0;
BASS_ChannelSetDSP(handle,(DSPPROC*)&autoamp,&amp);


How port to Delphi..?

Thanks alot

Best, LuQ
Logged
Keyman
Posts: 167


« Reply #3 on: 13 Nov '04 - 18:23 »
Reply with quoteQuote

Hi MrTDelphi,


Here's the compressor in Delphi:

type
  TAutoAmpStuff = Record
    gain  : float;                
    delay : QWord;  
    Count : integer;  
    High  : integer;    
    quiet : integer;
  end;

var
  AmpStuff: TAutoAmpStuff;

const
  amptarget = 30000;
  ampquiet  = 800;    
  amprate   = 0.02;


implementation

procedure DoAutoAmp(Handle, Channel: DWORD; Buffer: Pointer; BufLen, Amp: DWORD); stdcall;
var
  Data: ^Smallint;
  s, sa: Integer;
begin
  Data := Buffer;
  while (BufLen > 0) do
  begin
    s  := Trunc(Data^ * AmpStuff.gain);
    sa := Abs(s);
    if abs(data^) < ampquiet then
      Inc(AmpStuff.quiet)                              // sample is below quiet level
    else
      AmpStuff.quiet := 0;

    if sa < amptarget then                         // amplified level is below target
    begin
      if sa > AmpStuff.High then AmpStuff.High := sa;
      Inc(AmpStuff.Count);
      if AmpStuff.Count > AmpStuff.delay then              // been below target for a while
      begin
        if AmpStuff.quiet > AmpStuff.delay then            // it's quiet, go back towards normal level
        begin
            AmpStuff.gain := AmpStuff.gain + (10 * amprate * (1 - AmpStuff.gain));
        end
        else begin
          // increase amp
          AmpStuff.gain := AmpStuff.gain + (amprate * (amptarget / AmpStuff.High));
          AmpStuff.High  := 0;
          AmpStuff.Count := 0;                           // reset counts
      end;
    end
    else begin                                     // amplified level is above target
      if s < -32768 then s := -32768
      else if s > 32767 then s := 32767;
      AmpStuff.gain  := AmpStuff.gain - (amprate * (sa / amptarget)); // decrease amp
      AmpStuff.High  := 0;
      AmpStuff.Count := 0;
    end;
    data^ := Smallint(s);                          // replace original sample with amplified version
    Inc(Data);
    Dec(Buflen, 2);
  end;
end;


procedure LoadFile(AFile: TFileName);
begin
  // do whatever you do to load the file
  FStream := BASS_StreamCreateFile(FALSE, PChar(AFile), 0, 0, 0);

  AmpStuff.gain  := 1;
  AmpStuff.delay := Trunc((BASS_ChannelSeconds2Bytes(FChannels[FCurChan].Stream, 1) / 2));
  AmpStuff.Count := 0;
  AmpStuff.High  := 0;
  AmpStuff.quiet := 0;

  BASS_ChannelSetDSP(FStream, @DoAutoAmp, 0);
end;


Pred(Cool  -  Suc(6)
Logged
MrTDelphi
Posts: 111


« Reply #4 on: 20 Nov '04 - 11:15 »
Reply with quoteQuote

Hi.. keyman

Its seem works ok (not error anything), but
how I know its Working.., I mean
maybe with indicator or else..?
so how to set good gain, delay, count, high and quet value for that
than to remove it

Thanks again n again...
LuQ

Logged
Chris
Posts: 1507


« Reply #5 on: 20 Nov '04 - 11:31 »
Reply with quoteQuote

why are you not using Dynamic Amplification from the Bass_FX DLL Huh
(and it will make perfect AutoGain)
Greets Chris
Logged
Bert
Guest
« Reply #6 on: 22 Nov '04 - 15:23 »
Reply with quoteQuote

Chris,

which values do you use for Dynamic Amplification?
I want play some songs which are different in their loudness.
Logged
Chris
Posts: 1507


« Reply #7 on: 23 Nov '04 - 09:39 »
Reply with quoteQuote

I`m using here the following Values

fTarget:0.92
fQuiet:0.02
fRate:0.01
fGain:1.0
fDelay:0.5

Greets Chris
« Last Edit: 23 Nov '04 - 09:40 by Chris » Logged
MrTDelphi
Posts: 111


« Reply #8 on: 23 Nov '04 - 15:32 »
Reply with quoteQuote

Yes..
I used BASS_FX_DSPFX_DAMP (BASS_FX)..it real Dynamic Amplification... Wink
than I tried your value Chris..
so I combine both (compressor), its cool....
Chris
which values do you use for Compressor?

me
  vGain:= 2;
  vAttack:= 1.2;
  vRelease:= 400;
  vThreshold:= -20;
  vRatio:= 10;
  vPredelay:= 2;

Thanks  alot
LuQ
Logged
Chris
Posts: 1507


« Reply #9 on: 23 Nov '04 - 18:33 »
Reply with quoteQuote

Hi yup its the perfect Combination.......
I`m using the follwing Values..
 vGain:=0;
 vAttack:= 10;
 vRelease:= 200;
 vThreshold:= -20;
 vRatio:= 3;
 vPredelay:= 4;

the best way is that the User can change self the Values....
one will a hard Compression (like your values)...the other one will a soft Compression..
Greets Chris
Logged
MrTDelphi
Posts: 111


« Reply #10 on: 24 Nov '04 - 07:12 »
Reply with quoteQuote

yes I fill hard enough compression w my value N
Anytime the best way is that the User can change self the Values....yep  Wink
but, How to show AGC or Compression w Indicator (like outputlevel) ?

Best,
LuQ
Logged
(: JOBnik! :)
Posts: 991


« Reply #11 on: 24 Nov '04 - 10:41 »
Reply with quoteQuote

Hi Grin

but, How to show AGC or Compression w Indicator (like outputlevel) ?

To get the current values use: BASS_FX_DSP_GetParameters(..)
To set new values use: BASS_FX_DSP_SetParameters(..)

Have fun!

Cool JOBnik! Cool
Logged
Chris
Posts: 1507


« Reply #12 on: 24 Nov '04 - 11:52 »
Reply with quoteQuote

but, How to show AGC or Compression w Indicator (like outputlevel) ?


mmm interessenting Idea........I will try something here I`m not shure if  that`s possible....
Greets Chris
Logged
Chris
Posts: 1507


« Reply #13 on: 24 Nov '04 - 14:23 »
Reply with quoteQuote

Hi
at this Moment I will see no way .....
Maybe Ian has an Idea.....
Greets Chris
Logged
Rookie
Guest
« Reply #14 on: 6 Dec '04 - 18:30 »
Reply with quoteQuote

Hi,
im new to bass and very interested.

How do you combine these two, compressor and dynamic amp?
Do you have a little example?

Thank you!
Logged
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines