home *** CD-ROM | disk | FTP | other *** search
/ Dream 44 / Amiga_Dream_44.iso / Linux / Apps / xanim.tgz / xanim / xanim27064 / xa_au.c < prev    next >
C/C++ Source or Header  |  1997-01-26  |  4KB  |  161 lines

  1.  
  2. /*
  3.  * xa_au.c
  4.  *
  5.  * Copyright (C) 1994,1995,1996,1997 by Mark Podlipec.
  6.  * All rights reserved.
  7.  *
  8.  * This software may be freely copied, modified and redistributed without
  9.  * fee for non-commerical purposes provided that this copyright notice is
  10.  * preserved intact on all copies and modified copies.
  11.  *
  12.  * There is no warranty or other guarantee of fitness of this software.
  13.  * It is provided solely "as is". The author(s) disclaim(s) all
  14.  * responsibility and liability with respect to this software's usage
  15.  * or its effect upon hardware or computer systems.
  16.  *
  17.  */
  18.  
  19. /* NOTE: This code is based on code from Sun */
  20.  
  21. /*
  22.  * Copyright 1991, 1992, 1993 Guido van Rossum And Sundry Contributors.
  23.  * This source code is freely redistributable and may be used for
  24.  * any purpose.  This copyright notice must be maintained.
  25.  * Guido van Rossum And Sundry Contributors are not responsible for
  26.  * the consequences of using this software.
  27.  */
  28.  
  29. /*******************************
  30.  * Revision
  31.  *
  32.  ********************************/
  33.  
  34.  
  35. #include "xanim.h"
  36.  
  37. #define AU_MAGIC 0x2e736e64
  38. #define AU_HSIZE 0x18
  39.  
  40. #define AU_ULAW        1
  41. #define AU_LIN_8       2
  42. #define AU_LIN_16      3
  43.  
  44. xaULONG AU_Read_File();
  45. xaULONG au_max_faud_size;
  46. extern void  AVI_Print_ID();
  47.  
  48. xaULONG au_format,au_chans;
  49. xaULONG au_freq,au_bits,au_bps;
  50. xaULONG au_snd_time,au_snd_timelo;
  51. xaULONG au_audio_type;
  52. xaULONG UTIL_Get_MSB_Long();
  53. xaULONG UTIL_Get_LSB_Long();
  54. xaULONG UTIL_Get_LSB_Short();
  55. xaULONG XA_Add_Sound();
  56.  
  57. xaULONG AU_Read_File(fname,anim_hdr,audio_attempt)
  58. char *fname;
  59. XA_ANIM_HDR *anim_hdr;
  60. xaULONG audio_attempt;    /* xaTRUE if audio is to be attempted */
  61. {
  62.   FILE *fin;
  63.   xaLONG tmp,au_hdr_size,au_data_size;
  64.  
  65.   if ( (fin=fopen(fname,XA_OPEN_MODE)) == 0)
  66.   {
  67.     fprintf(stderr,"can't open AVI File %s for reading\n",fname);
  68.     return(xaFALSE);
  69.   }
  70.  
  71.   au_max_faud_size = anim_hdr->max_faud_size;
  72.   au_format = 0;
  73.   au_chans  = 0;
  74.   au_freq   = 0;
  75.   au_bits   = 0;
  76.   au_bps    = 0;
  77.   au_audio_type = 0;
  78.   au_hdr_size = 0;
  79.   au_data_size = 0;
  80.  
  81.   au_snd_time = 0;
  82.   au_snd_timelo = 0;
  83.  
  84. /* Read Header */
  85.   tmp          = UTIL_Get_MSB_Long(fin);  /* magic */
  86.   au_hdr_size  = UTIL_Get_MSB_Long(fin);  /* size of header */
  87.   if (au_hdr_size < 0x18) return(xaFALSE); /* header too small */
  88.   au_data_size = UTIL_Get_MSB_Long(fin);  /* size of header */
  89.   if (au_data_size == 0xffffffff) /* unknown data size */
  90.   { int ret,fpos = ftell(fin);
  91.     ret = fseek(fin,0,2);
  92.     if (ret < 0) return(xaFALSE);
  93.     au_data_size = ftell(fin) - au_hdr_size;
  94.     ret = fseek(fin,fpos,0);
  95.     if (ret < 0) return(xaFALSE);
  96.   }
  97.   au_format = UTIL_Get_MSB_Long(fin);
  98.   au_freq   = UTIL_Get_MSB_Long(fin);
  99.   au_chans  = UTIL_Get_MSB_Long(fin);
  100.   switch(au_format)
  101.   {
  102.     case AU_ULAW:
  103.     au_bits = 8;
  104.     au_bps  = 1;
  105.     au_audio_type = XA_AUDIO_SUN_AU;
  106.     break;
  107.     case AU_LIN_8:
  108.     au_bits = 8;
  109.     au_bps  = 1;
  110.     au_audio_type = XA_AUDIO_LINEAR;
  111.     break;
  112.     case AU_LIN_16:
  113.     au_bits = 16;
  114.     au_bps  = 2;
  115.     au_audio_type = XA_AUDIO_LINEAR 
  116.                 | XA_AUDIO_BIGEND_MSK | XA_AUDIO_BPS_2_MSK;
  117.     break;
  118.     default:
  119.     fprintf(stderr,"AU: Sound Format %x not yet supported\n",
  120.                                 au_format);
  121.     return(xaFALSE);
  122.     break;
  123.   }
  124.   if ((au_chans < 1) || (au_chans > 2))
  125.   {
  126.     fprintf(stderr,"AU: Chans %d not supported.\n",au_chans);
  127.     return(xaFALSE);
  128.   }
  129.   else if (au_chans == 2) au_audio_type |= XA_AUDIO_STEREO_MSK;
  130.  
  131.   anim_hdr->total_time =  (xaULONG)
  132.     (((float)au_data_size * 1000.0)
  133.         / (float)(au_chans * au_bps) )
  134.         / (float)(au_freq);
  135.  
  136.   fseek(fin,au_hdr_size,0);
  137.   { int ret;
  138.     xaUBYTE *snd = (xaUBYTE *)malloc(au_data_size);
  139.     if (snd==0) TheEnd1("AU: snd malloc err");
  140.     ret = fread( snd, au_data_size, 1, fin);
  141.     if (ret != 1) fprintf(stderr,"AU: snd rd err\n");
  142.     else
  143.     { int rets;
  144.       rets = XA_Add_Sound(anim_hdr,snd,au_audio_type, -1,
  145.       au_freq, au_data_size, &au_snd_time, &au_snd_timelo, 0, 0);
  146.     }
  147.   }
  148.  
  149.   fclose(fin);
  150.   if (xa_verbose)
  151.   {
  152.  /* POD NOTE: put switch here */
  153.     fprintf(stderr,"   freq=%d chans=%d size=%d\n",au_freq,au_chans,au_bits);
  154.   }
  155.  
  156.   anim_hdr->max_faud_size = au_max_faud_size;
  157.   return(xaTRUE);
  158. } /* end of read file */
  159.  
  160.  
  161.