MP3 - Bass.dll and volume levelling

1.9k Views Asked by At

I am using Bass.dll with MP3 files and it works well, but the MP3s seem to have been recorded with different levels of output volume.

Is there some way I can test for audible volume and then adjust the Bass Volume level accordingly so that all MP3s play at around the same level?

As it is now, if I turn down the loud one, the quiet ones are not audible, so I am forever shuffling volume up and down.

I found a link here for using Bass and listening to the microphone, but that does not seem like the best approach -- or is it?

1

There are 1 best solutions below

1
Rabi Jayasawal On

If I am not wrong, you want to adjust the volume of a channel which must be applicable for all the preceding tracks. I have posted some code for you. You can proceed same approach for playing a list of tracks. Once you set the volume, all the following tracks should play at the same volume level.

procedure TForm1.Button1Click(Sender: TObject);
begin
  if OpenDialog1.Execute then
  begin
    // Free the stream if a song is playing
    if Channel <> 0 then
      BASS_StreamFree(Channel);

    // Create a new stream
    Channel := BASS_StreamCreateFile(False, PChar(OpenDialog1.FileName), 0, 0, 0 {$IFDEF UNICODE} or BASS_UNICODE {$ENDIF});

    // Check if channel is unable to play
    if Channel = 0 then begin
      ShowMessage('Unable to play');
      Exit;
    end;

    // Set volume for every playback
    BASS_ChannelSetAttribute(Channel, BASS_ATTRIB_VOL, TrackBar1.Position / 100);

    // Play the track
    BASS_ChannelPlay(Channel, False);
  end;
end;

And the code when we adjust volume using trackbar.

procedure TForm1.TrackBar1Change(Sender: TObject);
begin
  // Adjust volume for the current track
  BASS_ChannelSetAttribute(Channel, BASS_ATTRIB_VOL, TrackBar1.Position / 100);
end;