0

i'm trying to manipulate a wav file with c ++, i've been reading stuff for a week but i couldn't get any good results..

what i want to do is this:

read wav files, change the volume of the frequencies, save new file.

so i want to read the wav file and save the volume of frequencies in an array, manipulate them, write them in the new file.

the first cout example would look like this:

frequency 60 = -8db frequency 1000 = -10db frequency 5000 = -9db etc

then change the volume of the frequency, for example I want the 1000 frequency to go to -8db, so I add 2db to it.

the following cout example after the modification would then be like this:

frequency 60 = -8db frequency 1000 = -8db frequency 5000 = -9db etc

save the new file.

i know it is a window(Q) of frequencies and not a single frequency, FTT and the like that i didn't understand anything about .. i don't even care if it is interpreted as db but any identifiable number would be fine,I just want to understand how to change the volume of the frequencies ..

so starting from here, what should I do?

rFile.open ("input.wav", ios::binary);
rFile.seekg (0, ios::end);
int rFileSize = rFile.tellg();
char * FileBuffer = new char [rFileSize];
rFile.seekg (0, ios::beg);
rFile.read (FileBuffer, rFileSize);
rFile.close();

wFile.open("test.wav", ios::binary);

// header end at 44 (I know how to read it)
for (int i = 44; i <rFileSize; i ++) {
  FileBuffer[i] = ??????;
}

wFile.write (FileBuffer, rFileSize);
wFile.close ();

up to now i have only managed to make an exact copy of the file, mix 2 wav together or change volume of the whole track .. anything else I tried to do results in an unreadable file for the player or unlistenable file with many clips and noise (discontinuity maybe) .. i think if i understand how to do the above then i can do anything else ..

I know that there are external libraries, but I have not found any or in any case I cannot use them, I think I lack the understanding of something .. I'd rather be able to do it by myself without using any external library, but if it makes things a lot easier then I would use the library ..

any help is appreciated, could you please tell me the exact steps to follow and the right path? thank you!

*sorry if there is any mistake in the translation I used the translator

edit: from the comments it seems like a thing too complicated to get on my own .. i'm ok with using external libraries, i tried to look for them but i miss the structure of the things i should do, so even if find a library , it i don't know if it's what i need or not , or how to use it, etc..

in case of libraries which one should I use and how?

an answer in pseudo code would be perfect, something like

use this library to get this data.. then use this to get this.. and then do this.. and this.. and this.. .. then save the file.

i know its very confusing, i need to know the precise steps i should do and exactly what libraries or things i need to be able to do it .. thanks!

Edd
  • 1
  • 1
  • 3
    Look for posts like this : https://stackoverflow.com/questions/13660777/c-reading-the-data-part-of-a-wav-file, and changing volume based on frequencies would require signal processing and that would probably involve fourier transforms (or a biquad filter). It will not be trivial so you might want to use a library for that too. – Pepijn Kramer Jul 24 '22 at 05:03
  • First of all, please don't try to handle the file format yourself, especially if you just skip the quite important headers and other meta-data that ells you how the actual data in the file should be interpreted. There are many libraries that will help you read WAV files and handle all their different formats (remember, `.wav` is just a *container* file format, how the actual sound is encoded might differ between files). – Some programmer dude Jul 24 '22 at 05:03
  • thanks for the timely replies, yes I know PCM and how to read save the information from the header for later use, I omitted these things because it is the central part (the one in the for loop) that I have no idea what to do there except how to save the new value. any changes I make to the sample reveal themselves in clip or noise .. i've been reading stuff for a week, whatever said on the subject i've probably read it .. but i can't put the pieces together.. thanks – Edd Jul 24 '22 at 05:39
  • This is not something you're unlikely to be able to bang out yourself unless you're a math major *and* a computer science grad. Get an audio library and use that instead. This is *considerably* more than a week of research to implement. Doing FFT from scratch is likely a month if it's your first time. – tadman Jul 24 '22 at 06:37
  • hello Tedman, yes, I guess it's something complicated .. I didn't graduate in any of this, i searched for libraries but i couldn't find anything that i can use, even if i find it i don't know how to use it or if it's what i need or not .. i just miss the structure of things i should do etc, i'm fine use a library to compute ftt for example, but then how do I use it if I can get it? it's all very confusing .. thanks – Edd Jul 24 '22 at 07:10

0 Answers0