home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 543a.lha / Nebula / source.LZH / source / easysound.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-10  |  21.2 KB  |  617 lines

  1. /*
  2.  
  3. ------------------------------------------------------------------
  4.  
  5. Black Nebula
  6.  
  7. File :                easysound.c
  8. Programmer:        Public Domain Source
  9. Date:                13/5/91
  10. Last Modified :    31/5/91
  11.  
  12. Description:
  13.  
  14. From the C manual.  Brilliant file that makes sound really simple!
  15. If only it used prototyping...
  16.  
  17. ------------------------------------------------------------------
  18.  
  19. */
  20.  
  21. /* Include some important header files: */
  22.  
  23. #include <exec/types.h>
  24. #include <exec/memory.h>
  25. #include <devices/audio.h> 
  26. #include <stdio.h>
  27.  
  28.  
  29. #define CLOCK_CONSTANT 3579545
  30. #define MUSIC_PRIORITY 0
  31.  
  32. /* Structure containing all necessary information about the sound: */
  33.  
  34. struct SoundInfo
  35. {
  36.   BYTE *SoundBuffer;   /* WaveForm Buffers */
  37.   UWORD RecordRate;    /* Record Rate */
  38.   ULONG FileLength;    /* WaveForm Lengths */
  39. };
  40.  
  41.  
  42. /* An IOAudio pointer to each sound channel: */
  43. struct IOAudio *IOA[ 4 ] = { NULL, NULL, NULL, NULL };
  44.  
  45.  
  46. typedef LONG Fixed;
  47.  
  48. typedef struct
  49. {
  50.   ULONG  oneShotHiSamples;  /* #samples in the high octave 1-shot part */
  51.   ULONG  repeatHiSamples;   /* #samples in the high octave repeat part */
  52.   ULONG  samplesPerHiCycle; /* #samples/cycle in high octave, else 0   */
  53.   UWORD  samplesPerSec;     /* Data sampling rate */
  54.   UBYTE  ctOctave;          /* Number of octaves of waveforms */
  55.   UBYTE  sCompression;      /* Data compression technique used */
  56.   Fixed  volume;            /* Playback volume from 0 to 0x10000 */
  57. } Voice8Header;
  58.  
  59.  
  60. /* Declare the functions we are going to use: */
  61. CPTR PrepareSound();
  62. BOOL PlaySound();
  63. void StopSound();
  64. void RemoveSound();
  65.  
  66. BOOL PrepareIOA();
  67. UWORD LoadSound();
  68. ULONG GetSize();
  69. ULONG SizeIFF();
  70. UWORD ReadIFF();
  71. BOOL MoveTo();
  72.  
  73.  
  74. /* PrepareSound()                                                       */
  75. /* PrepareSound() loads a sampled sound file (IFF or FutureSound) into  */
  76. /* a buffer that is automatically allocated. All information about the  */
  77. /* sound (record rate, length, buffersize etc) is put into an SoundInfo */
  78. /* structure. If PrepareSound() has successfully prepared the sound it  */
  79. /* returns a pointer to a SoundInfo structure, otherwise it returns     */
  80. /* NULL.                                                                */
  81. /*                                                                      */
  82. /* Synopsis: pointer = PrepareSound( filename );                        */
  83. /* pointer:  (CPTR) Actually a pointer to a SoundInfo structure, but    */
  84. /*           since we do not want to confuse the user, we simply use a  */
  85. /*           normal memory pointer.                                     */
  86. /* filename: (STRPTR) Pointer to a string containing the name of the    */
  87. /*           sound file. For example "df0:Explosion.snd".               */
  88.  
  89. CPTR PrepareSound( file )
  90. STRPTR file;
  91. {
  92.   /* Declare a pointer to a SoundInfo structure: */
  93.   struct SoundInfo *info;
  94.  
  95.   /* Allocate memory for a SoundInfo structure: (The memory can be of */
  96.   /* any type, and should be cleared.                                 */
  97.   info = (struct SoundInfo *) AllocMem( sizeof( struct SoundInfo ),
  98.                                         MEMF_PUBLIC|MEMF_CLEAR );
  99.  
  100.  
  101.   if( info )
  102.   {
  103.     /* The memory have been successfully allocated. */ 
  104.     
  105.     /* Get the size of the file, and store it in the SoundInfo struct.: */
  106.     if( info->FileLength = GetSize( file ) )
  107.     {
  108.       /* Allocate enough memory for the sampled sound, and store a */
  109.       /* pointer to the buffer in the SoundInfo structure:         */
  110.       info->SoundBuffer = (BYTE *) AllocMem( info->FileLength,
  111.                                           MEMF_CHIP|MEMF_CLEAR );
  112.  
  113.       if( info->SoundBuffer )
  114.       {
  115.         /* The memory have been successfully allocated. */ 
  116.  
  117.             /* Load the sound, and store the record rate in the SoundInfo  */
  118.                 /* structure. If the sound could not be loaded, 0 is returned: */
  119.         if( info->RecordRate = LoadSound( file, info ) )
  120.         {
  121.                     /* OK! The sound has successfully been loaded. */
  122.           
  123.                     /* Old FutureSound files were saved in kHz. If the record rate */
  124.                     /* is less than one hundered, we know it is an old FutureSound */
  125.                     /* file, and simply multiply the rate with one thousand:       */
  126.           if( info->RecordRate < 100 )
  127.             info->RecordRate *= 1000;
  128.           
  129.                     /* Return a pointer to the SoundInfo structure. (We return a */
  130.                     /* normal memory pointer.)                                   */
  131.                     return( (CPTR) info ); /* OK! */
  132.         }
  133.                 else
  134.         {
  135.                     /* ERROR! We could not load the sound! */
  136.                     
  137.           /* Deallocate the memory for the sound buffer: */
  138.           FreeMem( info->SoundBuffer, info->FileLength );
  139.         }
  140.       }
  141.     }
  142.     /* Deallocate the memory the SoundInfo structure: */
  143.     FreeMem( info, sizeof( struct SoundInfo ) );
  144.   }
  145.     
  146.     /* We have not been able to prepare the sound. All allocated memory */
  147.     /* have been deallocated, and we return NULL.                       */
  148.   return( NULL ); /* ERROR! */
  149. }
  150.  
  151.  
  152.  
  153. /* PlaySound()                                                          */
  154. /* PlaySound() plays one already prepared sound effect. You can decide  */
  155. /* what volume, which channel should, what rate, and how many times the */
  156. /* sound should be played.                                              */ 
  157. /*                                                                      */
  158. /* Synopsis: ok = PlaySound( pointer, volume, channel, drate, times );  */
  159. /* ok:       (BOOL) If the sound was played successfully TRUE is        */
  160. /*           returned, else FALSE.                                      */
  161. /* pointer:  (CPTR) Actually a pointer to a SoundInfo structure. This   */
  162. /*           pointer was returned by PrepareSound().                    */
  163. /* volume:   (UWORD) Volume, 0 to 64.                                   */
  164. /* channel:  (UBYTE) Which channel should be used. (LEFT0, RIGHT0,      */
  165. /*           RIGHT1 or LEFT1)                                           */
  166. /* drate:    (WORD) Delta rate. When the sound is prepared, the record  */
  167. /*           rate is automatically stored in the SoundInfo structure,   */
  168. /*           so if you do not want to change the rate, write 0.         */
  169. /* times:    (UWORD) How many times the sound should be played. If you  */
  170. /*           want to play the sound forever, write 0. (To stop a sound  */
  171. /*           call the function StopSound().)                            */ 
  172.  
  173. BOOL PlaySound( info, volume, channel, delta_rate, repeat )
  174. struct SoundInfo *info;
  175. UWORD volume;
  176. UBYTE channel;
  177. WORD delta_rate;
  178. UWORD repeat;
  179. {
  180.   /* Before we may play the sound, we must make sure that the sound is */
  181.     /* not already being played. We will therefore call the function     */
  182.     /* StopSound(), in order to stop the sound if it is playing:         */
  183.   StopSound( channel );
  184.  
  185.   /* Call the PrepareIOA() function that will declare and initialize an */
  186.     /* IOAudio structure:                                                 */
  187.   if( PrepareIOA( CLOCK_CONSTANT / info->RecordRate + delta_rate, volume,
  188.               repeat, channel, info ) )
  189.   {
  190.     /* We will now start playing the sound: */
  191.     BeginIO( IOA[ channel ] );
  192.     return( TRUE );  /* OK! */
  193.     }
  194.   else
  195.     return( FALSE ); /* ERROR! */
  196. }
  197.  
  198.  
  199. /* StopSound()                                                         */
  200. /* StopSound() will stop the specified audio channel from continuing   */
  201. /* to play the sound. It will also close all devices and ports that    */
  202. /* have been opened, and deallocate some memory that have been         */
  203. /* allocated.                                                          */
  204. /*                                                                     */
  205. /* Synopsis: StopSound( channel );                                     */
  206. /* channel:  (UBYTE) The audio channel that should be stopped. (LEFT0, */
  207. /*           LEFT1, RIGHT0 or RIGHT1.)                                 */
  208.  
  209. void StopSound( channel )
  210. UBYTE channel;
  211. {
  212.     /* Check if the IOAudio structure exist: */
  213.   if( IOA[ channel ] )
  214.   {
  215.         /* 1. Stop the sound: */
  216.     AbortIO( IOA[ channel ] );
  217.     
  218.     /* 2. If there exist a Sound Device, close it: */
  219.     if( IOA[ channel ]->ioa_Request.io_Device )
  220.       CloseDevice( IOA[ channel ] );
  221.  
  222.     /* 3. If there exist a Message Port, delete it: */
  223.     if( IOA[ channel ]->ioa_Request.io_Message.mn_ReplyPort )
  224.       DeletePort( IOA[ channel ]->ioa_Request.io_Message.mn_ReplyPort );
  225.  
  226.     FreeMem( IOA[ channel ], sizeof( struct IOAudio ) );
  227.     IOA[ channel ] = NULL;
  228.   }
  229. }
  230.  
  231.  
  232.  
  233. /* RemoveSound()                                                        */
  234. /* RemoveSound() will stop playing the sound, and deallocate all memory */
  235. /* that was allocated by the PrepareSound() function. Before your       */
  236. /* program terminates, all sound that has been prepared, MUST be        */
  237. /* removed.                                                             */
  238. /*                                                                      */
  239. /* IMPORTANT! The each channel that is currently playing the sound must */
  240. /* be stopped! (Use the StopSound() function.)                          */
  241.  
  242. /* Synopsis: RemoveSound( pointer );                                    */
  243. /* pointer:  (CPTR) Actually a pointer to a SoundInfo structure.        */
  244.  
  245. void RemoveSound( info )
  246. struct SoundInfo *info;
  247. {
  248.   /* IMPORTANT! The sound must have been */
  249.     /* stopped before you may remove it!!! */
  250.  
  251.   /* Have we allocated a SoundInfo structure? */
  252.   if( info )
  253.   {
  254.     /* Deallocate the sound buffer: */
  255.     FreeMem( info->SoundBuffer, info->FileLength );
  256.  
  257.     /* Deallocate the SoundInfo structure: */
  258.     FreeMem( info, sizeof( struct SoundInfo ) );
  259.     info = NULL;
  260.   }
  261. }
  262.  
  263.  
  264.  
  265. /* PrepareIOA()                                                           */
  266. /* PrepareIOA() allocates and initializes an IOAudio structure.           */
  267. /*                                                                        */
  268. /* Synopsis: ok = PrepareIOA( period, volume, cycles, channel, pointer ); */
  269. /*                                                                        */
  270. /* ok:       (BOOL) If the IOAudio structure was allocated and            */
  271. /*           initialized successfully, TRUE is returned, else FALSE.      */
  272. /* period:   (UWORD) Period time.                                         */
  273. /* volume:   (UWORD) Volume, 0 to 64.                                     */
  274. /* cycles:   (UWORD) How many times the sound should be played.           */
  275. /*           (0 : forever)                                                */
  276. /* channel:  (UBYTE) Which channel should be used. (LEFT0, RIGHT0,        */
  277. /*           RIGHT1 or LEFT1)                                             */
  278. /* pointer:  (CPTR) Actually a pointer to a SoundInfo structure.          */
  279.  
  280. BOOL PrepareIOA( period, volume, cycles, channel, info)
  281. UWORD period, volume, cycles;
  282. UBYTE channel;
  283. struct SoundInfo *info;
  284. {
  285.     UBYTE ch;
  286.  
  287.     /* Declare a pointer to a MsgPort structure: */ 
  288.   struct MsgPort *port;
  289.  
  290.   /* Allocate space for an IOAudio structure: */
  291.   IOA[ channel ] = (struct IOAudio *) AllocMem( sizeof( struct IOAudio ),
  292.                       MEMF_PUBLIC|MEMF_CLEAR );
  293.  
  294.   /* Could we allocate enough memory? */
  295.   if( IOA[ channel ] )
  296.   {
  297.     /* Create Message port: */
  298.     if((port = (struct MsgPort *) CreatePort( "Sound Port", 0 )) == NULL)
  299.     {
  300.       /* ERROR! Could not create message port! */
  301.             /* Deallocate the IOAudio structure: */
  302.       FreeMem( IOA[ channel ], sizeof(struct IOAudio) );
  303.       IOA[ channel ] = NULL;
  304.       
  305.             return( FALSE ); /* ERROR! */
  306.     }
  307.     else
  308.     {
  309.       /* Port created successfully! */
  310.       /* Initialize the IOAudion structure: */
  311.             
  312.             /* Priority: */
  313.       IOA[ channel ]->ioa_Request.io_Message.mn_Node.ln_Pri = MUSIC_PRIORITY;
  314.       
  315.             /* Port: */
  316.             IOA[ channel ]->ioa_Request.io_Message.mn_ReplyPort = port;
  317.       
  318.             /* Channel: */
  319.       ch = 1<<channel;
  320.             IOA[ channel ]->ioa_Data = &ch;
  321.       
  322.             /* Length: */
  323.             IOA[ channel ]->ioa_Length = sizeof( UBYTE );
  324.       
  325.       /* Open Audio Device: */
  326.       if( OpenDevice( AUDIONAME, 0, IOA[ channel ], 0) )
  327.       {
  328.         /* ERROR! Could not open the device! */
  329.         /* Delete Sound Port: */
  330.                 DeletePort( port );
  331.  
  332.                 /* Deallocate the IOAudio structure: */
  333.         FreeMem( IOA[ channel ], sizeof(struct IOAudio) );
  334.         IOA[ channel ] = NULL;
  335.  
  336.                 return( FALSE ); /* ERROR! */
  337.       }
  338.       else
  339.       {
  340.         /* Device opened successfully! */
  341.         /* Initialize the rest of the IOAudio structure: */
  342.         IOA[ channel ]->ioa_Request.io_Flags = ADIOF_PERVOL;
  343.         IOA[ channel ]->ioa_Request.io_Command = CMD_WRITE;
  344.         IOA[ channel ]->ioa_Period = period;
  345.         IOA[ channel ]->ioa_Volume = volume;
  346.         IOA[ channel ]->ioa_Cycles = cycles;
  347.  
  348.         /* The Audion Chip can of some strange reason not play sampled  */
  349.                 /* sound that is longer than 131KB. So if the sound is to long, */
  350.                 /* we simply cut it off:                                        */
  351.         if( info->FileLength > 131000 )
  352.           IOA[ channel ]->ioa_Length = 131000;
  353.         else
  354.           IOA[ channel ]->ioa_Length = info->FileLength;
  355.  
  356.         IOA[ channel ]->ioa_Data = info->SoundBuffer;
  357.  
  358.         return( TRUE ); /* OK! */
  359.       }
  360.     }
  361.   }
  362.   return( FALSE ); /* ERROR! */
  363. }
  364.  
  365.  
  366.  
  367. /* LoadSound()                                                         */
  368. /* LoadSound() will load sampled sound that was either saved in IFF or */
  369. /* FutureSound format.                                                 */
  370. /*                                                                     */
  371. /* Synopsis: rate = LoadSound( filename, pointer );                    */
  372. /* rate:     (UWORD) The record rate is returned if the sound was      */
  373. /*           successfully loaded, else 0.                              */
  374. /* filename: (STRPTR) Pointer to a string containing the name of the   */
  375. /*           sound file. For example "df0:Explosion.snd".              */
  376. /* pointer:  (CPTR) Actually a pointer to a SoundInfo structure.       */
  377.  
  378.  
  379. UWORD LoadSound( filename, info )
  380. STRPTR filename;
  381. struct SoundInfo *info;
  382. {
  383.   FILE  *file_ptr;   /* Pointer to a file. */
  384.   ULONG length;      /* Data Length. */
  385.   UWORD record_rate; /* Record rate. */
  386.  
  387.  
  388.   /* Check if it is an IFF File: */
  389.   if( SizeIFF( filename ) )
  390.   {
  391.     /* Yes, it is an IFF file. Read it: */
  392.     return( ReadIFF( filename, info ) );
  393.   }
  394.   else
  395.   {
  396.     /* No, then it is probably a FutureSound file. */
  397.     /* Open the file so we can read it:            */
  398.     if( (file_ptr = fopen( filename, "r" )) == 0 )
  399.       return( 0 ); /* ERROR! Could not open the file! */
  400.  
  401.     /* Read the data length: */
  402.     if( fread( (char *) &length, sizeof( ULONG ), 1, file_ptr ) == 0 )
  403.     {
  404.             /* ERROR! Could not read the data length! */
  405.             /* Close the file, and return zero:       */
  406.       fclose( file_ptr );
  407.       return( 0 );
  408.     }
  409.  
  410.     /* Read the record rate: */
  411.     if( fread( (char *) &record_rate, sizeof( UWORD ), 1, file_ptr ) == 0 )
  412.     {
  413.             /* ERROR! Could not read the record rate! */
  414.             /* Close the file, and return zero:       */
  415.       fclose( file_ptr );
  416.       return( 0 );
  417.     }
  418.  
  419.     /* Read the sampled sound data into the buffer: */
  420.     if( fread( (char *) info->SoundBuffer, length, 1, file_ptr ) == 0 )
  421.     {
  422.             /* ERROR! Could not read the data!  */
  423.             /* Close the file, and return zero: */        
  424.       fclose( file_ptr );
  425.       return( 0 );
  426.     }
  427.  
  428.     /* Close the file: */
  429.     fclose( file_ptr );
  430.  
  431.     /* Return the record rate: */
  432.     return( record_rate );
  433.   }
  434. }
  435.  
  436.  
  437.  
  438.  
  439. /* GetSize()                                                         */
  440. /* GetSize() returns the size of the file which was saved in either  */
  441. /* IFF or FutureSound format.                                        */
  442. /*                                                                   */
  443. /* Synopsis: length = GetSize( filename );                           */
  444. /* length:   (ULONG) Data length.                                    */
  445. /* filename: (STRPTR) Pointer to a string containing the name of the */
  446. /*           sound file. For example "df0:Explosion.snd".            */
  447.  
  448. ULONG GetSize( filename )
  449. STRPTR filename;
  450. {
  451.   FILE *file_ptr; /* Pointer to a file. */
  452.   ULONG length;  /* Data length. */
  453.  
  454.  
  455.   /* Check if it is an IFF File: */
  456.   if( ( length = SizeIFF( filename ) ) == 0 )
  457.   {
  458.     /* No, then it is probably a FutureSound file. */
  459.     /* Open the file so we can read it:            */
  460.     if( ( file_ptr = fopen( filename, "r" ) ) == 0 )
  461.       return( 0 ); /* ERROR! Could not open the file! */
  462.  
  463.     /* Read the data length: */
  464.     if( fread( (char *) &length, sizeof( ULONG ), 1, file_ptr ) == 0)
  465.     {
  466.             /* ERROR! Could not read the data length! */
  467.             /* Close the file, and return zero:       */
  468.       fclose( file_ptr );
  469.       return( 0 );
  470.     }
  471.         
  472.     /* Close the file: */
  473.     fclose( file_ptr );
  474.   }
  475.   return( length );
  476. }
  477.  
  478.  
  479.  
  480. /* SizeIFF()                                                         */
  481. /* SizeIFF() returns the size of an IFF file, or zero if something   */
  482. /* went wrong (for example, It was not an IFF file).                 */
  483. /*                                                                   */
  484. /* Synopsis: length = SizeIFF( filename );                           */
  485. /* length:   (ULONG) Data length.                                    */
  486. /* filename: (STRPTR) Pointer to a string containing the name of the */
  487. /*           IFF file. For example "df0:Explosion.snd".              */
  488.  
  489. ULONG SizeIFF( filename )
  490. STRPTR filename;
  491. {
  492.   FILE  *file_ptr;              /* Pointer to a file. */
  493.   STRPTR empty_string = "    "; /* Four spaces. */ 
  494.   LONG dummy;                   /* A dummy variable. */
  495.   Voice8Header Header;          /* Voice8Header structure. */
  496.  
  497.  
  498.   /* Try to open the file: */
  499.   if( file_ptr = fopen( filename, "r" ) )
  500.   {
  501.     fread( (char *) empty_string, 4, 1, file_ptr );
  502.     if( strcmp( empty_string, "FORM" ) == 0)
  503.     {
  504.             /* Read twice: */
  505.       fread( (char *) empty_string, 4, 1, file_ptr );
  506.       fread( (char *) empty_string, 4, 1, file_ptr );
  507.  
  508.       /* Check if it is a "8SVX" file, or not: */
  509.             if( strcmp( empty_string, "8SVX" ) == 0 )
  510.       {
  511.         MoveTo( "VHDR", file_ptr );
  512.         fread( (char *) &dummy, sizeof( LONG ), 1, file_ptr );
  513.         fread( (char *) &Header, sizeof( Header ), 1, file_ptr );
  514.  
  515.             /* Close the file, and return the length: */
  516.         fclose( file_ptr );
  517.         return( Header.oneShotHiSamples + Header.repeatHiSamples );
  518.       }
  519.     }
  520.         /* Close the file: */
  521.     fclose( file_ptr );
  522.   }
  523.     /* Return zero: (ERROR) */
  524.   return( 0 );
  525. }
  526.  
  527.  
  528.  
  529. /* ReadIFF()                                                           */
  530. /* ReadIFF() reads an IFF file into the buffer, and returns the record */
  531. /* rate.                                                               */
  532. /*                                                                     */
  533. /* Synopsis: rate = ReadIFF( filename, pointer );                      */
  534. /* rate:     (UWORD) The record rate is returned if the sound was      */
  535. /*           successfully loaded, else 0.                              */
  536. /* filename: (STRPTR) Pointer to a string containing the name of the   */
  537. /*           sound file. For example "df0:Explosion.snd".              */
  538. /* pointer:  (CPTR) Actually a pointer to a SoundInfo structure.       */
  539.  
  540. UWORD ReadIFF( filename, info )
  541. STRPTR filename;
  542. struct SoundInfo *info;
  543. {
  544.   FILE  *file_ptr;              /* Pointer to a file. */
  545.   STRPTR empty_string = "    "; /* Four spaces. */ 
  546.   LONG dummy;                   /* A dummy variable. */
  547.   Voice8Header Header;          /* Voice8Header structure. */
  548.  
  549.  
  550.   /* Try to open the file: */
  551.   if( file_ptr = fopen( filename, "r" ) )
  552.   {
  553.     fread( (char *) empty_string, 4, 1, file_ptr );
  554.     if( strcmp( empty_string, "FORM" ) == 0 )
  555.     {
  556.             /* Read twice: */
  557.       fread( (char *) empty_string, 4, 1, file_ptr );
  558.       fread( (char *) empty_string, 4, 1, file_ptr );
  559.  
  560.       /* Check if it is a "8SVX" file, or not: */
  561.       if( strcmp( empty_string, "8SVX" ) == 0 )
  562.       {
  563.         MoveTo( "VHDR", file_ptr );
  564.         fread( (char *) &dummy, sizeof( LONG ), 1, file_ptr );
  565.         fread( (char *) &Header, sizeof( Header ), 1, file_ptr );
  566.  
  567.         MoveTo( "BODY", file_ptr );
  568.         fread( (char *) &dummy, sizeof( LONG ), 1, file_ptr );
  569.         fread( (char *) info->SoundBuffer, Header.oneShotHiSamples +
  570.                                  Header.repeatHiSamples, 1, file_ptr );
  571.  
  572.             /* Close the file, and return the record rate: */
  573.         fclose( file_ptr );
  574.         return( Header.samplesPerSec );
  575.       }
  576.     }
  577.         /* Close the file: */
  578.     fclose( file_ptr );
  579.   }
  580.     /* Return zero: (ERROR) */
  581.   return( 0 );
  582.  
  583.  
  584.  
  585. /* MoveTo()                                                  */
  586. /* MoveTo() walks through an IFF file, and looks for chunks. */
  587. /*                                                           */
  588. /* Synopsis: MoveTo( chunk, file_ptr );                      */
  589. /* chunk:    (STRPTR) The chunk we want to get to.           */
  590. /* file_ptr: (FILE *) Pointer to an already opened file.     */
  591.  
  592. BOOL MoveTo( check_string, file_ptr )
  593. STRPTR check_string;
  594. FILE *file_ptr;
  595. {
  596.   STRPTR empty_string = "    "; /* Four spaces. */ 
  597.   int skip, loop;               /* How much data should be skiped. */
  598.   LONG dummy;                   /* A dummy variable. */
  599.  
  600.  
  601.   /* As long as we have not reached the EOF, continue: */
  602.   while( !feof( file_ptr ) )
  603.   {
  604.     fread( (char *) empty_string, 4, 1, file_ptr);
  605.  
  606.     /* Have we found the right chunk? */    
  607.         if( strcmp( check_string, empty_string ) ==0 )
  608.       return( 0 ); /* YES! Return nothing. */
  609.  
  610.     /* Move foreward: */
  611.     fread( (char *) &skip, sizeof( LONG ), 1, file_ptr );
  612.     for( loop = 0; loop < skip; loop++ )
  613.       fread( (char *) &dummy, 1, 1, file_ptr);
  614.   }
  615. }
  616.