Beispiel #1
0
int
openwavdest (char *filename, long bcount)
/* returns 0: failure (error_window has NOT been displayed), 1: success.
   bcount must be 4 * number_of_samples !
   Adapted from bplay.c
 */
{
  wavhead header;
  char *riff = "RIFF";
  char *wave = "WAVE";
  char *fmt = "fmt ";
  char *data = "data";

  if (*filename == '|')
    {
      destfileispipe = 1;	/* remember for closing */
      if ((destfile = popen (filename + 1, "w")) == NULL)
	return 0;
    }
  else
    {
      destfileispipe = 0;
      if ((destfile = fopen (filename, "wb")) == NULL)
	return 0;
    }


  memcpy (&(header.main_chunk), riff, 4);
  header.length = sizeof (wavhead) - 8 + bcount;
  memcpy (&(header.chunk_type), wave, 4);

  memcpy (&(header.sub_chunk), fmt, 4);
  header.sc_len = 16;
  header.format = 1;
  header.modus = /*stereo */ 1 + 1;
  header.sample_fq = /*speed */ 44100;
  header.byte_p_sec = /*((bits > 8)? 2:1)*(stereo+1)*speed */ 2 * 2 * 44100;
  header.byte_p_spl = /*(bits > 8)? 2:1 */ 4;	/* stereo & 16 bit..? */
  header.bit_p_spl = /*bits */ 16;	/* stereo doesn't count here? */

  memcpy (&(header.data_chunk), data, 4);
  header.data_length = bcount;

#ifdef SWAP_ENDIAN
  header.length = SwapFourBytes (header.length);
  header.sc_len = SwapFourBytes (header.sc_len);
  header.format = SwapTwoBytes (header.format);
  header.modus = SwapTwoBytes (header.modus);
  header.sample_fq = SwapFourBytes (header.sample_fq);
  header.byte_p_sec = SwapFourBytes (header.byte_p_sec);
  header.byte_p_spl = SwapTwoBytes (header.byte_p_spl);
  header.bit_p_spl = SwapTwoBytes (header.bit_p_spl);
  header.data_length = SwapFourBytes (header.data_length);
#endif

  fwrite (&header, sizeof (header), 1, destfile);

  num_write_samples_buffered = 0;  /* just in case */
  return 1;
}
Beispiel #2
0
WORD tenc_decode_int (BYTE *src)
{
	WORD value = *((WORD *) src);
	#if defined (TVM_BIG_ENDIAN)
	return value;
	#elif TVM_WORD_LENGTH == 4
	return SwapFourBytes (value);
	#elif TVM_WORD_LENGTH == 2
	return SwapTwoBytes (value);
	#else
	#error "Unknown TVM_WORD_LENGTH"
	#endif
}
Beispiel #3
0
int
openwavsource (char *filename)
/* returns 0: failure (error_window has been displayed), 1: success.
   More or less adapted from bplay.c, with stdio-patch by Axel Kohlmeyer
 */
{
  int count;
  char hd_buf[20];
  wavhead wavhd;

  if ((sourcefile = fopen (filename, "rb")) == NULL)
    {
      fprintf (stderr, "The source wav file [%s] could not be opened.\n", filename);
      return 0;
    }

  count = fread (hd_buf, 1, 20, sourcefile);
  if (count < 20)
    {
      fclose (sourcefile);
      fprintf (stderr, "The source file [%s] could not be read, or is too short.\n", filename);
      return 0;
    }

  if (strstr (hd_buf, "RIFF") == NULL)
    {
      fclose (sourcefile);
      fprintf (stderr, "The source file [%s] is not a .wav file, and can not be processed.\n", filename);
      return 0;
    }

  memcpy ((void *) &wavhd, (void *) hd_buf, 20);
  count = fread (((char *) &wavhd) + 20, 1, sizeof (wavhd) - 20, sourcefile);

  if (count < sizeof (wavhd) - 20)
    {
      fclose (sourcefile);
      fprintf (stderr, "The source file [%s]is too short. Probably it is not a .wav sound file.\n", filename);
      return 0;
    }

#ifdef SWAP_ENDIAN
  wavhd.format = SwapTwoBytes (wavhd.format);
  wavhd.sample_fq = SwapFourBytes (wavhd.sample_fq);
  wavhd.bit_p_spl = SwapTwoBytes (wavhd.bit_p_spl);
  wavhd.modus = SwapTwoBytes (wavhd.modus);
#endif

  if (wavhd.format != 1)
    {
      fclose (sourcefile);
      fprintf (stderr, "The source file [%s] is a .wav file with unknown format, and can not be processed.\n", filename);
      return 0;
    }

  if (wavhd.sample_fq != 44100)
    {
      fclose (sourcefile);
      fprintf (stderr, "The source file [%s] is not sampled at 44100 Hz, and can not be processed.\n", filename);
      return 0;
    }

  if (wavhd.bit_p_spl != 16)
    {
      fclose (sourcefile);
      fprintf (stderr, "The source file [%s] does not have 16 bit samples, and can not be processed.", filename);
      return 0;
    }

  if (wavhd.modus != 2)
    {
      fclose (sourcefile);
      fprintf (stderr, "The source file [%s] is not stereo, and can not be processed.", filename);
      return 0;
    }

  /* Well, everything seems to be OK */
  num_read_samples_buffered = 0;
  return 1;
}
Beispiel #4
0
/*{{{  TEncode functions based on those in tencode.c */
static UWORD avr_tenc_decode_int (const prog_char *src) {
    return SwapTwoBytes (pgm_read_word ((const prog_int16_t *) src));
}