Ok so i have a skeleton code in which i need to add my own coding.
You must write a program that performs audio processing on a sound wave stored in a file on the PC. You are provided with a skeleton program that will read and write a sound file to/from an array of samples. You must write code that will manipulate the sound wave once it is in the array. Your program should allow the user to determine what processing is performed on the sound wave and provide appropriate information to the user through the PC monitor. Additional technical details are provided at the end of this brief.
1. Amplify the sound by an integer value, where the user enters the amplification value
2. Normalise the level of the sound track
this is what we have been asked to do.
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");
}
is the coding, it needs to allow the user to input a value in which to ampify by and work this out. and say error if its above the max number of smaples and also allow them to normalise the sound.
I am new to this and dont know where to begin any help would be appreciated thanks.