fbpx
Skip to main content

MIDI Forum

What is the largest...
 
Notifications
Clear all

What is the largest size for a SMF file?

7 Posts
4 Users
0 Reactions
3,310 Views
Sema
 Sema
Posts: 180
Reputable Member
Topic starter
 

Dear all,

What is the largest size of SMF you have ever dealt with?
Looking for something really big for testing purposes...

Thanks a lot in advance!

 
Posted : 13/06/2023 7:22 pm
JohnG
Posts: 225
Estimable Member
 

From recollection, I think the last movement of Mahler's second symphony was pretty large at around 650 kilobytes.
But there may well be bigger files.
But actually the largest size is something like 268 million bytes per MThd and per MTrk, if my reading of the SMF spec. is correct.
0F FF FF FF hex.

 
Posted : 14/06/2023 3:22 am
Bavi_H
Posts: 266
Reputable Member
 

Previously, in the post Re: MIDI file request, Jason mentioned a page of MIDI file soundtracks -- that is, each one is a single MIDI file that plays the all the music heard in a game as if you played the game from start to finish:

[quotePost id=14598]For LARGE MIDI files, you can have a look here:
http://www.midimusicadventures.com/queststudios/midi-soundtracks/complete-soundtracks/
These are soundtracks from old PC games made by Sierra/Quest Studios.[/quotePost]
It looks like the largest file on that page is the first one, the soundtrack for The Adventures Of Willy Beamish, WILLYMT.MID. The file size is 1,513,074 bytes and the playback duration is about 2.5 hours.

_______

As for the theoretical maximum file size of a MIDI 1.0 Standard MIDI File...

The number of tracks is stored as two bytes, so the maximum number of tracks is 2^16 - 1 or 65535.

The size of each track is stored as four bytes (and is not a variable-length quantity), so the maximum number of data bytes in a track is 2^32 - 1 or 4294967295.

"MThd" 4
size 4
format 2
number of tracks 2
division 2
total size for header 14
"MTrk" 4
length 4
events 4294967295
total size for each track 4294967303
size of header and 65535 tracks 281470682202119

In other words, the maximum size is

14 + (2^16 - 1) × (8 + 2^32 - 1) = 281,470,682,202,119 bytes

or about 255.996 tebibytes

 
Posted : 14/06/2023 6:02 am
JohnG
Posts: 225
Estimable Member
 

As for the theoretical maximum file size of a MIDI 1.0 Standard MIDI File...

The number of tracks is stored as two bytes, so the maximum number of tracks is 2^16 - 1 or 65535.

The size of each track is stored as four bytes (and is not a variable-length quantity), so the maximum number of data bytes in a track is 2^32 - 1 or 4294967295.

Actually, Bavi, if you look at the structure of the four bytes making up the Header Length or Track Length, you'll find (as in so much with MIDI 1.0) it's only the least significant seven bits that are used in each of the four bytes for the count. The first bit of the first three bytes must be 1 and of the last byte must be zero. See the first few pages of the SMF specification.
(See page 2 of the SMF spec in complete MIDI 1.0 spec. - Sequences, Tracks, Chunks: File Block Structure - Conventions)

This reduces the count to 268,435,455. Should be enough.

 
Posted : 15/06/2023 2:16 am
Clemens Ladisch
Posts: 321
Reputable Member
 

[quotePost id=18825]if you look at the structure of the four bytes making up the Header Length or Track Length, you'll find (as in so much with MIDI 1.0) it's only the least significant seven bits that are used in each of the four bytes for the count.[/quotePost]

The specification actually says:

Some numbers in MIDI Files are represented in a form called a variable-length quantity.

The chunk length is not a variable-length quantity.

 
Posted : 15/06/2023 5:18 am
Bavi_H
Posts: 266
Reputable Member
 

Hello JohnG. You are describing the variable-length quantity format, which can take one to four bytes depending on how big the value to be stored is. The length in the chunk headers always uses four bytes and is not in the variable-length quantity format. See the next page of the Standard MIDI Files Specification (printed page 3 / PDF page 5):

MIDI Files are made up of chunks. Each chunk has a 4-character type and a 32-bit length [...]
Each chunk begins with a 4-character ASCII type. It is followed by a 32-bit length, most significant byte first (a length of 6 is stored as 00 00 00 06).

It goes on to say the chunk format is similar to Electronic Arts's IFF format. It appears the IFF format uses a signed 32-bit integer for the size. The calculation in my previous post assumed an unsigned 32-bit integer was being used. If a signed 32-bit integer is used, then the maximum number of data bytes in a track is 2^31 − 1. It's all theoretical of course, MIDI files are unlikely to get big enough to need to care if the chunk size is signed or unsigned.

 
Posted : 15/06/2023 5:19 am
JohnG
Posts: 225
Estimable Member
 

Ah!
My mistake, I stand corrected.
Yes, it's four bytes fixed length, not variable.
So, theoretically up to 4,294,967,295 ... per Mtrk.
Quite big then.

Apologies.

 
Posted : 15/06/2023 10:17 am
Share: