sounds.c

Go to the documentation of this file.
00001 
00002 /*  $Id: sounds.c 1201 2006-04-05 22:31:38Z karstenw $    */
00003 
00004 /******************************************************************************
00005 
00006     UserLand Frontier(tm) -- High performance Web content management,
00007     object database, system-level and Internet scripting environment,
00008     including source code editing and debugging.
00009 
00010     Copyright (C) 1992-2004 UserLand Software, Inc.
00011 
00012     This program is free software; you can redistribute it and/or modify
00013     it under the terms of the GNU General Public License as published by
00014     the Free Software Foundation; either version 2 of the License, or
00015     (at your option) any later version.
00016 
00017     This program is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020     GNU General Public License for more details.
00021 
00022     You should have received a copy of the GNU General Public License
00023     along with this program; if not, write to the Free Software
00024     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 
00026 ******************************************************************************/
00027 
00028 #include "frontier.h"
00029 #include "standard.h"
00030 
00031 #include "error.h"
00032 #include "strings.h"
00033 #include "sounds.h"
00034 
00035 #define squareWaveSynth 1
00036 #define ampCmd 43
00037 #define freqDurationCmd 40
00038 
00039 #if oldsounds
00040 
00041 static struct {
00042 
00043     short mode;
00044     
00045     Tone triplets [2];
00046     
00047     } myTone = {swMode, 0};
00048     
00049 static IOParam pb = {0, 0};
00050 
00051 
00052 
00053 boolean dosound (short duration, short amplitude, short frequency) {
00054     
00055     /*
00056     duration is in 60ths of a second.
00057     
00058     amplitude can range between 0 and 255, it determines the volume.
00059     
00060     10/12/91 dmb: limit amplitude to 255 explicity here
00061     */
00062 
00063     OSErr errcode;
00064 
00065     myTone.triplets [0].count = (short) (7833600 / frequency);
00066     
00067     myTone.triplets [0].amplitude = min (amplitude, 255);
00068     
00069     myTone.triplets [0].duration = duration;
00070 
00071     pb.ioRefNum = -4;
00072     
00073     pb.ioBuffer = (Ptr) &myTone;
00074     
00075     pb.ioReqCount = (long) sizeof (myTone);
00076 
00077     errcode = PBWrite ((ParmBlkPtr) &pb, false);
00078     
00079     return (errcode == noErr);
00080     } /*dosound*/
00081 
00082 #else
00083 
00084 boolean dosound (short duration, short amplitude, short frequency) {
00085     
00086 #ifdef MACVERSION
00087     //#if TARGET_API_MAC_CARBON
00088     //sysbeep();
00089     //return true;
00090     //#else
00091 
00092     SndChannelPtr channel;
00093     SndCommand cmd;
00094     long ltime;
00095     float note;
00096     OSErr err;
00097     
00098     channel = nil;
00099     
00100     err = SndNewChannel (&channel, squareWaveSynth, 0, nil);
00101     
00102     if (oserror (err))
00103         return (false);
00104     
00105     cmd.cmd = ampCmd;
00106     cmd.param1 = amplitude;
00107     cmd.param2 = 0;
00108     err = SndDoCommand (channel, &cmd, false);
00109     
00110     ltime = duration * (2000/60);
00111     
00112     ltime = min (infinity, ltime);
00113     
00114     note = (frequency / 129.0) / 69;
00115     
00116     note = 69 + 12.0 * (note - 1);
00117     
00118     cmd.cmd = freqDurationCmd;
00119     cmd.param1 = ltime;
00120     cmd.param2 = note;
00121     err = SndDoCommand (channel, &cmd, false);
00122     
00123     /*
00124     cmd.cmd = noteCmd;
00125     cmd.param1 = 30;
00126     cmd.param2 = $FF000000 + 83;
00127     err = SndDoCommand (channel, &cmd, false);
00128     
00129     
00130     cmd.cmd = quietCmd;
00131     cmd.param1 = 0;
00132     cmd.param2 = 0;
00133     err = SndDoCommand (channel, &cmd, false);
00134     */
00135     
00136     err = SndDisposeChannel (channel, false);
00137     
00138     return (!oserror (err));
00139 //#endif
00140 #endif
00141 
00142 #ifdef WIN95VERSION
00143     //NOTE:  Beep does not take amplitude.  
00144     //       Also the parameters are ignored on Windows 95/98
00145     long ltime;
00146 
00147     ltime = (duration * 1000L) / 60L;
00148     return (Beep (frequency, ltime));
00149 //  return (false); // *** WIN95 not implemented
00150 #endif
00151     } /*dosound*/
00152 
00153 #endif
00154 
00155 
00156 void motorsound (void) {
00157     
00158     dosound (1, 100, 100);
00159     } /*motorsound*/
00160 
00161 
00162 void ouch (void) {
00163     
00164 #ifdef MACVERSION
00165     sysbeep (); 
00166 #endif
00167 
00168 #ifdef WIN95VERSIOON
00169     Beep(1000, 500);
00170 #endif
00171     
00172     //dosound (1 /*duration*/, 250 /*amplitude*/, 14300 /*frequency*/);
00173     
00174     } /*ouch*/
00175 
00176 
00177 boolean playnamedsound (bigstring bsname) {
00178 
00179 #ifdef MACVERSION
00180     Handle hsound;
00181     
00182     hsound = GetNamedResource ('snd ', bsname);
00183     
00184     if (hsound == nil)
00185         return (false);
00186     
00187     return (SndPlay (nil, (SndListHandle) hsound, false) == noErr);
00188 #endif
00189 
00190 #ifdef WIN95VERSION
00191     char sndname[256];
00192     copyptocstring (bsname, sndname);
00193     return (PlaySound (sndname, NULL, SND_FILENAME | SND_NODEFAULT | SND_ASYNC));
00194 //  return (false); // *** WIN95 not implemented
00195 #endif
00196 
00197     } /*playnamedsound*/
00198 
00199 
00200 

Generated on Wed May 31 18:20:02 2006 for frontierkernel 10.1.10a by  doxygen 1.4.6