コード例 #1
0
ファイル: mveplay.c プロジェクト: paud/d2x-xl
static int audio_data_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context)
{
#ifdef AUDIO
	static const int selected_chan=1;
	int chan;
	int nsamp;
	if (mve_audio_canplay)
	{
		if (mve_audio_playing)
			SDL_LockAudio();

		chan = get_ushort(data + 2);
		nsamp = get_ushort(data + 4);
		if (chan & selected_chan)
		{
			/* HACK: +4 mveaudio_uncompress adds 4 more bytes */
			if (major == MVE_OPCODE_AUDIOFRAMEDATA) {
				if (mve_audio_compressed) {
					nsamp += 4;

					mve_audio_buflens[mve_audio_buftail] = nsamp;
					mve_audio_buffers[mve_audio_buftail] = (short *)mve_alloc(nsamp);
					mveaudio_uncompress(mve_audio_buffers[mve_audio_buftail], data, -1); /* XXX */
				} else {
					nsamp -= 8;
					data += 8;

					mve_audio_buflens[mve_audio_buftail] = nsamp;
					mve_audio_buffers[mve_audio_buftail] = (short *)mve_alloc(nsamp);
					memcpy(mve_audio_buffers[mve_audio_buftail], data, nsamp);
				}
			} else {
				mve_audio_buflens[mve_audio_buftail] = nsamp;
				mve_audio_buffers[mve_audio_buftail] = (short *)mve_alloc(nsamp);

				memset(mve_audio_buffers[mve_audio_buftail], 0, nsamp); /* XXX */
			}

			if (++mve_audio_buftail == TOTAL_AUDIO_BUFFERS)
				mve_audio_buftail = 0;

#ifndef WIN32
			if (mve_audio_buftail == mve_audio_bufhead)
				fprintf(stderr, "d'oh!  buffer ring overrun (%d)\n", mve_audio_bufhead);
#endif
		}

		if (mve_audio_playing)
			SDL_UnlockAudio();
	}
#endif

	return 1;
}
コード例 #2
0
ファイル: mveplay.c プロジェクト: jihnsius/d2r
static int video_data_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context)
{
	unsigned short nFlags;
	unsigned char *temp;

// don't need those but kept for further reference
// 	nFrameHot  = get_short(data);
// 	nFrameCold = get_short(data+2);
// 	nXoffset   = get_short(data+4);
// 	nYoffset   = get_short(data+6);
// 	nXsize     = get_short(data+8);
// 	nYsize     = get_short(data+10);
	nFlags     = get_ushort(data+12);

	if (nFlags & 1)
	{
		temp = (unsigned char *)g_vBackBuf1;
		g_vBackBuf1 = g_vBackBuf2;
		g_vBackBuf2 = temp;
	}

	/* convert the frame */
	if (g_truecolor) {
		decodeFrame16((unsigned char *)g_vBackBuf1, g_pCurMap, g_nMapLength, data+14, len-14);
	} else {
		decodeFrame8(g_vBackBuf1, g_pCurMap, g_nMapLength, data+14, len-14);
	}

	return 1;
}
コード例 #3
0
ファイル: uunfli.c プロジェクト: pseudotensor/harm_utilities
static int process_frame(unsigned char *pwork, int nchunks, int verbose)
{
  unsigned char *pmchunk;
  unsigned long chunk_size;
  int i, chunk_type;

  for (i=0; i< nchunks; i++)
    {
      chunk_size = get_ulong(&pwork[0]);
      chunk_type = get_ushort(&pwork[4]);

      pmchunk = pwork + CHUNK_HEAD_SIZE;
      if (verbose)
	fprintf(stdout,"chunk %d of type 0x%X and size %ld\n",
		i,chunk_type,chunk_size);

      if (chunk_type == FLI_COLOR)
	{
	  table_colors(pmchunk, COLOR_FLAG_64);
	}
      else if (chunk_type == FLI_256_COLOR)
	{
	  table_colors(pmchunk, COLOR_FLAG_256);
	}
      else if (chunk_type == FLI_DELTA)
	{
	  buffer_delta_chunk(pmchunk, image_buffer, 
			     image_height, image_width);
	}
      else if (chunk_type == FLI_LC)
	{
	  buffer_lc_chunk(pmchunk, image_buffer,
			  image_height, image_width);
	}
      else if (chunk_type == FLI_BRUN)
	{
	  buffer_brun_chunk(pmchunk, image_buffer,
			    image_height, image_width);
	}
      else
	{
	  fprintf(stderr,"unknown chunk type 0x%X -- chunk ignored\n",
		  chunk_type);
	}
      pwork += chunk_size;
    }

  return(1);
}
コード例 #4
0
ファイル: flag_u.c プロジェクト: w0dm4n/ft_printf
int				flag_u(t_string *string, int i)
{
	if (!ft_strncmp(string->converter.type, "ll", 2))
		conv_ll(string, get_ulong_long_int(string));
	else if (!ft_strncmp(string->converter.type, "l", 1))
		conv_l(string, get_ulong_int(string));
	else if (!ft_strncmp(string->converter.type, "hh", 2))
		conv_hh(string, (unsigned char)get_uint(string));
	else if (!ft_strncmp(string->converter.type, "h", 1))
		conv_h(string, get_ushort(string));
	else if (!ft_strncmp(string->converter.type, "z", 1))
		conv_z(string, get_size_t(string));
	else if (!ft_strncmp(string->converter.type, "j", 1))
		conv_j(string, get_intmax_t(string));
	else
		conv_default(string, get_uint(string));
	return (i + 1);
}
コード例 #5
0
ファイル: value.c プロジェクト: xyzmst/scanmem
bool valtostr(const value_t * val, char *str, size_t n)
{
    char buf[128];
    int max_bytes = 0;
    bool print_as_unsigned = false;

#define FLAG_MACRO(bytes, string) (val->flags.u##bytes##b && val->flags.s##bytes##b) ? (string " ") : (val->flags.u##bytes##b) ? (string "u ") : (val->flags.s##bytes##b) ? (string "s ") : ""

    /* set the flags */
    snprintf(buf, sizeof(buf), "[%s%s%s%s%s%s%s]",
             FLAG_MACRO(64, "I64"),
             FLAG_MACRO(32, "I32"),
             FLAG_MACRO(16, "I16"),
             FLAG_MACRO(8,  "I8"),
             val->flags.f64b ? "F64 " : "",
             val->flags.f32b ? "F32 " : "",
             (val->flags.ineq_reverse && !val->flags.ineq_forwards) ? "(reversed inequality) " : "");

    if (val->flags.u64b) {
        max_bytes = 8;
        print_as_unsigned =  true;
    }
    else if (val->flags.s64b) {
        max_bytes = 8;
        print_as_unsigned = false;
    }
    else if (val->flags.u32b) {
        max_bytes = 4;
        print_as_unsigned =  true;
    }
    else if (val->flags.s32b) {
        max_bytes = 4;
        print_as_unsigned = false;
    }
    else if (val->flags.u16b) {
        max_bytes = 2;
        print_as_unsigned =  true;
    }
    else if (val->flags.s16b) {
        max_bytes = 2;
        print_as_unsigned = false;
    }
    else if (val->flags.u8b ) {
        max_bytes = 1;
        print_as_unsigned =  true;
    }
    else if (val->flags.s8b ) {
        max_bytes = 1;
        print_as_unsigned = false;
    }

    /* find the right format, considering different integer size implementations */
    if (max_bytes == sizeof(long long)) snprintf(str, n, print_as_unsigned ? "%llu, %s" : "%lld, %s", print_as_unsigned ? get_ulonglong(val) : get_slonglong(val), buf);
    else if (max_bytes == sizeof(long))      snprintf(str, n, print_as_unsigned ? "%lu, %s"  : "%ld, %s" , print_as_unsigned ? get_ulong(val) : get_slong(val), buf);
    else if (max_bytes == sizeof(int))       snprintf(str, n, print_as_unsigned ? "%u, %s"   : "%d, %s"  , print_as_unsigned ? get_uint(val) : get_sint(val), buf);
    else if (max_bytes == sizeof(short))     snprintf(str, n, print_as_unsigned ? "%hu, %s"  : "%hd, %s" , print_as_unsigned ? get_ushort(val) : get_sshort(val), buf);
    else if (max_bytes == sizeof(char))      snprintf(str, n, print_as_unsigned ? "%hhu, %s" : "%hhd, %s", print_as_unsigned ? get_uchar(val) : get_schar(val), buf);
    else if (val->flags.f64b) snprintf(str, n, "%lf, %s", get_f64b(val), buf);
    else if (val->flags.f32b) snprintf(str, n, "%f, %s", get_f32b(val), buf);
    else {
        snprintf(str, n, "%#llx?, %s", get_slonglong(val), buf);
        return false;
    }

    return true;
}
コード例 #6
0
ファイル: mveplay.c プロジェクト: gameplayer22/d2x-1
static int create_audiobuf_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context)
{
#ifdef AUDIO
	int flags;
	int sample_rate;
	int desired_buffer;

	int stereo;
	int bitsize;
	int compressed;

	int format;

	if (!mve_audio_enabled)
		return 1;

	if (audiobuf_created)
		return 1;
	else
		audiobuf_created = 1;

	flags = get_ushort(data + 2);
	sample_rate = get_ushort(data + 4);
	desired_buffer = get_int(data + 6);

	stereo = (flags & MVE_AUDIO_FLAGS_STEREO) ? 1 : 0;
	bitsize = (flags & MVE_AUDIO_FLAGS_16BIT) ? 1 : 0;

	if (minor > 0) {
		compressed = flags & MVE_AUDIO_FLAGS_COMPRESSED ? 1 : 0;
	} else {
		compressed = 0;
	}

	mve_audio_compressed = compressed;

	if (bitsize == 1) {
#ifdef WORDS_BIGENDIAN
		format = AUDIO_S16MSB;
#else
		format = AUDIO_S16LSB;
#endif
	} else {
		format = AUDIO_U8;
	}

	fprintf(stderr, "creating audio buffers:\n");
	fprintf(stderr, "sample rate = %d, stereo = %d, bitsize = %d, compressed = %d\n",
			sample_rate, stereo, bitsize ? 16 : 8, compressed);

	mve_audio_spec = (SDL_AudioSpec *)d_malloc(sizeof(SDL_AudioSpec));
	mve_audio_spec->freq = sample_rate;
	mve_audio_spec->format = format;
	mve_audio_spec->channels = (stereo) ? 2 : 1;
	mve_audio_spec->samples = 4096;
	mve_audio_spec->callback = mve_audio_callback;
	mve_audio_spec->userdata = NULL;
	if (SDL_OpenAudio(mve_audio_spec, NULL) >= 0)
	{
		fprintf(stderr, "   success\n");
		mve_audio_canplay = 1;
	}
	else
	{
		fprintf(stderr, "   failure : %s\n", SDL_GetError());
		mve_audio_canplay = 0;
	}

	memset(mve_audio_buffers, 0, sizeof(mve_audio_buffers));
	memset(mve_audio_buflens, 0, sizeof(mve_audio_buflens));
#endif

	return 1;
}
コード例 #7
0
ファイル: mveplay.c プロジェクト: jihnsius/d2r
static int audio_data_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context)
{

#ifdef USE_SDLMIXER
	// MD2211: for audio conversion
	SDL_AudioCVT cvt;
	int clen;
	int out_freq;
	Uint16 out_format;
	int out_channels;
	// end MD2211
#endif

	static const int selected_chan=1;
	int chan;
	int nsamp;
	if (mve_audio_canplay)
	{
		if (mve_audio_playing)
			SDL_LockAudio();

		chan = get_ushort(data + 2);
		nsamp = get_ushort(data + 4);
		if (chan & selected_chan)
		{
			/* HACK: +4 mveaudio_uncompress adds 4 more bytes */
			if (major == MVE_OPCODE_AUDIOFRAMEDATA) {
				if (mve_audio_compressed) {
					nsamp += 4;

					mve_audio_buflens[mve_audio_buftail] = nsamp;
					mve_audio_buffers[mve_audio_buftail] = (short *)mve_alloc(nsamp);
					mveaudio_uncompress(mve_audio_buffers[mve_audio_buftail], data, -1); /* XXX */
				} else {
					nsamp -= 8;
					data += 8;

					mve_audio_buflens[mve_audio_buftail] = nsamp;
					mve_audio_buffers[mve_audio_buftail] = (short *)mve_alloc(nsamp);
					memcpy(mve_audio_buffers[mve_audio_buftail], data, nsamp);
				}
			} else {
				mve_audio_buflens[mve_audio_buftail] = nsamp;
				mve_audio_buffers[mve_audio_buftail] = (short *)mve_alloc(nsamp);

				memset(mve_audio_buffers[mve_audio_buftail], 0, nsamp); /* XXX */
			}

			// MD2211: the following block does on-the-fly audio conversion for SDL_mixer
#ifdef USE_SDLMIXER
			if (!GameArg.SndDisableSdlMixer) {
				// build converter: in = MVE format, out = SDL_mixer output
				Mix_QuerySpec(&out_freq, &out_format, &out_channels); // get current output settings

				SDL_BuildAudioCVT(&cvt, mve_audio_spec->format, mve_audio_spec->channels, mve_audio_spec->freq,
					out_format, out_channels, out_freq);

				clen = nsamp * cvt.len_mult;
				cvt.buf = malloc(clen);
				cvt.len = nsamp;

				// read the audio buffer into the conversion buffer
				memcpy(cvt.buf, mve_audio_buffers[mve_audio_buftail], nsamp);

				// do the conversion
				if (SDL_ConvertAudio(&cvt)) con_printf(CON_DEBUG,"audio conversion failed!\n");

				// copy back to the audio buffer
				mve_free(mve_audio_buffers[mve_audio_buftail]); // free the old audio buffer
				mve_audio_buflens[mve_audio_buftail] = clen;
				mve_audio_buffers[mve_audio_buftail] = (short *)mve_alloc(clen);
				memcpy(mve_audio_buffers[mve_audio_buftail], cvt.buf, clen);
			}
#endif

			if (++mve_audio_buftail == TOTAL_AUDIO_BUFFERS)
				mve_audio_buftail = 0;

			if (mve_audio_buftail == mve_audio_bufhead)
				con_printf(CON_CRITICAL, "d'oh!  buffer ring overrun (%d)\n", mve_audio_bufhead);
		}

		if (mve_audio_playing)
			SDL_UnlockAudio();
	}

	return 1;
}
コード例 #8
0
ファイル: mveplay.c プロジェクト: jihnsius/d2r
static int create_audiobuf_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context)
{
	int flags;
	int sample_rate;
	int desired_buffer;

	int stereo;
	int bitsize;
	int compressed;

	int format;

	if (!mve_audio_enabled)
		return 1;

	if (audiobuf_created)
		return 1;
	else
		audiobuf_created = 1;

	flags = get_ushort(data + 2);
	sample_rate = get_ushort(data + 4);
	desired_buffer = get_int(data + 6);

	stereo = (flags & MVE_AUDIO_FLAGS_STEREO) ? 1 : 0;
	bitsize = (flags & MVE_AUDIO_FLAGS_16BIT) ? 1 : 0;

	if (minor > 0) {
		compressed = flags & MVE_AUDIO_FLAGS_COMPRESSED ? 1 : 0;
	} else {
		compressed = 0;
	}

	mve_audio_compressed = compressed;

	if (bitsize == 1) {
#ifdef WORDS_BIGENDIAN
		format = AUDIO_S16MSB;
#else
		format = AUDIO_S16LSB;
#endif
	} else {
		format = AUDIO_U8;
	}

#ifdef USE_SDLMIXER
	if (GameArg.SndDisableSdlMixer)
#endif
	{
		con_printf(CON_CRITICAL, "creating audio buffers:\n");
		con_printf(CON_CRITICAL, "sample rate = %d, desired buffer = %d, stereo = %d, bitsize = %d, compressed = %d\n",
				sample_rate, desired_buffer, stereo, bitsize ? 16 : 8, compressed);
	}

	mve_audio_spec = (SDL_AudioSpec *)mve_alloc(sizeof(SDL_AudioSpec));
	mve_audio_spec->freq = sample_rate;
	mve_audio_spec->format = format;
	mve_audio_spec->channels = (stereo) ? 2 : 1;
	mve_audio_spec->samples = 4096;
	mve_audio_spec->callback = mve_audio_callback;
	mve_audio_spec->userdata = NULL;

	// MD2211: if using SDL_Mixer, we never reinit the sound system
#ifdef USE_SDLMIXER
	if (GameArg.SndDisableSdlMixer)
#endif
	{
		if (SDL_OpenAudio(mve_audio_spec, NULL) >= 0) {
			con_printf(CON_CRITICAL, "   success\n");
			mve_audio_canplay = 1;
		}
		else {
			con_printf(CON_CRITICAL, "   failure : %s\n", SDL_GetError());
			mve_audio_canplay = 0;
		}
	}

#ifdef USE_SDLMIXER
	else {
		// MD2211: using the same old SDL audio callback as a postmixer in SDL_mixer
		Mix_SetPostMix(mve_audio_spec->callback, mve_audio_spec->userdata);
		mve_audio_canplay = 1;
	}
#endif

	memset(mve_audio_buffers, 0, sizeof(mve_audio_buffers));
	memset(mve_audio_buflens, 0, sizeof(mve_audio_buflens));

	return 1;
}
コード例 #9
0
ファイル: uunfli.c プロジェクト: pseudotensor/harm_utilities
int unfli
(
FILE *input, 
char *out_name_base, 
char *out_name_ext, 
int outtype,
int begin_frame, 
int max_frames,
int verbose,
int compress_flag
)
{
  unsigned char file_header[FILE_HEAD_SIZE];
  unsigned char frame_header[FRAME_HEAD_SIZE];
  unsigned char *frame_buffer;
  int buffer_len;
  int work_len;
  int file_len, file_type, frame_len, frame_type;
  int n, nframes;
  int last_frame, digits, help;
  int nchunks;

  if (fread(file_header, 1, FILE_HEAD_SIZE, input) != FILE_HEAD_SIZE)
    return(-1);

  file_len = get_ulong(&file_header[0]);
  if (verbose) fprintf(stdout,"Size of input file: %d\n", file_len);

  file_type = get_ushort(&file_header[4]);
  if (verbose) fprintf(stdout,"Type of input file: 0x%X\n", file_type);

  if (!((file_type == FLI_FILE_MAGIC) || (file_type == FLC_FILE_MAGIC)))
    {
      fprintf(stdout,"Unknown file type!\n");
      return(0);
    }

  nframes = get_ushort(&file_header[6]);
  image_width = get_ushort(&file_header[8]);
  image_height = get_ushort(&file_header[10]);
  if (verbose)
    {
      fprintf(stdout,"Number of frames: %d\n", nframes);
      fprintf(stdout,"Width:  %d\n", image_width);
      fprintf(stdout,"Height: %d\n", image_height);
    }

  buffer_len = image_width * image_height;

  frame_buffer = malloc(buffer_len);
  image_buffer = malloc(buffer_len);

  if ((frame_buffer == NULL) || (image_buffer == NULL))
    return(-2);

  memset(image_buffer, 0, buffer_len);
  memset(palette, 0, MAXCOLORS * 3);

  if (max_frames <= 0) max_frames = nframes;
  nframes++;

  if ((begin_frame < 1) || (begin_frame > nframes))
    {
      fprintf(stderr,"Begin frame-number %d out of range (1 .... %d)\n",
	      begin_frame, nframes);
      return(0);
    }

  last_frame = begin_frame + max_frames - 1;

  if (last_frame > nframes) last_frame = nframes;

  help = nframes;
  digits=0;
  while (help > 0)
    {
      help = (help - (help % 10))/10;
      digits++;
    }
  if (digits < 3) digits = 3;

  if (last_frame == begin_frame)
    fprintf(stdout,"Extracting frame %d\n",begin_frame);
  else
    fprintf(stdout,"Extracting frames from %d to %d\n",
	    begin_frame, last_frame);

  for (n = 1; n <= nframes; n++)
    {
      if (n > last_frame) break;

      if (fread(frame_header, 1, FRAME_HEAD_SIZE, input) != FRAME_HEAD_SIZE)
	return(-1);
      frame_len = get_ulong(&frame_header[0]);
      if (verbose)
	fprintf(stdout,"Frame %d  --  size: %d\n", n, frame_len);

      frame_type = get_ushort(&frame_header[4]);
      if (frame_type != FLI_FRAME_MAGIC)
	{
	  fprintf(stderr,"Invalid frame type: 0x%X\n", frame_type);
	  return(0);
	}

      work_len = frame_len - FRAME_HEAD_SIZE;
      if (work_len > 0)
	{
	  if (buffer_len < work_len)
	    {
	      free(frame_buffer);
	      buffer_len = work_len;
	      frame_buffer = malloc(buffer_len);
	      if (frame_buffer == NULL) return(-2);
	    }
      
	  if (fread(frame_buffer, 1, work_len, input) != work_len) return(-1);
	  nchunks = get_ushort(&frame_header[6]);
	  process_frame(frame_buffer, nchunks, verbose);
	}

      if (n >= begin_frame)
	{
	  if (!out_image(image_buffer,palette,image_width,image_height,
		       outtype,out_name_base,out_name_ext,digits,n,
		       compress_flag))
	    return(0);
	}
    }

  return(1);
}