void DiskInUGenInternalFloatBigEndian::processBlock(bool& shouldDelete, const unsigned int blockID, const int /*channel*/) throw() { if(clearOutputsAndReadData(shouldDelete) == noErr) { for(int channel = 0; channel < numChannels_; channel++) { float *outputSamples = proxies[channel]->getSampleData(); float* audioFileSamples = (float*)audioData + channel; int numSamplesToProcess = numPackets; while(numSamplesToProcess--) { *outputSamples = bigEndianFloat((const char*)audioFileSamples); outputSamples++; audioFileSamples += numChannels_; } } } }
Vector3* PFMLoader::readPFMImage(const char * filename, int * width, int * height) { FILE *infile = 0; float *lineBuffer = 0; Vector3 *img = 0; char junk; try { fopen_s(&infile, filename, "rb"); if (!infile) throw std::runtime_error("cannot open file."); int a = fgetc(infile); int b = fgetc(infile); fgetc(infile); if ((a != 'P') || ((b != 'F') && (b != 'f'))) throw std::runtime_error("not a PFM image file."); b = (b == 'F'); // 'F' = RGB, 'f' = monochrome fscanf_s(infile, "%d %d%c", width, height, &junk); if ((*width <= 0) || (*height <= 0)) throw std::runtime_error("invalid width or height."); float scaleFactor; fscanf_s(infile, "%f%c", &scaleFactor, &junk); img = new Vector3[*width * *height]; a = *width * (b ? 3 : 1); lineBuffer = new float[a]; for (int y = 0; y < *height; ++y) { Vector3 *cur = &img[y * *width]; if (fread(lineBuffer, sizeof(float), a, infile) != (size_t) a) throw std::runtime_error("cannot read pixel data."); float *temp = lineBuffer; for (int x = 0; x < *width; x++) { if (b) { // color (*cur)[0] = *temp++; (*cur)[1] = *temp++; (*cur)[2] = *temp++; if (scaleFactor > 0.0) { bigEndianFloat((*cur)[0]); bigEndianFloat((*cur)[1]); bigEndianFloat((*cur)[2]); } else { littleEndianFloat((*cur)[0]); littleEndianFloat((*cur)[1]); littleEndianFloat((*cur)[2]); } } else { // black and white float c = *temp++; if (scaleFactor > 0.0) bigEndianFloat (c); else littleEndianFloat (c); (*cur)[0] = (*cur)[1] = (*cur)[2] = c; } cur++; } } delete [] lineBuffer; fclose(infile); return img; } catch (const std::exception &e) { printf("Unable to read image file \"%s\": %s", filename, e.what()); delete [] lineBuffer; delete [] img; if (infile) fclose (infile); return 0; } catch (...) { printf("Unable to read image file \"%s\".", filename); delete [] lineBuffer; delete [] img; if (infile) fclose (infile); return 0; } }
// // Process the arguments given a pointer to a typetag field (including comma). // Specify in 'argOffset' where the arguments start. // void osc_dispatch_callbacks(char * typetag, int argOffset, int maxLength) { int * intVal = NULL; int argNum = 1; UARTprintf("Packet:\n"); printHexDump(typetag, 32); UARTprintf("osc_dispatch_callbacks(\"%s\", %d, %d)\n", typetag, argOffset, maxLength); if (typetag[0] != ',') { UARTprintf("[WARNING] This lacks a comma and is thus not a typetag?\n"); } while (typetag[argNum] && argNum < maxLength) { switch(typetag[argNum]) { case 'i': // 32-bit integer intVal = (int *) (typetag + argOffset); g_osc_state.intCallback(argNum, ntohl(*intVal)); argOffset += 4; break; case 'f': // 32-bit float g_osc_state.floatCallback(argNum, bigEndianFloat(typetag + argOffset)); argOffset += 4; break; case 'S': // Symbol case 's': // String g_osc_state.stringCallback(argNum, typetag + argOffset, maxLength - argOffset); // For some reason, strnlen is implicitly declared here though // I've #included string.h. The code still links and runs though. argOffset += strnlen(typetag + argOffset, maxLength - argOffset); // Pad to be a multiple of 4 bytes (as OSC strings must be) argOffset = (argOffset + 3) & ~0x03; break; case 'b': // Binary blob (32-bit size comes first) // This value gives the length of the blob in bytes. intVal = (int *) (typetag + argOffset); argOffset += 4; g_osc_state.blobCallback(argNum, typetag + argOffset, ntohl(*intVal)); argOffset += *intVal; // Pad to be a multiple of 4 bytes (as blob data must also be) argOffset = (argOffset + 3) & ~0x03; break; case 'h': // Untested (oscP5 won't send longs?) { // long val = bigEndianLong(typetag + argOffset); // Can't print longs this way: // UARTprintf("Arg %d: Long %ld\n", argNum, val); } argOffset += 8; break; case 't': UARTprintf("[ERROR] Arg %d is a timetag; not implemented!\n", argNum); break; case 'd': // Untested { //double val = bigEndianDouble(typetag + argOffset); UARTprintf("Arg %d: Double (not printing value)\n", argNum); } argOffset += 8; break; case 'c': // Character is ASCII, but represented in 32 bits { int * tmp = (int *) (typetag + argOffset); UARTprintf("Arg %d: ASCII character %d\n", argNum, ntohl(*tmp)); } argOffset += 4; break; case 'r': // Untested UARTprintf("Arg %d: RGBA color ", argNum); printHexDump(typetag + argOffset, 4); argOffset += 4; // { // intVal = (int *) (typetag + argOffset); // ntohl(*intVal) ... // } break; case 'm': // Untested UARTprintf("Arg %d: 4 bytes of MIDI data, ", argNum); printHexDump(typetag + argOffset, 4); argOffset += 4; break; // For args T, F, N, I, no bytes are allocated. case 'T': UARTprintf("Arg %d: Boolean true\n", argNum); break; case 'F': UARTprintf("Arg %d: Boolean false\n", argNum); break; case 'N': // Untested UARTprintf("Arg %d: Nil\n", argNum); break; case 'I': // Untested UARTprintf("Arg %d: Infinitum\n", argNum); break; // Arrays (not handled): case '[': case ']': UARTprintf("Arrays are not supported! \n", argNum); break; default: { char tmp[2]; tmp[1] = 0; tmp[0] = typetag[argNum]; UARTprintf("Arg %d has unknown typetag %s\n", argNum, tmp); } break; } ++argNum; } }