void OSCBundle::send(Print &p){ //don't send a bundle with errors if (hasError()){ return; } //write the bundle header static uint8_t header[] = {'#', 'b', 'u', 'n', 'd', 'l', 'e', 0}; p.write(header, 8); //write the timetag { osctime_t time = timetag; uint32_t d = BigEndian(time.seconds); uint8_t * ptr = (uint8_t *) &d; p.write(ptr, 4); d = BigEndian(time.fractionofseconds); ptr = (uint8_t *) &d; p.write(ptr, 4); } //send the messages for (int i = 0; i < numMessages; i++){ OSCMessage * msg = getOSCMessage(i); int msgSize = msg->bytes(); //turn the message size into a pointer uint32_t s32 = BigEndian((uint32_t) msgSize); uint8_t * sptr = (uint8_t *) &s32; //write the messsage size p.write(sptr, 4); msg->send(p); } }
static void sha256_compress(unsigned int* iv, const uint8_t* data) { unsigned int a, b, c, d, e, f, g, h; unsigned int s0, s1; unsigned int t1, t2; unsigned int work_space[16]; unsigned int n; unsigned int i; a = iv[0]; b = iv[1]; c = iv[2]; d = iv[3]; e = iv[4]; f = iv[5]; g = iv[6]; h = iv[7]; for (i = 0; i < 16; ++i) { n = BigEndian(&data); t1 = work_space[i] = n; t1 += h + Sigma1(e) + Ch(e, f, g) + k256[i]; t2 = Sigma0(a) + Maj(a, b, c); h = g; g = f; f = e; e = d + t1; d = c; c = b; b = a; a = t1 + t2; } for (; i < 64; ++i) { s0 = work_space[(i + 1) & 0x0f]; s0 = sigma0(s0); s1 = work_space[(i + 14) & 0x0f]; s1 = sigma1(s1); t1 = work_space[i & 0xf] += s0 + s1 + work_space[(i + 9) & 0xf]; t1 += h + Sigma1(e) + Ch(e, f, g) + k256[i]; t2 = Sigma0(a) + Maj(a, b, c); h = g; g = f; f = e; e = d + t1; d = c; c = b; b = a; a = t1 + t2; } iv[0] += a; iv[1] += b; iv[2] += c; iv[3] += d; iv[4] += e; iv[5] += f; iv[6] += g; iv[7] += h; }
// Convert Integer to Synchsafe Integer (see ID3v2.4 specs) // Basically, it's a BigEndian integer, but the MSB of all bytes is 0. // Thus, a 32-bit integer turns into a 28-bit integer. uint32_t CFileTagging::intToSynchsafe(uint32_t iIn) //--------------------------------------------- { uint32_t iOut = 0, iSteps = 0; do { iOut |= (iIn & 0x7F) << iSteps; iSteps += 8; } while(iIn >>= 7); return BigEndian(iOut); }
//does not validate the incoming OSC for correctness void OSCBundle::decode(uint8_t incomingByte){ addToIncomingBuffer(incomingByte); switch (decodeState){ case STANDBY: if (incomingByte == '#'){ decodeState = HEADER; } else if (incomingByte == '/'){ decodeState = MESSAGE; } break; case HEADER: if (incomingBufferSize == 8){ decodeHeader(); decodeState = TIMETAG; } break; case TIMETAG: if (incomingBufferSize == 8){ decodeTimetag(); decodeState = MESSAGE_SIZE; } break; case MESSAGE_SIZE: if (incomingBufferSize == 4){ //make sure the message size is valid int32_t msgSize; memcpy(&msgSize, incomingBuffer, 4); msgSize = BigEndian(msgSize); if (msgSize % 4 != 0 || msgSize == 0){ error = INVALID_OSC; } else { //add a message to the buffer decodeState = MESSAGE; incomingMessageSize = msgSize; clearIncomingBuffer(); //add a new empty message add(); } } break; case MESSAGE: decodeMessage(incomingByte); break; } }
void nemo_main() { bool q = BigEndian(); bool v = getbparam("verbose"); if (v) printf("%s\n", q ? "BigEndian" : "LittleEndian"); else printf("%d\n", q ? 1 : 0); #ifdef WORDS_BIGENDIAN if (v) printf("autoconf -> big endian\n"); if (!q) error("conflict-1 determining endianism, try verbose=t"); #else if (v) printf("autoconf -> little endian\n"); if (q) error("conflict-2 determining endianism, try verbose=t"); #endif }
int main(void) { const char *filedir = "dirfile"; const char *format = "dirfile/format"; const char *data = "dirfile/data"; char format_data[1000]; uint32_t c = 0x2000001, d = 0; const int big_endian = BigEndian(); int fd, n, error, r = 0; DIRFILE *D; rmdirfile(); mkdir(filedir, 0777); sprintf(format_data, "data RAW UINT32 1\nENDIAN %s\n", (big_endian) ? "little" : "big"); fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); write(fd, format_data, strlen(format_data)); close(fd); D = gd_open(filedir, GD_RDWR | GD_UNENCODED | GD_VERBOSE); n = gd_putdata(D, "data", 5, 0, 1, 0, GD_UINT32, &c); error = gd_error(D); gd_close(D); fd = open(data, O_RDONLY | O_BINARY); lseek(fd, 5 * sizeof(uint32_t), SEEK_SET); read(fd, &d, sizeof(uint32_t)); close(fd); unlink(data); unlink(format); rmdir(filedir); CHECKI(error,0); CHECKI(n,1); CHECKX(d,0x1000002); return r; }
bool module_renderer::ReadMID(const uint8_t *lpStream, uint32_t dwMemLength) //--------------------------------------------------------------- { const MIDIFILEHEADER *pmfh = (const MIDIFILEHEADER *)lpStream; const MIDITRACKHEADER *pmth; MODCHANNELSTATE chnstate[MAX_BASECHANNELS]; MIDICHANNELSTATE midichstate[16]; MIDITRACK miditracks[MIDI_MAXTRACKS]; uint32_t dwMemPos, dwGlobalFlags, tracks, tempo; UINT row, pat, midimastervol; short int division; int midi_clock, nTempoUsec, nPPQN, nTickMultiplier; // Fix import parameters if (gnMidiImportSpeed < 2) gnMidiImportSpeed = 2; if (gnMidiImportSpeed > 6) gnMidiImportSpeed = 6; if (gnMidiPatternLen < 64) gnMidiPatternLen = 64; if (gnMidiPatternLen > 256) gnMidiPatternLen = 256; // Detect RMI files if ((dwMemLength > 12) && (*(uint32_t *)(lpStream) == IFFID_RIFF) && (*(uint32_t *)(lpStream+8) == 0x44494D52)) { lpStream += 12; dwMemLength -= 12; while (dwMemLength > 8) { uint32_t id = *(uint32_t *)lpStream; uint32_t len = *(uint32_t *)(lpStream+4); lpStream += 8; dwMemLength -= 8; if ((id == IFFID_data) && (len < dwMemLength)) { dwMemLength = len; pmfh = (const MIDIFILEHEADER *)lpStream; break; } if (len >= dwMemLength) return false; lpStream += len; dwMemLength -= len; } } // MIDI File Header if ((dwMemLength < sizeof(MIDIFILEHEADER)+8) || (pmfh->id != 0x6468544D)) return false; dwMemPos = 8 + BigEndian(pmfh->len); if (dwMemPos >= dwMemLength - 8) return false; pmth = (MIDITRACKHEADER *)(lpStream+dwMemPos); tracks = BigEndianW(pmfh->wTrks); if ((pmth->id != 0x6B72544D) || (!tracks)) return false; if (tracks > MIDI_MAXTRACKS) tracks = MIDI_MAXTRACKS; // Reading File... m_nType = MOD_TYPE_MID; m_nChannels = 32; m_nSamples = 0; m_nInstruments = 0; m_dwSongFlags |= SONG_LINEARSLIDES; // MIDI->MOD Tempo Conversion division = BigEndianW(pmfh->wDivision); if (division < 0) { int nFrames = -(division>>8); int nSubFrames = (division & 0xff); nPPQN = nFrames * nSubFrames / 2; if (!nPPQN) nPPQN = 1; } else
bool LittleEndian(void) { return !BigEndian(); }
int main(int argc, char* argv[]) { printf( BigEndian() ? "Big endian\n" : "Little endian\n" ) ; return 0 ; }