home *** CD-ROM | disk | FTP | other *** search
/ CLIX - Fazer Clix Custa Nix / CLIX-CD.cdr / mac / lib / Mac / Sound.xs < prev    next >
Text File  |  1998-04-05  |  16KB  |  695 lines

  1. /* $Header: /home/neeri/MacCVS/MacPerl/perl/ext/Mac/ExtUtils/MakeToolboxModule,v 1.2 1997/11/18 00:52:19 neeri Exp 
  2.  *    Copyright (c) 1997 Matthias Neeracher
  3.  *
  4.  *    You may distribute under the terms of the Perl Artistic License,
  5.  *    as specified in the README file.
  6.  *
  7.  * $Log: MakeToolboxModule,v  Revision 1.2  1997/11/18 00:52:19  neeri
  8.  * MacPerl 5.1.5
  9.  * 
  10.  * Revision 1.1  1997/04/07 20:49:35  neeri
  11.  * Synchronized with MacPerl 5.1.4a1
  12.  * 
  13.  */
  14.  
  15. #define MAC_CONTEXT
  16.  
  17. #include "EXTERN.h"
  18. #include "perl.h"
  19. #include "XSUB.h"
  20. #include <Types.h>
  21. #include <Sound.h>
  22.  
  23. #ifndef __CFM68K__
  24. #include <FixMath.h>
  25. #else
  26. #define fixed1              ((Fixed) 0x00010000L)
  27. #define fract1              ((Fract) 0x40000000L)
  28. #define positiveInfinity    ((long)  0x7FFFFFFFL)
  29. #define negativeInfinity    ((long)  0x80000000L)
  30.  
  31. extern pascal long double Frac2X(Fract x) = 0xA845;
  32. extern pascal long double Fix2X(Fixed x) = 0xA843;
  33. extern pascal Fixed X2Fix(long double x) = 0xA844;
  34. extern pascal Fract X2Frac(long double x) = 0xA846;
  35.  
  36. #define UnsignedFixedMulDiv(x,y,z)      not_here("UnsignedFixedMulDiv")
  37. #define GetCompressionInfo(x,y,z,a,b)   not_here("GetCompressionInfo")
  38. #define SetSoundPreference(x,y,z)       not_here("SetSoundPreference")
  39. #define GetSoundPreference(x,y,z)       not_here("GetSoundPreference")
  40. #define GetCompressionName(x,y)         not_here("GetCompressionName")
  41. #endif
  42.  
  43. #define SndChannel  SndChannelPtr
  44.  
  45. static int
  46. not_here(s)
  47. char *s;
  48. {
  49.     croak("Mac::Sound::%s not implemented in CFM68K (Apple's fault)", s);
  50.     return -1;
  51. }
  52.  
  53. MODULE = Mac::Sound PACKAGE = Mac::Sound
  54.  
  55. =head2 Structures
  56.  
  57. =over 4
  58.  
  59. =cut
  60.  
  61. STRUCT SndCommand
  62.     U16             cmd;
  63.     short           param1;
  64.     long            param2;
  65.  
  66. STRUCT SCStatus
  67.     UnsignedFixed   scStartTime;
  68.     UnsignedFixed   scEndTime;
  69.     UnsignedFixed   scCurrentTime;
  70.     Boolean         scChannelBusy;
  71.     Boolean         scChannelDisposed;
  72.     Boolean         scChannelPaused;
  73.     Boolean         scUnused;
  74.     U32             scChannelAttributes;
  75.     long            scCPULoad;
  76.  
  77. STRUCT SMStatus
  78.     short           smMaxCPULoad;
  79.     short           smNumChannels;
  80.     short           smCurCPULoad;
  81.  
  82. STRUCT CompressionInfo
  83.     long            recordSize;
  84.     OSType          format;
  85.     short           compressionID;
  86.     U16             samplesPerPacket;
  87.     U16             bytesPerPacket;
  88.     U16             bytesPerFrame;
  89.     U16             bytesPerSample;
  90.  
  91. STRUCT SPB
  92.     long            inRefNum;                   /*reference number of sound input device*/
  93.     unsigned long   count;                      /*number of bytes to record*/
  94.     unsigned long   milliseconds;               /*number of milliseconds to record*/
  95.     unsigned long   bufferLength;               /*length of buffer in bytes*/
  96.     Ptr             bufferPtr;                  /*buffer to store sound data in*/
  97.     OSErr           error;                      /*error*/
  98.  
  99. =back
  100.  
  101. =head2 Functions
  102.  
  103. =over 4
  104.  
  105. =cut
  106.  
  107. void
  108. SysBeep(duration)
  109.     short   duration
  110.  
  111. MacOSRet
  112. SndDoCommand(chan, cmd, noWait)
  113.     SndChannel  chan
  114.     SndCommand &cmd
  115.     Boolean     noWait
  116.  
  117. MacOSRet
  118. SndDoImmediate(chan, cmd)
  119.     SndChannel  chan
  120.     SndCommand &cmd
  121.  
  122. SndChannel
  123. SndNewChannel(synth, init, callback=0)
  124.     short   synth
  125.     long    init
  126.     SV *    callback
  127.     CODE:
  128.     RETVAL = nil;
  129.     if (gLastMacOSErr = SndNewChannel(&RETVAL, synth, init, nil)) {
  130.         XSRETURN_UNDEF;
  131.     }
  132.     OUTPUT:
  133.     RETVAL
  134.  
  135. MacOSRet
  136. SndDisposeChannel(chan, quietNow=false)
  137.     SndChannel  chan
  138.     Boolean quietNow
  139.  
  140. MacOSRet
  141. _SndPlay(chan, sndHandle, async=false)
  142.     SndChannel  chan
  143.     Handle  sndHandle
  144.     Boolean async
  145.     CODE:
  146.     RETVAL = SndPlay(chan, (SndListHandle)sndHandle, async);
  147.     OUTPUT:
  148.     RETVAL
  149.  
  150. SndCommand
  151. SndControl(id, cmd)
  152.     short   id
  153.     SndCommand &cmd
  154.     CODE:
  155.     RETVAL = cmd;
  156.     if (gLastMacOSErr = SndControl(id, &RETVAL)) {
  157.         XSRETURN_UNDEF;
  158.     }
  159.     OUTPUT:
  160.     RETVAL
  161.  
  162. NumVersion
  163. SndSoundManagerVersion()
  164.  
  165. MacOSRet
  166. SndStartFilePlay(chan, fRefNum, resNum, bufferSize, theSelection, theCompletion=0, async=false)
  167.     SndChannel  chan
  168.     short   fRefNum
  169.     short   resNum
  170.     long    bufferSize
  171.     AudioSelection  &theSelection
  172.     SV *    theCompletion
  173.     Boolean async
  174.     CODE:
  175.     RETVAL =
  176.         SndStartFilePlay(
  177.             chan, fRefNum, resNum, bufferSize, nil, &theSelection, nil, async);
  178.     OUTPUT:
  179.     RETVAL
  180.  
  181. MacOSRet
  182. SndPauseFilePlay(chan)
  183.     SndChannel  chan
  184.  
  185. MacOSRet
  186. SndStopFilePlay(chan, quietNow)
  187.     SndChannel  chan
  188.     Boolean quietNow
  189.  
  190. SCStatus
  191. SndChannelStatus(chan)
  192.     SndChannel  chan
  193.     CODE:
  194.     if (gLastMacOSErr = SndChannelStatus(chan, sizeof(RETVAL), &RETVAL)) {
  195.         XSRETURN_UNDEF;
  196.     }
  197.     OUTPUT:
  198.     RETVAL
  199.  
  200. SMStatus
  201. SndManagerStatus()
  202.     CODE:
  203.     if (gLastMacOSErr = SndManagerStatus(sizeof(RETVAL), &RETVAL)) {
  204.         XSRETURN_UNDEF;
  205.     }
  206.     OUTPUT:
  207.     RETVAL
  208.  
  209. short
  210. SndGetSysBeepState()
  211.     CODE:
  212.     SndGetSysBeepState(&RETVAL);
  213.     OUTPUT:
  214.     RETVAL
  215.  
  216. MacOSRet
  217. SndSetSysBeepState(sysBeepState)
  218.     short   sysBeepState
  219.  
  220. =begin ignore
  221.  
  222. MacOSRet
  223. SndPlayDoubleBuffer(chan, theParams)
  224.     SndChannel  chan
  225.     SndDoubleBufferHeaderPtr    theParams
  226.  
  227. =end ignore
  228.  
  229. =cut
  230.  
  231. NumVersion
  232. MACEVersion()
  233.  
  234. void
  235. Comp3to1(inBuffer, inState=, numChannels=1, whichChannel=1)
  236.     SV *            inBuffer
  237.     StateBlock      inState
  238.     unsigned long   numChannels
  239.     unsigned long   whichChannel
  240.     PPCODE:
  241.     {
  242.         unsigned long   cnt = SvCUR(inBuffer);
  243.         SV *            outBuffer = newSVpv("", cnt / 3);
  244.         StateBlock      outState;
  245.         Comp3to1(
  246.             SvPV(inBuffer, na), SvPV(outBuffer, na), cnt, 
  247.             (items > 1) ? &inState : nil, &outState, numChannels, whichChannel);
  248.         PUSHs(sv_2mortal(outBuffer));
  249.         if (GIMME == G_ARRAY) {
  250.             XS_PUSH(StateBlock, outState);
  251.         }
  252.     }
  253.  
  254. void
  255. Exp1to3(inBuffer, inState=, numChannels=1, whichChannel=1)
  256.     SV *            inBuffer
  257.     StateBlock      inState
  258.     unsigned long   numChannels
  259.     unsigned long   whichChannel
  260.     PPCODE:
  261.     {
  262.         unsigned long   cnt = SvCUR(inBuffer) / 2;
  263.         SV *            outBuffer = newSVpv("", cnt*6);
  264.         StateBlock      outState;
  265.         Exp1to3(
  266.             SvPV(inBuffer, na), SvPV(outBuffer, na), cnt, 
  267.             (items > 1) ? &inState : nil, &outState, numChannels, whichChannel);
  268.         PUSHs(sv_2mortal(outBuffer));
  269.         if (GIMME == G_ARRAY) {
  270.             XS_PUSH(StateBlock, outState);
  271.         }
  272.     }
  273.  
  274. void
  275. Comp6to1(inBuffer, inState=, numChannels=1, whichChannel=1)
  276.     SV *            inBuffer
  277.     StateBlock      inState
  278.     unsigned long   numChannels
  279.     unsigned long   whichChannel
  280.     PPCODE:
  281.     {
  282.         unsigned long   cnt = SvCUR(inBuffer);
  283.         SV *            outBuffer = newSVpv("", cnt / 6);
  284.         StateBlock      outState;
  285.         Comp6to1(
  286.             SvPV(inBuffer, na), SvPV(outBuffer, na), cnt, 
  287.             (items > 1) ? &inState : nil, &outState, numChannels, whichChannel);
  288.         PUSHs(sv_2mortal(outBuffer));
  289.         if (GIMME == G_ARRAY) {
  290.             XS_PUSH(StateBlock, outState);
  291.         }
  292.     }
  293.  
  294. void
  295. Exp1to6(inBuffer, inState=, numChannels=1, whichChannel=1)
  296.     SV *            inBuffer
  297.     StateBlock      inState
  298.     unsigned long   numChannels
  299.     unsigned long   whichChannel
  300.     PPCODE:
  301.     {
  302.         unsigned long   cnt = SvCUR(inBuffer);
  303.         SV *            outBuffer = newSVpv("", cnt * 6);
  304.         StateBlock      outState;
  305.         Exp1to6(
  306.             SvPV(inBuffer, na), SvPV(outBuffer, na), cnt, 
  307.             (items > 1) ? &inState : nil, &outState, numChannels, whichChannel);
  308.         PUSHs(sv_2mortal(outBuffer));
  309.         if (GIMME == G_ARRAY) {
  310.             XS_PUSH(StateBlock, outState);
  311.         }
  312.     }
  313.  
  314. long
  315. GetSysBeepVolume()
  316.     CODE:
  317.     if (gLastMacOSErr = GetSysBeepVolume(&RETVAL)) {
  318.         XSRETURN_UNDEF;
  319.     }
  320.     OUTPUT:
  321.     RETVAL
  322.  
  323. MacOSRet
  324. SetSysBeepVolume(level)
  325.     long    level
  326.  
  327. long
  328. GetDefaultOutputVolume()
  329.     CODE:
  330.     if (gLastMacOSErr = GetDefaultOutputVolume(&RETVAL)) {
  331.         XSRETURN_UNDEF;
  332.     }
  333.     OUTPUT:
  334.     RETVAL
  335.  
  336. MacOSRet
  337. SetDefaultOutputVolume(level)
  338.     long    level
  339.  
  340. long
  341. GetSoundHeaderOffset(sndHandle)
  342.     Handle  sndHandle
  343.     CODE:
  344.     if (gLastMacOSErr = GetSoundHeaderOffset((SndListHandle)sndHandle, &RETVAL)) {
  345.         XSRETURN_UNDEF;
  346.     }
  347.     OUTPUT:
  348.     RETVAL
  349.  
  350. UnsignedFixed
  351. UnsignedFixedMulDiv(value, multiplier, divisor)
  352.     UnsignedFixed   value
  353.     UnsignedFixed   multiplier
  354.     UnsignedFixed   divisor
  355.  
  356. CompressionInfo
  357. GetCompressionInfo(compressionID, format, numChannels, sampleSize)
  358.     short   compressionID
  359.     OSType  format
  360.     short   numChannels
  361.     short   sampleSize
  362.     CODE:
  363.     if (gLastMacOSErr = 
  364.         GetCompressionInfo(
  365.             compressionID, format, numChannels, sampleSize, &RETVAL)
  366.     ) {
  367.         XSRETURN_UNDEF;
  368.     }
  369.     OUTPUT:
  370.     RETVAL
  371.  
  372. MacOSRet
  373. SetSoundPreference(theType, name, settings)
  374.     OSType  theType
  375.     Str255  name
  376.     Handle  settings
  377.  
  378. MacOSRet
  379. _GetSoundPreference(theType, name, settings)
  380.     OSType  theType
  381.     Str255  name
  382.     Handle  settings
  383.     CODE:
  384.     RETVAL = GetSoundPreference(theType, name, settings);
  385.     OUTPUT:
  386.     RETVAL
  387.  
  388. =begin ignore
  389.  
  390. MacOSRet
  391. OpenMixerSoundComponent(outputDescription, outputFlags, mixerComponent)
  392.     SoundComponentDataPtr   outputDescription
  393.     long    outputFlags
  394.     ComponentInstance * mixerComponent
  395.  
  396. MacOSRet
  397. CloseMixerSoundComponent(ci)
  398.     ComponentInstance   ci
  399.  
  400. MacOSRet
  401. SndGetInfo(chan, selector, infoPtr)
  402.     SndChannel  chan
  403.     OSType  selector
  404.     void *  infoPtr
  405.  
  406. MacOSRet
  407. SndSetInfo(chan, selector, infoPtr)
  408.     SndChannel  chan
  409.     OSType  selector
  410.     const void *    infoPtr
  411.  
  412. MacOSRet
  413. GetSoundOutputInfo(outputDevice, selector, infoPtr)
  414.     Component   outputDevice
  415.     OSType  selector
  416.     void *  infoPtr
  417.  
  418. MacOSRet
  419. SetSoundOutputInfo(outputDevice, selector, infoPtr)
  420.     Component   outputDevice
  421.     OSType  selector
  422.     const void *    infoPtr
  423.  
  424. =end ignore
  425.  
  426. =cut
  427.  
  428. Str255
  429. GetCompressionName(compressionType)
  430.     OSType  compressionType
  431.     CODE:
  432.     if (gLastMacOSErr = GetCompressionName(compressionType, RETVAL)) {
  433.         XSRETURN_UNDEF;
  434.     }
  435.     OUTPUT:
  436.     RETVAL
  437.  
  438. =begin ignore
  439.  
  440. MacOSRet
  441. SoundConverterOpen(inputFormat, outputFormat, sc)
  442.     const SoundComponentData *  inputFormat
  443.     const SoundComponentData *  outputFormat
  444.     SoundConverter *    sc
  445.  
  446. MacOSRet
  447. SoundConverterClose(sc)
  448.     SoundConverter  sc
  449.  
  450. MacOSRet
  451. SoundConverterGetBufferSizes(sc, inputBytesTarget, inputFrames, inputBytes, outputBytes)
  452.     SoundConverter  sc
  453.     unsigned long   inputBytesTarget
  454.     unsigned long * inputFrames
  455.     unsigned long * inputBytes
  456.     unsigned long * outputBytes
  457.  
  458. MacOSRet
  459. SoundConverterBeginConversion(sc)
  460.     SoundConverter  sc
  461.  
  462. MacOSRet
  463. SoundConverterConvertBuffer(sc, inputPtr, inputFrames, outputPtr, outputFrames, outputBytes)
  464.     SoundConverter  sc
  465.     const void *    inputPtr
  466.     unsigned long   inputFrames
  467.     void *  outputPtr
  468.     unsigned long * outputFrames
  469.     unsigned long * outputBytes
  470.  
  471. MacOSRet
  472. SoundConverterEndConversion(sc, outputPtr, outputFrames, outputBytes)
  473.     SoundConverter  sc
  474.     void *  outputPtr
  475.     unsigned long * outputFrames
  476.     unsigned long * outputBytes
  477.  
  478. =end ignore
  479.  
  480. =cut
  481.  
  482. NumVersion
  483. SPBVersion()
  484.         
  485.  
  486. Handle
  487. SndRecord(filterProc, corner, quality)
  488.     SV *    filterProc
  489.     Point   corner
  490.     OSType  quality
  491.     CODE:
  492.     {
  493.         RETVAL = nil;
  494.         if (gLastMacOSErr = 
  495.             SndRecord(nil, corner, quality, (SndListHandle *)&RETVAL)
  496.         ) {
  497.             XSRETURN_UNDEF;
  498.         }
  499.     }
  500.     OUTPUT:
  501.     RETVAL
  502.  
  503. MacOSRet
  504. SndRecordToFile(filterProc, corner, quality, fRefNum)
  505.     SV *    filterProc
  506.     Point   corner
  507.     OSType  quality
  508.     short   fRefNum
  509.     CODE:
  510.     RETVAL = SndRecordToFile(nil, corner, quality, fRefNum);
  511.     OUTPUT:
  512.     RETVAL
  513.  
  514. MacOSRet
  515. SPBSignInDevice(deviceRefNum, deviceName)
  516.     short   deviceRefNum
  517.     Str255  deviceName
  518.  
  519. MacOSRet
  520. SPBSignOutDevice(deviceRefNum)
  521.     short   deviceRefNum
  522.  
  523. void
  524. SPBGetIndexedDevice(count)
  525.     short   count
  526.     PPCODE:
  527.     {
  528.         Str255  name;
  529.         Handle  icon;
  530.         
  531.         if (gLastMacOSErr = SPBGetIndexedDevice(count, name, &icon)) {
  532.             XSRETURN_UNDEF;
  533.         }
  534.         XS_PUSH(Str255, name);
  535.         if (GIMME == G_ARRAY) {
  536.             XS_XPUSH(Handle, icon);
  537.         } else {
  538.             DisposeHandle(icon);
  539.         }
  540.     }
  541.  
  542. long
  543. SPBOpenDevice(deviceName, permission)
  544.     Str255  deviceName
  545.     short   permission
  546.     CODE:
  547.     if (gLastMacOSErr = SPBOpenDevice(deviceName, permission, &RETVAL)) {
  548.         XSRETURN_UNDEF;
  549.     }
  550.     OUTPUT:
  551.     RETVAL
  552.  
  553. MacOSRet
  554. SPBCloseDevice(inRefNum)
  555.     long    inRefNum
  556.  
  557. MacOSRet
  558. SPBRecord(inParamPtr, asynchFlag=false)
  559.     SPB    &inParamPtr
  560.     Boolean asynchFlag
  561.  
  562. MacOSRet
  563. SPBRecordToFile(fRefNum, inParamPtr, asynchFlag=false)
  564.     short   fRefNum
  565.     SPB    &inParamPtr
  566.     Boolean asynchFlag
  567.  
  568. MacOSRet
  569. SPBPauseRecording(inRefNum)
  570.     long    inRefNum
  571.  
  572. MacOSRet
  573. SPBResumeRecording(inRefNum)
  574.     long    inRefNum
  575.  
  576. MacOSRet
  577. SPBStopRecording(inRefNum)
  578.     long    inRefNum
  579.  
  580. void
  581. SPBGetRecordingStatus(inRefNum)
  582.     long    inRefNum
  583.     PPCODE:
  584.     {
  585.         short recordingStatus;
  586.         short meterLevel;
  587.         unsigned long totalSamplesToRecord;
  588.         unsigned long numberOfSamplesRecorded;
  589.         unsigned long totalMsecsToRecord;
  590.         unsigned long numberOfMsecsRecorded;
  591.         
  592.         if (gLastMacOSErr = 
  593.             SPBGetRecordingStatus(
  594.                 inRefNum, &recordingStatus, &meterLevel,
  595.                 &totalSamplesToRecord, &numberOfSamplesRecorded,
  596.                 &totalMsecsToRecord, &numberOfMsecsRecorded)
  597.         ) {
  598.             XSRETURN_EMPTY;
  599.         }
  600.         XS_XPUSH(short, recordingStatus);
  601.         XS_XPUSH(short, meterLevel);
  602.         XS_XPUSH(U32, totalSamplesToRecord);
  603.         XS_XPUSH(U32, numberOfSamplesRecorded);
  604.         XS_XPUSH(U32, totalMsecsToRecord);
  605.         XS_XPUSH(U32, numberOfMsecsRecorded);
  606.     }
  607.  
  608. =begin ignore
  609.  
  610. MacOSRet
  611. SPBGetDeviceInfo(inRefNum, infoType, infoData)
  612.     long    inRefNum
  613.     OSType  infoType
  614.     void *  infoData
  615.  
  616. MacOSRet
  617. SPBSetDeviceInfo(inRefNum, infoType, infoData)
  618.     long    inRefNum
  619.     OSType  infoType
  620.     void *  infoData
  621.  
  622. =end ignore
  623.  
  624. long
  625. SPBMillisecondsToBytes(inRefNum)
  626.     long    inRefNum
  627.     CODE:
  628.     if (gLastMacOSErr = SPBMillisecondsToBytes(inRefNum, &RETVAL)) {
  629.         XSRETURN_UNDEF;
  630.     }
  631.     OUTPUT:
  632.     RETVAL
  633.     
  634. long
  635. SPBBytesToMilliseconds(inRefNum)
  636.     long    inRefNum
  637.     CODE:
  638.     if (gLastMacOSErr = SPBBytesToMilliseconds(inRefNum, &RETVAL)) {
  639.         XSRETURN_UNDEF;
  640.     }
  641.     OUTPUT:
  642.     RETVAL
  643.  
  644. short
  645. SetupSndHeader(sndHandle, numChannels, sampleRate, sampleSize, compressionType, baseNote, numBytes)
  646.     Handle  sndHandle
  647.     short   numChannels
  648.     UnsignedFixed   sampleRate
  649.     short   sampleSize
  650.     OSType  compressionType
  651.     short   baseNote
  652.     unsigned long   numBytes
  653.     CODE:
  654.     if (gLastMacOSErr = 
  655.         SetupSndHeader(
  656.             (SndListHandle)sndHandle, numChannels, sampleRate, sampleSize, 
  657.             compressionType, baseNote, numBytes, &RETVAL)
  658.     ) {
  659.         XSRETURN_UNDEF;
  660.     }
  661.     OUTPUT:
  662.     RETVAL
  663.  
  664. MacOSRet
  665. SetupAIFFHeader(fRefNum, numChannels, sampleRate, sampleSize, compressionType, numBytes, numFrames)
  666.     short   fRefNum
  667.     short   numChannels
  668.     UnsignedFixed   sampleRate
  669.     short   sampleSize
  670.     OSType  compressionType
  671.     unsigned long   numBytes
  672.     unsigned long   numFrames
  673.  
  674. =begin ignore
  675.  
  676. MacOSRet
  677. ParseAIFFHeader(fRefNum, sndInfo, numFrames, dataOffset)
  678.     short   fRefNum
  679.     SoundComponentData *    sndInfo
  680.     unsigned long * numFrames
  681.     unsigned long * dataOffset
  682.  
  683. MacOSRet
  684. ParseSndHeader(sndHandle, sndInfo, numFrames, dataOffset)
  685.     SndListHandle   sndHandle
  686.     SoundComponentData *    sndInfo
  687.     unsigned long * numFrames
  688.     unsigned long * dataOffset
  689.  
  690. =end ignore
  691.  
  692. =back
  693.  
  694. =cut
  695.