473,569 Members | 2,683 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

wav file fade in/out help

Hi I have an assignment to hand in shortly for which I am after some
guidance. The task is to read a WAV file, request a fade in /out time
for the track from the user and the do the fade by modifying the binary
file then writing it as a new file I have attached my code so far but
do not know how to do the fade and how to write it as a new file.
Please help!

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void main ()
{
FILE *oldwav,*newwav ;
char *stgfilename;
char riff[5];
char wave[5];
char fmt[5];
char data[5];
unsigned long int length, binary, stereo, mono, bits, sample, bps,
bpsam, bitsps, sound, ldata;
int s, m, time, count;
float fadein, track, track1, fadeout;

/* */
stgfilename=(ch ar*)malloc(81);
printf("Please enter the file path of your wav file\n\r");
gets(stgfilenam e);

oldwav=fopen(st gfilename,"rb+" );

if(oldwav==NULL )
{
printf("Cannot find the file specified\n\r") ;
exit(1);
}

/* To start the RIFF Chunk must be determined*/

fread(riff,1,4, oldwav);
riff[4]='\0';

printf("header contains %s this is a wav file!!\n\r", riff);
if (strcmp(riff,"R IFF")!=0)
{
printf("error in header not wav file\n\r");
fclose(oldwav);
exit(1);
}
fread(&length,4 ,1,oldwav);

printf("The length of the wav file is %lx hex\n\r", length);
printf("The length of the wav file is %ld decimal\n\r", length);
fread(wave,1,4, oldwav);
wave[5]='\0';

printf("the format header contains %s\n\r", wave);
if (strcmp(wave,"W AVE")!=0)
{
printf("error not in WAV format\n\r");
fclose(oldwav);
exit(1);
}

/* Secondly the FORMAT Chunk must be determined*/

fread(fmt,1,4,o ldwav);
fmt[3]='\0';
fmt[4]='\0';

printf("the format header contains %s\n\r", fmt);
if (strcmp(fmt,"fm t")!=0)
{
printf("error\n \r");
fclose(oldwav);
exit(1);
}

fread(&binary,4 ,1,oldwav);

if (binary!=0X10)
{
printf("error\n \r");
fclose(oldwav);
exit(1);
}
printf("header file contains %lx\n\r",binary );

fread(&bits,2,1 ,oldwav);

if (bits!=0X01)
{
printf("error corrupted file this should be 01 always!\n\r");
fclose(oldwav);
exit(1);
}
printf("Check bytes 8-9 are 01 ---> Correct 01\n\r");
fread (&stereo,2,1,ol dwav);

if (stereo!=0X02)
{
printf("the file is not stereo\n\r");
}
if (stereo==0x02)
{
printf("the file is stereo\n\r");
s=2;
}
if (stereo!=0X01)
{
printf("the file is not mono\n\r");
}
if (stereo==0x01)
{
printf("the file is mono\n\r");
m=1;
}

fread(&sample,4 ,1,oldwav);

printf("The sample rate of the wav file is %lx hex\n\r", sample);
printf("The sample rate of the wav file is %ld decimal\n\r", sample);

fread(&bps,4,1, oldwav);

printf("The bytes per second of the wav file is %lx hex\n\r", bps);
printf("The bytes per second of the wav file is %ld decimal\n\r", bps);

fread(&bpsam,2, 1,oldwav);

printf("The bytes per sample of the wav file is %lx hex\n\r", bpsam);
printf("The bytes per sample of the wav file is %ld decimal\n\r",
bpsam);
if (bpsam==0x01)
{
printf("this is 8 bit mono!!\n\r");
s=1;
}
if (bpsam==0X02)
{
printf("this is 8 bit stereo or 16 bit mono!!\n\r");
s=2;
}

if (bpsam==0X04)
{
printf("this is 16 bit stereo!!\n\r");
s=4;
}

printf("the value of s is ---> %d this a multiplier for?\n\r",s);
fread(&bitsps,2 ,1,oldwav);

printf("the bits per sample of this wav file is %lx hex\n\r", bitsps);
printf("the bits per sample of this wav file is %ld decimal\n\r",
bitsps);

/* Thirdly the DATA Chunk must be determined*/

fread(data,1,4, oldwav);
data[4]='\0';

if (strcmp(data,"d ata")!=0)
{
printf("error\n \r");
fclose(oldwav);
exit(1);
}
printf("third line contains %s !!\n\r", data);

fread(&sound,4, 1,oldwav);

printf("length of data to follow %lx hex\n\r", sound);
printf("length of data to follow %ld decimal\n\r", sound);
/* Convert the length of the file into seconds */

time=sound/(s*sample);
printf("time of track = %d seconds\n\r",ti me);

/* Providing the fadein time the user requires*/

printf("INPUT TIME FOR FADEIN FROM START...\n\r");
scanf("%f",&fad ein);
printf("The fade in time is %f seconds\n\n\r", fadein);
track=(fadein*b ps);
printf("the fadein in bytes = %f\n\r",track);

/* Check the fadein time to make sure it is not less than or equal to
zero*/

if (fadein<=0)
{
printf("error time can't be less than or equal to zero\n\r");
printf(" INPUT TIME FOR FADEIN FROM START...\n\r");
scanf("%f",&fad ein);
printf("The fade in time is %f seconds\n\n\r", fadein);
track=fadein*bp s;
printf("the fadein in bytes = %f\n\r",track);
}

if (fadein>=time)
{
printf("error time can't be more than or equal time of
track\n\r");
printf(" INPUT TIME FOR FADEIN FROM START...\n\r");
scanf("%f",&fad ein);
printf("The fade in time is %f seconds\n\n\r", fadein);
track=fadein*bp s;
printf("the fadein in bytes = %f\n\r",track);
}
/* Providing the fadeout time the user requires*/

printf("INPUT TIME FOR FADEOUT TO START...\n\r");
scanf("%f",&fad eout);
printf("The fade out time is %f seconds\n\n\r", fadeout);
track1=fadeout* bps;
printf("the fadeout in bytes = %f\n\r",track1) ;

/* Check the fadeout time to make sure it is not less than or equal
to zero*/

if (fadeout>=time)
{
printf("error time can't be more than or equal to the length of the
track\n\r");
printf(" INPUT TIME FOR FADEOUT TO START...\n\r");
scanf("%f",&fad eout);
printf("The fade out time is %f seconds\n\n\r", fadeout);
track1=fadeout* bps;
printf("the fadeout in bytes = %f\n\r",track1) ;
}

if (fadeout<=fadei n)
{
printf("THIS IS IMPOSSIBLE PLEASE CHECK YOUR FADE OUT
TIME\n\r");
printf(" INPUT TIME FOR FADEOUT TO START...\n\r");
scanf("%f",&fad eout);
printf("The fade out time is %f seconds\n\n\r", fadeout);
track1=fadeout* bps;
printf("the fadeout in bytes = %f\n\r",track1) ;
}
/* Fade in Calculation*/
}

Jul 23 '05 #1
1 4332
ja************@ yahoo.com wrote:
Hi I have an assignment to hand in shortly for which I am after some
guidance. The task is to read a WAV file, request a fade in /out time
for the track from the user and the do the fade by modifying the binary
file then writing it as a new file I have attached my code so far but
do not know how to do the fade and how to write it as a new file.
Please help!
[...]


The code you posted seems to be rather C and not C++, it uses 'void main'
(which is known to be a non-standard extension on some compilers), and
your problem is not of the _language_ nature. Is there any particular
reason you didn't post your question on fading in/out in an audio forum?

All I know about fading is that samples need to be scaled accordingly, but
scaling of samples is not a language problem (unless you're unsure how to
use the multiplication operator).

So, here is your guidance: news:comp.games .development.au dio. They must
know much more about fading of sounds than all the language newsgroups
combined.

V
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
8421
by: Acer | last post by:
Hi, Can somebody help me to create a php function which show an image, fade-out to another images ? thx
1
2015
by: Krhis | last post by:
A friend of mine gave me a link to these two sites, he wanted to know the scripts that are used here... but it seems that not even I can help him. So I am hoping some one else could help us by showing were we could get the sources of these two "fade" effects. Text links are blue, but when you put your mouse on them, they turn white (from...
1
7264
by: Robert Skidmore | last post by:
I am building an application that will fade one panel to another panel. Both panels will have picture boxes in them (thumbnails). This is what I have tried: private void fade(System.Windows.Forms.Panel fP){ for (int i = 255; i >= 0;i--){ System.Threading.Thread.Sleep(10); fP.BackColor = System.Drawing.Color.FromArgb(i, 255,255,255);...
4
3521
by: Chris Lieb | last post by:
Hi, I am writing a class in JavaScript to cause a repeating fade effect. The fade class takes care of the fading and the rgb class takes care of manipulating rgb values: function rgb(red, green, blue) { // private variable initialization this.red = red; this.green = green;
2
2688
by: Emil | last post by:
Hi, if you open the link below and click on "Show Me" and then "Toggle Transition" Button you will see a wonderfull fade in / fade out transition of 2 pictures. http://msdn.microsoft.com/library/default.asp?url=/workshop/author/filter/reference/filters/fade.asp I want to have the same effect in Visual C++, dosen't matter with / or...
1
1996
by: John Smith | last post by:
I'm looking for javascript that will rotate 3-6 jpg images with a fade to white transition between images. I've got a script that will handle the rotation but not the fade. Maybe it can't be done with JS? Thanks!
1
1611
by: Cylix | last post by:
I have a form with a irregular background image, let say a circle. I would like the form shows and that fade out and close slowly. I have already done the fade out part by the timmer to set the form opacity. However, I set the transparent key of the form be white in color, when the form start to fade out, The white part of the form is not...
6
2357
by: Jake Barnes | last post by:
Please go look at this page using FireFox: http://www.ralphkrubner.com/Commercial/ Click the "Next" button a few times. The images fade out and then fade in. It's a nice effect. Now do try to do the same in IE (6.0). The images don't fade into each other. Instead, they hesitate, which is annoying, and then jump from one image to the...
18
9625
by: hopper | last post by:
I am having a memory block today and for the life of me cant seem to get it right. Can someone help me with code to fade text in 8 seconds after the page has loaded. This is what i have but i dont want it to appear straight away. How do i add an 8 second delay to the text fading in.?? <html> <head> <script language="javascript">...
0
7698
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7970
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.