Author Topic: Does BASS provide Replay Gain function?  (Read 16315 times)

qindagg

  • Posts: 12
Does BASS provide Replay Gain function?
« on: 1 Sep '08 - 03:57 »
I don't know whether Replay Gain has been a standard,
http://replaygain.hydrogenaudio.org/ describe this question as:

The Problem
Not all CDs sound equally loud. The perceived loudness of mp3s is even more variable. Whilst different musical moods require that some tracks should sound louder than others, the loudness of a given CD has more to do with the year of issue or the whim of the producer than the intended emotional effect. If we add to this chaos the inconsistent quality of mp3 encoding, it's no wonder that a random play through your music collection can have you leaping for the volume control every other track.

...
I searched in BASS documents, but No results was found. Does BASS provide Replay Gain function? How to use it? Thanks you all!

Ian @ un4seen

  • Administrator
  • Posts: 23288
Re: Does BASS provide Replay Gain function?
« Reply #1 on: 1 Sep '08 - 15:25 »
BASS won't apply Replaygain, but you can do so yourself by reading the Replaygain information from the tags and then applying it in a DSP function (or use BASS_FX's volume effect).

qindagg

  • Posts: 12
Re: Does BASS provide Replay Gain function?
« Reply #2 on: 3 Sep '08 - 09:07 »
BASS won't apply Replaygain, but you can do so yourself by reading the Replaygain information from the tags and then applying it in a DSP function (or use BASS_FX's volume effect).

Thank you , Ian, but I have another question, to analyze music files such as mp3,
---------------------------------------------------------------------------------
 *  Pseudo-code to process an album:
 *
 *    Float_t       l_samples [4096];
 *    Float_t       r_samples [4096];
 *    size_t        num_samples;
 *    unsigned int  num_songs;
 *    unsigned int  i;
 *
 *    InitGainAnalysis ( 44100 );
 *    for ( i = 1; i <= num_songs; i++ ) {
 *        while ( ( num_samples = getSongSamples ( song, left_samples, right_samples ) ) > 0 )
 *            AnalyzeSamples ( left_samples, right_samples, num_samples, 2 );
 *        fprintf ("Recommended dB change for song %2d: %+6.2f dB\n", i, GetTitleGain() );
 *    }
 *    fprintf ("Recommended dB change for whole album: %+6.2f dB\n", GetAlbumGain() );
 */
----------------------------------------------------------------------------------------
Could I get song samples of mp3 or wma file using BASS? how can I do it?

dhft

  • Guest
Re: Does BASS provide Replay Gain function?
« Reply #3 on: 3 Sep '08 - 12:55 »
but you can do so yourself by reading the Replaygain information from the tags
could you be more informative ? which tags ?

Ian @ un4seen

  • Administrator
  • Posts: 23288
Re: Does BASS provide Replay Gain function?
« Reply #4 on: 3 Sep '08 - 15:05 »
Could I get song samples of mp3 or wma file using BASS? how can I do it?

Yep, you can use decoding channels (see the BASS_STREAM_DECODE flag). For WMA support, you will need the BASSWMA add-on, which can be plugged into the standard BASS stream creation functions via BASS_PluginLoad.

but you can do so yourself by reading the Replaygain information from the tags
could you be more informative ? which tags ?

The "replaygain_album_gain" and "replaygain_track_gain" entries. Pretty much any tag type that allows custom entries can contain them. In the case of ID3v2 tags, they will be stored in "TXXX" frames.

hamsen

  • Posts: 22
Re: Does BASS provide Replay Gain function?
« Reply #5 on: 21 Dec '09 - 12:23 »
BASS won't apply Replaygain, but you can do so yourself by reading the Replaygain information from the tags and then applying it in a DSP function (or use BASS_FX's volume effect).

Hi Ian

If I use MP3gain, the audiofile will be modified and the replaygain will work without player intervention.
But if I use dbPoweramp, only the tags are placed in the file.
This means I will have to use your suggested action.
Do you have any examples (delphi) how to do that?
I'm playing using this statement:

PLAY.Hdl:=BASS_StreamCreateFile(False, f, 0, 0, BASS_UNICODE);

Regards
Thomas

Ian @ un4seen

  • Administrator
  • Posts: 23288
Re: Does BASS provide Replay Gain function?
« Reply #6 on: 21 Dec '09 - 15:54 »
I don't use Delphi myself, so I'm afraid I can't advise on the specifics of that, but the basic process is to read the Replaygain tags and then apply the gain. If you're dealing with MP3 files, then that probably means ID3v2 tags, which are available via BASS_ChannelGetTags (BASS_TAG_ID3V2). For simplicity, you may want to use a 3rd-party library to parse the ID3v2 tag block (extract the Replaygain info), eg. something like id3lib. The 2nd part (applying the gain) can most simply be achieved with the BASS_FX add-on's BASS_FX_BFX_VOLUME effect, like this (in C)...

Code: [Select]
HFX volfx=BASS_ChannelSetFX(stream, BASS_FX_BFX_VOLUME, 0); // set volume FX on stream
BASS_BFX_VOLUME volparam;
volparam.lChannel=0; // "global" volume
volparam.fVolume=pow10(gain/20); // convert the replaygain dB gain to a linear value
BASS_FXSetParameters(volfx, &volparam); // apply it

hamsen

  • Posts: 22
Re: Does BASS provide Replay Gain function?
« Reply #7 on: 21 Dec '09 - 17:28 »
I don't use Delphi myself, so I'm afraid I can't advise on the specifics of that, but the basic process is to read the Replaygain tags and then apply the gain. If you're dealing with MP3 files, then that probably means ID3v2 tags, which are available via BASS_ChannelGetTags (BASS_TAG_ID3V2). For simplicity, you may want to use a 3rd-party library to parse the ID3v2 tag block (extract the Replaygain info), eg. something like id3lib. The 2nd part (applying the gain) can most simply be achieved with the BASS_FX add-on's BASS_FX_BFX_VOLUME effect, like this (in C)...

Code: [Select]
HFX volfx=BASS_ChannelSetFX(stream, BASS_FX_BFX_VOLUME, 0); // set volume FX on stream
BASS_BFX_VOLUME volparam;
volparam.lChannel=0; // "global" volume
volparam.fVolume=pow10(gain/20); // convert the replaygain dB gain to a linear value
BASS_FXSetParameters(volfx, &volparam); // apply it

Thanks, Ian.
I'll give it a try.

Regards
Thomas

hamsen

  • Posts: 22
Re: Does BASS provide Replay Gain function?
« Reply #8 on: 22 Dec '09 - 12:28 »
I don't use Delphi myself, so I'm afraid I can't advise on the specifics of that, but the basic process is to read the Replaygain tags and then apply the gain. If you're dealing with MP3 files, then that probably means ID3v2 tags, which are available via BASS_ChannelGetTags (BASS_TAG_ID3V2). For simplicity, you may want to use a 3rd-party library to parse the ID3v2 tag block (extract the Replaygain info), eg. something like id3lib. The 2nd part (applying the gain) can most simply be achieved with the BASS_FX add-on's BASS_FX_BFX_VOLUME effect, like this (in C)...

Code: [Select]
HFX volfx=BASS_ChannelSetFX(stream, BASS_FX_BFX_VOLUME, 0); // set volume FX on stream
BASS_BFX_VOLUME volparam;
volparam.lChannel=0; // "global" volume
volparam.fVolume=pow10(gain/20); // convert the replaygain dB gain to a linear value
BASS_FXSetParameters(volfx, &volparam); // apply it

Thanks, Ian.
I'll give it a try.

Regards
Thomas

I have an error 19.

This is the sequence of statements:

PLAY.Hdl:=BASS_StreamCreateFile(False, f, 0, 0, BASS_UNICODE);

PLAY.HdlFX:=BASS_ChannelSetFX(PLAY.Hdl,BASS_FX_BFX_VOLUME,0);

PLAY.hdlFX contains 0 and the errorcode is 19.

This is as far as I get. Any ideas?

Regards
Thomas

hamsen

  • Posts: 22
Re: Does BASS provide Replay Gain function?
« Reply #9 on: 22 Dec '09 - 13:10 »
Hi Ian

Apparently it helped to include a version check for BASS:FX.

If (HiWord(BASS_FX_GetVersion()) <> BASSVERSION) then....

So I will continue my test.

Regards
Thomas

Ian @ un4seen

  • Administrator
  • Posts: 23288
Re: Does BASS provide Replay Gain function?
« Reply #10 on: 22 Dec '09 - 13:22 »
Yep. Error code 19 is BASS_ERROR_ILLTYPE, which meant that BASS_FX_BFX_VOLUME was unrecognised, due to BASS_FX not being loaded. Adding the BASS_FX_GetVersion call forced it to be loaded.

hamsen

  • Posts: 22
Re: Does BASS provide Replay Gain function?
« Reply #11 on: 23 Dec '09 - 18:36 »
Hi Ian

I have the code working now.
The problem is, I'm not really sure it makes a difference.

Maybe I don't understand the concept.

Let me give you an example:

A given mp3file has the following values:

MP3gain       = TrackGain +0.495db TrackPeak 0.534013
dbPowerAmp = TrackGain +0.460db TrackPeak 0.532684

These values are apparently close to each other.

TrackGain +0.46db means lower the volume. or?
TrackPeak means the highest level in the file, but what does the value represent? db?

Anyway, following your example and use TrackGain gives this result:

pow10(+0,46 / 20) yields about 1,05...

My statement is: BassFXvol.fVolume:=power(10,RGinfo.Gain/20)

Can that be right? The global volume is 1 and now I set it to 1,05?

I'm confused, please help (after Christmas will be fine).

radio42

  • Posts: 4705
Re: Does BASS provide Replay Gain function?
« Reply #12 on: 23 Dec '09 - 18:50 »
Yes, your meth is correct!
The peak level value is denoted as a float (1.0 means 0dB) - so your track seems to be quite silent, as the peak is a around -6dB.
So you need to amplify it a bit and such 0.46-0.46dB is about 1.05 in float.

hamsen

  • Posts: 22
Re: Does BASS provide Replay Gain function?
« Reply #13 on: 23 Dec '09 - 19:17 »
Yes, your meth is correct!
The peak level value is denoted as a float (1.0 means 0dB) - so your track seems to be quite silent, as the peak is a around -6dB.
So you need to amplify it a bit and such 0.46-0.46dB is about 1.05 in float.

Thanks for the reply.

I should have mentioned, that the +.046db is related to my standard value 89db, meaning that the volume should be cut by 0,46db from 90db (calculated by MP3gain).

In order to accomplish that, which value should I pass to BassFXvol.fVolume? 1,05?

radio42

  • Posts: 4705
Re: Does BASS provide Replay Gain function?
« Reply #14 on: 23 Dec '09 - 21:10 »
Yes, as your standard/reference value is already taken into account during the replay gain calculation.

bits

  • Posts: 44
Re: Does BASS provide Replay Gain function?
« Reply #15 on: 23 Dec '09 - 22:16 »
Replay gain data in id3v2 is typically in the RVA2 or RGAD frames.

If mp3 encoded by lame it can also be in the xing header.

Vorbis comments and APE tags normally have it in
REPLAYGAIN_TRACK_GAIN
REPLAYGAIN_TRACK_PEAK
REPLAYGAIN_ALBUM_GAIN
REPLAYGAIN_ALBUM_PEAK

hamsen

  • Posts: 22
Re: Does BASS provide Replay Gain function?
« Reply #16 on: 24 Dec '09 - 07:52 »
Yes, as your standard/reference value is already taken into account during the replay gain calculation.

I really appriciate your help since I'm not exactly an expert in this area.
If I understand you correctly, a higher value in BassFXvol.fVolume than 1 lowers the volume and a lower value will raise the volume?

By the way, I'm trying to make my player replaygain capable.

Regarding the tags, it seems that there are many ways to store the values.
dbPowerAmp stores the values in ID3v2 TXXX frames.

Regards and merry christmas

Thomas

radio42

  • Posts: 4705
Re: Does BASS provide Replay Gain function?
« Reply #17 on: 24 Dec '09 - 09:39 »
Yes, the BassFXvol.fVolume is defined like this:
0.0 : silence
0.0 ... 1.0 : lowers the volume
1.0 : no change
> 1.0 : amplifies the volume

Yes, a lot of different applications might store the replay gain values to different tags, but normally they are stores in the text tags called: "REPLAYGAIN_TRACK_GAIN" and "REPLAYGAIN_TRACK_PEAK".
So it should be quite save to use only these.

hamsen

  • Posts: 22
Re: Does BASS provide Replay Gain function?
« Reply #18 on: 24 Dec '09 - 11:38 »
Yes, that's what I thought.

I think I had my reference tracks wrong.

Example1:
Gain -3.3db
Peak 0.941182
This will give a volume of .6839 which means lowering the volume.

Example2:
Gain +1.25db
Peak 0.936561
This will give a volume of 1.1547 which means raising the volume.

All values from dbPowerAmp.


Does that sound ok to you?
Would it mean, that playing those two tracks, the volume would sound at the same level?


Regards
Thomas

radio42

  • Posts: 4705
Re: Does BASS provide Replay Gain function?
« Reply #19 on: 24 Dec '09 - 12:20 »
Yes, that might sound okay - of course I don't know your tracks.
However, for most modern tracks lowering the volume is required, so that they sound qually lound to 'older' tracks which doesn't have the same dynamic range.

hamsen

  • Posts: 22
Re: Does BASS provide Replay Gain function?
« Reply #20 on: 24 Dec '09 - 12:23 »
Thanks very much.

Now I can finish work on my player.

Merry Christmas and a happy new year.

Thomas

mxdeluxe2012

  • Guest
Re: Does BASS provide Replay Gain function?
« Reply #21 on: 29 Oct '12 - 09:28 »
Could I get song samples of mp3 or wma file using BASS? how can I do it?

Yep, you can use decoding channels (see the BASS_STREAM_DECODE flag). For WMA support, you will need the BASSWMA add-on, which can be plugged into the standard BASS stream creation functions via BASS_PluginLoad.

but you can do so yourself by reading the Replaygain information from the tags
could you be more informative ? which tags ?

The "replaygain_album_gain" and "replaygain_track_gain" entries. Pretty much any tag type that allows custom entries can contain them. In the case of ID3v2 tags, they will be stored in "TXXX" frames.

I tried to open my stream with BASS_STREAM_DECODE - my tags ("replaygain_track_peak" and "replaygain_track_gain") are always the same (gain: "-100.0" and peak:"-1.0").
Any ideas why this is always the same?

Ian @ un4seen

  • Administrator
  • Posts: 23288
Re: Does BASS provide Replay Gain function?
« Reply #22 on: 29 Oct '12 - 13:00 »
Please confirm how you are getting those gain and peak values, as they don't look valid.