Code:
//
// Skeleton program for assignment 2
//
// Reads 44100 samples from a 16 bit raw PCM audio file (not a wave file)
// The file must be called 'input.pcm'
// into an array called 'sound_data'. You can use any sample rate.
// You can process the data by writing code in the process_sound function
// The program then writes the sound_data array to a destination file, 'output.pcm', in raw PCM format
//
#include <iostream>
#include <fstream> //header to access files
using namespace std;
// define constants
const int max_number_samples = 44100; //max number samples in array
const int max_number_bytes = 2 * max_number_samples; //max number of bytes in file assuming samples are 16 bits
const char in_file[] = "input.pcm";
const char out_file[] = "output.pcm";
int n;
fstream f_in; // filestream for source file
fstream f_out; // filesteam for destination file
short signed int sound_data[max_number_samples]; // array of sound samples, 16 bit integer
bool file_found;
void open_source()
{
// Opens source file as binary (NOT text) stream
do
{
file_found = false;
cout << "\nOpening file: " << in_file << "\n\n";
f_in.open (in_file, ios::in | ios::binary);
if (!f_in)
{
cout << "Cannot open file: " << in_file << "\n";
}
else
{
file_found = true;
}
}while (file_found == false);
}
void read_source()
{
// Reads source file into the array
cout << "Reading " << in_file << " into array\n\n";
f_in.read ((char*)sound_data, max_number_bytes);
}
void close_source()
{
// Closes source file
cout << "Closing " << in_file << "\n\n";
f_in.close();
}
void open_destination()
{
// Opens destination file for writing
do
{
file_found = false;
cout << "\nOpening file: " << out_file << "\n\n";
f_out.open (out_file, ios::out | ios::binary);
if (!f_out)
{
cout << "Cannot open file: " << out_file << "\n\n";
}
else
{
file_found = true;
}
}while (file_found == false);
}
void write_destination()
{
// Write sound array to destination file
cout << "Writing array to " << out_file << "\n\n";
f_out.write ((char*)sound_data, max_number_bytes);
}
void close_destination()
{
// Close destination file
cout << "Closing " << out_file << "\n\n";
f_out.close();
}
void process_sound()
{
cout << "Beginning processing of sound data\n\n";
// Put your code to process the sound here
// The original sound is in the array sound_data
// The number of samples in the array is max_number_samples
cout << "Processing complete\n\n";
}
void main()
{
open_source();
read_source();
close_source();
process_sound();
open_destination();
write_destination();
close_destination();
cout << "Program complete.\n";
system("pause");
}
2. Normalise the level of the sound track
i dont no where to begin, i have a soundfile im soo stuck, please help!


