int main (int argc, char * const argv[]) { char inputFile[]="blip.mp3"; static const double threshold=0.50; int hardware=macbookpro; double x,y,z,prev_x,prev_y,prev_z; AudioFileID audioFile; CFURLRef theURL = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (UInt8*)inputFile, strlen(inputFile), false); XThrowIfError (AudioFileOpenURL (theURL, kAudioFileReadPermission, 0, &audioFile), "AudioFileOpenURL"); // get the number of channels of the file CAStreamBasicDescription fileFormat; UInt32 propsize = sizeof(CAStreamBasicDescription); XThrowIfError (AudioFileGetProperty(audioFile, kAudioFilePropertyDataFormat, &propsize, &fileFormat), "AudioFileGetProperty"); // lets set up our playing state now AUGraph theGraph; CAAudioUnit fileAU; // this makes the graph, the file AU and sets it all up for playing MakeSimpleGraph (theGraph, fileAU, fileFormat, audioFile); // now we load the file contents up for playback before we start playing // this has to be done the AU is initialized and anytime it is reset or uninitialized Float64 fileDuration = PrepareFileAU (fileAU, fileFormat, audioFile); printf ("file duration: %f secs\n", fileDuration); read_sms_real(hardware,&x,&y,&z); prev_x=x; prev_y=y; prev_z=z; for(;;) { read_sms_real(hardware,&x,&y,&z); //printf("x: %f y: %f z: %f\n",x,y,z); if(isDelta(threshold,x,y,z,prev_x,prev_y,prev_z)) XThrowIfError (AUGraphStart (theGraph), "AUGraphStart"); prev_x=x; prev_y=y; prev_z=z; } // sleep until the file is finished //usleep ((int)(fileDuration * 1000. * 1000.)); // lets clean up XThrowIfError (AUGraphStop (theGraph), "AUGraphStop"); XThrowIfError (AUGraphUninitialize (theGraph), "AUGraphUninitialize"); XThrowIfError (AudioFileClose (audioFile), "AudioFileClose"); XThrowIfError (AUGraphClose (theGraph), "AUGraphClose"); return 0; }
static PyObject* pymotion_read_real(PyObject *self, PyObject *args) { if (!PyArg_ParseTuple(args, "")) return NULL; double x, y, z; if (!read_sms_real(g_accelerometerType, &x, &y, &z)) { PyErr_SetString(PyExc_RuntimeError, "Failed to read accelerometer data."); return NULL; } return Py_BuildValue("(ddd)", x, y, z); }
//-------------------------------- bool ofxSuddenMotion::readMotion(){ if(!bHasHardware){ if(bVerbose)printf("ofxSuddenMotion - no hardware found / make sure to call setupHardware() first \n"); return false; } bool bRead = false; if( valueMode == OFX_SM_RAW ){ int rawX, rawY, rawZ; bRead = read_sms_raw(hardwareType, &rawX, &rawY, &rawZ); if(bRead){ actualX = (double)rawX; actualY = (double)rawY; actualZ = (double)rawZ; } }else if(valueMode == OFX_SM_REAL){ double realX, realY, realZ; bRead = read_sms_real(hardwareType, &realX, &realY, &realZ); if(bRead){ actualX = realX; actualY = realY; actualZ = realZ; } }else if(valueMode == OFX_SM_SCALED){ int scaledX, scaledY, scaledZ; bRead = read_sms_scaled(hardwareType, &scaledX, &scaledY, &scaledZ); if(bRead){ actualX = (double)scaledX; actualY = (double)scaledY; actualZ = (double)scaledZ; } }else{ if(bVerbose)printf("ofxSuddenMotion - incorrect value mode\n"); return false; } if( bRead ){ x = actualX - offsetX; y = actualY - offsetY; z = actualZ - offsetZ; //smooth values smoothX *= smoothPct; smoothY *= smoothPct; smoothZ *= smoothPct; smoothX += x * (1.0- smoothPct); smoothY += y * (1.0- smoothPct); smoothZ += z * (1.0- smoothPct); }else { if(bVerbose)printf("ofxSuddenMotion - problem reading sms data\n"); } return bRead; }