Exemple #1
0
/* 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;
}
Exemple #2
0
static 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;
}
Exemple #3
0
void
ar9380_swap_rom(struct athn_softc *sc)
{
#if BYTE_ORDER == BIG_ENDIAN
	struct ar9380_eeprom *eep = sc->eep;
	struct ar9380_base_eep_hdr *base = &eep->baseEepHeader;
	struct ar9380_modal_eep_header *modal;
	int i;

	base->regDmn[0] = swap16(base->regDmn[0]);
	base->regDmn[1] = swap16(base->regDmn[1]);
	base->swreg = swap32(base->swreg);

	modal = &eep->modalHeader2G;
	modal->antCtrlCommon = swap32(modal->antCtrlCommon);
	modal->antCtrlCommon2 = swap32(modal->antCtrlCommon2);
	modal->papdRateMaskHt20 = swap32(modal->papdRateMaskHt20);
	modal->papdRateMaskHt40 = swap32(modal->papdRateMaskHt40);
	for (i = 0; i < AR9380_MAX_CHAINS; i++)
		modal->antCtrlChain[i] = swap16(modal->antCtrlChain[i]);

	modal = &eep->modalHeader5G;
	modal->antCtrlCommon = swap32(modal->antCtrlCommon);
	modal->antCtrlCommon2 = swap32(modal->antCtrlCommon2);
	modal->papdRateMaskHt20 = swap32(modal->papdRateMaskHt20);
	modal->papdRateMaskHt40 = swap32(modal->papdRateMaskHt40);
	for (i = 0; i < AR9380_MAX_CHAINS; i++)
		modal->antCtrlChain[i] = swap16(modal->antCtrlChain[i]);
#endif
}
Exemple #4
0
static void
swap_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);
}
Exemple #5
0
/* 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;
}
Exemple #6
0
bool 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;
}
Exemple #7
0
void 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);
}
Exemple #8
0
bool 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;
}
Exemple #9
0
static u32
swap32 (u32 value)
{
	u16 l, h;

	conv32to16 (value, &l, &h);
	conv16to32 (swap16 (h), swap16 (l), &value);
	return value;
}
Exemple #10
0
/*
 * reimplement pcap_open_offline with privsep, this is the
 * unprivileged part.
 * XXX merge with above?
 */
static void
swap_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);
}
Exemple #11
0
//----------------------------------------------------------------------
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
}
Exemple #12
0
 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.");
 }
char *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;
}
Exemple #14
0
static 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);
}
Exemple #15
0
static 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);
}
Exemple #16
0
//----------------------------------------------------------------------
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
}
Exemple #17
0
}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)
Exemple #18
0
}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)
Exemple #19
0
Psmf::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;
		}
	}
}
Exemple #20
0
}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*/
Exemple #21
0
FXbool InputPlugin::read_int16_be(FXshort & value) {
  if (read(&value,2)==2) {
    value = swap16(value);
    return true;
    }
  return false;
  }
//-------------------------------------------------------------------------
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);
}
Exemple #23
0
long 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);
}
Exemple #24
0
}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)
Exemple #25
0
/* 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;
}
void PortableFile::write16(uint16 value)
{
    if (system_big_endian != big_endian_) {
        value = swap16(value);
    }
    f_.write((const char *)&value, 2);
}
Exemple #27
0
}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)
Exemple #28
0
}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)
Exemple #29
0
void 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);
}
int 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;
}