Last active
August 29, 2015 14:23
-
-
Save ranisalt/1b0dbc84ea874a04db3f to your computer and use it in GitHub Desktop.
Broken code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdint> | |
#include <iostream> | |
#include <iomanip> | |
#include "fft.h" | |
FFT::FFT(const std::string& filename) | |
: file(filename, std::ifstream::binary) | |
{ | |
int32_t chunk_id; | |
file.read(reinterpret_cast<char*>(&chunk_id), 4); | |
int32_t file_size; | |
file.read(reinterpret_cast<char*>(&file_size), 4); | |
int32_t type; | |
file.read(reinterpret_cast<char*>(&type), 4); // should be WAVE | |
int32_t format; | |
file.read(reinterpret_cast<char*>(&format),4); // should be fmt\0 | |
int32_t format_length; | |
file.read(reinterpret_cast<char*>(&format_length), 4); | |
int16_t wave_type; | |
file.read(reinterpret_cast<char*>(&wave_type), 2); | |
int16_t channels; | |
file.read(reinterpret_cast<char*>(&channels), 2); | |
int32_t sample_rate; | |
file.read(reinterpret_cast<char*>(&sample_rate), 4); | |
int32_t byte_rate; | |
file.read(reinterpret_cast<char*>(&byte_rate), 4); | |
int16_t align; | |
file.read(reinterpret_cast<char*>(&align), 2); | |
int16_t bits_per_sample; | |
file.read(reinterpret_cast<char*>(&bits_per_sample), 2); | |
int32_t data_length; | |
file.read(reinterpret_cast<char*>(&data_length), 4); | |
int16_t data[data_length]; | |
file.read(reinterpret_cast<char*>(&data), data_length * 2); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef FFT_FFT_H | |
#define FFT_FFT_H | |
#include <fstream> | |
#include <string> | |
class FFT { | |
public: | |
FFT(const std::string& filename); | |
private: | |
std::fstream file; | |
}; | |
#endif //FFT_FFT_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment