这篇教程C++ swap16函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中swap16函数的典型用法代码示例。如果您正苦于以下问题:C++ swap16函数的具体用法?C++ swap16怎么用?C++ swap16使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了swap16函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: generate_sine16_2/* a stereo sine-wave 16bps stream */static FLAC__bool generate_sine16_2(const char *fn, const double sample_rate, const unsigned samples, const double f1, const double a1, const double f2, const double a2, double fmult){ const FLAC__int16 full_scale = 32767; const double delta1 = 2.0 * M_PI / ( sample_rate / f1); const double delta2 = 2.0 * M_PI / ( sample_rate / f2); FILE *f; double theta1, theta2; unsigned i; if(0 == (f = fopen(fn, mode))) return false; for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) { double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale; FLAC__int16 v = (FLAC__int16)(val + 0.5); swap16(&v); if(fwrite(&v, sizeof(v), 1, f) < 1) goto foo; val = -(a1*sin(theta1*fmult) + a2*sin(theta2*fmult))*(double)full_scale; v = (FLAC__int16)(val + 0.5); swap16(&v); if(fwrite(&v, sizeof(v), 1, f) < 1) goto foo; } fclose(f); return true;foo: fclose(f); return false;}
开发者ID:CoolOppo,项目名称:audacity,代码行数:32,
示例2: correct_datastatic void correct_data(struct SS_GAMEPAD *data){ data->motion.acc_x = swap16(data->motion.acc_x) - zeroG; data->motion.acc_y = swap16(data->motion.acc_y) - zeroG; data->motion.acc_z = swap16(data->motion.acc_z) - zeroG; data->motion.z_gyro = swap16(data->motion.z_gyro) - zeroG;}
开发者ID:xerpi,项目名称:ds3ps2drv,代码行数:7,
示例3: swap_old_headerstatic voidswap_old_header(struct s_ospcl *os){ os->c_type = swap32(os->c_type); os->c_date = swap32(os->c_date); os->c_ddate = swap32(os->c_ddate); os->c_volume = swap32(os->c_volume); os->c_tapea = swap32(os->c_tapea); os->c_inumber = swap16(os->c_inumber); os->c_magic = swap32(os->c_magic); os->c_checksum = swap32(os->c_checksum); os->c_odinode.odi_mode = swap16(os->c_odinode.odi_mode); os->c_odinode.odi_nlink = swap16(os->c_odinode.odi_nlink); os->c_odinode.odi_uid = swap16(os->c_odinode.odi_uid); os->c_odinode.odi_gid = swap16(os->c_odinode.odi_gid); os->c_odinode.odi_size = swap32(os->c_odinode.odi_size); os->c_odinode.odi_rdev = swap32(os->c_odinode.odi_rdev); os->c_odinode.odi_atime = swap32(os->c_odinode.odi_atime); os->c_odinode.odi_mtime = swap32(os->c_odinode.odi_mtime); os->c_odinode.odi_ctime = swap32(os->c_odinode.odi_ctime); os->c_count = swap32(os->c_count);}
开发者ID:sofuture,项目名称:bitrig,代码行数:25,
示例4: generate_wbps16/* a stereo wasted-bits-per-sample 16bps stream */static FLAC__bool generate_wbps16(const char *fn, unsigned samples){ FILE *f; unsigned sample; if(0 == (f = fopen(fn, mode))) return false; for(sample = 0; sample < samples; sample++) { FLAC__int16 l = (sample % 2000) << 2; FLAC__int16 r = (sample % 1000) << 3; swap16(&l); swap16(&r); if(fwrite(&l, sizeof(l), 1, f) < 1) goto foo; if(fwrite(&r, sizeof(r), 1, f) < 1) goto foo; } fclose(f); return true;foo: fclose(f); return false;}
开发者ID:CoolOppo,项目名称:audacity,代码行数:26,
示例5: setWavFilebool WvOut :: setWavFile( const char *fileName ){ char name[128]; strncpy(name, fileName, 128); if ( strstr(name, ".wav") == NULL) strcat(name, ".wav"); fd = fopen(name, "wb"); if ( !fd ) { sprintf(msg, "WvOut: Could not create WAV file: %s", name); return false; } struct wavhdr hdr = {"RIF", 44, "WAV", "fmt", 16, 1, 1, (SINT32) Stk::sampleRate(), 0, 2, 16, "dat", 0}; hdr.riff[3] = 'F'; hdr.wave[3] = 'E'; hdr.fmt[3] = ' '; hdr.data[3] = 'a'; hdr.num_chans = (SINT16) channels; if ( dataType == STK_SINT8 ) hdr.bits_per_samp = 8; else if ( dataType == STK_SINT16 ) hdr.bits_per_samp = 16; else if ( dataType == STK_SINT32 ) hdr.bits_per_samp = 32; else if ( dataType == MY_FLOAT32 ) { hdr.format_tag = 3; hdr.bits_per_samp = 32; } else if ( dataType == MY_FLOAT64 ) { hdr.format_tag = 3; hdr.bits_per_samp = 64; } hdr.bytes_per_samp = (SINT16) (channels * hdr.bits_per_samp / 8); hdr.bytes_per_sec = (SINT32) (hdr.sample_rate * hdr.bytes_per_samp); byteswap = false;#ifndef __LITTLE_ENDIAN__ byteswap = true; swap32((unsigned char *)&hdr.file_size); swap32((unsigned char *)&hdr.chunk_size); swap16((unsigned char *)&hdr.format_tag); swap16((unsigned char *)&hdr.num_chans); swap32((unsigned char *)&hdr.sample_rate); swap32((unsigned char *)&hdr.bytes_per_sec); swap16((unsigned char *)&hdr.bytes_per_samp); swap16((unsigned char *)&hdr.bits_per_samp);#endif if ( fwrite(&hdr, 4, 11, fd) != 11 ) { sprintf(msg, "WvOut: Could not write WAV header for file %s", name); return false; } printf("/nCreating WAV file: %s/n", name); return true;}
开发者ID:NickeyWoo,项目名称:VoiceAnalysis,代码行数:58,
示例6: test_macrosvoid test_macros(){ assert(swap16(0) == 0); assert(swap16(0x0102) == 0x0201); assert(swap32(0) == 0); assert(swap32(0x01020304) == 0x04030201); assert(swap64(0) == 0); assert(swap64(0x0102030405060708ULL) == 0x0807060504030201ULL);}
开发者ID:007gzs,项目名称:android-platform-ndk,代码行数:9,
示例7: setWavFilebool WvOut :: setWavFile( const char *fileName ){ char name[8192]; strncpy(name, fileName, 8192); if ( strstr(name, ".wav") == NULL) strcat(name, ".wav"); fd_ = fopen(name, "wb"); if ( !fd_ ) { errorString_ << "WvOut: could not create WAV file: " << name; return false; } struct wavhdr hdr = {"RIF", 44, "WAV", "fmt", 16, 1, 1, (SINT32) Stk::sampleRate(), 0, 2, 16, "dat", 0}; hdr.riff[3] = 'F'; hdr.wave[3] = 'E'; hdr.fmt[3] = ' '; hdr.data[3] = 'a'; hdr.num_chans = (SINT16) channels_; if ( dataType_ == STK_SINT8 ) hdr.bits_per_samp = 8; else if ( dataType_ == STK_SINT16 ) hdr.bits_per_samp = 16; else if ( dataType_ == STK_SINT32 ) hdr.bits_per_samp = 32; else if ( dataType_ == STK_FLOAT32 ) { hdr.format_tag = 3; hdr.bits_per_samp = 32; } else if ( dataType_ == STK_FLOAT64 ) { hdr.format_tag = 3; hdr.bits_per_samp = 64; } hdr.bytes_per_samp = (SINT16) (channels_ * hdr.bits_per_samp / 8); hdr.bytes_per_sec = (SINT32) (hdr.sample_rate * hdr.bytes_per_samp); byteswap_ = false;#ifndef __LITTLE_ENDIAN__ byteswap_ = true; swap32((unsigned char *)&hdr.file_size); swap32((unsigned char *)&hdr.chunk_size); swap16((unsigned char *)&hdr.format_tag); swap16((unsigned char *)&hdr.num_chans); swap32((unsigned char *)&hdr.sample_rate); swap32((unsigned char *)&hdr.bytes_per_sec); swap16((unsigned char *)&hdr.bytes_per_samp); swap16((unsigned char *)&hdr.bits_per_samp);#endif if ( fwrite(&hdr, 4, 11, fd_) != 11 ) { errorString_ << "WvOut: could not write WAV header for file " << name << '.'; return false; } errorString_ << "WvOut: creating WAV file: " << name; handleError( StkError::WARNING ); return true;}
开发者ID:Cycling74,项目名称:percolate,代码行数:57,
示例8: swap32static u32swap32 (u32 value){ u16 l, h; conv32to16 (value, &l, &h); conv16to32 (swap16 (h), swap16 (l), &value); return value;}
开发者ID:anbangr,项目名称:bitvisor-dev,代码行数:9,
示例9: swap_hdr/* * reimplement pcap_open_offline with privsep, this is the * unprivileged part. * XXX merge with above? */static voidswap_hdr(struct pcap_file_header *hp){ hp->version_major = swap16(hp->version_major); hp->version_minor = swap16(hp->version_minor); hp->thiszone = swap32(hp->thiszone); hp->sigfigs = swap32(hp->sigfigs); hp->snaplen = swap32(hp->snaplen); hp->linktype = swap32(hp->linktype);}
开发者ID:ajinkya93,项目名称:OpenBSD,代码行数:15,
示例10: swap_pef_reloc_header//----------------------------------------------------------------------static void swap_pef_reloc_header(pef_reloc_header_t &prh){#if __MF__ qnotused(prh);#else prh.sectionIndex = swap16(prh.sectionIndex); prh.reservedA = swap16(prh.reservedA); prh.relocCount = swap32(prh.relocCount); prh.firstRelocOffset = swap32(prh.firstRelocOffset);#endif}
开发者ID:nealey,项目名称:vera,代码行数:12,
示例11: readff void readff(const char * filename) { std::string temp(filename); if(temp.size() <= 3) { puts("fixing filename"); temp += ".ff"; filename = temp.data(); } // Unfortunately I have to duplicate code or else use gotos or logic variables. else if(temp.substr(temp.length()-3) != ".ff") { puts("fixing filename"); temp += ".ff"; filename = temp.data(); } FILE* file = fopen(filename, "rb"); printf("reading file %s/n", filename); if(file != NULL) { char name[8]; fread(name, 1, 8, file); printf("%.8s -- header magic/n", name); if(memcmp(name, "farbfeld", 8) == 0) { { unsigned int scratch[2]; fread(scratch, 4, 2, file); width = swap32(scratch[0]); height = swap32(scratch[1]); std::cout << width << " " << height << " -- dimensions/n"; dimensions(width, height); } for(auto& t : data) { unsigned short scratch[4]; fread(scratch, 2, 4, file); t.r = swap16(scratch[0])*1.0/0xFFFF; t.g = swap16(scratch[1])*1.0/0xFFFF; t.b = swap16(scratch[2])*1.0/0xFFFF; } } else puts("Not a valid farbfeld file."); fclose(file); std::cout << data.size() << " -- number of pixels in farbfeld/n"; } else puts("Error opening file."); }
开发者ID:wareya,项目名称:median,代码行数:54,
示例12: sprintfchar *devprop_generate_string(struct DevPropString *string){ char *buffer = (char*)MALLOC(string->length * 2); char *ptr = buffer; if(!buffer) return NULL; sprintf(buffer, "%08x%08x%04x%04x", swap32(string->length), string->WHAT2, swap16(string->numentries), string->WHAT3); buffer += 24; int i = 0, x = 0; while(i < string->numentries) { sprintf(buffer, "%08x%04x%04x", swap32(string->entries[i]->length), swap16(string->entries[i]->numentries), string->entries[i]->WHAT2); buffer += 16; sprintf(buffer, "%02x%02x%04x%08x%08x", string->entries[i]->acpi_dev_path.type, string->entries[i]->acpi_dev_path.subtype, swap16(string->entries[i]->acpi_dev_path.length), string->entries[i]->acpi_dev_path._HID, swap32(string->entries[i]->acpi_dev_path._UID)); buffer += 24; for(x=0; x < string->entries[i]->num_pci_devpaths; x++) { sprintf(buffer, "%02x%02x%04x%02x%02x", string->entries[i]->pci_dev_path[x].type, string->entries[i]->pci_dev_path[x].subtype, swap16(string->entries[i]->pci_dev_path[x].length), string->entries[i]->pci_dev_path[x].function, string->entries[i]->pci_dev_path[x].device); buffer += 12; } sprintf(buffer, "%02x%02x%04x", string->entries[i]->path_end.type, string->entries[i]->path_end.subtype, swap16(string->entries[i]->path_end.length)); buffer += 8; uint8_t *dataptr = string->entries[i]->data; for(x = 0; x < (string->entries[i]->length) - (24 + (6 * string->entries[i]->num_pci_devpaths)) ; x++) { sprintf(buffer, "%02x", *dataptr++); buffer += 2; } i++; } return ptr;}
开发者ID:AlexSeverinov,项目名称:Chameleon,代码行数:51,
示例13: sibling_extentstatic void sibling_extent(ffs_sort_t *entry, uint32_t size_sib_entry, block_info_t *block_info){ f3s_extptr_t next, dir_next; f3s_head_t dir_extent; uint32_t pos, nbytes; uint16_t extent_flags; // // Setup 'next' pointer to new extent // dir_next.logi_unit = swap16(target_endian,block_info->block_index + 1); dir_next.index = swap16(target_endian,block_info->extent_index); // // now write the entry to the correct place // 'next' entry is // pos = entry->extent_pos; lseek(flashimage, pos, SEEK_SET); if (read(flashimage,&dir_extent,sizeof(dir_extent)) != sizeof(dir_extent)) mk_flash_exit("read failed: %s/n",strerror(errno)); dir_extent.status &= swap16(target_endian,~F3S_EXT_NO_NEXT); dir_extent.next = dir_next; lseek(flashimage, pos, SEEK_SET); memcpy(blk_buffer_ptr,&dir_extent, sizeof(dir_extent)); if ((nbytes = write(flashimage,blk_buffer_ptr,sizeof(dir_extent))) !=sizeof(dir_extent)) mk_flash_exit("write failed: %s/n",strerror(errno)); entry->status |=FFS_SORT_ENTRY_SET; // // write extent for the new entry // extent_flags = ~F3S_EXT_TYPE & 0xff00; extent_flags |= (F3S_EXT_DIR | F3S_EXT_NO_NEXT | F3S_EXT_NO_SUPER | F3S_EXT_ALLOC | F3S_EXT_LAST | F3S_EXT_NO_SPLIT); next.logi_unit = FNULL; next.index = FNULL; write_extent(block_info, next, extent_flags, size_sib_entry);}
开发者ID:vocho,项目名称:openqnx,代码行数:51,
示例14: __icmp_echostatic size_t __icmp_echo(icmp_hdr_t *hdr, uint8_t type, uint16_t id, uint16_t seq, void *data, size_t dlen){ loc_t pkt; hdr->ping.id = swap16(id); hdr->ping.seq = swap16(seq); pkt.addr = hdr; pkt.linear += sizeof(icmp_hdr_t); memcpy(pkt.addr, data, dlen); return __icmp_gen(hdr, type, 0, dlen);}
开发者ID:Debug-Orz,项目名称:ramooflax,代码行数:15,
示例15: swap_pef//----------------------------------------------------------------------static void swap_pef(pef_t &pef){#if __MF__ qnotused(pef);#else pef.formatVersion = swap32(pef.formatVersion); pef.dateTimeStamp = swap32(pef.dateTimeStamp); pef.oldDefVersion = swap32(pef.oldDefVersion); pef.oldImpVersion = swap32(pef.oldImpVersion); pef.currentVersion = swap32(pef.currentVersion); pef.reservedA = swap32(pef.reservedA); pef.sectionCount = swap16(pef.sectionCount); pef.instSectionCount = swap16(pef.instSectionCount);#endif}
开发者ID:nealey,项目名称:vera,代码行数:16,
示例16: udpCreateSocket}int udpCreateSocket(int8u bindOption, int32u ip, int16u port, int8u seq){ int8u buf[9]; buf[0] = SNIC_UDP_CREATE_SOCKET_REQ; buf[1] = seq; buf[2] = bindOption; if (bindOption) { int32u myip = swap32(ip); int16u myport = swap16(port); memcpy(buf+3, (int8u*)&myip, 4); memcpy(buf+7, (int8u*)&myport, 2); serial_transmit(CMD_ID_SNIC, buf, 9, ACK_NOT_REQUIRED); } else serial_transmit(CMD_ID_SNIC, buf, 3, ACK_NOT_REQUIRED); printf("-udpCreateSocket/n/r"); while (1) { if(SN8200_API_HasInput()) { ProcessSN8200Input(); } if(IsCreateSocketResponsed) { IsCreateSocketResponsed = false; break; } mdelay(1); } return 0;}int udpSendFromSock(int32u ip, int16u iPort, int8u shortsock, int8u conMode, int8u *sendbuf, int16u len, int8u seq)
开发者ID:hgk333,项目名称:SmartBell,代码行数:26,
示例17: udpSendFromSock}int udpSendFromSock(int32u ip, int16u iPort, int8u shortsock, int8u conMode, int8u *sendbuf, int16u len, int8u seq){ int8u buf[2048+12]; int16u mybufsize; if (len == 0 || len > MAX_BUFFER_SIZE) { len = MAX_BUFFER_SIZE; } buf[0] = SNIC_UDP_SEND_FROM_SOCKET_REQ; buf[1] = seq; memcpy(buf+2, (int8u*)&ip, 4); memcpy(buf+6, (int8u*)&iPort, 2); buf[8] = shortsock; buf[9] = conMode; mybufsize = swap16(len); memcpy(buf+10, (int8u*)&mybufsize, 2); memcpy(buf+12, sendbuf, len); serial_transmit(CMD_ID_SNIC, buf, 12+len, ACK_NOT_REQUIRED); printf("-udpSendFromSock/n/r"); timeout = 10000; while (timeout--) { if(SN8200_API_HasInput()) { ProcessSN8200Input(); } if(sendUDPDone) { sendUDPDone = 0; break; } mdelay(1); } return 0;}int udpStartRecv(int32u sock, int16u bufsize, int8u seq)
开发者ID:hgk333,项目名称:SmartBell,代码行数:30,
示例18: swap32Psmf::Psmf(u32 data) { headerOffset = data; magic = Memory::Read_U32(data); version = Memory::Read_U32(data + 4); streamOffset = swap32(Memory::Read_U32(data + 8)); streamSize = swap32(Memory::Read_U32(data + 12)); streamDataTotalSize = swap32(Memory::Read_U32(data + 0x50)); presentationStartTime = getMpegTimeStamp(Memory::GetPointer(data + PSMF_FIRST_TIMESTAMP_OFFSET)); presentationEndTime = getMpegTimeStamp(Memory::GetPointer(data + PSMF_LAST_TIMESTAMP_OFFSET)); streamDataNextBlockSize = swap32(Memory::Read_U32(data + 0x6A)); streamDataNextInnerBlockSize = swap32(Memory::Read_U32(data + 0x7C)); numStreams = swap16(Memory::Read_U16(data + 0x80)); currentStreamNum = -1; currentAudioStreamNum = -1; currentVideoStreamNum = -1; for (int i = 0; i < numStreams; i++) { PsmfStream *stream = 0; u32 currentStreamAddr = data + 0x82 + i * 16; int streamId = Memory::Read_U8(currentStreamAddr); if ((streamId & PSMF_VIDEO_STREAM_ID) == PSMF_VIDEO_STREAM_ID) { stream = new PsmfStream(PSMF_AVC_STREAM, ++currentVideoStreamNum); stream->readMPEGVideoStreamParams(currentStreamAddr, this); } else if ((streamId & PSMF_AUDIO_STREAM_ID) == PSMF_AUDIO_STREAM_ID) { stream = new PsmfStream(PSMF_ATRAC_STREAM, ++currentAudioStreamNum); stream->readPrivateAudioStreamParams(currentStreamAddr, this); } if (stream) { currentStreamNum++; streamMap[currentStreamNum] = stream; } }}
开发者ID:andont,项目名称:ppsspp,代码行数:34,
示例19: fillNSendHttpReq}int fillNSendHttpReq(int8u seq, char* domain, char* uri, char method, char* contentType, char* otherHeader, int contentLen, char* content, unsigned char timeout, char moreData, char isHttps){ char *ptr = NULL; int8u buf[1024]; int16u encodedLen = moreData?contentLen|0x8000:contentLen; memset(buf, 0, sizeof(buf)); buf[0] = SNIC_HTTP_REQ; buf[1] = seq; *((int16u*)&buf[2]) = 0x5000; //swapped buf[4] = method; buf[5] = timeout; if (isHttps) { buf[0] = SNIC_HTTPS_REQ; *((int16u*)&buf[2]) = 0xbb01; // 443 swapped } ptr = (char*)buf+6; ptr += sprintf(ptr, "%s", domain)+1; ptr += sprintf(ptr, "%s", uri)+1; ptr += sprintf(ptr, "%s", contentType)+1; ptr += sprintf(ptr, "%s", otherHeader)+1; *((int16u*)ptr) = swap16(encodedLen); ptr += 2; if (contentLen) memcpy(ptr, content, contentLen); serial_transmit(CMD_ID_SNIC, buf, ptr-(char*)buf+contentLen, ACK_NOT_REQUIRED); return 0;}/*add HttpMoreReq cmd*/
开发者ID:hgk333,项目名称:SmartBell,代码行数:27,
示例20: swap16FXbool InputPlugin::read_int16_be(FXshort & value) { if (read(&value,2)==2) { value = swap16(value); return true; } return false; }
开发者ID:sophom,项目名称:gogglesmm,代码行数:7,
示例21: swap_prc//-------------------------------------------------------------------------static void swap_prc(DatabaseHdrType &h){ h.attributes = swap16(h.attributes); h.version = swap16(h.version); h.creationDate = swap32(h.creationDate); h.modificationDate = swap32(h.modificationDate); h.lastBackupDate = swap32(h.lastBackupDate); h.modificationNumber = swap32(h.modificationNumber); h.appInfoID = swap32(h.appInfoID); h.sortInfoID = swap32(h.sortInfoID);// h.type = swap32(h.type);// h.id = swap32(h.id); h.uniqueIDSeed = swap32(h.uniqueIDSeed); h.nextRecordListID = swap32(h.nextRecordListID); h.numRecords = swap16(h.numRecords);}
开发者ID:nihilus,项目名称:ida_objectivec_plugins,代码行数:17,
示例22: cdda_readlong cdda_read(cdrom_drive *d, void *buffer, long beginsector, long sectors){ if(d->opened){ if(sectors>0){ sectors=d->read_audio(d,buffer,beginsector,sectors); if(sectors!=-1){ /* byteswap? */ if(d->bigendianp==-1) /* not determined yet */ d->bigendianp=data_bigendianp(d); if(d->bigendianp!=bigendianp()){ int i; u_int16_t *p=(u_int16_t *)buffer; long els=sectors*CD_FRAMESIZE_RAW/2; for(i=0;i<els;i++)p[i]=swap16(p[i]); } } } return(sectors); } cderror(d,"400: Device not open/n"); return(-400);}
开发者ID:jamesyan84,项目名称:zbase,代码行数:25,
示例23: getTCPinfo}int getTCPinfo(void){ char tempIPstr[32]; char teststr[8]; if (strlen(IPstr)==0) strcpy(IPstr, "192.168.10.101"); if (strlen(Portstr)==0) strcpy(Portstr, "0x6990"); printf("Enter server IP to connect: /n/r"); scanf("%s", tempIPstr); printf("/n/r"); if (strlen(tempIPstr)) strcpy(IPstr, tempIPstr); destIP = inet_addr(IPstr); if (destIP == INADDR_NONE || destIP == INADDR_ANY) { return CMD_ERROR; } printf("Enter server port number: /n/r"); scanf("%s", teststr); printf("/n/r"); if (strlen(teststr)) strcpy(Portstr, teststr); destPort = strtol(Portstr, NULL, 0); destPort = swap16(destPort); if (destPort > 0xFFFF) { printf("Invalid port, max limit 0xFFFF /n/r"); return CMD_ERROR; } return 0;}int setTCPinfo(void)
开发者ID:hgk333,项目名称:SmartBell,代码行数:30,
示例24: generate_fsd16/* a mono full-scale deflection 16bps stream */static FLAC__bool generate_fsd16(const char *fn, const int pattern[], unsigned reps){ FILE *f; unsigned rep, p; FLAC__ASSERT(pattern != 0); if(0 == (f = fopen(fn, mode))) return false; for(rep = 0; rep < reps; rep++) { for(p = 0; pattern[p]; p++) { FLAC__int16 x = pattern[p] > 0? 32767 : -32768; swap16(&x); if(fwrite(&x, sizeof(x), 1, f) < 1) goto foo; } } fclose(f); return true;foo: fclose(f); return false;}
开发者ID:CoolOppo,项目名称:audacity,代码行数:26,
示例25: swap16void PortableFile::write16(uint16 value){ if (system_big_endian != big_endian_) { value = swap16(value); } f_.write((const char *)&value, 2);}
开发者ID:spippolatore,项目名称:freesynd,代码行数:7,
示例26: tcpConnectToServer}int tcpConnectToServer(int8u shortSock, int32u ip, int16u port, int16u bufsize, int8u timeout, int8u seq){ int8u buf[12]; if (bufsize == 0 || bufsize > MAX_BUFFER_SIZE) { bufsize = MAX_BUFFER_SIZE; } buf[0] = SNIC_TCP_CONNECT_TO_SERVER_REQ; buf[1] = seq; buf[2] = shortSock; memcpy(buf+3, (int8u*)&ip, 4); memcpy(buf+7, (int8u*)&port, 2); bufsize = swap16(bufsize); memcpy(buf+9, (int8u*)&bufsize, 2); buf[11] = timeout; serial_transmit(CMD_ID_SNIC, buf, 12, ACK_NOT_REQUIRED); printf("-tcpConnectToServer/n/r"); mdelay(1000); //Wait module return value while (1) { if(SN8200_API_HasInput()) { ProcessSN8200Input(); } if(IsSNICTCPConnectToServerResponsed) { IsSNICTCPConnectToServerResponsed = false; break; } mdelay(1); } return 0;}int tcpCreateConnection(int8u shortSock, int16u size, int8u maxClient, int8u seq)
开发者ID:hgk333,项目名称:SmartBell,代码行数:28,
示例27: sendFromSock}int sendFromSock(int8u shortSocket, int8u * sendBuf, int16u len, int8u timeout, int8u seq){ int8u buf[MAX_BUFFER_SIZE+6]; int16u mybufsize; if (len == 0 || len > MAX_BUFFER_SIZE) { len = MAX_BUFFER_SIZE; } buf[0] = SNIC_SEND_FROM_SOCKET_REQ; buf[1] = seq; buf[2] = shortSocket; buf[3] = 0; mybufsize = swap16(len); memcpy(buf+4, (int8u*)&mybufsize, 2); memcpy(buf+6, sendBuf, len); serial_transmit(CMD_ID_SNIC, buf, 6+len, ACK_NOT_REQUIRED); printf("-sendFromSock/n/r"); while (1) { if(SN8200_API_HasInput()) { ProcessSN8200Input(); } if(IsSNICSendFromSocketResponsed) { IsSNICSendFromSocketResponsed = false; break; } mdelay(1); } return 0;}int udpCreateSocket(int8u bindOption, int32u ip, int16u port, int8u seq)
开发者ID:hgk333,项目名称:SmartBell,代码行数:27,
示例28: writeDatavoid WvOut :: writeData( unsigned long frames ){ if ( dataType == STK_SINT8 ) { if ( fileType == WVOUT_WAV ) { // 8-bit WAV data is unsigned! unsigned char sample; for ( unsigned long k=0; k<frames*channels; k++ ) { sample = (unsigned char) (data[k] * 127.0 + 128.0); if ( fwrite(&sample, 1, 1, fd) != 1 ) goto error; } } else { signed char sample; for ( unsigned long k=0; k<frames*channels; k++ ) { sample = (signed char) (data[k] * 127.0); //sample = ((signed char) (( data[k] + 1.0 ) * 127.5 + 0.5)) - 128; if ( fwrite(&sample, 1, 1, fd) != 1 ) goto error; } } } else if ( dataType == STK_SINT16 ) { SINT16 sample; for ( unsigned long k=0; k<frames*channels; k++ ) { sample = (SINT16) (data[k] * 32767.0); //sample = ((SINT16) (( data[k] + 1.0 ) * 32767.5 + 0.5)) - 32768; if ( byteswap ) swap16( (unsigned char *)&sample ); if ( fwrite(&sample, 2, 1, fd) != 1 ) goto error; } } else if ( dataType == STK_SINT32 ) { SINT32 sample; for ( unsigned long k=0; k<frames*channels; k++ ) { sample = (SINT32) (data[k] * 2147483647.0); //sample = ((SINT32) (( data[k] + 1.0 ) * 2147483647.5 + 0.5)) - 2147483648; if ( byteswap ) swap32( (unsigned char *)&sample ); if ( fwrite(&sample, 4, 1, fd) != 1 ) goto error; } } else if ( dataType == MY_FLOAT32 ) { FLOAT32 sample; for ( unsigned long k=0; k<frames*channels; k++ ) { sample = (FLOAT32) (data[k]); if ( byteswap ) swap32( (unsigned char *)&sample ); if ( fwrite(&sample, 4, 1, fd) != 1 ) goto error; } } else if ( dataType == MY_FLOAT64 ) { FLOAT64 sample; for ( unsigned long k=0; k<frames*channels; k++ ) { sample = (FLOAT64) (data[k]); if ( byteswap ) swap64( (unsigned char *)&sample ); if ( fwrite(&sample, 8, 1, fd) != 1 ) goto error; } } return; error: sprintf(msg, "WvOut: Error writing data to file."); handleError(msg, StkError::FILE_ERROR);}
开发者ID:NickeyWoo,项目名称:VoiceAnalysis,代码行数:59,
示例29: Vme_Write16int Vme_Write16(Cmd_Write16 *pCmd_Write16){ short *pRd = pCmd_Write16->vals; short *pWr; int c = pCmd_Write16->cnt; vmeBusToLocalAdrs(0x39, (char *)((long)pCmd_Write16->addr),(char **)&pWr); vmeBusLock(); if(pCmd_Write16->flags & CRATE_MSG_FLAGS_ADRINC) while(c--) *pWr++ = swap16(*pRd++); else while(c--) *pWr = swap16(*pRd++); vmeBusUnlock(); return 0;}
开发者ID:JeffersonLab,项目名称:fe_diaggui,代码行数:17,
注:本文中的swap16函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ swap2函数代码示例 C++ swap128函数代码示例 |