fbpx
Skip to main content

MIDI Forum

Notifications
Clear all

RIFF File

13 Posts
5 Users
0 Reactions
5,771 Views
Carlos
Posts: 86
Estimable Member
Topic starter
 

I found a midi file contained within a riff file, are they all the same?, because I have only found one among 1671 midi files that I have, and it seems that I only have to omit the first bytes and treat it as a normal midi file. I'm surprised musescore can't read it. Is there anything else I should know? I attached the file.

[code type=markup]0000:0000 | 52 49 46 46 80 53 00 00 52 4D 49 44 64 61 74 61 | RIFF.S..RMIDdata
0000:0010 | 74 53 00 00 4D 54 68 64 00 00 00 06 00 01 00 2D | tS..MThd.......[/code]

I found this RIFF File Structure but it is not clear to me if it can contain more than one file at the same time, just as a midi file contains several chunk.

 
Posted : 09/03/2023 6:56 am
Jason
Posts: 429
Honorable Member
 

Nice find! I don't think I've come across one myself. I'll check it out later today and see if my instrument switcher will load it, or crash and burn :p

 
Posted : 09/03/2023 7:00 am
Geoff
Posts: 1040
Noble Member
 

A RIFF file is a 'package' file, somewhat akin to a .zip file but not using any data compression. The file can contain any number of 'chunks' of data, and the data can be organised so that there can be chunks of chunks, rather like a directory tree of files on your HD.

The problem from the point of view of your enquiry is that each chunk will have a small header, with 'admin' data. Such data will mess up the midi process if you try to do something with the RIFF file directly.

I don't know if the size of a chunk is fixed, or can vary. Probably if a single midi file size is less than the chunk size then is could be a simple matter to remove the initial header and 'play' the rest directly. But NOT if the midi file is bigger than a chunk.

I don't think that the structure of a RIFF is very complex, so extracting all the files, or even all the midi files, could be fairly simple.

Geoff

 
Posted : 09/03/2023 7:55 am
Carlos
Posts: 86
Estimable Member
Topic starter
 

Thanks, that's what I thought, it could be much more difficult than it seems, I've seen that wav files are also saved like this.

Does anyone have a riff file that contains more than one midi file? Or is there a way to create it?

 
Posted : 09/03/2023 8:58 am
Geoff
Posts: 1040
Noble Member
 

Carlos,

Most normal .WAV files are actually a RIFF file, but all WAV files that I've dealt with contain one 'wave' file only. I've not seen any with more than one.

Audacity has an option to turn a .WAV file into a headerless data file, in effect a .WAV file with the RIFF header removed. Also an option to go the other way, i.e. add the RIFF header to wave data to make a .WAV file (i.e. a RIFF file).

I think that some DAW systems can save projects as RIFF, this could include both midi and wave data? But might be midi only?

Also seen reference to the idea that a RIFF file containing specifically midi data should be called a RMI file, rather than RIFF. So watch out for .RMI files?

I don't see the point of a RIFF file, as opposed to a .MID or a .WAV, unless it is to contain a number of files (i.e. a .jpg and a .mid etc). Where did the RIFF file you found come from?

Geoff

 
Posted : 09/03/2023 10:46 am
Carlos
Posts: 86
Estimable Member
Topic starter
 

I don't remember exactly who gave it to me, but they gave it to me in this forum, it was in the folder: XG/Yamaha-XG-Midi-Library/XGSONG/

He's right, the riff format with a single midi doesn't make sense.

Look at the timidity code and it just skips the riff header

[code type=c]//Timidity++ 2.15.0
if(memcmp(magic, "MThd", 4) == 0)
{
readmidi_read_init();
err = read_smf_file(tf);
}
else if(memcmp(magic, "RCM-", 4) == 0 || memcmp(magic, "COME", 4) == 0)
{
readmidi_read_init();
err = read_rcp_file(tf, magic, fn);
}
else if (strncmp(magic, "RIFF", 4) == 0) {
if (tf_read(magic, 1, 4, tf) == 4 &&
tf_read(magic, 1, 4, tf) == 4 &&
strncmp(magic, "RMID", 4) == 0 &&
tf_read(magic, 1, 4, tf) == 4 &&
strncmp(magic, "data", 4) == 0 &&
tf_read(magic, 1, 4, tf) == 4) {
goto retry_read;
} else {
err = 1;
ctl->cmsg(CMSG_WARNING, VERB_NORMAL,
"%s: Not a MIDI file!", current_filename);
}
}
else if(memcmp(magic, "melo", 4) == 0)
{
readmidi_read_init();
err = read_mfi_file(tf);
}[/code]

And the vlc code is not clear to me if it just skips it or tries to read more than one chunk
[code type=c]//VLC 3.0.17.4
/* Skip RIFF MIDI header if present */
if (!memcmp (peek, "RIFF", 4) && !memcmp (peek + 8, "RMID", 4))
{
uint32_t riff_len = GetDWLE (peek + 4);

msg_Dbg (demux, "detected RIFF MIDI file %"PRIu32" bytes", riff_len);//I had to remove the parentheses from '%"PRIu32" bytes' because otherwise it is not sent, forum error.
if ((vlc_stream_Read (stream, NULL, 12) < 12))
return VLC_EGENERIC;

/* Look for the RIFF data chunk */
for (;;)
{
char chnk_hdr[8];
uint32_t chnk_len;

if ((riff_len < 8)
|| (vlc_stream_Read (stream, chnk_hdr, 8) < 8))
return VLC_EGENERIC;

riff_len -= 8;
chnk_len = GetDWLE (chnk_hdr + 4);
if (riff_len < chnk_len)
return VLC_EGENERIC;
riff_len -= chnk_len;

if (!memcmp (chnk_hdr, "data", 4))
break; /* found! */

if (vlc_stream_Read (stream, NULL, chnk_len) < (ssize_t)chnk_len)
return VLC_EGENERIC;
}

/* Read real SMF header. Assume RIFF data chunk length is proper. */
if (vlc_stream_Peek (stream, &peek, 14) < 14)
return VLC_EGENERIC;
}[/code]

 
Posted : 09/03/2023 11:27 am
Pedro Lopez-Cabanillas
Posts: 154
Estimable Member
 

I've posted a question here long time ago about this matter.

RIFF MIDI files are bundles of Standard MIDI files with an optional DLS Soundfont. The file extension is usually RMI.

The open source Drumstick project has support for reading RIFF MIDI files since v2.4.0

 
Posted : 09/03/2023 10:02 pm
Clemens Ladisch
Posts: 323
Reputable Member
 

RIFF "RMID" files contain exactly one SMF file in the "data" chunk. But the file might contain other chunks; Microsoft suggests that "INFO" makes sense.

You have to search for the "data" chunk. The Timidity code assumes that the "data" chunk is the first chunk; I do not know if this is correct.

Also see aplaymidi:
[code type=c]static int read_riff(void)
{
/* skip file length */
read_byte();
read_byte();
read_byte();
read_byte();

/* check file type ("RMID" = RIFF MIDI) */
if (read_id() != MAKE_ID('R', 'M', 'I', 'D')) {
invalid_format:
errormsg("%s: invalid file format", file_name);
return 0;
}
/* search for "data" chunk */
for (;;) {
int id = read_id();
int len = read_32_le();
if (feof(file)) {
data_not_found:
errormsg("%s: data chunk not found", file_name);
return 0;
}
if (id == MAKE_ID('d', 'a', 't', 'a'))
break;
if (len < 0)
goto data_not_found;
skip((len + 1) & ~1);
}
/* the "data" chunk must contain data in SMF format */
if (read_id() != MAKE_ID('M', 'T', 'h', 'd'))
goto invalid_format;
return read_smf();
}[/code]

 
Posted : 09/03/2023 10:25 pm
Carlos
Posts: 86
Estimable Member
Topic starter
 

[quotePost id=17951]I've posted a question here long time ago about this matter.

RIFF MIDI files are bundles of Standard MIDI files with an optional DLS Soundfont. The file extension is usually RMI.

The open source Drumstick project has support for reading RIFF MIDI files since v2.4.0
[/quotePost]

I thought I had seen this before around here but I couldn't find it. I downloaded these files and they are larger than usual.

[quotePost id=17952]RIFF "RMID" files contain exactly one SMF file in the "data" chunk. But the file might contain other chunks; Microsoft suggests that "INFO" makes sense.

You have to search for the "data" chunk. The Timidity code assumes that the "data" chunk is the first chunk; I do not know if this is correct.

[/quotePost]

So I shouldn't assume that I will find the midi in the first block. Thank you.

 
Posted : 10/03/2023 3:45 am
Jason
Posts: 429
Honorable Member
 

I tested the file out with my instrument switcher. It appears the file loads, and I can probably change instruments, but the exported midi file afterwards does not play. If I load the unmodified file in Winamp, it plays fine.

Does not load:
Domino
MidiEditor
Sekaiju

Does load/play:
Anvil Studio
Cakewalk
MidiPlayer
MidiTrail
Winamp

 
Posted : 10/03/2023 7:32 am
Carlos
Posts: 86
Estimable Member
Topic starter
 

I found this, which curiously before was in this same place.

http://www.midi.org/about-midi/rp29spec(rmid).pd f"> https://web.archive.org/web/20110610135604/http://www.midi.org/about-midi/rp29spec(rmid).pdf

Note that it is perfectly legal to include additional RIFF chunks after the chunk. For example, an INFO chunk may be added to provide copyright, author and other textual information describing the file. However, the chunk must be the first chunk found within the RMID form

[code type=c]
RIFF( 'RMID'
data( )
)
a Standard MIDI File, as defined in The Complete MIDI 1.0 Detailed Specification[/code]

 
Posted : 11/03/2023 1:48 pm
Pedro Lopez-Cabanillas
Posts: 154
Estimable Member
 

[quotePost id=17982]I found this, which curiously before was in this same place.

http://www.midi.org/about-midi/rp29spec(rmid).pd f"> https://web.archive.org/web/20110610135604/http://www.midi.org/about-midi/rp29spec(rmid).pdf [/quotePost]

In my post I've asked if this file could be published here again, perhaps with a prominent "deprecated" marking on it. But nobody answered to that request.

The link you posted is available from the LOC page, in the Sustainability factors / Documentation section. But I feel that being an official MIDI.org document, the RP-029 should be also available here.

 
Posted : 12/03/2023 12:25 am
Carlos
Posts: 86
Estimable Member
Topic starter
 

[quotePost id=17985]In my post I've asked if this file could be published here again, perhaps with a prominent "deprecated" marking on it. But nobody answered to that request.

The link you posted is available from the LOC page, in the Sustainability factors / Documentation section. But I feel that being an official MIDI.org document, the RP-029 should be also available here.[/quotePost]

Yes, I also think that it should be published here even if it is obsolete, the files already exist and they will not disappear.

Is it legal to attach these files to my project as documentation?

Just out of curiosity, how do you use SMF and DLS now that RMI is deprecated?

 
Posted : 13/03/2023 4:05 am
Share: