M
M
mr_blond972018-09-03 15:43:55
Audio
mr_blond97, 2018-09-03 15:43:55

How to merge two wav files into one using OpenTK?

We need to mix two wav files into one in .net core. To do this, I use the OpenTK OpenAl wrapper for C#.
1) I load wav like in this example
2) I create two byte[] arrays:

var sound_data1 = LoadWave(path1, FileMode.Open), out channels, out bits_per_sample, out sample_rate);

var sound_data2 = LoadWave(path2, FileMode.Open), out channels, out bits_per_sample, out sample_rate);

3) I write the averaged sum of bytes to the result_sound_data array:
for (int i = 0; i < sound_data1; i++)
{
result_sound_data[i] = (byte)((sound_data1[i] + sound_data2[i]) / 2);
}

4) Then I play result_sound_data
AL.BufferData(buffer, GetSoundFormat(channels, bits_per_sample), result_sound_data, result_sound_data.Length, sample_rate);

AL.Source(source, ALSourcei.Buffer, buffer);
AL.SourcePlay(source);

The output is a "hissing" "broken" signal. How to merge two wav files?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Gaydak, 2018-09-03
@mr_blond97

https://www.codeproject.com/Articles/29676/CWave-A...
well, as I understand it, you can't just take two files and send the average data to another array ..
headers. number of channels, sample rate.
that is, your version of "banal" gluing will work in fact only for "same-type" files. Yes, and probably the same length.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question