home *** CD-ROM | disk | FTP | other *** search
- /*
- * ⌐ Graeme Gerrard 1990
- * Faculty of Music, University of Melbourne
- * Parkville Victoria 3052 Australia.
- *
- * ARPANET: grae@murdu.ucs.unimelb.edu.au
- * telephone: (613) 344 4127, Fax: (613) 344 5346
- */
- #include "Music4C.h"
- #include <unix.h>
- #include "Music4C_Prototype.h"
- #include "SDtype.h"
-
- void prepareSDfile(double);
-
-
- void prepareSDfile(TotalDuration)
- double TotalDuration;
- {
- WaveRec Header;
- WavPtr HeaderPtr;
- register int i;
- double x;
- extern OSErr errnum;
- long aLong;
- int resid;
- extern double srate; /* sampling rate */
- extern Str255 SoundFileName;
- extern ioParam myIOParmBlk;
- extern Str255 theMess1;
-
- HeaderPtr = &Header;
-
- /* initialize Header info to default values */
- Header.HeaderSize = 1336;
- Header.Version = 0;
- Header.Preview = 0;
- Header.WPtr = 0L;
- Header.WPeek = 0L;
- Header.HInxPage = 0L;
- Header.HInxLine = 0L;
- Header.VInxPage = 0L;
- Header.VInxLine = 0L;
- Header.HCtlPage = 0L;
- Header.HCtlLine = 0L;
- Header.VCtlPage = 255L;
- Header.VCtlLine = 65536L;
- Header.VOffset = 0L;
- Header.HOffset = 0L;
- Header.VOffConst = -1L;
- Header.ZF.v = -256;
- Header.ZF.h = -128L;
- Header.SF.VFactor = 327L;
- Header.SF.VType = 1032;
- PstringCopy((char *)Header.SF.VString, "\p%Scale");
- Header.SF.HFactor = 1;
- Header.SF.HType = 30L;
- PstringCopy((char *)Header.SF.HString, "\p secs");
- Header.VScrUpdate = 0;
- Header.BufPtr = 0L;
- Header.BufBytes = 0L;
- Header.BufOffset = 0L;
- Header.WaveRgn = 0L;
- Header.ClipArea = 0L;
- Header.ScaleArea = 0L;
- Header.CtlWidth.top = 0;
- Header.CtlWidth.left = 29;
- Header.CtlWidth.bottom = 33;
- Header.CtlWidth.right = 15;
- Header.VScroll = 0L;
- Header.HScroll = 0L;
-
- aLong = (long)(TotalDuration * srate);
- resid = (int)(aLong % 512L);
- if ( resid != 0 ) {
- aLong += (long)(512 - resid) + 512L;;
- }
- Header.FileSize = aLong * sizeof(int);
- PstringCopy((char *)Header.BUName, "\p");
- PstringCopy((char *)Header.FileName, (char *)SoundFileName);
- Header.BURefNum = 0;
- Header.refNum = myIOParmBlk.ioRefNum;
- Header.vRefNum = myIOParmBlk.ioVRefNum;
- Header.BufChanged = 0;
- Header.FileChanged = 0;
- Header.NoBackup = 0;
- Header.Mode = 0;
- Header.Edit.HiAddr = 0L;
- Header.Edit.LoAddr = 0L;
- Header.Edit.ExtendSide = 0;
- Header.CursorPos = 0L;
- Header.CursorRgn = 0L;
- for ( i = 0; i < 10; i++ ) {
- Header.MarkerData[i].Free = 1;
- Header.MarkerData[i].Position = 0L;
- PstringCopy((char *)Header.MarkerData[i].Name, "\p");
- }
- Header.MarkerOffset = 0L;
- Header.LoopStart = -1L;
- Header.LoopEnd = -1L;
- Header.ZeroLineOn = 0;
- Header.CursorOn = 0;
- Header.ScalesOn = 511;
- PstringCopy((char *)Header.Comment, "\p");
- Header.SampRate = srate;
- x = (1.0/srate) * 1000000.0;
- Header.SampPeriod = (long)(x + 0.5);
- Header.SampSize = 16;
- PstringCopy((char *)Header.CodeType, "\pLinear");
- PstringCopy((char *)Header.UserStr1, "\p");
- Header.BufSize = 0L;
- Header.Loop2Start = -1L;
- Header.Loop2End = -1L;
- Header.Loop1Type = 1;
- Header.Loop2Type = 1;
- Header.User4 = 0;
-
- /* write out header info */
- myIOParmBlk.ioReqCount = Header.HeaderSize;
- myIOParmBlk.ioBuffer = (Ptr)HeaderPtr;
- if ( (errnum = PBWrite(&myIOParmBlk, FALSE)) != noErr ) {
- PstringCopy((char *)theMess1, "\pError writing Header to sample file");
- OSError(theMess1, NIL, NIL);
- }
- if ( myIOParmBlk.ioActCount != Header.HeaderSize) {
- PstringCopy((char *)theMess1, "\pError writing Header to file, wrote wrong number of bytes");
- OSError(theMess1, NIL, NIL);
- }
- }