| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Little Help With audio processing!
Hi people, im attemting a university project using c++. The assignment requires me to create a C++ program that manipulates the sample data contained within an audio file. The audio file should be of wav format. The application should open a file containing audio data, manipulate the date then save it to another file. I think i am going to be ok witht the manipulation parts of the assignment ( I will be using normalisation and gain change algorithms) and i already have some code from a previous assignment. What i need really is someone to go through my code and put comments on it. I havent done any C++ in a while, and i have forgotten quite alot of the text! If someone would read through my code, stick some comments on it and give a few pointers/their view it would be greatly appreciated! Thanks a lot, Michael Code:
//VERSION 2_1
#include <iostream>
#include <math.h>
#include <fstream>
#include <iomanip>
using namespace std;
#define WAVELENGTHSECONDS 1
#define FREQUENCY 1000.0
#define SAMPLINGRATE 44100
#define PI 3.1415926535897932384626433832795
#define RAWFILENAME "d:\\wave.raw"
#define FILENAME "d:\\wave.txt"
#define STEPS SAMPLINGRATE * WAVELENGTHSECONDS
#define ARRAYLENGTH STEPS
#define OUTPUTLENGTH 2000
#define MAXIMUM_AMPLITUDE 32767
#define MINIMUM_AMPLITUDE -32768
#define CHARARRAYLENGTH ARRAYLENGTH * 2
class wave
{
private:
double sample[ARRAYLENGTH];
double interval;
char charArray[CHARARRAYLENGTH];
public:
wave()
{
// constructor
// interval is time step
interval = 1.0/(SAMPLINGRATE);
// always start with a sine wave 1000 hz maximum amplitude
createSineWave(1000.0,MAXIMUM_AMPLITUDE);
}
double getSample(int sampleNumber)
{
return sample[sampleNumber];
}
void setSample(int sampleNumber, double value)
{
sample[sampleNumber] = value;
}
bool saveToRawFile(void)
{
bool fileOpened = false;
ofstream outfile;
outfile.open(RAWFILENAME, ofstream::binary);
if(outfile.good() != 1)
{
cout << "There is a problem with opening "<< RAWFILENAME;
return fileOpened;
}
signed short s =0;
int charCount = 0;
signed char c1, c2;
for(int i =0;i<ARRAYLENGTH;i++)
{
s = (signed short)getSample(i);
// write the wrong way around!!!
c1 = (signed char)(s >> 8);
c2 = (signed char)(s & 0x00ff);
charArray[charCount++] = (signed char)(s >> 8);
charArray[charCount++] = (signed char)(s & 0x00ff);
}
outfile.write(charArray,CHARARRAYLENGTH);
outfile.close();
cout << RAWFILENAME << " written" << endl;
return fileOpened;
}
bool saveToTxtFile(void)
{
bool fileOpened = false;
ofstream outfile;
outfile.open(FILENAME);
if(outfile.good() != 1)
{
cout << "There is a problem with opening "<< FILENAME;
return fileOpened;
}
for(int i =0;i<OUTPUTLENGTH;i++)
{
outfile << (signed short)getSample(i) << endl;
}
outfile.close();
cout << FILENAME << " written" << endl;
return fileOpened;
}
void createSineWave(double frequency, double amplitude)
{
// sets up sine wave values
int i;
double value;
double time = 0.0;
for(i=0;i<ARRAYLENGTH;i++)
{
value = sin(2* PI* frequency* time)* amplitude;
setSample(i,value);
time = time + interval;
}
cout << "sinewave created" << endl;
}
void createSquareWave(double frequency, double amplitude)
{
int i;
createSineWave(frequency, amplitude);
for(i=0;i<ARRAYLENGTH;i++)
{
if(sample[i] >= 0)
{
sample[i] = MAXIMUM_AMPLITUDE;
}
else
{
sample[i] = MINIMUM_AMPLITUDE;
}
}
}
void processGain(double gain)
{
// got to do this!
}
void fadeIn(void)
{
// got to do this!
}
void fadeOut(void)
{
// got to do this!
}
};
void main(void)
{
wave w;
w.saveToRawFile();
}
|
|
#2
|
|||
|
|||
|
I am not clear what you need. Do you want someone to document your program? If so , then this is not the riight place.Ask if you are facing some implementation problem.
What sort of pointers, tips do you need. Specify. |
|
#3
|
|||
|
|||
|
I made this program about two years ago and now i cant work out how the program manages to open the wav file are re save.
Im just looking for someone to go through it and stick a few comments on to tell me what each bit does? Ive just started learning again and it would be a big help thats all ![]() thanks alot michael |
|
#4
|
|||
|
|||
|
(i stupidly deleted my help files and course note on c++!)
i didnt think i would be needing them again this is the problem! |
|
#5
|
|||
|
|||
|
Can no-one help?
![]() |
|
#6
|
|||
|
|||
|
not even 1 person!?
![]() |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Little Help With audio processing! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|