home *** CD-ROM | disk | FTP | other *** search
- /***********************************************************/
- /* */
- /* Amiga C Encyclopedia (ACE) V3.0 Amiga C Club (ACC) */
- /* ------------------------------- ------------------ */
- /* */
- /* Book: ACM Sound Amiga C Club */
- /* Chapter: IncludeSound Tulevagen 22 */
- /* File: Example.c 181 41 LIDINGO */
- /* Author: Anders Bjerin SWEDEN */
- /* Date: 92-05-10 */
- /* Version: 1.15 */
- /* */
- /* Copyright 1992, Anders Bjerin - Amiga C Club (ACC) */
- /* */
- /* Registered members may use this program freely in their */
- /* own commercial/noncommercial programs/articles. */
- /* */
- /***********************************************************/
-
- /* IncludeSound allows you to include the sound files as normal source */
- /* code which is then compiled and linked together with your own programs. */
- /* (Use the "PrintSound" program to convert sound files into source code.) */
- /* The advantage with this compared to use EasySound is that your program */
- /* do not need to load any sound files which means your programs will be */
- /* faster. Since you do not need to load any sound files your program will */
- /* also be smaller. Finally, since the sound is included with the program */
- /* itself you do not need to include a lot of extra files together with */
- /* your program, and your program will be more "portable". */
- /* */
- /* Note that you should only use IncludeSound in programs that use short */
- /* samples. If you use long ones (several seconds or so) it is best to */
- /* stick to EasySound. Even short samples seems to generate very large */
- /* files when converted to source code. (However, once the file has been */
- /* compiled it will not use more memory than normal.) */
- /* */
- /* IncludeSound is specially intended for programs that only use some */
- /* small sound effects that does not need to be replaced. You can of course */
- /* combine IncludeSound with EasySound in order to have some samples */
- /* fixed (included in the program itself) and some "lose". If you want to */
- /* do this you should only link your program with the EasySound.o module. */
- /* (IncludeSound.o is exactly the same as EasySound.o except that all */
- /* sound loading routines have been removed.) */
- /* */
- /* */
- /* I N S T R U C T I O N S */
- /* ----------------------- */
- /* */
- /* 1. Convert the sound file into source code with help of the PrintSound */
- /* program. */
- /* */
- /* PrintSound > "output file" "sound file" "name of array" */
- /* */
- /* Example: "PrintSound > RAM:Data Explosion.snd Bang" */
- /* */
- /* PrintSound will load file "Explosion.snd", and print the sound */
- /* data in file "RAM:Data". The SoundInfo structure will be called */
- /* "Bang". */
- /* */
- /* */
- /* 2. Include the file PrintSound has generated into your own program. */
- /* */
- /* */
- /* 3. Use the function PlaySound() to play the sound date. */
- /* */
- /* Synopsis: ok = PlaySound( ptr, vol, cha, pri, drate, times, ddata, */
- /* time, wait ); */
- /* */
- /* ok: (BOOL) If the sound was played successfully TRUE is */
- /* returned, else FALSE. */
- /* */
- /* ptr: (struct SoundInfo *) Pointer to the SoundInfo structure which */
- /* has been generated by PrintSound. */
- /* */
- /* vol: (UWORD) Volume, 0 to 64. */
- /* */
- /* cha: (UBYTE) Which channel should be used. (LEFT0, RIGHT0, */
- /* RIGHT1 or LEFT1) */
- /* */
- /* pri (BYTE) What sound priority should be used. For normal sound */
- /* effects, set the priority to "SOUND_PRI_EFFECT". See file */
- /* "IncludeSound.h" for a complete list of recommended priorities. */
- /* */
- /* drate: (WORD) Delta rate. When the sound is prepared, the record */
- /* rate is automatically stored in the SoundInfo structure, */
- /* so if you do not want to change the rate, write NORMALRATE. */
- /* */
- /* times: (UWORD) How many times the sound should be played. If you */
- /* want to play the sound forever, write NONSTOP. (To stop a */
- /* sound call the function StopSound().) */
- /* */
- /* ddata: (ULONG) Where in the sound data we should start to play. (If */
- /* you want to start at the beginning of the sound data set ddata */
- /* to 0.) */
- /* */
- /* time: (ULONG) For how long time the sound should be played. If you */
- /* want to play all of the sound data set time to 0. */
- /* */
- /* wait: (BOOL) If you want that the program waits for the sound to */
- /* to be completed set the flag "WAIT". If you do not want to */
- /* wait for the sound to be completed, set the flag "DO_NOT_WAIT". */
- /* */
- /* */
- /* 4. Remember to "stop" all sound channels you have used before your */
- /* program terminates. Use the function StopSound(). */
- /* */
- /* Synopsis: StopSound( channel ); */
- /* */
- /* channel: (UBYTE) The audio channel that should be stopped. (LEFT0, */
- /* LEFT1, RIGHT0 or RIGHT1.) */
- /* */
- /* 5. Compile your program as normal, and when you link it include the */
- /* file "IncludeSound.o". (See file Example.lnk for more information.) */
- /* */
- /* */
- /* ------------------------------------------------------------------------- */
- /* Special thanks to Michael Loughman who wrote to me about his excellent */
- /* idea to "include" sound. */
- /* ------------------------------------------------------------------------- */
-
-
-
- /* Include some important header files: */
- #include <exec/types.h> /* Declares CPTR, BOOL and STRPTR. */
- #include "IncludeSound.h" /* Declares LEFT0, LEFT1, RIGHT0, etc. */
-
-
-
- /************************************/
- /* SoundData prepared by PrintSound */
- /* Anders Bjerin Amiga C Club */
- /* */
- /* File name: Beep.snd */
- /* Record Rate: 10100 */
- /* File Length: 602 */
- /************************************/
-
- BYTE chip Beep_data[]=
- {
- 4,11,9,0,-11,-9,3,15,17,-6,-34,
- -31,22,93,63,-20,-106,-85,0,104,84,-9,
- -98,-68,17,114,57,-42,-109,-33,61,101,9,
- -88,-95,7,101,46,-39,-109,-33,60,114,14,
- -79,-79,19,112,46,-53,-111,-20,73,104,3,
- -95,-80,22,111,36,-57,-111,-19,84,96,-11,
- -103,-63,34,114,23,-71,-107,-7,90,82,-15,
- -106,-55,47,119,22,-69,-103,-4,98,87,-20,
- -107,-53,46,117,20,-77,-103,1,100,73,-25,
- -111,-47,58,122,17,-77,-96,6,111,66,-26,
- -107,-39,60,122,22,-79,-93,19,117,53,-39,
- -109,-23,82,115,3,-90,-74,30,122,41,-57,
- -111,-14,85,100,-6,-103,-68,42,123,28,-61,
- -109,-11,93,101,-9,-103,-61,41,123,28,-68,
- -106,-3,96,92,-11,-107,-58,52,123,19,-73,
- -100,0,104,87,-20,-109,-49,55,119,12,-85,
- -96,11,111,73,-25,-114,-41,68,115,4,-88,
- -85,15,119,65,-38,-114,-30,73,112,4,-93,
- -87,23,119,50,-42,-111,-25,79,114,3,-92,
- -82,22,120,47,-52,-114,-19,82,107,-1,-100,
- -73,38,122,28,-66,-101,-6,100,92,-25,-111,
- -46,58,119,9,-88,-92,14,114,63,-36,-115,
- -33,76,109,-4,-96,-76,23,127,58,-44,-115,
- -26,76,103,0,-96,-85,19,119,57,-38,-114,
- -34,74,103,-4,-96,-77,25,122,44,-57,-112,
- -14,88,84,-19,-109,-61,47,123,23,-74,-103,
- 6,109,57,-44,-117,-33,69,111,6,-95,-88,
- 25,117,39,-53,-119,-25,85,100,-7,-104,-74,
- 33,123,36,-61,-115,-9,93,84,-15,-111,-63,
- 52,122,19,-73,-106,6,111,61,-33,-114,-38,
- 68,114,7,-84,-88,23,117,44,-50,-114,-17,
- 88,93,-4,-101,-76,41,120,28,-60,-107,-6,
- 103,80,-19,-109,-58,50,122,23,-71,-101,7,
- 109,68,-22,-111,-52,65,119,12,-79,-88,19,
- 120,58,-41,-114,-28,80,101,-1,-98,-73,42,
- 122,30,-61,-107,-4,106,77,-26,-106,-39,71,
- 109,7,-88,-88,30,119,42,-49,-109,-14,100,
- 92,-11,-101,-66,47,119,33,-63,-107,-1,103,
- 73,-22,-106,-49,69,109,11,-80,-90,22,111,
- 49,-46,-106,-22,84,88,-4,-92,-68,52,107,
- 23,-63,-95,3,101,66,-28,-98,-36,69,95,
- 7,-79,-69,38,100,31,-53,-87,-3,85,63,
- -26,-88,-38,58,88,14,-68,-73,20,87,41,
- -38,-80,-17,68,63,-14,-73,-42,42,79,22,
- -50,-63,11,73,44,-25,-68,-22,53,65,0,
- -58,-44,26,69,28,-41,-61,-3,58,46,-15,
- -65,-38,34,65,17,-42,-53,3,57,38,-23,
- -55,-17,41,49,-1,-52,-41,25,61,22,-38,
- -58,-6,60,53,-7,-60,-39,31,68,25,-39,
- -65,-4,57,47,-11,-60,-36,34,57,11,-44,
- -58,-1,55,41,-12,-55,-31,30,53,17,-33,
- -50,-4,44,39,-3,-42,-30,19,41,12,-26,
- -36,-3,34,31,-3,-34,-28,7,42,20,-12,
- -28,-9,17,22,1,-19,-15,3,15,7,-9,
- -14,-3,9,9,-1,-7,-4,3
- };
-
- struct SoundInfo Beep=
- {
- Beep_data, /* WaveForm Buffers */
- 10100, /* Record Rate */
- 602 /* WaveForm Length */
- };
-
- /************************************/
- /* End of sound: Beep.snd */
- /************************************/
-
-
-
- /* Declare the functions in this module: */
- void main();
-
-
- void main()
- {
- int loop;
-
-
- printf("\nINCLUDE-SOUND\n");
- printf("Amiga C Club (ACC)\nAnders Bjerin\nTulevagen 22\n");
- printf("181 41 LIDINGO\nSWEDEN\n\n");
-
-
- for( loop=0; loop < 10; loop++ )
- {
- /* Play the sound: NOTE! Do NOT forget to put a "&" sign infront */
- /* of the structure name! */
- if( PlaySound( &Beep, MAXVOLUME, RIGHT1, SOUND_PRI_EFFECT,
- NORMALRATE, ONCE, 0, 0, DO_NOT_WAIT ) )
- printf( "OK!\n" );
- else
- printf( "ERROR!\n" );
-
- /* Wait one second... */
- Delay( 1 * 50 );
- }
-
-
- /* Remember to stop all sound channels you have used! */
- StopSound( RIGHT1 );
- }
-