November 25, 2020, 05:50:21 AM

Author Topic: [bmx] HOT.IFF8SVXloader by Hotcakes [ 1+ years ago ]  (Read 726 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bmx] HOT.IFF8SVXloader by Hotcakes [ 1+ years ago ]
« on: June 29, 2017, 12:28:42 AM »
Title : HOT.IFF8SVXloader
Author : Hotcakes
Posted : 1+ years ago

Description : Used exactly the same as the ogg and wav loaders, this module will load IFF 8SVX (from Amiga days) sounds.

Plays basic sounds only - compressed and multi octave sounds aren't supported.

<a href="http://members.dodo.com.au/~tzuyd/hotmods.rar" target="_blank">http://members.dodo.com.au/~tzuyd/hotmods.rar[/url]


Code :
Code: BlitzMax
  1. Strict
  2.  
  3. Rem
  4. bbdoc: IFF 8SVX loader
  5. End Rem ' bbdoc
  6. Module HOT.IFF8SVXLoader
  7.  
  8. ModuleInfo "Version: 1.00"
  9. ModuleInfo "Author: Toby Zuijdveld"
  10. ModuleInfo "License: Blitz Shared Source Code"
  11. ModuleInfo "Copyright: Jerry Morrison and Steve Hayes, Electronic Arts (public domain)"
  12. ModuleInfo "Modserver: n/a"
  13.  
  14. ModuleInfo "History: 1.00 Release"
  15. ModuleInfo "History:     Does not support volume flag"
  16. ModuleInfo "History:     Does not support Fibonacci-Delta compression"
  17. ModuleInfo "History:     Does not support multi-octave samples"
  18.  
  19. Import BRL.AudioSample
  20. Import BRL.EndianStream
  21.  
  22. ' '#Region Private block
  23. Private
  24.  
  25. Function ReadTag$( stream:TStream )
  26.         Local tag:Byte[4]
  27.         If stream.ReadBytes( tag,4 )<>4 Return
  28.         Return Chr(tag[0])+Chr(tag[1])+Chr(tag[2])+Chr(tag[3])
  29. End Function
  30.  
  31. ' sCompression: Choice of compression algorithm applied to the samples
  32. Const sCmpNone          = 0             ' not compressed
  33. Const sCmpFibDelta      = 1             ' Fibonacci-Delta encoding
  34. '#End Region
  35.  
  36. Public
  37.  
  38. Type TAudioSampleLoaderIFF8SVX Extends TAudioSampleLoader
  39.  
  40.         Method LoadAudioSample:TAudioSample( stream:TStream )
  41.  
  42.                 stream=BigEndianStream(stream)
  43.  
  44.                 If ReadTag( stream )<>"FORM" Return
  45.  
  46.                 Local   dud%    = stream.Readint()      ' length of file after 8SVX header
  47.  
  48.                 If ReadTag( stream )<>"8SVX" Return
  49.                 If ReadTag( stream )<>"VHDR" Return
  50.  
  51.                                 dud             = stream.Readint()      ' length of Voice8Header chunk
  52.                
  53.                 Local   oneShotHiSamples%       = stream.ReadInt()
  54.                 Local   repeatHiSamples%        = stream.ReadInt()
  55.                 Local   samplesPerHiCycle%      = stream.ReadInt()
  56.                 Local   samplesPerSec:Short     = stream.ReadShort()
  57.                 Local   ctOctave:Byte           = stream.ReadByte();If ctOctave>1 Then Return
  58.                 Local   sCompression:Byte       = stream.ReadByte();If sCompression<>sCmpNone Then Return
  59.                 Local   volume:Short            = stream.ReadShort()    ' ;If volume<>1 Then Return
  60.  
  61.                 Local   format  = SF_MONO8
  62.  
  63.                 stream.SkipBytes(dud-18)        ' handle extended header information
  64.                
  65.                 While Not stream.Eof()
  66.  
  67.                         If Readtag$(stream)<>"BODY"
  68.                                 Local   dud     = stream.Readint()
  69.                                 stream.SkipBytes(dud)
  70.                                 Continue
  71.                         EndIf
  72.  
  73.                         Local   w_sizebytes             = stream.Readint()
  74.                         Local   t:TAudioSample  = TAudioSample.Create(w_sizebytes,samplesPerSec,format)
  75.  
  76.                         stream.ReadBytes t.samples,w_sizebytes
  77.  
  78.                         For dud=0 To w_sizebytes-1
  79.                                 If t.samples[dud]>127
  80.                                         t.samples[dud]=383-(t.samples[dud]+1)
  81.                                 Else
  82.                                         t.samples[dud]=128-t.samples[dud]
  83.                                 EndIf   ' signed --> unsigned conversion
  84.                         Next    ' dud=0 To w_sizebytes-1
  85.                        
  86.                         Return t
  87.                        
  88.                 Wend    ' Not stream.EOF()
  89.  
  90.         End Method
  91.  
  92. End Type
  93.  
  94. AddAudioSampleLoader New TAudioSampleLoaderIFF8SVX


Comments :


ozak(Posted 1+ years ago)

 2xSweet!


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal