home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************************************/
- /* */
- /* Module Name: LineRecord */
- /* */
- /* File Name: LineRecord.c */
- /* */
- /* © Apple Computer, Inc. 1994-1995 */
- /* All Rights Reserved */
- /* */
- /* Revision History: */
- /* */
- /* Date Who Modification */
- /* */
- /* 1994-05-20 Jaakko Railo Original version */
- /* 1994-08-06 Gary Anwyl Modified GetDNSndInOut to make this module */
- /* */
- /************************************************************************************************/
-
- /****************************************** DESCRIPTION ******************************************
-
- When this module is invoked it allocates a 500K buffer and records
- asynchronously from the telephone line until the buffer is filled or
- the user presses the mouse button. The module then uses the StandardFile
- interface to get the name of a file in which to store the sound in the
- form of a 'snd ' 128 resource. During the recording the elapsed time is
- printed in the log window.
-
- *************************************************************************************************/
-
- /******************************************** HEADERS *******************************************/
-
- #include "Events.h"
- #include "Resources.h"
- #include "Sound.h"
- #include "SoundInput.h"
- #include "TextUtils.h"
- #include "Types.h"
-
- #ifndef __TELEPHONES__
- #include "Telephones.h"
- #endif
-
- #include "TestModule.h"
-
- /****************************************** DEFINITIONS *****************************************/
-
- /****************************************** PROTOTYPES ******************************************/
-
- OSErr GetDeviceSettings (long myInRefNum, short *numChannels, Fixed *sampleRate, short *sampleSize, OSType *compressionType, Str255 dName);
- void RecordSnd (CHRSPtr paramPtr, long myInRefNum);
- void DoTest (CHRSPtr paramPtr);
-
- /************************************************************************************************/
- /************************************************************************************************/
-
-
- pascal short TestModule (CHRSPtr paramPtr)
- {
- short returnValue = noErr;
-
- if (paramPtr->version <= kTestModuleVersion) {
-
- DoTest (paramPtr);
-
- }
- else
- returnValue = kWrongVersion;
-
- return (returnValue);
- }
-
-
- OSErr GetDeviceSettings (long myInRefNum, short *numChannels, Fixed *sampleRate, short *sampleSize, OSType *compressionType, Str255 dName)
- {
- OSErr myErr;
-
- if (((myErr = SPBGetDeviceInfo (myInRefNum, siNumberChannels, (Ptr) numChannels)) == noErr) &&
- ((myErr = SPBGetDeviceInfo (myInRefNum, siSampleRate, (Ptr) sampleRate)) == noErr) &&
- ((myErr = SPBGetDeviceInfo (myInRefNum, siSampleSize, (Ptr) sampleSize)) == noErr) &&
- ((myErr = SPBGetDeviceInfo (myInRefNum, siCompressionType, (Ptr) compressionType)) == noErr) &&
- ((myErr = SPBGetDeviceInfo (myInRefNum, siDeviceName, (Ptr) dName)) == noErr))
- return (myErr);
- else
- return (myErr);
- }
-
-
- void RecordSnd (CHRSPtr paramPtr, long myInRefNum)
- {
- Handle mySndH;
- SPB mySPB;
- OSErr myErr;
- long myBuffSize;
- short myHeadrLen, myNumChans, mySampSize;
- Fixed mySampRate;
- OSType myCompType;
- Str255 myDevName;
- StandardFileReply sfReply;
- short fileRefNum, i;
- long tickCount, secCount;
-
- for (i=1000; i!=0; i -= 250) {
- mySndH = TempNewHandle(i*1024, &myErr);
- if (mySndH!=0 && myErr==noErr)
- break;
- }
-
- if (i==0) {
- Print (paramPtr, "NewHandle failed");
- return;
- }
-
- myErr = GetDeviceSettings (myInRefNum, &myNumChans, &mySampRate, &mySampSize, &myCompType, myDevName);
- // Print (paramPtr, "Number of channels : %d", myNumChans);
- // Print (paramPtr, "Sample rate : %lx", mySampRate);
- // Print (paramPtr, "Sample size : %d", mySampSize);
- // Print (paramPtr, "Compression type : %lx", myCompType);
- // Print (paramPtr, "Device name : %*.*s", myDevName[0], myDevName[0], &myDevName[1]);
- myErr = SetupSndHeader ((SndListHandle) mySndH, myNumChans, mySampRate, mySampSize, myCompType, 60, 0, &myHeadrLen);
- myBuffSize = GetHandleSize (mySndH) - myHeadrLen;
- HLock (mySndH);
- mySPB.inRefNum = myInRefNum;
- mySPB.count = myBuffSize;
- mySPB.milliseconds = 0;
- mySPB.bufferLength = myBuffSize;
- mySPB.bufferPtr = (Ptr)((long) *mySndH + myHeadrLen);
- mySPB.completionRoutine = nil;
- mySPB.interruptRoutine = nil;
- mySPB.userLong = 0;
- mySPB.error = noErr;
- mySPB.unused1 = 0;
- Print (paramPtr, "Start of recording (%ld KB)", GetHandleSize(mySndH)/1024);
- Print (paramPtr, "Click mouse to quit");
- myErr = SPBRecord (&mySPB, true);
- if (myErr != noErr) {
- Print (paramPtr, "SPBRecord failed: %d", myErr);
- goto exit1;
- }
- tickCount = TickCount();
- secCount = 0;
-
- while (1) {
- short recordingStatus, meterLevel;
- unsigned long totalSamplesToRecord, numberOfSamplesRecorded,totalMSecToRecord, numberOfMSecRecorded;
-
- if (Button())
- break;
-
- myErr = SPBGetRecordingStatus(myInRefNum, &recordingStatus, &meterLevel,
- &totalSamplesToRecord, &numberOfSamplesRecorded, &totalMSecToRecord,
- &numberOfMSecRecorded);
- if (myErr != noErr) {
- Print (paramPtr, "SPBGetRecordingStatus failed: %d", myErr);
- return;
- }
-
- if (recordingStatus <= 0)
- break;
-
- if ((TickCount() - tickCount) >= 60) {
- tickCount = TickCount();
- if ((++secCount % 5)==0)
- Print (paramPtr, " %4ld seconds", secCount);
- }
- }
-
- SPBStopRecording(myInRefNum);
- Print (paramPtr, "End of recording");
- HUnlock (mySndH);
- myErr = SetupSndHeader ((SndListHandle) mySndH, myNumChans, mySampRate, mySampSize, myCompType, 60, mySPB.count, &myHeadrLen);
- SetHandleSize(mySndH, mySPB.count+myHeadrLen);
-
- StandardPutFile("\pSave SND file as:", "\pGeoPortSND", &sfReply);
- if (sfReply.sfGood) {
- if (sfReply.sfReplacing)
- FSpDelete(&sfReply.sfFile);
- FSpCreateResFile(&sfReply.sfFile, 'movr', 'sfil', -1);
- myErr = ResError();
- if (myErr != noErr) {
- Print (paramPtr, "FSpCreateResFile failed: %d", myErr);
- goto exit1;
- }
- fileRefNum = FSpOpenResFile(&sfReply.sfFile, fsWrPerm);
- myErr = ResError();
- if (myErr != noErr) {
- Print (paramPtr, "FSpOpenResFile failed: %d", myErr);
- goto exit1;
- }
- AddResource(mySndH, 'snd ', 128, sfReply.sfFile.name);
- myErr = ResError();
- if (myErr != noErr) {
- Print (paramPtr, "AddResource failed: %d", myErr);
- goto exit2;
- }
- exit2:
- CloseResFile(fileRefNum);
- }
- exit1:
- DisposeHandle(mySndH);
- }
-
-
- void DoTest (CHRSPtr paramPtr)
- {
- TELHandle termHand = GetCurrentTELHandle (paramPtr);
- TELDNHandle dnHand;
- OSErr errCode;
- long inRefNum = 0;
- Str255 deviceName;
-
- if ((dnHand = GetDNHandle (paramPtr)) != nil) {
- if ((errCode = TELGetDNSoundInput (dnHand, deviceName)) == noErr &&
- (errCode = SPBOpenDevice (deviceName, siWritePermission, &inRefNum)) == noErr) {
- Print (paramPtr, "TELGetDNSoundInput --> DeviceName = %*.*s", deviceName[0], deviceName[0], &deviceName[1]);
- Print (paramPtr, "SPBOpenDevice --> inRefNum = %ld", inRefNum);
- RecordSnd (paramPtr, inRefNum);
-
- if ((errCode = SPBCloseDevice (inRefNum)) == noErr &&
- (errCode = TELDisposeDNSoundInput (dnHand, deviceName)) == noErr)
- Print (paramPtr, "TELDisposeDNSoundInput --> deviceName %*.*s disposed", deviceName[0], deviceName[0], &deviceName[1]);
- else
- Print (paramPtr, "### SPBCloseDevice/TELDisposeDNSoundInput failed : %d", errCode);
- }
- }
- else
- Print (paramPtr, "### Unable to retrieve the DN handle");
- }
-
-
-