Create an mp3 file from scratch C# - 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.

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
Find the frequency of the wave you want. Look at this. C# (nice choice by the way!) is 17.32HZ
Convert the frequency to LPCM, which is just a series of amplitude values.
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.

I would try using NAudio it's quite powerful. The main purpose was to manipulate audio files but it's worth to try.

Related

WP 8.1 Trimming MP3 FILES

Is there a way to trim a mp3 file?
I did some research and every search was leading me to NAudio.
However NAudio doesn't support WP8.1. Actually I don't think it support any version of windows phone.
Is there any other way to trim a mp3 file? MP3s are made of frames and ID3 tags.
Is there a helper that could read mp3 frames and then copy them into a new file?
An MP3 file is a collection of MPEG frames that you can manipulate fairly easily. If you read the NAudio source code (specifically the Mp3Frame class) you'll find a fairly good set of C# code for reading the individual frames. From there you can index the frames, figure out their positions in time and copy out only the ones you're interested in to the output file.
It may be a bit more complex than that, but have a look at Mark's code in and around the Mp3Frame class for some more information on how it works.
Oh, and don't forget to credit him if you use his code.

Extracting and splitting a MP3 audio stream from an AVI file

I want to develop a desktop application by programming in C# and using the .Net framework 4.
The goal of my application is to extract a MP3 audio stream from a supplied AVI file.
I have learned from the Internet that an AVI file is a container and it might contain different audio streams.
If the supplied AVI file contains one MP3 audio stream at least then I want to extract it and split it.
I want to split the MP3 audio stream into MP3 audio parts identified with a start time and an end time.
I have looked on the Internet for any .Net library I could use but without success.
Does someone know what documented .Net library would be useful ?
Maybe you can try this:
Simple C# Wrapper for the AviFile Library
It is targeted at AVI video but there might be some clues as how to use the same methods to extract the audio only.
Either use it as-is or use the example to incorporate what you need into your own code.
Since tools for this task already exist, I see no point in creating another one unless you're curious about how to do this yourself and learn something new.
If so, using a ready-made library would defeat the entire idea of learning something which is why I strongly recommend you try implementing the splitter yourself.
You can find descriptions of the AVI file format online, that should get you started.

Is there a way to play a CCITT u-Law .wav file in C#?

Having failed to find a way to programmatically convert a CCITT u-Law wave file to a PCM file (which Soundplayer demands) in accord with this question: How to play non-PCM file or convert it to PCM on the fly ?
(SOX looks like it might work, but I can't find any examples for converting from CCITT u-Law .wav file to a "regular" (PCM) .wav file using it from C#),
I wonder if I'm going about it the wrong way: maybe I should find a way to play CCITT u-Law .wav files, rather than trying to convert such to a PCM .wav file.
Does anybody know how this is possible? SoundPlayer always says, "Sound API only supports playing PCM wave files" so maybe there's another API I can use?
Note: Alvas.Audio is also "not an option" due to it not being free or open source.
The way to do it is to use newkie's code at: http://www.codeproject.com/Articles/175030/PlaySound-A-Better-Way-to-Play-Wav-Files-in-C?msg=4366037#xx4366037xx
In my case, at least, I had to change all of the lowercase x's to uppercase x's, though, to get it to work.

Audio Conversion C#

What is the best way to convert various audio formats to PCM?
For example: mp3, evrc, ogg vox.
Is there a library out there that will allow me to implement this relatively easily?
EDIT:
I guess my initial question wasn't really what I needed. Most of the libs I have found are file converters. What I need is a block converter, where I pass in a 1Kb block of vox data and it returns its converted PCM block. Of course I’ll have to tell the converter what type of data it is and various pieces of codec information.
The solution I am going for is to save and VOIP formats into a common wav format and to play that conformed file in real time. I thought there should be an easy way to do this because all audio is eventually turned into PCM before it is outputted anyways.
You can use NAudio to pass blocks of compressed audio into any ACM codecs you have installed on your machine. You do need to know how to create the appropriate WAVEFORMAT structure to describe the compressed audio type correctly though.
Check out AVBlocks SDK for .NET. It supports several audio formats, and audio transforms like Multi-channel audio to Stereo audio, resampling and bitrate conversion.
Try modified code from http://alvas.net/alvas.audio,tips.aspx#tip91
static void AnyToWav(string fileName)
{
DsReader dr = new DsReader(fileName);
IntPtr formatPcm = dr.ReadFormat();
byte[] dataPcm = dr.ReadData();
dr.Close();
WaveWriter ww = new WaveWriter(File.Create(fileName + ".wav"), AudioCompressionManager.FormatBytes(formatPcm));
ww.WriteData(formatPcm);
ww.Close();
}
Don't know any lib that does it all but we do mp3->wav using madxlib.
It's free but I suggest paying the $10 for the sdk as it comes with documentation and examples.
There is a c# tutorial on youtube that might be helpful to you. It shows how to use a specific audio library called alvas.audio that really does some neat things with audio. I found the video to be very educational. The audio library is completely written in c#. Watch the video for more details: http://www.youtube.com/watch?v=2DIQECXFPeU

Video Conversion to WMV

A project I am currently working on at work requires the ability to convert videos from other formats to the WMV format. We need to be able to convert virtually any video format that is commonly used to a WMV format. I am looking for a solution allot like On2's flix engine converts other video types to .flv videos. I am aware of the encoder that windows offers, but it has a very limited list of video types that it can convert from. Please let me know if you have any suggestions or opinions, or recommendation of software I can use to do this. I need to be able to do the conversions in batch and I need to be able to do them programmatically with C#.
Have you had a look at ffmpeg?
It seems to be at the core of many open source video conversion utilities, so I imagine you could use it in the scenario you describe.
SUPER, the name is really covering the load!
Well, first you have to be able to decode the file format. You need to set this up with directshow, which is very hard to work with. You can take a look at the mediaportal project for a directshow file player written in C#. Instead of using the video renderer at the end of the directshow graph, you would reencode the video and audio and mux them into a .wmv file. This is a very involved project to get right. You essentially have to mimic a player's ability to play any format and handle failure.
I've been very satisfied using Quick Media Converter.

Categories

Resources