私は以前に同様の問題を投稿したことがあります(新たに始めて、うまくいけば、それについてより多くの意見を得る方がよいと思いました)。基本的に、問題は .wav ファイルからデータを読み込もうとしていることですが、出力は MatLab の出力とは異なります。
C++ では、出力は次のようになります。
-128
一方、Matlab では:
0
小さな違いだけでなく、出力が完全に異なりますが、データセット全体が間違っており、その理由がわかりません。エンディアンと関係があるのではないかと思いますが、よくわかりません。.wav ファイルに関するヘッダー情報は次のとおりです。
**** WAV FILE *****
Chunk IDRIFFN?
Chunk Size: 57934
Format: WAVEfmt
Format: IDfmt
FormatSize: 18
Format2: 1
Channel Num: 1
Sample Rate: 22050
Byte Rate: 22050
Align: 1
Bits Per Sample: 8
そしてコード:
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);
cout << "**** WAV FILE *****" << endl;
cout << "Chunk ID" << this->chunkId << endl;
cout << "Chunk Size" << this->chunkSize << endl;
cout << "Format: " << this->format << endl;
cout << "Format ID" << this->formatId << endl;
cout << "FormatSize" << this->formatSize << endl;
cout << "Format2 " << this->format2 << endl;
cout << "Channel Num" << this->numChannels << endl;
cout << "Sample Rate" << this->sampleRate << endl;
cout << "Byte Rate" << this->byteRate << endl;
cout << "Align" << this->align << endl;
cout << "Bits Per Sample" << this->bitsPerSample << endl;
cout << "Size" << testingSize << endl;
for(unsigned i=0; (i < 20); i++){
cout << (float) data[i] << endl;
}
return true;
誰が私が間違っているのかを見ることができますか? 私はそれをデバッグしようとしましたが、喜びがありませんでした(コンパイルにg ++を使用しています)。どんな助けでも大歓迎です:)申し訳ありませんが、私はこれを求め続けています。今は本当に迷惑です!
ありがとう