Hi all,
I'm a newbie with C or C++. I have a raw PCM file 16-bit (like a wav file but no header). I need to build a console application that can read the file, store data in an array, modify it (ex: add 100 to each value of the data array), then play it in sound (with a known frequency sampling, ex Fs = 16000 Hz).
It would be very nice if someone can explain to me how to do that.
Thank you very much.

Sure, which bit exactly are you having problems with?

- reading into an array
- adding values
- playing it

Sure, which bit exactly are you having problems with?

- reading into an array
- adding values
- playing it

Thks for your answer
Here is my code of reading values into an array

#include <iostream>
#include <fstream>
using namespace std;

void main()
{
	std::fstream f_in;
	short speech, value[10000];
	

	f_in.open ("myfile.pcm", std::ios::in | std::ios::binary);
	

	int i = 0;
	while (i < 10000) {
		f_in.read((char *)&speech, 2);
               value[i] = speech;
		cout << speech << std::endl;
		i++;
	}
}

I think it works well.
The problem is how to play sound from value array, with frequency sampling Fs = 16000hz.
Thks for any advice

I can't help you with your problem, but you don't need that while loop f_in.read(speech, 10000 * sizeof(short)); But of course there is no guarentee that sizeof(short) will be 2. It might be on your system but if you intend to port that porgram to another os then the size may be something else.

Sir can u tell me the answer

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.