Esempio n. 1
0
static int rec_get_length(const char *file, int *length){
	wave_header_t header;
	int fd=open(file,O_RDONLY|O_BINARY);
	int ret=ms_read_wav_header_from_fd(&header,fd);
	close(fd);
	if (ret>0){
		*length=le_uint32(header.data_chunk.len);
	}else{
		*length=0;
	}
	return ret;
}
Esempio n. 2
0
static void write_wav_header(int fd, int rate, int nchannels, int size){
	wave_header_t header;
	memcpy(&header.riff_chunk.riff,"RIFF",4);
	header.riff_chunk.len=le_uint32(size+32);
	memcpy(&header.riff_chunk.wave,"WAVE",4);

	memcpy(&header.format_chunk.fmt,"fmt ",4);
	header.format_chunk.len=le_uint32(0x10);
	header.format_chunk.type=le_uint16(0x1);
	header.format_chunk.channel=le_uint16(nchannels);
	header.format_chunk.rate=le_uint32(rate);
	header.format_chunk.bps=le_uint32(rate*2*nchannels);
	header.format_chunk.blockalign=le_uint16(2*nchannels);
	header.format_chunk.bitpspl=le_uint16(16);

	memcpy(&header.data_chunk.data,"data",4);
	header.data_chunk.len=le_uint32(size);
	lseek(fd,0,SEEK_SET);
	if (write(fd,&header,sizeof(header))!=sizeof(header)){
		ms_warning("Fail to write wav header.");
	}
}
Esempio n. 3
0
static void write_wav_header(int rate,int size, char *filename){
	wave_header_t header;
	DWORD bytes_written=0;
	HANDLE fd;
	memcpy(&header.riff_chunk.riff,"RIFF",4);
	header.riff_chunk.len=le_uint32(size+32);
	memcpy(&header.riff_chunk.wave,"WAVE",4);

	memcpy(&header.format_chunk.fmt,"fmt ",4);
	header.format_chunk.len=le_uint32(0x10);
	header.format_chunk.type=le_uint16(0x1);
	header.format_chunk.channel=le_uint16(0x1);
	header.format_chunk.rate=le_uint32(rate);
	header.format_chunk.bps=le_uint32(rate*2);
	header.format_chunk.blockalign=le_uint16(2);
	header.format_chunk.bitpspl=le_uint16(16);

	memcpy(&header.data_chunk.data,"data",4);
	header.data_chunk.len=le_uint32(size);

	/* TODO: replace with "lseek" equivalent for windows */
	fd=CreateFile(filename, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
	if (fd==INVALID_HANDLE_VALUE){
#if !defined(_WIN32_WCE)
		ms_warning("Cannot open %s: %s",filename,strerror(errno));
#else
		ms_warning("Cannot open %s: %i",filename,WSAGetLastError());
#endif
		return;
	}
	WriteFile(fd,&header,sizeof(header), &bytes_written, NULL);
	if (bytes_written!=sizeof(header)){
		ms_warning("Fail to write wav header.");
	}
	CloseHandle(fd);
}
Esempio n. 4
0
static int read_wav_header(PlayerData *d){
	char header1[sizeof(riff_t)];
	char header2[sizeof(format_t)];
	char header3[sizeof(data_t)];
	int count;
	
	riff_t *riff_chunk=(riff_t*)header1;
	format_t *format_chunk=(format_t*)header2;
	data_t *data_chunk=(data_t*)header3;
	
	unsigned long len=0;
	
	len = read(d->fd, header1, sizeof(header1)) ;
	if (len != sizeof(header1)){
		goto not_a_wav;
	}
	
	if (0!=strncmp(riff_chunk->riff, "RIFF", 4) || 0!=strncmp(riff_chunk->wave, "WAVE", 4)){	
		goto not_a_wav;
	}
	
	len = read(d->fd, header2, sizeof(header2)) ;            
	if (len != sizeof(header2)){
		ms_warning("Wrong wav header: cannot read file");
		goto not_a_wav;
	}
	
	d->rate=le_uint32(format_chunk->rate);
	d->nchannels=le_uint16(format_chunk->channel);
	
	if (format_chunk->len-0x10>0)
	{
		lseek(d->fd,(format_chunk->len-0x10),SEEK_CUR);
	}
	
	d->hsize=sizeof(wave_header_t)-0x10+format_chunk->len;
	
	len = read(d->fd, header3, sizeof(header3)) ;
	if (len != sizeof(header3)){
		ms_warning("Wrong wav header: cannot read file");
		goto not_a_wav;
	}
	count=0;
	while (strncmp(data_chunk->data, "data", 4)!=0 && count<30)
	{
		ms_warning("skipping chunk=%s len=%i", data_chunk->data, data_chunk->len);
		lseek(d->fd,data_chunk->len,SEEK_CUR);
		count++;
		d->hsize=d->hsize+len+data_chunk->len;
	
		len = read(d->fd, header3, sizeof(header3)) ;
		if (len != sizeof(header3)){
			ms_warning("Wrong wav header: cannot read file");
			goto not_a_wav;
		}
	}
	#ifdef WORDS_BIGENDIAN
	if (le_uint16(format_chunk->blockalign)==le_uint16(format_chunk->channel) * 2)
		d->swap=TRUE;
	#endif
	return 0;

	not_a_wav:
		/*rewind*/
		lseek(d->fd,0,SEEK_SET);
		d->hsize=0;
		return -1;
}
Esempio n. 5
0
int main (int argc, char *argv[])
{
    FILE *fp;
    uint32_t blocks = 0;

	fp = fopen(argv[1], "rb");
	if (!fp) {
		perror(argv[1]);
        return -1;
	}

    struct stat sb;
    int ret = stat(argv[1], &sb);
    if (!fp || ret) {
        perror(argv[1]);
        return -1;
    }
    blocks = sb.st_size / RK_BLK_SIZE;
    if (sb.st_size % RK_BLK_SIZE) {
        printf("size should align %d", RK_BLK_SIZE);
        return -1;
    }

    printf("totle blocks:0x%08x\n", blocks);

    uint32_t buf_size = CONFIG_FASTBOOT_TRANSFER_BUFFER_SIZE_EACH;
    void* buf = malloc(buf_size);
    uint16_t buf_blocks = buf_size / RK_BLK_SIZE;
    uint32_t offset = 0;
#ifndef CONFIG_QUICK_CHECKSUM
    uint32_t* crc_array = (uint32_t*) malloc(buf_size);
    uint16_t crc_counts = 0;
	uint32_t checksum = 0;
#else
    uint64_t checksum = 0;
#endif
    while (blocks > 0) {
        uint16_t read_blocks = blocks > buf_blocks? buf_blocks : blocks;

        if (fread(buf, read_blocks * RK_BLK_SIZE, 1, fp) != 1) {
            printf("read failed, offset:0x%08x, blocks:0x%08x\n",
                    offset, read_blocks);
            return -1;
        }
        offset += read_blocks;
        blocks -= read_blocks;
#ifndef CONFIG_QUICK_CHECKSUM
        crc_array[crc_counts] = crc32(0, buf, read_blocks * RK_BLK_SIZE);
        printf("offset:0x%08x, blocks:0x%08x, crc:0x%08lx\n",
                offset, read_blocks, crc_array[crc_counts]);
        crc_counts++;
#else
        int i = 0;
        uint32_t* data = (uint32_t*) buf;
        for (i = 0;i < read_blocks * RK_BLK_SIZE >> 2;i++)
            checksum += le_uint32(data[i]);
        printf("offset:0x%08x, blocks:0x%08x, checksum:0x%016llx\n",
                offset, read_blocks, checksum);
#endif
    }

#ifndef CONFIG_QUICK_CHECKSUM
    //3:compute whole checksum
    checksum = (crc_counts == 1)? crc_array[0] :
        crc32(0, (unsigned char*)crc_array, sizeof(uint32_t) * crc_counts);
    printf("whole checksum:0x%08lx\n", checksum);
    free(crc_array);
#else
    printf("whole checksum:0x%016llx\n", checksum);
#endif
    free(buf);

    fclose (fp);
    return 0;
}
Esempio n. 6
0
int main (int argc, char *argv[])
{
    FILE *out, *fp;
    int offset = 0;
    int size = 0;
    int level = 0;
#define LEVEL_OPT "-level="

    char buf[RK_BLK_SIZE];
    int i = 0, j = 0;
    bmp_image_header_t header;
    header.tag = le_uint32(BMP_IMAGE_TAG);

    if (argc < 2) {
		usage(argv[0]);
        return -1;
	}

	out = fopen(argv[1], "wb+");
	if (!out) {
		perror(argv[1]);
        return -1;
	}

    printf("/*\n"
    " * Automatically generated by \"tools/bmp_image\"\n"
    " *\n"
    " * DO NOT EDIT\n"
    " *\n"
    " */\n\n\n"
    "#ifndef __BMP_IMAGE_DATA_H__\n"
    "#define __BMP_IMAGE_DATA_H__\n\n"
    "#include <bmp_image.h>\n\n"
    "bmp_image_t bmp_images[] = \n{\n");


    argc -= 2;
    argv += 2;
    for (i = 0;i < argc;i++) {
        if (!memcmp(LEVEL_OPT, argv[i], strlen(LEVEL_OPT))) {
            level = atoi(argv[i] + strlen(LEVEL_OPT));
            continue;
        }
        fp = fopen(argv[i], "rb+");
        struct stat sb;
        int ret = stat(argv[i], &sb);
        if (!fp || ret) {
            perror(argv[i]);
            return -1;
        }
        //fseek(out, offset * RK_BLK_SIZE, SEEK_SET);

        size = sb.st_size / RK_BLK_SIZE + 2;

        memset(buf, 0, sizeof(buf));                                                                                               

        memcpy(buf, &header, sizeof(header));
        fwrite(buf, sizeof(buf), 1, out);

        for (j = 0;j < size - 1;j++) {
            memset(buf, 0, sizeof(buf));
            fread(buf, 1, sizeof(buf), fp);
            fwrite(buf, sizeof(buf), 1, out);
        }
        fclose(fp);

        //output index map:   index  offset size
        printf("    {\n"
        "        .offset = %d, //%s\n"
        "        .size   = %d,\n"
        "        .level  = %d,\n"
        "        .loaded = 0,\n"
        "    },\n", offset, argv[i], size, level);

        offset += size;
        fflush(out);
    }
    printf("};\n\n\n#endif //BMP_IMAGE_DATA_H__\n");

    fclose (out);
    return 0;
}
Esempio n. 7
0
static int read_wav_header(PlayerData *d){

  char header1[sizeof(riff_t)];
  char header2[sizeof(format_t)];
  char header3[sizeof(data_t)];
  int count;

  riff_t *riff_chunk=(riff_t*)header1;
	format_t *format_chunk=(format_t*)header2;
	data_t *data_chunk=(data_t*)header3;

  unsigned long len=0;
  BOOL res;
    
  res = ReadFile(d->fd, header1, sizeof(header1), &len, NULL) ;
  if (!res ||  len != sizeof(header1)){
		ms_warning("Wrong wav header: cannot read file");
		return -1;
	}
	
  if (0!=strncmp(riff_chunk->riff, "RIFF", 4) || 0!=strncmp(riff_chunk->wave, "WAVE", 4)){	
		ms_warning("Wrong wav header (not RIFF/WAV)");
		return -1;
	}

  res = ReadFile(d->fd, header2, sizeof(header2), &len, NULL) ;            
  if (!res ||  len != sizeof(header2)){
		ms_warning("Wrong wav header: cannot read file");
		return -1;
	}

  d->rate=le_uint32(format_chunk->rate);
	d->nchannels=le_uint16(format_chunk->channel);

  if (format_chunk->len-0x10>0)
  {
    SetFilePointer(d->fd, (format_chunk->len-0x10), NULL, FILE_CURRENT);
  }

  d->hsize=sizeof(wave_header_t)-0x10+format_chunk->len;

  res = ReadFile(d->fd, header3, sizeof(header3), &len, NULL) ;
  if (!res ||  len != sizeof(header3)){
		ms_warning("Wrong wav header: cannot read file");
		return -1;
	}
  count=0;
  while (strncmp(data_chunk->data, "data", 4)!=0 && count<30)
  {
    SetFilePointer(d->fd, data_chunk->len, NULL, FILE_CURRENT);
    count++;
    d->hsize=d->hsize+len+data_chunk->len;

    res = ReadFile(d->fd, header3, sizeof(header3), &len, NULL) ;
    if (!res ||  len != sizeof(header3)){
		  ms_warning("Wrong wav header: cannot read file");
		  return -1;
	  }
  }
#ifdef WORDS_BIGENDIAN
	d->swap=TRUE;
#endif
	return 0;
}