code check please? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

code check please?

dorwin1990dorwin1990 Posts: 7Member
Hey ppl

i got this code which is suppose to play wav files easily in turbo c++.

but i get 26 errors on compiling. can someone help??

thanx

Quote


void Load_Wave_File(char *fname)
{
FILE *fp;

fp = fopen(fname,"rb");
if (fp)
{
char id[4], *sound_buffer; //four bytes to hold 'RIFF'
DWORD size; //32 bit value to hold file size
short format_tag, channels, block_align, bits_per_sample; //our 16 values
DWORD format_length, sample_rate, avg_bytes_sec, data_size, i; //our 32 bit values

fread(id, sizeof(id), 4, fp); //read in first four bytes
if (!strcmp(id, "RIFF"))
{ //we had 'RIFF' let's continue
fread(size, sizeof(DWORD), 1, fp); //read in 32bit size value
fread(id, sizeof(id), 4, fp); //read in 4 byte string now
if (!strcmp(id,"WAVE"))
{ //this is probably a wave file since it contained "WAVE"
fread(id, sizeof(BYTE), 4, fp); //read in 4 bytes "fmt ";
fread(&format_length, sizeof(DWORD),1,fp);
fread(&format_tag, sizeof(short), 1, fp); //check mmreg.h (i think?) for other
// possible format tags like ADPCM
fread(&channels, sizeof(short),1,fp); //1 mono, 2 stereo
fread(&sample_rate, sizeof(DWORD), 1, fp); //like 44100, 22050, etc...
fread(&avg_bytes_sec, sizeof(short), 1, fp); //probably won't need this
fread(&block_align, sizeof(short), 1, fp); //probably won't need this
fread(&bits_per_sample, sizeof(short), 1, fp); //8 bit or 16 bit file?
fread(id, sizeof(BYTE), 4, fp); //read in 'data'
fread(&data_size, sizeof(DWORD), 1, fp); //how many bytes of sound data we have
sound_buffer = (id *) malloc (sizeof(BYTE) * data_size); //set aside sound buffer space
fread(sound_buffer, sizeof(id), data_size, fp); //read in our whole sound data chunk
}
else
printf("Error: RIFF file but not a wave file
");
}
else
printf("Error: not a RIFF file
");
}
}
void main()
{
Load_Wave_File("1.wav");
}

Unquote

Comments

  • tsagldtsagld Posts: 621Member
    : Hey ppl
    :
    : i got this code which is suppose to play wav files easily in turbo c++.
    :
    : but i get 26 errors on compiling. can someone help??
    :
    : thanx
    :
    : Quote
    :
    [code]
    : void Load_Wave_File(char *fname)
    : {
    : FILE *fp;
    :
    : fp = fopen(fname,"rb");
    : if (fp)
    : {
    : char id[4], *sound_buffer; //four bytes to hold 'RIFF'
    : DWORD size; //32 bit value to hold file size
    : short format_tag, channels, block_align, bits_per_sample; //our 16 values
    : DWORD format_length, sample_rate, avg_bytes_sec, data_size, i; //our 32 bit values
    :
    : fread(id, sizeof(id), 4, fp); //read in first four bytes
    : if (!strcmp(id, "RIFF"))
    : { //we had 'RIFF' let's continue
    : fread([red]&[/red]size, sizeof(DWORD), 1, fp); //read in 32bit size value [red]note the ampersand here[/red]
    : fread(id, sizeof(id), 4, fp); //read in 4 byte string now
    : if ([red]strcmp(id,"WAVE") == 0[/red])
    : { //this is probably a wave file since it contained "WAVE"
    : fread(id, sizeof(BYTE), 4, fp); //read in 4 bytes "fmt ";
    : fread(&format_length, sizeof(DWORD),1,fp);
    : fread(&format_tag, sizeof(short), 1, fp); //check mmreg.h (i think?) for other
    : // possible format tags like ADPCM
    : fread(&channels, sizeof(short),1,fp); //1 mono, 2 stereo
    : fread(&sample_rate, sizeof(DWORD), 1, fp); //like 44100, 22050, etc...
    : fread(&avg_bytes_sec, sizeof(short), 1, fp); //probably won't need this
    : fread(&block_align, sizeof(short), 1, fp); //probably won't need this
    : fread(&bits_per_sample, sizeof(short), 1, fp); //8 bit or 16 bit file?
    : fread(id, sizeof(BYTE), 4, fp); //read in 'data'
    : fread(&data_size, sizeof(DWORD), 1, fp); //how many bytes of sound data we have
    : sound_buffer = ([grey]id*[/grey][red]char *[/red]) malloc (sizeof(BYTE) * data_size); //set aside sound buffer space
    : fread(sound_buffer, sizeof(id), data_size, fp); //read in our whole sound data chunk
    : }
    : else
    : printf("Error: RIFF file but not a wave file
    ");
    : }
    : else
    : printf("Error: not a RIFF file
    ");
    : }
    : }
    : void main()
    : {
    : Load_Wave_File("1.wav");
    : }
    :
    [/code]

    Start with the red remarks above.

    Greets,
    Eric Goldstein
    http://www.gvh-maatwerk.nl


Sign In or Register to comment.