Author Topic: BASS MP3 free missing frames  (Read 771 times)

Cristian1980

  • Posts: 60
BASS MP3 free missing frames
« on: 24 Feb '17 - 15:33 »
Hi,

I am using BASS mp3-free version and I just noticed that some of my MP3 files are missing some frames (approximately 3500 frames) in the beginning of the track see attached image.
In the attached image the first track is loaded by Audacity from the MP3 file while the second is loaded from a raw file generated by the following BASS code:
Code: [Select]
float bufferTest[1024];
HSTREAM _bassFileHandle = BASS_StreamCreateFile(FALSE, L"D:\\mp3\\01GirlTalk.mp3", 0, 0, BASS_STREAM_DECODE | BASS_STREAM_PRESCAN | BASS_SAMPLE_FLOAT | BASS_SAMPLE_SOFTWARE | BASS_UNICODE);
int sz;
FILE* fout = fopen("d:\\out.tst","wb");
while ((sz = BASS_ChannelGetData(_bassFileHandle, bufferTest, BASS_DATA_FLOAT | sizeof(bufferTest))) != (DWORD)-1)
fwrite(bufferTest, 1, sz, fout);;
fclose(fout);

I have some beat grids generated by third party programs and it's important for us to get the right positions.

I will email you the link to a track that has this issue.


Thank you for any help,
Cristian
« Last Edit: 24 Feb '17 - 15:39 by Cristian1980 »

Ian @ un4seen

  • Administrator
  • Posts: 20210
Re: BASS MP3 free missing frames
« Reply #1 on: 24 Feb '17 - 16:09 »
The BASS output seems to be correct; it's the same as XMPlay/Winamp/FB2K produce. My guess is that Audacity doesn't process the file's LAME header, so it doesn't exclude the encoder's delay and padding from its output.

Cristian1980

  • Posts: 60
Re: BASS MP3 free missing frames
« Reply #2 on: 28 Feb '17 - 13:27 »
My previous example was on Windows but using the same method to extract the RAW data from MP3 on OSX 10.12 will actually cut a little piece of the track, see attached image. This is not acceptable...
In my opinion too much is cut.
I wasn't aware of LAME header stuff, but note that most profesional DJ applications(Traktor, Rekordbox ) seem to ignore it especially since is something that is not standard.
Is there a way to ignore the LAME header?
Most of the professional music you can buy on DJ Platform have very short silence at the beginning...

Best regards,
Cristian

Ian @ un4seen

  • Administrator
  • Posts: 20210
Re: BASS MP3 free missing frames
« Reply #3 on: 28 Feb '17 - 16:13 »
I guess the top track in the screenshot is the BASS output on OSX, and the middle track is the BASS output on Windows? If so, that's strange, as I'm seeing identical output from the Windows and OSX BASS versions here. For comparison, please try the standard BASS version (not "mp3-free") and see what you get from that.

There isn't currently any way to tell BASS to ignore LAME headers, but I will look into that. Note you may still see a difference of 529 samples between different MP3 decoders even when LAME headers are ignored.

Cristian1980

  • Posts: 60
Re: BASS MP3 free missing frames
« Reply #4 on: 1 Mar '17 - 14:04 »
My mistake, it seems I was using a older BASS-free version on MAC.
Updating to the latest version of BASS-free produces the same result as Windows BASS-free.

However I am still interested in disabling the LAME tag it is not useful for my project and can cause problems.
I read on forums that people using other software like mp3trim will actually mess LAME header and cause it to malfunction(they are probably ignoring it too and reduce the size of the track), I would like to avoid this by ignoring LAME header.

I attached a comparison image between Traktor, BASS and Audacity.

Thank you.
Cristian

Cristian1980

  • Posts: 60
Re: BASS MP3 free missing frames
« Reply #5 on: 6 Mar '17 - 07:29 »
Hi,

Do you think BASS ignoring LAME headers is a possibility?

Regards,
Cristian

Ian @ un4seen

  • Administrator
  • Posts: 20210
Re: BASS MP3 free missing frames
« Reply #6 on: 6 Mar '17 - 17:38 »
Here's an update for you to try:

   www.un4seen.com/stuff/bass.zip

It adds the following BASS_StreamCreateFile flag to ignore delay/padding info in MP3 files:

Code: [Select]
#define BASS_MP3_IGNOREDELAY 0x200 // ignore LAME/Xing/VBRI/iTunes delay & padding info (MP3)

Cristian1980

  • Posts: 60
Re: BASS MP3 free missing frames
« Reply #7 on: 7 Mar '17 - 20:12 »
Thank you a lot.
I will test it and let you know how it works.
Is this mp3-free?
Can I please have it for 64bit MAC too?

Cristian1980

  • Posts: 60
Re: BASS MP3 free missing frames
« Reply #8 on: 8 Mar '17 - 10:29 »
OK, I did some tests and I attached the results.
With the new flag the silence in the beginning of the file is a little bigger but still too short.
Maybe the issue is not caused just by the LAME tags.
In the attached image you can see that the silence length is the same in Audacity, Traktor and Rekordbox and is about 2500 samples(BASS with ignore flag silence is ~790 and ~150 with no flags).
Note that in the Traktor case their waveform is upside down(they have -1 up and 1 down) but the silence is pretty much equal to Audacity.
I added the equal red and green squares, to attached image, so it is easier to see how long the silence is.


Ian @ un4seen

  • Administrator
  • Posts: 20210
Re: BASS MP3 free missing frames
« Reply #9 on: 8 Mar '17 - 17:46 »
The LAME header in the file states a delay of 576 samples, so ignoring the header (via BASS_MP3_IGNOREDELAY) will mean that there is an extra 576 sample gap at the start. As I mentioned earlier, there may be a 529 sample difference between MP3 decoders, depending on whether they remove the decoder delay (the LAME/etc headers give the encoder delay). In the past, BASS only removed that delay when it also removed the encoder delay, but that was changed for consistency between the standard and "mp3-free" BASS versions on all supported platforms, because some of the OS MP3 decoders (on OSX/iOS/Android) remove it themselves. I'm not sure where the extra 1700 samples are coming from with the other decoder in your test. To be honest, if you need exactly the same result everywhere (with different software), it may be better to use a different file format that doesn't have this delay/padding issue, eg. Ogg Vorbis.

Cristian1980

  • Posts: 60
Re: BASS MP3 free missing frames
« Reply #10 on: 9 Mar '17 - 13:24 »
As a background on what I am trying to do, I am saving inside custom ID3 tags the position of beats and some user defined cue points.
The user can then take his music library on USB stick and go to another computer Windows or MAC and have his tracks prepared.
This points, saved in tags, are usually exactly before specific sounds like kicks and beats, where missing 500 samples is a serious issue.
So it is important for me that BASS-free decoding used by my app to be consistent between platforms and future BASS versions(so I can update BASS) or my tags won't match.
I have to support MP3 files because this is what people still use.

I did a new test, I generated a WAV file with 300 samples of silence in the beginning then encoded to MP3 using LAME. Then decoded the MP3 using bass-free for Windows, bass-free for MAC and audacity.
The results are attached.
The conclusion is everyone is wrong and BASS is right :)
Of course using other encoders than LAME things may change.

Is BASS-free guaranteed to be consistent between MAC and Windows versions?
Is the non free version guaranteed to be consistent since it does not depend on the OS?
I understand the last MP3 patents will expire this year, does BASS(non free) use any of patent that did not expire yet?
« Last Edit: 9 Mar '17 - 15:29 by Cristian1980 »

Ian @ un4seen

  • Administrator
  • Posts: 20210
Re: BASS MP3 free missing frames
« Reply #11 on: 9 Mar '17 - 16:04 »
Is BASS-free guaranteed to be consistent between MAC and Windows versions?

It is currently. Of course, the OS's decoders are out of our control, so there's no guarantee that will always be true, but I don't see why it would change.

By the way, just to be clear, that BASS version is called "mp3-free" not "bass-free". It is free of an MP3 decoder, but it isn't free ;)

Is the non free version guaranteed to be consistent since it does not depend on the OS?

Yes, it should be.

I understand the last MP3 patents will expire this year, does BASS(non free) use any of patent that did not expire yet?

If I recall correctly, all MP3 decoding patents have expired by now, but I could be wrong about that (it's a while since I last looked into it).

saga

  • Posts: 2152
Re: BASS MP3 free missing frames
« Reply #12 on: 9 Mar '17 - 16:50 »
In case it's any indication, Fedora (the Linux distribution) now also includes an MP3 decoder, so they also seem to agree about the decoding patents being expired - encoding patents may still be applicable until the end of the year, though.

Cristian1980

  • Posts: 60
Re: BASS MP3 free missing frames
« Reply #13 on: 10 Mar '17 - 09:27 »
Quote
By the way, just to be clear, that BASS version is called "mp3-free" not "bass-free". It is free of an MP3 decoder, but it isn't free

Yes, sorry for the mistype.

Quote
If I recall correctly, all MP3 decoding patents have expired by now, but I could be wrong about that (it's a while since I last looked into it).

The basic MP3 decoding and encoding technology is patent-free in the European Union, all patents having expired there by 2012 at the latest. In the United States, the technology will be substantially patent-free on 31 December 2017 https://en.wikipedia.org/wiki/MP3#Licensing.2C_ownership_and_legislation

Quote
encoding patents may still be applicable until the end of the year, though

I see there are 3 more patents that will expire this year and the refer to:

1/Method and apparatus for encoding digital signals employing bit allocation using combinations of different threshold models to achieve desired bit rates(expires April 16, 2017)
2/Digital coding process for transmission or storage of acoustical signals by transforming of scanning values into spectral coefficients(expires August 29, 2017)
3/Process for reducing data in the transmission and/or storage of digital signals from several interdependent channels(expires December 30, 2017)

These all seem to refer to encoding process see https://www.tunequest.org/a-big-list-of-mp3-patents/20070226/ .
I am only interested in decoding so I wonder if I can use the non mp3-free version...


saga

  • Posts: 2152
Re: BASS MP3 free missing frames
« Reply #14 on: 10 Mar '17 - 14:07 »
You basically answered your own question, didn't you? :) Decoding is believed to be patent-free even in the US by now, so you should be safe to use the non-mp3-free version. Nobody can guarantee that it will be 100% safe, of course - in theory there still could be some applicable patent out there that noone has identified so far, and if some evil corporation owned that patent they could sue users for the remaining year. But I guess the risk is pretty low, given that even some Linux distributions like Fedora ship with an MP3 decoder by default now. If you want to be absolutely safe, you will have to keep using the mp3-free version until the end of the year.

saga

  • Posts: 2152
Re: BASS MP3 free missing frames
« Reply #15 on: 21 Apr '17 - 17:43 »
It's official now: MP3 licensing ends this weekend: https://madfileformatscience.garymcgath.com/2017/04/20/mp3-april-23/

radio42

  • Posts: 4542
Re: BASS MP3 free missing frames
« Reply #16 on: 21 Apr '17 - 20:02 »
That's good news, and might make the bass-free obsolete!