audiocogs / mp3.js

A JavaScript MP3 decoder for Aurora.js
http://audiocogs.org/codecs/mp3
263 stars 45 forks source link

How to build MP3 file using sequence of small MP3 file & MIDI data #24

Closed shivrajsa closed 7 years ago

shivrajsa commented 7 years ago

I am wondering if this is right place to ask this question, but I think at least my question will be directed to experts of this topic

I have developed an application using MIDI.js where I am playing sequence of notes [ small base64 MP3 files ]using MIDI protocol. So I have two types of data

  1. Small base64 MP3 files extracted from .SF2 file for each note
  2. MIDI protocol for each note of sequence i.e. Velocity, Duration, etc.

I want to build single MP3 file using this data. Could you please guide to progress on this requirement.

fasterthanlime commented 7 years ago

You'll need an encoder for that! mp3.js is just a decoder.

shivrajsa commented 7 years ago

@fasterthanlime my each MP3 file is encoded in base64 format. And I want to create single MP3 file by joining sequence of such MP3s with MIDI protocol.

I posted this question here, because I think authors of audiocogs libraries are expert in this area and may guide me to correct direction / steps to achieve that.

fasterthanlime commented 7 years ago

Yep! And the first step is: you need an mp3 encoder.

You'll basically need to:

There's really no way around it, MP3 files can't be concatenated in compressed form (even less overlaid on top of one another!)

UCIS commented 7 years ago

Actually you can just concatenate MP3 files in compressed form. It's not pretty, but if all the MP3 files are complete (no partial bit reservoir at the beginning) and are similar (number of channels, maybe bitrate mode and bitrate) or if you have a decent decoder, it should work. There may be gaps of silence or glitches in between files, and timestamp calculations by the player may be incorrect. This works because the MP3 format was designed to be self synchronizing and tolerant of errors in the stream.

fasterthanlime commented 7 years ago

Actually you can just concatenate MP3 files

Let me revise my comment with "really shouldn't" then.

More importantly, concatenation isn't enough for what the OP wanted to do.

By the way, we finished up that discussion by e-mail, so I'm going to close this issue since it's not directly an mp3.js issue.