Working with sound in .NET

2

In .NET, it is relatively easy and simple to work with images. It is possible to use the System.Drawing.Bitmap class to open images in Bitmap, Jpeg and PNG formats and play with their pixels. The code below, for example, gets any image and returns its grayscale representation:

public void RemoverCores(Bitmap input)
{
    Bitmap output = new Bitmap(input.Width, input.Height);

    for (int i = 0; i <= input.Width; i++)
    {
        for (int j = 0; j <= input.Height; j++)
        {
            Color cores = input.GetPixel(i, j);
            int media = (cores.R + cores.G + cores.B) / 3;
            output.SetPixel(j, j, Color.FromArgb(media, media, media));
        }
    }
    return output;
}

I learned in college that images and sounds are just two distinct forms of signs of a similar nature, and that algorithms that apply to one form also apply to another >.

For example, the same algorithm that "clears" an image serves to remove noise from an audio track. We simply use time rather than height and width when we treat a sound rather than an image and, if I remember correctly, instead of color bands we have ranges of sound frequencies.

In college we did this with Matlab. However I'd like to work with sounds in .NET, with C #. Is there any embedded or official API for this? If it does not exist, at least is there any project with which I can at least generate and manipulate a .wav or .mp3 file?

    
asked by anonymous 18.07.2017 / 14:03

1 answer

1

I do not know what kind of manipulation you will need to do, unfortunately there will not be any "semi-ready" function as we have with Matlab, in Matlab everything is very simple if we want to create a filter (IIR) observed in certain frequency bands it is possible to general the coefficients of the function transfer with a simple line of code and then to apply the filter in the audio using the coefficients ...

Before doing any type of manipulation it will be necessary to use some lib that is able to decode sounds (wav, mp3, etc), I know these two and they work well:

Alvas

Naudio

Open your files using some class that decodes your audio file, usually you will have the values decoded in vector (mono audio) or matrix (audio in stereo) and manipulate in whatever way you feel it is necessary ...

PS: I can count on finger manipulation techniques for images that are reused in audio, the most common are filters and interpolations, filters are really similar as you said, image interpolation is used to change (change) the size of an image trying to maintain the best possible quality, there are different interpolation techniques for this, the simplest "linear interpolation" is used to repeat or omit pixels from an image (stretch or decrease) in audio the same technique is used to change the speed + frequency of the audio (make speech quick with squirrel sound or slow speech with demon voice)

    
01.09.2017 / 17:09