Search code examples
c#audiomp3

Create an mp3 file from scratch C#


As part of some experimentation, I thought of something, how can I create a .mp3 file from scratch in C#, that actually sounds like something, e.g, create an mp3 file that plays the note: C#, or B flat?

How can I achieve this, and it must be an mp3 file, not a wav, or anything else.


Solution

  • So I'm not going to be able to give you exact code, but I can give a starting point.

    So basically the steps would be

    1. Find the frequency of the wave you want. Look at this. C# (nice choice by the way!) is 17.32HZ
    2. Convert the frequency to LPCM, which is just a series of amplitude values.
    3. Convert the LPCM encoded array to an MP3 file. This is probably the hardest, but LPCM forms that basis of the WAV format and there are converters to convert that to MP3. Have a look at the NAudio baalazamon found. It supports PCM.