Manipulating audio in C ++

I hope this is the right place to post and someone can help.

I am a student of music technology, and recently I studied C ++, as it would help my career a lot, knowing a programming language, especially this one, because it is used in the video game industry.

In any case, on the main topic. What I want to create is a program (in C ++) that allows the user to download a 16-bit linear PCM WAVE file. Then I want to manipulate the data of the audio samples in this wave file. I want to either delete every nth sample, or randomize them within a specific parameter (± 10%). Then write it as a new WAVE file.

I am familiar with the structure of WAVE files and the RIFF header. I also currently use Xcode as my IDE (since my macbook pro is my working computer), but if necessary, I can encode on my PC using code blocks.

So, should simple expressions display something similar to this? I know there are errors in this, so that you get an idea of ​​what I need:

#include <iostream>
using namespace std;

class main()    //function start
{
    string fileinput;   //variable
    string outlocation; //variable

    cout << "please type file path directory: \n \n";
    cin >> fileinput;   //navigate to file by typing

    cout << "Where would you like to save new file? \n \n";
    cin >> outlocation; //select output by typing

    // Then all the maths and manipulation is done

    cout << "Your file has been created at ";
    cout << outlocation;
    cout << "\n \n";

    system("pause");

    return 0;
}

Is it possible to do this in Xcode, if at all? What libraries do I need? I understand that this is not simple material, so any help would be greatly appreciated.

Thanks for your help and time.

James

+3
source share
3 answers

If you know the structure of the RIFF file, you may already know how PCM sound is stored in it.

- 16- pcm. 2 , ( + ). . , 16- wcm wcm wcm.

16- (short, _int16, int16_t). , , . 2, , . . .

, RIFF , .

, , riff. , , 10- , 9 * 4 = 36 , 4 , 36 . - , . - . , . , , , (FFT).

:

. ++ Binary File I/O -. , RIFF, , . 44 . .

, 12 ( , , ). . , ('fmt' 'data'), , .

, :

ifstream myFile ("example.wav", ios::in | ios::binary);
char buffer[12];
myFile.read (buffer, 12); // skip RIFF header

char chunkName[5];
unsigned long chunksize;
while (myFile.read (chunkName, 4)) {
    chunkName[4]='\0'; // add trailing zero
    myFile.read((char*)&chunksize, 4);

    // if chunkname is 'fmt ' or 'data' process it here,
    // otherwise skip any unknown chunk:
    myFile.seekg(chunksize, ios_base::cur);
}
+5
0

All Articles