Author Topic: Stem files (multi-track MP4)  (Read 188 times)

mhuellwegen

  • Posts: 20
Stem files (multi-track MP4)
« on: 29 Jul '24 - 17:27 »
Hi Ian,

Your example file isn't actually an fMP4 (that was just trojannemo's files)...
Ah, okay, good. So having a fragmented MP4 is something different from what i've with my grouped 10 channels to 5 stereo tracks?

... It seems like your example MP4 file may have the same sound in all 5 tracks? If so, can you provide a file with different sound in each track?
Yes, you're right.

My STEM.MP4 file, i created for you with the free Win/Mac "Stem Creator" from Native Instruments for debugging, has stupidly the same sound on all 5 tracks.
After uploading the file I also thought that this was not a good idea for a demo file, sorry about that. I will upload another file with different content on all 10 channels / 5 tracks.
But if someone else is interested in STEM Files......

Here everyone can find the free Stem Creator Tool:

  https://www.stems-music.com/stem-creator-tool/





And here everyone can download free STEM Files:

  https://www.native-instruments.com/en/specials/stems-for-all/free-stems-tracks/


Regards
Martin

mhuellwegen

  • Posts: 20
Re: Stem files (multi-track MP4)
« Reply #1 on: 29 Jul '24 - 17:40 »
If so, can you provide a file with different sound in each track? That'll be better for testing purposes.
Just uploaded two other STEM.MP4 files to your incomming ftp folder.

The "MJ" file was created by myself using the NI Stem Creator Tool again and the second one was a file i got from a company preparing tracks for DJs and was not modified by myself in any way.

Ian @ un4seen

  • Administrator
  • Posts: 26035
Re: Stem files (multi-track MP4)
« Reply #2 on: 30 Jul '24 - 17:18 »
So having a fragmented MP4 is something different from what i've with my grouped 10 channels to 5 stereo tracks?

Yes, fragmented MP4 is where there are multiple media data blocks ("mdat" atoms/boxes), usually for streaming purposes. In your case, there's a single data block containing all 5 tracks.

Just uploaded two other STEM.MP4 files to your incomming ftp folder.

The "MJ" file was created by myself using the NI Stem Creator Tool again and the second one was a file i got from a company preparing tracks for DJs and was not modified by myself in any way.

Thanks. Initial tests for accessing the other tracks with Media Foundation on Windows look quite promising. I'll try to check things on the other platforms later this week. I'll post an update here when there's something ready for testing, if all goes well.

Ian @ un4seen

  • Administrator
  • Posts: 26035
Re: Stem files (multi-track MP4)
« Reply #3 on: 6 Aug '24 - 14:31 »
Here's a BASS_AAC update that adds support for multiple tracks in MP4 files:

   www.un4seen.com/stuff/bass_aac.zip

It adds a new BASS_POS_TRACK position mode:

Code: [Select]
#define BASS_POS_TRACK 7

That can be used with BASS_ChannelGetLength to get the number of tracks in the file and with BASS_ChannelSetPosition to change the current track (it will jump to the start of the track). Note this still only allows one track to be decoded/played at a time, so if you want to play multiple tracks from a file simultaneously then you will need to create multiple streams (one for each track). Let me know if you encounter any problems.

Not done yet, but it will hopefully be possible to extend support for this BASS_POS_TRACK option to when using the OS codecs (eg. Media Foundation) instead of BASS_AAC.

mhuellwegen

  • Posts: 20
Re: Stem files (multi-track MP4)
« Reply #4 on: 6 Aug '24 - 17:35 »
Here's a BASS_AAC update.
Many thanx, just playing around with the update.

Quote
That can be used with BASS_ChannelGetLength to get the number of tracks in the file
That works well for me.   As a result i get 5 (= my 5 Stereo Channels, 1 Stereo Sum + 4 Stereo Stem tracks :-) Great!

Quote
with BASS_ChannelSetPosition to change the current track
That works for me as well.

BASS_ChannelSetPosition(hStream, 0, BASS_POS_TRACK) plays the 1 Stereo Sum,

BASS_ChannelSetPosition(hStream, 1, BASS_POS_TRACK) plays the 1st Stereo Stem track,
BASS_ChannelSetPosition(hStream, 2, BASS_POS_TRACK) plays the 2nd Stereo Stem track,
BASS_ChannelSetPosition(hStream, 3, BASS_POS_TRACK) plays the 3rd Stereo Stem track,
BASS_ChannelSetPosition(hStream, 4, BASS_POS_TRACK) plays the 4th Stereo Stem track

Quote
Note this still only allows one track to be decoded/played at a time, so
if you want to play multiple tracks from a file simultaneously
then you will need to create multiple streams (one for each track).
Okay, does this mean i have to call

hStem1 = BASS_StreamCreateFile(FALSE, waveFile, 0, 0, BASS_SAMPLE_LOOP | BASS_STREAM_DECODE | BASS_SAMPLE_FLOAT);
BASS_ChannelSetPosition(hStem1, 1, BASS_POS_TRACK);

hStem2 = BASS_StreamCreateFile(FALSE, waveFile, 0, 0, BASS_SAMPLE_LOOP | BASS_STREAM_DECODE | BASS_SAMPLE_FLOAT);
BASS_ChannelSetPosition(hStem2, 2, BASS_POS_TRACK);

... and so on?

And how do i play all the Stem-Tracks in sync? And does this mean that file/disk traffic will be 4 times of normal playback when using 4 stem tracks?

Regards
Martin


Ian @ un4seen

  • Administrator
  • Posts: 26035
Re: Stem files (multi-track MP4)
« Reply #5 on: 7 Aug '24 - 13:28 »
Okay, does this mean i have to call

hStem1 = BASS_StreamCreateFile(FALSE, waveFile, 0, 0, BASS_SAMPLE_LOOP | BASS_STREAM_DECODE | BASS_SAMPLE_FLOAT);
BASS_ChannelSetPosition(hStem1, 1, BASS_POS_TRACK);

hStem2 = BASS_StreamCreateFile(FALSE, waveFile, 0, 0, BASS_SAMPLE_LOOP | BASS_STREAM_DECODE | BASS_SAMPLE_FLOAT);
BASS_ChannelSetPosition(hStem2, 2, BASS_POS_TRACK);

... and so on?

And how do i play all the Stem-Tracks in sync?

Yes, something like that. To keep the tracks in sync with each other, I would recommend using a mixer, something like this:

Code: [Select]
for (int n = 0; n < 4; n++) {
stem[n] = BASS_StreamCreateFile(FALSE, waveFile, 0, 0, BASS_STREAM_DECODE | BASS_SAMPLE_FLOAT); // create n'th decoder
BASS_ChannelSetPosition(stem[n], 1 + n, BASS_POS_TRACK); // set its track
if (!n) { // create the mixer...
BASS_CHANNELINFO info;
BASS_ChannelGetInfo(stem[n], &info); // get sample format info
mixer = BASS_Mixer_StreamCreate(info.freq, info.chans, BASS_SAMPLE_FLOAT | BASS_MIXER_END); // create mixer with same format
}
BASS_Mixer_StreamAddChannel(mixer, stem[n], 0); // add to the mix
}
BASS_ChannelStart(mixer); // start the mixer

Note I haven't included the BASS_SAMPLE_LOOP flag. I've noticed that the tracks can have slightly different lengths, which means they'll get out of sync if looped individually. If you want to loop the whole thing, you should instead set a mixtime BASS_SYNC_END sync on the mixer and then restart everything in the callback, like this:

Code: [Select]
BASS_ChannelSetSync(mixer, BASS_SYNC_END | BASS_SYNC_MIXTIME, 0, MixerEndSync, 0);

...

void CALLBACK MixerEndSync(HSYNC handle, DWORD channel, DWORD data, void *user)
{
// restart the tracks and mixer
for (int n = 0; n < 4; n++)
BASS_ChannelSetPosition(stem[n], 0, BASS_POS_BYTE);
BASS_ChannelSetPosition(channel, 0, BASS_POS_BYTE);
}

Please see the documentation for details on the mentioned functions.

And does this mean that file/disk traffic will be 4 times of normal playback when using 4 stem tracks?

There won't be any extra disk activity from opening the same file multiple times because the file will be placed in the OS's in-memory file cache when it's first read, and subsequent reads will get it from there.