Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8472261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:00:55+00:00 2026-06-10T17:00:55+00:00

So I know I have asked this question before, however, I am still stuck

  • 0

So I know I have asked this question before, however, I am still stuck and before I can move on with my project. Basically, I’m trying to read in a .wav file, I have read in all of the required header information and then stored all the data inside a char array. This is all good, however, I then recast the data as an integer and try and output the data.

I have tested the data in MatLab, however, I get very different results:

Matlab -0.0078

C++: 1031127695

Now these are very wrong results, and someone kindly from here said it’s because I’m outputting it as an integer, however, I have tried pretty much every single data type and still get the wrong results. Someone has suggestion that it could be something to do with Endianness (http://en.wikipedia.org/wiki/Endianness) .. Does this seem logical?

Here is the code:

bool Wav::readHeader(ifstream &file)
{

file.read(this->chunkId,                                 4);
file.read(reinterpret_cast<char*>(&this->chunkSize),     4);
file.read(this->format,                                  4);

file.read(this->formatId,                                4);
file.read(reinterpret_cast<char*>(&this->formatSize),    4);
file.read(reinterpret_cast<char*>(&this->format2),       2);
file.read(reinterpret_cast<char*>(&this->numChannels),   2);
file.read(reinterpret_cast<char*>(&this->sampleRate),    4);
file.read(reinterpret_cast<char*>(&this->byteRate),      4);
file.read(reinterpret_cast<char*>(&this->align),         2);
file.read(reinterpret_cast<char*>(&this->bitsPerSample), 4);

char testing[4] = {0};
int testingSize = 0;

while(file.read(testing, 4) && (testing[0] != 'd' ||
                                testing[1] != 'a' ||
                                testing[2] != 't' ||
                                testing[3] != 'a'))
{

file.read(reinterpret_cast<char*>(&testingSize), 4);
file.seekg(testingSize, std::ios_base::cur);

  }

      this->dataId[0] = testing[0];
      this->dataId[1] = testing[1];
      this->dataId[2] = testing[2];
      this->dataId[3] = testing[3];
     file.read(reinterpret_cast<char*>(&this->dataSize),     4);

     this->data = new char[this->dataSize];

     file.read(data,                     this->dataSize);

     unsigned int *te;

     te = reinterpret_cast<int*>(&this->data);

     cout << te[3];

     return true;
     }

Any help would be really appreciated. I hope I’ve given enough details.

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T17:00:57+00:00Added an answer on June 10, 2026 at 5:00 pm

    I think there’re several issues with your code. One of them are the casts, for instance this one:

     unsigned int *te;                           
     te = reinterpret_cast<int*>(&this->data);     // (2)
     cout << te[3];                                
    

    te is a pointer to unsigned int, while you try to cast to a pointer to int. I would expect compilation error at line (2)…

    And what do you mean by te[3]? I expect some garbage from *(te + 3) memory location to be outputed here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know many have asked this question before, but as far as I can
I know variants of this question have been asked before (even by me), but
I know this sort of question has been asked before , but I still
I know variants of this question have been asked frequently before (see here and
I know this question has been asked quite a few times, however, I have
Yes, I know this question has been asked dozens of times before. However, when
Hi I know this question have been asked before but the answers there isn't
I know this question was asked before but I have the following simple code
I'm aware that this question may have been asked before, but I still haven't
I know similar permutations of this question have been asked before, but the answers

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.