void WavFile::read() { fseek(_f, 0, SEEK_SET); u32 riff = read_32le(); read_32le(); if (riff != 0x46464952) throw std::runtime_error("invalid riff file signature"); u32 format = read_32le(); if (format != 0x45564157) throw std::runtime_error("only wave format supported"); while(!ok()) { u32 id = read_32le(); u32 size = read_32le(); LOG_DEBUG(("id: 0x%08x, size: %u", id, size)); if (id == 0x20746d66) { Buffer fmt; read(fmt, size); read_format(fmt); } else if (id == 0x61746164) { read(_data, size); #if !defined(_WINDOWS) && __BYTE_ORDER == __BIG_ENDIAN if (_spec.bytes_per_sample() == 2) { u8 *ptr = static_cast<u8 *>(_data.get_ptr()); for(size_t i = 0; i + 1 < _data.get_size(); i += 2, ptr += 2) std::swap(ptr[0], ptr[1]); } #endif } else fseek(_f, size, SEEK_CUR); } }
int main(int argc, char *argv[]) { midi_format format; FILE *fd; char buffer[1024]; int trk_len; int read_count; int i; midi_track tracks[5]; // fd = fopen("beethoven_fur_elise.mid", "r"); // fd = fopen("Beethoven_Symphony_No._5_4th.mid", "r"); fd = fopen("clemtine.mid", "r"); if (fd == 0) { printf("unable to open midi file.\n"); return 1; } fread(buffer, 1, 4, fd); if (!check_file(buffer)) { printf("not a midi file.\n"); fclose(fd); return 1; } fread(buffer, 1, 4, fd); if (check_length(buffer)) { printf("not a valid header length.\n"); fclose(fd); return 1; } fread(buffer, 1, 6, fd); read_format(buffer, &format); printf("Midi Info:\n"); printf(" Format: %i\n", format.format); printf(" Delta Time Ticks: %i\n", format.deltatime_ticks); printf(" # of Tracks: %i\n", format.number_of_tracks); // read tracks for (i = 0; i < format.number_of_tracks; i++) { fread(buffer, 1, 8, fd); trk_len = read_track_length(buffer); printf("Track %i: length = %i\n", i, trk_len); read_count = fread(buffer, 1, trk_len, fd); if (read_count != trk_len) { printf("unable to read track.\n"); fclose(fd); return 1; } read_midi_events(buffer, trk_len, &tracks[i]); break; } fclose(fd); return 0; }
static enum piglit_result test_format(const struct format_info *info) { int num_texels = ARRAY_SIZE(texels_s); uint32_t texels[ARRAY_SIZE(texels_s)][4]; GLenum type; int lbits, abits, ibits, rbits, gbits, bbits; int i, readf; enum piglit_result result = PIGLIT_SKIP; if (!test_rg && ((info->base_format == GL_RED_INTEGER && !strstr(info->name, "GL_INTENSITY")) || info->base_format == GL_RG_INTEGER)) { return PIGLIT_SKIP; } if (!test_rgb10_a2ui && info->internal_format == GL_RGB10_A2UI) return PIGLIT_SKIP; /* FINISHME: We only test conversion from large signed to * small signed or large unsigned to small unsigned. The * rules just say that when reading pixels, the value is * clamped to the representable range, not how/when sign * extension occurs, and whether the clamping applies before * or after */ if (!strstr(info->name, "32")) return PIGLIT_SKIP; if (info->sign) { memcpy(texels, texels_s, sizeof(texels_s)); type = GL_INT; } else { memcpy(texels, texels_u, sizeof(texels_u)); type = GL_UNSIGNED_INT; } glTexImage2D(GL_TEXTURE_2D, 0, info->internal_format, num_texels, 1, 0, GL_RGBA_INTEGER_EXT, type, texels); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_LUMINANCE_SIZE, &lbits); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_ALPHA_SIZE, &abits); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTENSITY_SIZE, &ibits); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_RED_SIZE, &rbits); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_GREEN_SIZE, &gbits); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_BLUE_SIZE, &bbits); /* Compute the RGBA channels that should be read from the * texture given the input RGBA texels we gave. See Table 6.1 * ("Texture, table, and filter return values") of the GL 3.0 * specification. Note that input R is always mapped to L or * I, and comes back out in R (except for ALPHA). */ if (ibits || lbits) { for (i = 0; i < num_texels; i++) { texels[i][1] = 0; texels[i][2] = 0; } } else { if (!rbits) { for (i = 0; i < num_texels; i++) texels[i][0] = 0; } if (!gbits) { for (i = 0; i < num_texels; i++) texels[i][1] = 0; } if (!bbits) { for (i = 0; i < num_texels; i++) texels[i][2] = 0; } } /* Everybody's consistent on A bits in table 6.1. */ if (!abits) { for (i = 0; i < num_texels; i++) texels[i][3] = 1; } for (readf = 0; readf < ARRAY_SIZE(read_formats); readf++) { piglit_merge_result(&result, read_format(info, &read_formats[readf], texels, num_texels)); if (result == PIGLIT_FAIL) return result; } return result; }