EasyPlayRecord.c

#include    <Quickdraw.h>
#include    <Windows.h>
#include    <dialogs.h>
#include    <OSEvents.h>
#include    <Memory.h>
#include    <StandardFile.h>
#include    <Sound.h>
#include    <SoundInput.h>
#include    <OSUtils.h>
 
#define TRUE            0xFF
#define FALSE           0
 
#ifdef powerc
   QDGlobals    qd;
#endif
 
 
main()
{
    Point               where = {20,20};
    Point               whereto = {100,100};
    OSErr               err;
    StandardFileReply   reply;
    short               refnum;
    Handle              SNDHand;
    SndChannelPtr       chan;
        
    InitGraf(&qd.thePort);
    FlushEvents(everyEvent, 0);
    InitWindows();
    InitDialogs(nil);
    InitCursor();
    
    StandardGetFile (nil, -1, nil, &reply);
 
    err = HOpen(reply.sfFile.vRefNum, reply.sfFile.parID, reply.sfFile.name, fsRdPerm, &refnum);
    
    if (err != noErr)
      Debugger();
    
    err = SndStartFilePlay (nil, refnum, 0, 74000, nil, nil, nil, TRUE);
    if (err != noErr)
        Debugger();
        
    SNDHand = NewHandle (0xc9000);
    if (MemError() != noErr || SNDHand == nil)
        Debugger();
 
    err = SndRecord (nil, whereto, siBestQuality, &SNDHand);
    if (err != noErr)
        Debugger();
        
    FSClose (refnum);
 
    chan = nil;
    err = SndNewChannel (&chan, 0, 0, nil);
    if (err != noErr)
        Debugger();
    
    err = SndPlay (chan, SNDHand, FALSE);
    if (err != noErr)
        Debugger();
 
    err = SndDisposeChannel (chan,FALSE);
    if (err != noErr)
        Debugger();
}