Work with sound on . NET

Asked

Viewed 108 times

2

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

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 only two distinct forms of signals of a similar nature, and that algorithms that apply to one form also apply to another.

For example, the same algorithm that "blurs" an image serves to remove noises from an audio track. We simply use time instead of height and width when we treat a sound instead of an image and, if I remember correctly, instead of color tracks we have sound frequency ranges.

In college we did this with Matlab. However I would like to work with . NET sounds, with C#. Is there an on-board or official API for this? If it does not exist, at least there is some project with which I can at least generate and manipulate a file . wav or . mp3?

1 answer

1

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

Before performing any kind of manipulation you will need to use some lib that is able to decode sounds (wav, mp3, etc), I know these two and they work well:

Alvas

Naudium

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

PS: I can count on the fingers images manipulation techniques that are reused in audio, the most common are the filters and interpolations, the filters are really similar as you said, the interpolation in images are 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 shrink) in audio the same technique is used to change the speed + frequency of the audio (let the speech fast with squirrel sound or let the speech slow with demon voice)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.