home *** CD-ROM | disk | FTP | other *** search
/ The Best of Mecomp Multimedia 2 / MECOMP-CD-II.iso / amiga / datatypes / 16sv_datatype / classbase.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-11-09  |  12.1 KB  |  409 lines

  1.  
  2. /*
  3. **
  4. **  $VER: classbase.c 1.2 (9.11.97)
  5. **  16sv.datatype 1.1
  6. **
  7. **  Library routines for a DataTypes class
  8. **
  9. **  Written 1996/97 by Roland 'Gizzy' Mainz
  10. **  Original example source from David N. Junod
  11. **
  12. */
  13.  
  14.  
  15. /* main includes */
  16. #include "classbase.h"
  17.  
  18.  
  19. /****** 16sv.datatype/MAIN ***************************************************
  20. *
  21. *    INTRODUCTION
  22. *        Datatypes class for IFF 16SV samples. Based on the CBM datatypes
  23. *        example source/ documents written by David Junod and infos got from
  24. *        "SoundBox" by Richard Koerber.
  25. *
  26. *    REQUIREMENTS
  27. *        - You need at least Kick/WB 3.0.
  28. *
  29. *        - "datatypes/sound.datatype", >= V39.
  30. *
  31. *    USAGE
  32. *        If the datatypes descriptor file was activated, any attempt to load
  33. *        an IFF 16SV sample using GMultiView, MultiView, AmigaGuide or
  34. *        SwitchWindow will load and play the sample.
  35. *
  36. *        16sv.datatype supports also the clipboard as input, e.g.
  37. *        "MultiView CLIPBOARD", ClipView or SwitchWindow are able to play
  38. *        IFF 16SVs from clipboard.
  39. *
  40. *        If you want to save the current sample in 16sv.datatype's local
  41. *        format, use MultiView's "Project/Save As..." menu (or GMultiView's
  42. *        "Project/Save As Raw...").
  43. *
  44. *    INSTALLATION
  45. *        After unpacking this archive:
  46. *        Because this version does not include an Installer script, you have
  47. *        to do the installation manually through the shell:
  48. *
  49. *          - Unpack this archive and copy the "16sv.datatype" to
  50. *            SYS:Classes/DataTypes:
  51. *
  52. *     Copy CLONE FROM "16sv.datatype" TO "SYS:Classes/DataTypes/16sv.datatype"
  53. *
  54. *          - Then copy the datatypes descriptor into the DEVS:DataTypes
  55. *            directory.
  56. *            If the descriptor already exists, you should not replace it,
  57. *            otherwise you may loose "toolnodes" and other settings stored in
  58. *            the existing descriptor.
  59. *
  60. *     Copy CLONE FROM "16SV(%|.info)" TO DEVS:Datatypes/
  61. *
  62. *    SOURCE
  63. *        This is the official datatypes.library V45 reference implementation
  64. *        of a sound.datatype subclass which supports saving in it's local
  65. *        format (such an encoder is used by "DTConvert" and other tools which
  66. *        uses DataTypes for conversion, e.g. DataType -> DataType (e.g. MPEG 
  67. *        Audio -> IFF 16SV etc.)).
  68. *
  69. *        Source is fully included here.
  70. *
  71. *    AUTHOR
  72. *        If you want to blame me, report any bugs, or wants a new version
  73. *        send your letter to:
  74. *                        Roland Mainz
  75. *                        Hohenstaufenstraße 8
  76. *                        52388 Nörvenich
  77. *                        GERMANY
  78. *
  79. *        Phone: (+49)(0)2426/901568
  80. *        Fax:   (+49)(0)2426/901569
  81. *
  82. *        EMAIL is also available (if you want to send me attachments
  83. *        larger than 1MB (up to 5MB, more with my permission):
  84. *
  85. *        GISBURN@w-specht.rhein-ruhr.de
  86. *
  87. *        Up to December 1997 I'm reachable using this email address, too:
  88. *        Reinhold.A.Mainz@KBV.DE
  89. *
  90. *        | Please put your name and address in your mails !
  91. *        | German mailers should add their phone numbers.
  92. *        | See BUGS section above when submitting bug reports.
  93. *
  94. *        Sorry, but I can only look once a week for mails.
  95. *        If you don't hear something from me within three weeks, please
  96. *        send your mail again (but watch about new releases) (problems with
  97. *        this email port are caused by reconfigurations, hackers, network
  98. *        problems etc.).
  99. *
  100. *        The  entire  "16sv.datatype"  package  may  be  noncommercially
  101. *        redistributed, provided  that  the package  is always  distributed
  102. *        in it's complete  form (including it's documentation). A small
  103. *        copy fee  for media costs is okay but any kind of commercial
  104. *        distribution is strictly forbidden without my permission !
  105. *        Comments and suggestions how to improve this program are
  106. *        generally appreciated!
  107. *
  108. *        Thanks to David Junod, who wrote the datatypes environment and lots
  109. *        of the datatypes example code, Richard Koerber for his "SoundBox",
  110. *        Matt Dillon for his DICE, Olaf 'Olsen' Barthel for his help, 
  111. *        ideas and some text clips from his documentations.
  112. *
  113. ******************************************************************************
  114. *
  115. */
  116.  
  117.  
  118. /****** 16sv.datatype/--datasheed-- ******************************************
  119. *
  120. *   NAME
  121. *       16sv.datatype -- data type for IFF 16SV samples
  122. *
  123. *   SUPERCLASS
  124. *       sound.datatype
  125. *
  126. *   DESCRIPTION
  127. *       The 16sv datatype, a sub-class of the sound.datatype, is
  128. *       used to load and save IFF 16SV samples.
  129. *
  130. *       This class is offloaded from the datatypes.library V45 example code
  131. *       and is the reference implementation of a sound.datatype subclass
  132. *       which supports saving in it's local format (as used by converters
  133. *       like "DTConvert").
  134. *
  135. *   METHODS
  136. *       OM_NEW -- Create a new sound object from a description file. The
  137. *           source may be a file or a clipboard unit. An empty object
  138. *           (DTST_RAM) can also be created.
  139. *
  140. *       OM_UPDATE -- Perform an ICM_CHECKLOOP check, and if succesfull, the
  141. *           method will be executed like OM_SET downstairs.
  142. *
  143. *       OM_SET -- Pass msg to superclass and call GM_RENDER if retval from
  144. *           superclass was != 0UL.
  145. *
  146. *       DTM_WRITE -- Save data in local (IFF 16SV) or superclass (IFF 8SVX)
  147. *           format.
  148. *
  149. *       All other methods are passed unchanged to superclass.
  150. *
  151. *   ATTRIBUTES
  152. *       Following attributes are set by the object and are READ-ONLY for
  153. *       applications (if the datatype is used for saving (e.g. the
  154. *       application creates an empty 16SV.datatype object and fills
  155. *       in some required atrributes as shown in the "DTConvert" example),
  156. *       these attributes are used by the encoder to create an IFF 16SV
  157. *       sound file):
  158. *
  159. *       DTA_ObjName         -- Set by an IFF NAME chunk. If missing,
  160. *                              DTA_ObjName will take DTA_Name's value.
  161. *       DTA_ObjAuthor       -- Set by an IFF AUTH chunk.
  162. *       DTA_ObjAnnotation   -- Set by an IFF ANNO chunk.
  163. *       DTA_ObjCopyright    -- Set by an IFF (C) chunk.
  164. *       DTA_ObjVersion      -- Set by an IFF FVER chunk.
  165. *       SDTA_VoiceHeader    -- Filled by the 16SV VHDR chunk
  166. *       SDTA_Sample         -- 8 bit sample data
  167. *       SDTA_SampleLength   -- length of 8 bit sample data
  168. *       SDTA_Volume         -- volume (got from the voiceheader)
  169. *       SDTA_Period         -- created from (VoiceHeader -> vh_SamplesPerSec)
  170. *                              and system's clock
  171. *
  172. *   BUGS
  173. *       The project has been not very well tested yet. Therefore...
  174. *       ... no known bugs.
  175. *
  176. *   TODO
  177. *       - Fixing the bugs above.
  178. *
  179. *       - Add stereo support, e.g. interleave the sound data when left/right
  180. *         channels occur...
  181. *
  182. *       - Compression support (e.g. CMP_FIBDELTA).
  183. *
  184. *       - More speed during encoding.
  185. *
  186. *       - Support for SDTM_LOADFRAME / SDTM_UNLOADFRAME (implies also support
  187. *         for 16-bit audio á la RTA /  AHI).
  188. *
  189. *   HISTORY
  190. *       V1.1
  191. *         First public release.
  192. *
  193. *       V1.2
  194. *         - Replaced stack swapping code by my "standard" module
  195. *
  196. *         - Minor source code cleanup.
  197. *
  198. *         - Improved the "smakefile" a little bit
  199. *
  200. *   SEE ALSO
  201. *       sound.datatype
  202. *
  203. *******************************************************************************
  204. *
  205. */
  206.  
  207.  
  208. /****** 16sv.datatype/--input_format-- ****************************************
  209. *
  210. *    NAME
  211. *        IFF 16SV -- 16 bit Samples Voice
  212. *
  213. *    DESCRIPTION
  214. *        FORM 16SV has the same format as FORM 8SVX except the normal BODY
  215. *        chunk contains 16 bit samples instead of 8 bit samples.
  216. *
  217. *    SEE ALSO
  218. *        - ARKM Devices: IFF part
  219. *
  220. *        - iffparse.library autodocs
  221. *
  222. *        - IFF 8SVX docs
  223. *
  224. *******************************************************************************
  225. *
  226. */
  227.  
  228.  
  229.  
  230. /*****************************************************************************/
  231.  
  232. DISPATCHERFLAGS
  233. struct IClass *Obtain16SVEngine( REGA6 struct ClassBase *cb )
  234. {
  235.     return( (cb -> cb_Lib . cl_Class) );
  236. }
  237.  
  238. /*****************************************************************************/
  239.  
  240. DISPATCHERFLAGS
  241. struct Library *LibInit( REGD0 struct ClassBase *cb, REGA0 BPTR seglist, REGA6 struct ExecBase *sysbase )
  242. {
  243.     cb -> cb_SegList = seglist;
  244.     cb -> cb_SysBase = sysbase;
  245.  
  246.     InitSemaphore( (&(cb -> cb_Lock)) );
  247.  
  248. #ifdef REQUIREDAFF
  249.     /* Check if the requested cpu/fpu is available */
  250.     if( ((sysbase -> AttnFlags) | REQUIREDAFF) != (sysbase -> AttnFlags) )
  251.     {
  252.       return( NULL );
  253.     }
  254. #endif /* REQUIREDAFF */
  255.  
  256.     if( (cb -> cb_SysBase -> LibNode . lib_Version) >= 39UL )
  257.     {
  258.       /* Obtain ROM libs */
  259.       if( cb -> cb_UtilityBase = OpenLibrary( "utility.library", 39UL ) )
  260.       {
  261.         if( cb -> cb_DOSBase = OpenLibrary( "dos.library", 39UL ) )
  262.         {
  263.  
  264.           if( cb -> cb_IntuitionBase = OpenLibrary( "intuition.library", 39UL ) )
  265.           {
  266.             return( (&(cb -> cb_Lib . cl_Lib)) );
  267.  
  268. #ifdef COMMENTED_OUT
  269.               CloseLibrary( (cb -> cb_IntuitionBase) );
  270. #endif /* COMMENTED_OUT */
  271.           }
  272.  
  273.           CloseLibrary( (cb -> cb_DOSBase) );
  274.         }
  275.  
  276.         CloseLibrary( (cb -> cb_UtilityBase) );
  277.       }
  278.     }
  279.  
  280.     return( NULL );
  281. }
  282.  
  283. /*****************************************************************************/
  284.  
  285. DISPATCHERFLAGS
  286. LONG LibOpen( REGA6 struct ClassBase *cb )
  287. {
  288.     LONG retval = (LONG)cb;
  289.     BOOL success = TRUE;
  290.  
  291.     ObtainSemaphore( (&(cb -> cb_Lock)) );
  292.  
  293.     /* Use an internal use counter */
  294.     cb -> cb_Lib . cl_Lib . lib_OpenCnt++;
  295.     cb -> cb_Lib . cl_Lib . lib_Flags &= ~LIBF_DELEXP;
  296.  
  297.     if( (cb -> cb_Lib . cl_Lib . lib_OpenCnt) == 1U )
  298.     {
  299.       if( (cb -> cb_Lib . cl_Class) == NULL )
  300.       {
  301.         success = FALSE;
  302.  
  303.         if( cb -> cb_IFFParseBase = OpenLibrary( "iffparse.library", 39UL ) )
  304.         {
  305.           if( cb -> cb_DataTypesBase = OpenLibrary( "datatypes.library", 39UL ) )
  306.           {
  307.             if( cb -> cb_SuperClassBase = OpenLibrary( "datatypes/sound.datatype", 39UL ) )
  308.             {
  309.               if( cb -> cb_Lib . cl_Class = initClass( cb ) )
  310.               {
  311.                 success = TRUE;
  312.               }
  313.             }
  314.           }
  315.         }
  316.       }
  317.     }
  318.  
  319.     if( !success )
  320.     {
  321.       CloseLibrary( (cb -> cb_SuperClassBase) );
  322.       CloseLibrary( (cb -> cb_DataTypesBase) );
  323.       CloseLibrary( (cb -> cb_IFFParseBase) );
  324.  
  325.       cb -> cb_IFFParseBase = cb -> cb_DataTypesBase = cb -> cb_SuperClassBase = NULL;
  326.  
  327.       (cb -> cb_Lib . cl_Lib . lib_OpenCnt)--;
  328.  
  329.       retval = 0L;
  330.     }
  331.  
  332.     ReleaseSemaphore( (&(cb -> cb_Lock)) );
  333.  
  334.     return( retval );
  335. }
  336.  
  337. /*****************************************************************************/
  338.  
  339. DISPATCHERFLAGS
  340. LONG LibClose( REGA6 struct ClassBase *cb )
  341. {
  342.     LONG retval = 0L;
  343.  
  344.     ObtainSemaphore( (&(cb -> cb_Lock)) );
  345.  
  346.     if( cb -> cb_Lib . cl_Lib . lib_OpenCnt )
  347.     {
  348.       (cb -> cb_Lib . cl_Lib . lib_OpenCnt)--;
  349.     }
  350.  
  351.     if( ((cb -> cb_Lib . cl_Lib . lib_OpenCnt) == 0U) && (cb -> cb_Lib . cl_Class) )
  352.     {
  353.       if( FreeClass( (cb -> cb_Lib . cl_Class) ) )
  354.       {
  355.         cb -> cb_Lib . cl_Class = NULL;
  356.  
  357.         CloseLibrary( (cb -> cb_SuperClassBase) );
  358.         CloseLibrary( (cb -> cb_DataTypesBase) );
  359.         CloseLibrary( (cb -> cb_IFFParseBase) );
  360.       }
  361.       else
  362.       {
  363.         cb -> cb_Lib . cl_Lib . lib_Flags |= LIBF_DELEXP;
  364.       }
  365.     }
  366.  
  367.     ReleaseSemaphore( (&(cb -> cb_Lock)) );
  368.  
  369.     if( cb -> cb_Lib . cl_Lib . lib_Flags & LIBF_DELEXP )
  370.     {
  371.       retval = LibExpunge( cb );
  372.     }
  373.  
  374.     return( retval );
  375. }
  376.  
  377. /*****************************************************************************/
  378.  
  379. DISPATCHERFLAGS
  380. LONG LibExpunge( REGA6 struct ClassBase *cb )
  381. {
  382.     BPTR seg;
  383.  
  384.     if( cb -> cb_Lib . cl_Lib . lib_OpenCnt )
  385.     {
  386.       cb -> cb_Lib . cl_Lib . lib_Flags |= LIBF_DELEXP;
  387.  
  388.       seg = NULL;
  389.     }
  390.     else
  391.     {
  392.       Remove( (&(cb -> cb_Lib . cl_Lib . lib_Node)) );
  393.  
  394.       seg = cb -> cb_SegList;
  395.  
  396.       CloseLibrary( (cb -> cb_IntuitionBase) );
  397.       CloseLibrary( (cb -> cb_DOSBase) );
  398.       CloseLibrary( (cb -> cb_UtilityBase) );
  399.  
  400.       FreeMem( (APTR)((ULONG)(cb) - (ULONG)(cb -> cb_Lib . cl_Lib . lib_NegSize)), (ULONG)((cb -> cb_Lib . cl_Lib . lib_NegSize) + (cb -> cb_Lib . cl_Lib . lib_PosSize)) );
  401.     }
  402.  
  403.     return( (LONG)seg );
  404. }
  405.  
  406.  
  407.  
  408.  
  409.