5

I have 400,000 MIDIs that I need to automatically convert to MP3s. I know that MIDIs don't define waveforms. I also know that I can import MIDIs into a DAW and map synths to individual tracks so obviously it's possible to do this automatically. I've been looking for a way to do this. Each MIDI should have a randomly generated synth mapped to each track.

I've looked at SoundFonts but I don't know how to create them or automatically generate them or automatically apply them to MIDIs.

Does anyone know of tools or SDKs that exist for creating synths that can be mapped to MIDI tracks or ways to generate and apply SoundFonts programmaticly? If not, does anyone understand the low level steps involved in a tool that would allow me to do this? I've looked for tools to do this with no success. Maybe if I understood the parts involved I could write something to do this, but I wouldn't even know what to look up.

Any help would be appreciated, Thanks.

Charlie
  • 55
  • 6
  • Are you looking to actually randomly *generate* the sounds through synthesis, or just to randomly *select* them from existing soundfont(s)? – j b Nov 15 '11 at 11:21
  • I am looking to generate the sounds through synthesis AND to randomly select soundfonts to apply to midis. – Charlie Nov 15 '11 at 15:56
  • OK, the question then is, why use soundfonts? Why not have a means to generate the sounds (a couple of softsynths), and to randomly select them, and then trigger the sounds directly via MIDI? Something like MIDI file -> (random) synth -> WAV -> MP3? – j b Nov 15 '11 at 16:33
  • I suppose that would be the preferred solution. I was just wondering about sound fonts because that's where most of my research was leading me. – Charlie Nov 16 '11 at 16:44

1 Answers1

5

OK, there are few different questions here, each with their own difficulties.

MIDI to MP3 conversion

Assuming you want to go MIDI -> SF2 -> MP3, the Timidity++ source code would be a good starting point. Timidity++ "can play MIDI files by converting them into PCM waveform data". A recent fork of Timidity++ can be found on Github.

To convert to MP3, you need an additional tool. LAME would be a good starting point here. Stitching together Timidity and LAME, you can go from MIDI to MP3 via an SF2. This script illustrates how this can be achieved without writing your own app.

for file in *.mid do
    timidity $file -Ow -o - | lame - $file.mp3
done

Random Synthesis

The other element of your question, which concerns randomly generated synths, can't really be addressed easily through the above approach. If I understand the question correctly, you want to do the following:

  • synthesise some sounds where some aspects of the synthesis are randomised
  • randomly select the sounds to be assigned to each MIDI channel for playback

SF2 is a primarily sample-based format, and would introduce unnecessary complexity if you essentially want to play random synths via MIDI and save the output to an audio file.

To address your problem, I would therefore suggest skipping the SF2 step, and looking at an audio processing framework like Synthesis ToolKit (STK). STK is capable of reading MIDI files, and sound synthesis. You can then use LAME for the audio buffer to MP3 conversion.

j b
  • 5,147
  • 5
  • 41
  • 60
  • STK appears to have a MidiFileIn function and a WvOut function. So I would import the MIDI, do what I need to do, output a wave and then run a script like the one above to convert all the waves to MP3s? – Charlie Nov 16 '11 at 17:18
  • Yes, you could do that. Or you could write your data to an `StkFrames` instance, which basically holds a buffer of `StkFloat`. `StkFloat` is typedef'd to `double` so you *should* be able to pass this to lame_encode_buffer_interleaved_ieee_float() from liblame to perform the conversion to MP3 directly in your app. – j b Nov 17 '11 at 10:51
  • I'm trying to use the synthesis toolkit and I just get linker errors that complain about undefined references to all of the functions I try to use. Do you know why this might be? – Charlie Nov 20 '11 at 03:19
  • I can't answer that without significantly more detail. I suggest starting a new question giving details of your platform, compiler, error messages, steps taken so far, and a minimal code example. – j b Nov 21 '11 at 13:19