// // SmoothingModifier.m // WiiToMidi // // Created by Mike Verdone on 03/02/07. // Copyright 2007 __MyCompanyName__. All rights reserved. // #import "SmoothingModifier.h" #import "WiiStateArrayRing.h" @implementation SmoothingModifier -(id) init { [self setSmoothingFrames:4]; return self; } -(void) setSmoothingFrames: (int)frames { _frames = (frames >= 0) ? frames : 0; if (_stateRing) freeRing(_stateRing); if (_frames != 0) { _stateRing = createRing(_frames); } else { _stateRing = nil; } } -(void) manipulate:(WiiStateArray)state { // Copy raw values to the RAW value slots. memcpy(&(state[SA_ACC_RAWX]), &(state[SA_ACC_X]), 3); memcpy(&(state[SA_ACC_RAWNX]), &(state[SA_ACC_NX]), 3); // If smoothing frames is zero, do nothing. if (0 == _frames) return; // copy this state data into the ring memcpy(_stateRing->state, state, STATE_ARR_SIZE); // advance the ring _stateRing = _stateRing->next; // Average the array int i; WiiStateArrayNode* node = _stateRing; for (i = 0; i < SEND_ARR_SIZE; i++) { state[i] = 0; } do { for (i = 0; i < SEND_ARR_SIZE; i++) { state[i] += (node->state[i] / _frames); } node = node->next; } while (node != _stateRing); } -(int) smoothingFrames { return _frames; } @end