| 100 | } |
| 101 | |
| 102 | bool b3ReadWavFile::getWavInfo(const char *fileName) |
| 103 | { |
| 104 | fd_ = fopen(fileName, "rb"); |
| 105 | if (fd_ == 0) |
| 106 | return false; |
| 107 | |
| 108 | char header[12]; |
| 109 | if (fread(&header, 4, 3, fd_) != 3) |
| 110 | return false; |
| 111 | bool res = false; |
| 112 | |
| 113 | if (!strncmp(header, "RIFF", 4) && |
| 114 | !strncmp(&header[8], "WAVE", 4)) |
| 115 | res = true; |
| 116 | //getWavInfo( fileName ); |
| 117 | |
| 118 | // Find "format" chunk ... it must come before the "data" chunk. |
| 119 | char id[4]; |
| 120 | int chunkSize; |
| 121 | if (fread(&id, 4, 1, fd_) != 1) |
| 122 | return false; |
| 123 | while (strncmp(id, "fmt ", 4)) |
| 124 | { |
| 125 | if (fread(&chunkSize, 4, 1, fd_) != 1) |
| 126 | return false; |
| 127 | if (!m_machineIsLittleEndian) |
| 128 | { |
| 129 | b3Swap32((unsigned char *)&chunkSize); |
| 130 | } |
| 131 | if (fseek(fd_, chunkSize, SEEK_CUR) == -1) |
| 132 | return false; |
| 133 | if (fread(&id, 4, 1, fd_) != 1) |
| 134 | return false; |
| 135 | } |
| 136 | |
| 137 | // Check that the data is not compressed. |
| 138 | unsigned short format_tag; |
| 139 | if (fread(&chunkSize, 4, 1, fd_) != 1) |
| 140 | return false; // Read fmt chunk size. |
| 141 | if (fread(&format_tag, 2, 1, fd_) != 1) |
| 142 | return false; |
| 143 | if (!m_machineIsLittleEndian) |
| 144 | { |
| 145 | b3Swap16((unsigned char *)&format_tag); |
| 146 | b3Swap32((unsigned char *)&chunkSize); |
| 147 | } |
| 148 | if (format_tag == 0xFFFE) |
| 149 | { // WAVE_FORMAT_EXTENSIBLE |
| 150 | dataOffset_ = ftell(fd_); |
| 151 | if (fseek(fd_, 14, SEEK_CUR) == -1) |
| 152 | return false; |
| 153 | unsigned short extSize; |
| 154 | if (fread(&extSize, 2, 1, fd_) != 1) |
| 155 | return false; |
| 156 | if (!m_machineIsLittleEndian) |
| 157 | { |
| 158 | b3Swap16((unsigned char *)&extSize); |
| 159 | } |
no test coverage detected