JOBnik's Forum

BASS_FX => BASS_FX => Topic started by: Jeroennl on May 16, 2007, 06:42:45 PM

Title: Changing volume of a WAV file
Post by: Jeroennl on May 16, 2007, 06:42:45 PM
I'm trying to change the volume of my wave file but it doens't seems to work.

I'm using;
Code: [Select]
  BASS_FX_DSP_SetParameters(chan, BASS_FX_DSPFX_VOLUME, @volume); where @volume;
Code: [Select]
  volume.lChannel := 0; volume.fVolume := 0.5;  .

The rest of the code:

Code: [Select]
  chan := BASS_StreamCreateFile(FALSE, PChar(SourceFileName), 0, 0, BASS_STREAM_DECODE);

  BASS_ChannelGetInfo(chan, chaninfo);
nChannels := chaninfo.chans;
  if (chaninfo.flags and BASS_SAMPLE_8BITS > 0)then
  begin
    wBitsPerSample := 8;
  end
  else
  begin
    wBitsPerSample := 16;
  end;
nBlockAlign := nChannels * wBitsPerSample div 8;
BASS_ChannelGetAttributes(chan, frq, vl, Tmp);
  BASS_FX_DSP_SetParameters(chan, BASS_FX_DSPFX_VOLUME, @volume);
  BASS_FX_DSP_Set(chan, BASS_FX_DSPFX_VOLUME, 0);
  nSamplesPerSec := frq;
nAvgBytesPerSec := nSamplesPerSec * nBlockAlign;

  RecStream := TFileStream.Create(naam, fmCreate);
 
  frmProgress.Show;
  frmProgress.Label43.Caption := 'MP3 naar WAV converteren:';

// Write header portion of wave file
  temp := 'RIFF'; RecStream.write(temp[1], length(temp));
  temp := #0#0#0#0; RecStream.write(temp[1], length(temp));
  temp := 'WAVE'; RecStream.write(temp[1], length(temp));
  temp := 'fmt '; RecStream.write(temp[1], length(temp));
  temp := #$10#0#0#0; RecStream.write(temp[1], length(temp));
  temp := #1#0; RecStream.write(temp[1], length(temp));
  if nChannels = 1 then
     temp := #1#0
  else
     temp := #2#0;
  RecStream.write(temp[1], length(temp));
  RecStream.write(nSamplesPerSec, 2);
  temp := #0#0; RecStream.write(temp[1], length(temp));
  RecStream.write(nAvgBytesPerSec, 4);
  RecStream.write(nBlockAlign, 2);
  RecStream.write(wBitsPerSample, 2);
  temp := 'data'; RecStream.write(temp[1],length(temp));
  temp := #0#0#0#0; RecStream.write(temp[1],length(temp));
  while (BASS_ChannelIsActive(chan) > 0) do
  begin
    BytesRead := BASS_ChannelGetData(chan, @buf, 10000);
    RecStream.Write(buf, BytesRead);
    Application.ProcessMessages;
    PercentDone := Trunc(100 * (BASS_ChannelGetPosition(Chan) / BASS_ChannelGetLength(chan)));
    frmProgress.ProgressBar.Position := PercentDone;
    frmProgress.LabelOp.Caption      := 'Voortgang ' + IntToStr(PercentDone) + '%';
  end;
  BASS_StreamFree(chan);

  frmProgress.LabelOp.Caption      := 'Bestand sluiten ...';
  i := RecStream.Size - 8;
  RecStream.Position := 4;
  RecStream.write(i, 4);
  i := i - $24;
  RecStream.Position := 40;
  RecStream.write(i, 4);
  RecStream.Free;
  frmProgress.LabelOp.Caption      := 'Klaar';
  frmProgress.Close;

But i don't get the volume change to work can anyone help me with this?
Title: Re: Changing volume of a WAV file
Post by: (: JOBnik! :) on May 23, 2007, 04:58:51 PM
Hi ;D

Sorry for a long delay with reply... I didn't enter the forum ;)

In your code, you should 1st Set the effect and only the SetParameters on it ;)

i.e:
Code: [Select]
...
  BASS_FX_DSP_Set(chan, BASS_FX_DSPFX_VOLUME, 0);
  BASS_FX_DSP_SetParameters(chan, BASS_FX_DSPFX_VOLUME, @volume);
...
Title: Re: Changing volume of a WAV file
Post by: dbaxter on October 05, 2007, 09:46:26 AM
The volume change works fine on the front speakers of a 5.1 system, but I'm having trouble controlling the rear and center.
This code works fine for the front, but although it enters the rear speaker block, the output doesn't change.
  If (Speakers = 0) then BASS_ChannelSetAttributes(CChan,0,Vol,Pan);
  If (Speakers=16777216) then begin
     //BASS_FX_DSP_GetParameters(CChan,BASS_FX_DSPFX_VOLUME,@fxvol);
     fxvol.lChannel := Bass_fx_dsp_Chan1;
     fxvol.fVolume := RxSlider1.value/100;
     BASS_FX_DSP_SetParameters(CChan,BASS_FX_DSPFX_VOLUME,@fxvol);
     fxvol.lChannel := Bass_fx_dsp_Chan2;
     fxvol.fVolume := RxSlider2.value/100;
     BASS_FX_DSP_SetParameters(CChan,BASS_FX_DSPFX_VOLUME,@fxvol);
    end;
  If (Speakers=33554432) then begin
     //BASS_FX_DSP_GetParameters(CChan,BASS_FX_DSPFX_VOLUME,@fxvol);
     fxvol.lChannel := Bass_fx_dsp_Chan5;
     fxvol.fVolume := RxSlider1.value/100;
     BASS_FX_DSP_SetParameters(CChan,BASS_FX_DSPFX_VOLUME,@fxvol);
     fxvol.lChannel := Bass_fx_dsp_Chan6;
     fxvol.fVolume := RxSlider2.value/100;
     BASS_FX_DSP_SetParameters(CChan,BASS_FX_DSPFX_VOLUME,@fxvol);
    end;

The slider values go from 0 to 100. I tried various other values for fxvol.lChannel just as a shot in the dark, but no luck. What obvious thing am I missing? Thanks!
Dave
Title: Re: Changing volume of a WAV file
Post by: (: JOBnik! :) on October 08, 2007, 01:43:19 PM
Hi ;D

The volume change works fine on the front speakers of a 5.1 system, but I'm having trouble controlling the rear and center.
This code works fine for the front, but although it enters the rear speaker block, the output doesn't change.
  If (Speakers = 0) then BASS_ChannelSetAttributes(CChan,0,Vol,Pan);
  If (Speakers=16777216) then begin
     //BASS_FX_DSP_GetParameters(CChan,BASS_FX_DSPFX_VOLUME,@fxvol);
     fxvol.lChannel := Bass_fx_dsp_Chan1;
     fxvol.fVolume := RxSlider1.value/100;
     BASS_FX_DSP_SetParameters(CChan,BASS_FX_DSPFX_VOLUME,@fxvol);
     fxvol.lChannel := Bass_fx_dsp_Chan2;
     fxvol.fVolume := RxSlider2.value/100;
     BASS_FX_DSP_SetParameters(CChan,BASS_FX_DSPFX_VOLUME,@fxvol);
    end;
  If (Speakers=33554432) then begin
     //BASS_FX_DSP_GetParameters(CChan,BASS_FX_DSPFX_VOLUME,@fxvol);
     fxvol.lChannel := Bass_fx_dsp_Chan5;
     fxvol.fVolume := RxSlider1.value/100;
     BASS_FX_DSP_SetParameters(CChan,BASS_FX_DSPFX_VOLUME,@fxvol);
     fxvol.lChannel := Bass_fx_dsp_Chan6;
     fxvol.fVolume := RxSlider2.value/100;
     BASS_FX_DSP_SetParameters(CChan,BASS_FX_DSPFX_VOLUME,@fxvol);
    end;

The slider values go from 0 to 100. I tried various other values for fxvol.lChannel just as a shot in the dark, but no luck. What obvious thing am I missing? Thanks!
Dave

I just tested the BASS_FX_DSPFX_VOLUME with 5.1 wma file and it works very well by changing the volume of a chosen channel.

BASS_FX_DSPFX_VOLUME will not change the volume of a chosen speaker, it will change the volume of a chosen channel of a played/decoded stream ;)

i.e: If you're playing a stereo file on a rear speakers, the lChannel values should be BASS_FX_DSP_CHAN1 and BASS_FX_DSP_CHAN2