home *** CD-ROM | disk | FTP | other *** search
/ AMIGA PD 1 / AMIGA-PD-1.iso / Programme_zum_Heft / Programmieren / Kurztests / ACE / include / parse_sound.h < prev    next >
Text File  |  1994-10-23  |  2KB  |  99 lines

  1.   << parse a sound file and return 
  2.      offset (in bytes) of sample data 
  3.      start and sampling rate. >>
  4.  
  5.   Currently handles IFF 8SVX format.
  6.   If format is unknown, a default 
  7.   sampling rate is assumed. 
  8.   
  9.   Author: David J Benn
  10.     Date: 6th,7th April,16th May,
  11.       30th June,
  12.       1st,3rd,4th,8th July 1992,
  13.       7th January 1992
  14. }
  15.  
  16. library exec
  17.  
  18. declare function AllocMem& library exec
  19. declare function FreeMem   library exec
  20. declare function xRead&       library dos
  21.  
  22. longint offset&,samples_per_second&
  23.  
  24. SUB parse_sample(f$)
  25. shared offset&,samples_per_second&
  26. const default_rate=10000&
  27. const NOTOK=-1
  28. const OK=0
  29.  
  30.  { if IFF 8SVX sample, return
  31.    offset from start of file to
  32.    sample data and sampling rate in
  33.    samples per second. }
  34.  
  35.  open "I",1,f$
  36.  
  37.  '..FORM#### ?
  38.  dummy$ = input$(8,#1)
  39.  
  40.  '..8SVX ?
  41.  x$ = input$(4,#1)
  42.  
  43.  if x$="8SVX" then
  44.    sample_format$="IFF 8SVX"
  45.    '..skip VHDR###
  46.    dummy$ = input$(8,#1)
  47.  
  48.    '..skip ULONGs x 3
  49.    dummy$ = input$(12,#1) 
  50.    '..get sampling rate bytes
  51.    hi%=asc(input$(1,#1))  '..high byte
  52.    lo%=asc(input$(1,#1))  '..low byte
  53.    samples_per_second&=hi%*256 + lo%
  54.  
  55.    '..find BODY
  56.    '..skip rest of Voice8Header structure
  57.    dummy$ = input$(6,#1)
  58.    offset&=40  '..bytes up to this point
  59.    repeat 
  60.     repeat
  61.       x$=input$(1,#1)
  62.       offset&=offset&+1
  63.     until x$="B" and not eof(1)
  64.     if not eof(1) then
  65.       body$=input$(3,#1)
  66.       offset&=offset&+3
  67.     end if
  68.    until body$="ODY" and not eof(1) 
  69.  
  70.    if not eof(1) then
  71.      x$=input$(4,#1)  '..skip ####   
  72.      offset&=offset&+4
  73.    else
  74.      close 1
  75.      parse_sample=NOTOK
  76.      library close exec
  77.      exit sub
  78.    end if
  79.    close 1
  80.  else
  81.    close 1
  82.    sample_format$="unknown"
  83.    offset&=0
  84.    samples_per_second&=default_rate
  85.    parse_sample=OK
  86.    library close exec
  87.  end if
  88.  
  89. END SUB
  90.  
  91. SUB calc_period&(samples_per_second&)
  92.   calc_period& = 3579546 \ samples_per_second&  
  93. END SUB
  94.  
  95. SUB calc_duration(per&,bytes&)  
  96.   calc_duration=.279365*per&*bytes&/1e6*18.2
  97. END SUB
  98.