spchksum.c

来自「speech signal process tools」· C语言 代码 · 共 86 行

C
86
字号
/* File: sp_compute_short_checksum.c, Updated 10/31/91.This function for computing a speech waveform checksum was adaptedfrom a function contributed by Mike Phillips at M.I.T.  It differsfrom his function in that it computes an unsigned (vs. signed) integerchecksum.  It takes as arguments a pointer to an array of shortscontaining the waveform samples (wav) and the number of shorts/samplesin the array (len).  Please note that it works on 16-bit data ONLY andit is not guaranteed to work on machines with less than 32-bit longs *//*Modified by Charles Hemphill at TI to provide a better functionalinterface and increased portability.*//* Modifications: Jon Fiscus  June 20, 1993    This function did not take into account arrays which do not    have the same byte format orientation as the host machine.  If    the flag, swap_bytes is true, a byte swap is performed before the    sample is added to the checksum.*/#include <stddef.h>		/* for size_t */#include <stdio.h>#define SPHERE_LIBRARY_CODE#include <sp/sphere.h>SP_CHECKSUM sp_compute_short_checksum(short int *wav, size_t len,				      int do_swap){   unsigned short *p;  unsigned short *end;  unsigned long checksum;  short sample;  char *s_ptr, *p_ptr;  checksum = 0;  p = (unsigned short *) wav;  end = p + len;  if (! do_swap){      while (p < end) {	  checksum = (checksum + (*p++)) & 0xffff;      }  } else {      s_ptr = (char *)&sample;      p_ptr = (char *)p;      while (p_ptr < (char *)end) {	  *s_ptr = *(p_ptr+1);	  *(s_ptr+1) = *p_ptr;	  checksum = (checksum + sample) & 0xffff;	  p_ptr += 2;      }  }  return (SP_CHECKSUM) checksum;}SP_CHECKSUM sp_compute_char_checksum(char *wav, size_t len){   unsigned char *p;  unsigned char *end;  unsigned long checksum;  checksum = 0;  p = (unsigned char *) wav;  end = p + len;  while (p < end)       checksum = (checksum + (*p++)) & 0xffff;    return (SP_CHECKSUM) checksum;}SP_CHECKSUM sp_add_checksum(SP_CHECKSUM csum1, SP_CHECKSUM csum2){    long checksum;    checksum = (csum1 + csum2) & 0xffff;    return((SP_CHECKSUM) checksum);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?