C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 1st, 2005, 03:54 AM
Parkin_m Parkin_m is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 10 Parkin_m User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 44 m 58 sec
Reputation Power: 0
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();
}

Reply With Quote
  #2  
Old April 1st, 2005, 05:03 AM
Cirus Cirus is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 276 Cirus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 48 m 58 sec
Reputation Power: 4
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.

Reply With Quote
  #3  
Old April 1st, 2005, 05:58 AM
Parkin_m Parkin_m is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 10 Parkin_m User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 44 m 58 sec
Reputation Power: 0
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

Reply With Quote
  #4  
Old April 1st, 2005, 05:59 AM
Parkin_m Parkin_m is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 10 Parkin_m User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 44 m 58 sec
Reputation Power: 0
(i stupidly deleted my help files and course note on c++!)

i didnt think i would be needing them again this is the problem!

Reply With Quote
  #5  
Old April 3rd, 2005, 04:30 AM
Parkin_m Parkin_m is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 10 Parkin_m User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 44 m 58 sec
Reputation Power: 0
Can no-one help?

Reply With Quote
  #6  
Old April 5th, 2005, 04:20 PM
Parkin_m Parkin_m is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 10 Parkin_m User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 44 m 58 sec
Reputation Power: 0
not even 1 person!?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Little Help With audio processing!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT