⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 headers.c

📁 音频信号的重采样程序,如44.1K的WAV转换成采样频率为48K的WAV.
💻 C
📖 第 1 页 / 共 5 页
字号:
			  comment_end = comment_start + chunksize - 5;			}		      else 			{			  if ((match_four_chars((unsigned char *)(hdrbuf + 8), I_SU7M)) ||			      (match_four_chars((unsigned char *)(hdrbuf + 8), I_SU7R)))			    {			      mus_print("this is an SU700 ssp file?");			      data_location = 512;			      chans = 1;			      /* actually SU7M and SU7R point to 2 chan data as separate chunks */			    }			}		    }		  else		    {		      if (match_four_chars((unsigned char *)hdrbuf, I_INST))			{			  base_note = hdrbuf[8];			  base_detune = hdrbuf[9];			  loop_modes[0] = mus_char_to_bshort((unsigned char *)(hdrbuf + 16));			  loop_starts[0] = mus_char_to_bshort((unsigned char *)(hdrbuf + 18));			  loop_ends[0] = mus_char_to_bshort((unsigned char *)(hdrbuf + 20));			  loop_modes[1] = mus_char_to_bshort((unsigned char *)(hdrbuf + 22));			  loop_starts[1] = mus_char_to_bshort((unsigned char *)(hdrbuf + 24));			  loop_ends[1] = mus_char_to_bshort((unsigned char *)(hdrbuf + 26));			  /* these are mark numbers */			}		      else			{			  if (match_four_chars((unsigned char *)hdrbuf, I_MARK))			    {			      int num_marks, m, moff, msize;			      /* unsigned short #marks, each mark: id pos name (pstring damn it) */			      num_marks = mus_char_to_ubshort((unsigned char *)(hdrbuf + 8));			      if (num_marks > markers)				{				  if (markers > 0)				    {				      if (marker_ids) FREE(marker_ids); 				      if (marker_positions) FREE(marker_positions);				    }				  markers = num_marks;				  marker_ids = (int *)CALLOC(markers, sizeof(int));				  marker_positions = (int *)CALLOC(markers, sizeof(int));				}			      moff = 10;			      for (m = 0; m < num_marks; m++)				{				  if (seek_and_read(chan, (unsigned char *)hdrbuf, offset + moff, 8) > 0)				    {				      msize = read_aiff_marker(m, (unsigned char *)hdrbuf);				      moff += msize;				    }				}			    }			}		    }		}	    }	}      chunkloc = (8 + chunksize);      if (chunksize & 1) chunkloc++; /* extra null appended to odd-length chunks */      if ((offset + chunkloc) >= update_form_size) happy = false;    }  if (!got_comm)    return(mus_error(MUS_HEADER_READ_FAILED, "%s: no COMM chunk", filename));  if (data_location == 0)    return(mus_error(MUS_HEADER_READ_FAILED, "%s: no SSND (data) chunk", filename));  if (data_size > true_file_length)    {      data_size = true_file_length - data_location;      if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = " OFF_TD "?", filename, data_size));    }  if ((data_size > ssnd_bytes) && (data_format != MUS_UNKNOWN))    data_size = ssnd_bytes;  data_size = mus_bytes_to_samples(data_format, data_size);  return(MUS_NO_ERROR);}static int sndlib_format_to_aiff_bits(int format){  switch (format)    {    case MUS_BSHORT: case MUS_LSHORT: case MUS_UBSHORT: case MUS_ULSHORT:  return(16); break;    case MUS_B24INT: case MUS_L24INT:                                      return(24); break;    case MUS_BINT: case MUS_LINT: case MUS_BFLOAT: case MUS_LFLOAT:        return(32); break;    case MUS_BDOUBLE: case MUS_LDOUBLE:                                    return(64); break;    case MUS_BYTE: case MUS_UBYTE: case MUS_MULAW: case MUS_ALAW:          return(8);  break;    default:       return(mus_error(MUS_UNSUPPORTED_DATA_FORMAT, "aiff header: can't write data format: %d (%s)",		       format,		       any_data_format_name(format)));      break;    }}static const char *sndlib_format_to_aifc_name(int format){  switch (format)    {    case MUS_BSHORT: case MUS_B24INT: case MUS_BINT: case MUS_BYTE: return((const char *)I_NONE); break; /* use in24 and in32? */    case MUS_LSHORT: case MUS_L24INT: case MUS_LINT:                return((const char *)I_sowt); break; /* should this use ni23? */    case MUS_BFLOAT:                                                return((const char *)I_fl32); break;    case MUS_BDOUBLE:                                               return((const char *)I_fl64); break;    case MUS_UBYTE: case MUS_UBSHORT:                               return((const char *)I_raw_); break;    case MUS_MULAW:                                                 return((const char *)I_ulaw); break;    case MUS_ALAW:                                                  return((const char *)I_alaw); break;    default:                                                        return((const char *)I_NONE); break;    }}static int write_aif_header(int chan, int wsrate, int wchans, int siz, int format, const char *comment, int len, bool aifc_header){  /* we write the simplest possible AIFC header: AIFC | COMM | APPL-MUS_ if needed | SSND eof. */  /* the assumption being that we're going to be appending sound data once the header is out   */  /* INST and MARK chunks added Jul-95 for various programs that expect them (MixView).        */  int i, j, lenhdr, lenloop, curend, extra; /* set aifc to 0 to get old-style AIFF header */  char *str;  lenhdr = 0;  extra = 0;  curend = 0;  lenloop = 38;  if ((loop_modes[0] != 0) || (loop_modes[1] != 0)) lenloop = 42 + 28;  if (len != 0)     {      lenhdr = 12;      if ((len % 4) != 0)	extra = (4 - (len % 4));    }  write_four_chars((unsigned char *)hdrbuf, I_FORM);  if (aifc_header)     mus_bint_to_char((unsigned char *)(hdrbuf + 4), len + 30 + 16 + lenloop + siz + lenhdr + extra + 12 + 10);  else mus_bint_to_char((unsigned char *)(hdrbuf + 4), len + 30 + 16 + lenloop + siz + lenhdr + extra);  /*    * comment length + 4 for AIFF 18+8 for I_COMM info + 16 for I_SSND info + 38 for INST and MARK +   * siz for data + 12 for comment header if any + padding == total size - 8 (i.e. FORM header).      * INST+MARK (38) added 3-Jul-95 for Notam software compatibility    */  if (aifc_header)     {      write_four_chars((unsigned char *)(hdrbuf + 8), I_AIFC);       CHK_WRITE(chan, hdrbuf, 12);      curend = 12;      write_four_chars((unsigned char *)hdrbuf, I_FVER);      mus_bint_to_char((unsigned char *)(hdrbuf + 4), 4);      mus_bint_to_char((unsigned char *)(hdrbuf + 8), 0xA2805140);    }  else write_four_chars((unsigned char *)(hdrbuf + 8), I_AIFF);  write_four_chars((unsigned char *)(hdrbuf + 12), I_COMM);  if (aifc_header)     mus_bint_to_char((unsigned char *)(hdrbuf + 16), 18 + 10);   else mus_bint_to_char((unsigned char *)(hdrbuf + 16), 18);  mus_bshort_to_char((unsigned char *)(hdrbuf + 20), (short)wchans);  if (wchans > 0)    mus_bint_to_char((unsigned char *)(hdrbuf + 22), siz / (wchans * mus_bytes_per_sample(format)));  mus_bshort_to_char((unsigned char *)(hdrbuf + 26), sndlib_format_to_aiff_bits(format));  double_to_ieee_80((double)wsrate, (unsigned char *)(hdrbuf + 28));  if (aifc_header)    {      str = (char *)sndlib_format_to_aifc_name(format);      write_four_chars((unsigned char *)(hdrbuf + 38), (const unsigned char *)str);      (*(unsigned char *)(hdrbuf + 42)) = 4; /* final pad null not accounted-for */      write_four_chars((unsigned char *)(hdrbuf + 43), (const unsigned char *)str);      (*(unsigned char *)(hdrbuf + 47)) = 0;      i = 48;    }  else i = 38;  if (len != 0)    {      if (aifc_header)	{	  write_four_chars((unsigned char *)(hdrbuf + 48), I_APPL);	  mus_bint_to_char((unsigned char *)(hdrbuf + 52), len + 4 + extra);	  write_four_chars((unsigned char *)(hdrbuf + 56), I_MUS_);	  i = 60;	}      else	{	  write_four_chars((unsigned char *)(hdrbuf + 38), I_APPL);	  mus_bint_to_char((unsigned char *)(hdrbuf + 42), len + 4 + extra);	  write_four_chars((unsigned char *)(hdrbuf + 46), I_MUS_);	  i = 50;	}      for (j = 0; j < len; j++)	{	  if (i == HDRBUFSIZ)	    {	      curend += HDRBUFSIZ;	      CHK_WRITE(chan, hdrbuf, HDRBUFSIZ);	      i = 0;	    }	  hdrbuf[i] = comment[j];	  i++;	}      if (extra != 0)	{	  if ((i + extra) > HDRBUFSIZ)	    {	      curend += i;	      CHK_WRITE(chan, hdrbuf, i);	      i = 0;	    }	  for (j = 0; j < extra; j++)	    {	      hdrbuf[i] = 0;	      i++;	    }	}    }  curend += i;  CHK_WRITE(chan, hdrbuf, i);  if ((loop_modes[0] == 0) && (loop_modes[1] == 0))    {      write_four_chars((unsigned char *)hdrbuf, I_MARK);   /* SoundHack includes a blank MARK chunk for some reason */      mus_bint_to_char((unsigned char *)(hdrbuf + 4), 2);      mus_bshort_to_char((unsigned char *)(hdrbuf + 8), 0);      write_four_chars((unsigned char *)(hdrbuf + 10), I_INST);      mus_bint_to_char((unsigned char *)(hdrbuf + 14), 20);      mus_bint_to_char((unsigned char *)(hdrbuf + 18), 0x3c00007f); /* base-note = middle C, detune = 0, lownote = 0, highnote = 0x7f */      mus_bint_to_char((unsigned char *)(hdrbuf + 22), 0x017f0000); /* lowvelocity = 1, highvelocity = 0x7f, gain = 0 */      mus_bint_to_char((unsigned char *)(hdrbuf + 26), 0);          /* no loops */      mus_bint_to_char((unsigned char *)(hdrbuf + 30), 0);       mus_bint_to_char((unsigned char *)(hdrbuf + 34), 0);      CHK_WRITE(chan, hdrbuf, 38);      curend += 38;    }  else    {      write_four_chars((unsigned char *)hdrbuf, I_MARK);       mus_bint_to_char((unsigned char *)(hdrbuf + 4), 8 * 4 + 2); /* 2 for mark#, then 2:id + 4:pos + 2:pstr */      /* loop_info: 0..3 are markers positions (ids 1..4) */      mus_bshort_to_char((unsigned char *)(hdrbuf + 8), 4);      for (j = 0; j < 4; j++)	{	  mus_bshort_to_char((unsigned char *)(hdrbuf + 10 + 8 * j), j + 1);	  switch (j)	    {	    case 0: mus_bint_to_char((unsigned char *)(hdrbuf + 10 + 8 * j + 2), loop_starts[0]); break;	    case 1: mus_bint_to_char((unsigned char *)(hdrbuf + 10 + 8 * j + 2), loop_ends[0]);   break;	    case 2: mus_bint_to_char((unsigned char *)(hdrbuf + 10 + 8 * j + 2), loop_starts[1]); break;	    case 3: mus_bint_to_char((unsigned char *)(hdrbuf + 10 + 8 * j + 2), loop_ends[1]);   break;	    }	  mus_bshort_to_char((unsigned char *)(hdrbuf + 10 + 8 * j + 6), 0);	}      CHK_WRITE(chan, hdrbuf, 42);      curend += 42;      write_four_chars((unsigned char *)hdrbuf, I_INST);       mus_bint_to_char((unsigned char *)(hdrbuf + 4), 20);      mus_bint_to_char((unsigned char *)(hdrbuf + 8), 0x3c00007f);      mus_bint_to_char((unsigned char *)(hdrbuf + 12), 0x017f0000);      hdrbuf[8] = (unsigned char)(base_note);      hdrbuf[9] = (unsigned char)(base_detune);      mus_bshort_to_char((unsigned char *)(hdrbuf + 16), loop_modes[0]);      mus_bshort_to_char((unsigned char *)(hdrbuf + 18), 1);      mus_bshort_to_char((unsigned char *)(hdrbuf + 20), 2);      mus_bshort_to_char((unsigned char *)(hdrbuf + 22), loop_modes[1]);      mus_bshort_to_char((unsigned char *)(hdrbuf + 24), 3);      mus_bshort_to_char((unsigned char *)(hdrbuf + 26), 4);      CHK_WRITE(chan, hdrbuf, 28);      curend += 28;    }  write_four_chars((unsigned char *)(hdrbuf), I_SSND);  mus_bint_to_char((unsigned char *)(hdrbuf + 4), siz + 8);  mus_bint_to_char((unsigned char *)(hdrbuf + 8), 0);                        /* "offset" */  mus_bint_to_char((unsigned char *)(hdrbuf + 12), 0);                       /* "blocksize " */  CHK_WRITE(chan, hdrbuf, 16);  data_location = 16 + curend;  return(MUS_NO_ERROR);}char *mus_header_aiff_aux_comment(const char *name, off_t *starts, off_t *ends){  /* AIFC: look for aux comments (ANNO chunk

⌨️ 快捷键说明

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