void processMIDINoteOFF(void) { midi_notesON[midi_data1] = 0; notesON--; if (notesON) { if (midi_data1 == midi_note) //Si on relache la note la plus aigue { u8 x = midi_data1; while (midi_notesON[x] == 0 && x) x--; midi_note = x; // on jouera la note enfoncee en dessous calculatePitch(read_period_preset(&OSC1), &OSC1); calculatePitch(read_period_preset(&OSC2), &OSC2); } } else { OSC1.Env.cur_env = REL; OSC1.Env.compteur = 0; OSC2.Env.cur_env = REL; OSC2.Env.compteur = 0; midi_note = 0; u8 x; for (x = 0; x < 88; x++) midi_notesON[x] = 0; } resetMIDIMessage(); }
void processMIDINoteON(void) { if (midi_data2 && !midi_notesON[midi_data1]) { midi_notesON[midi_data1] = midi_data2; if (!notesON) { OSC1.Env.compteur = 0; OSC1.Env.pourcentage = 0; OSC1.Env.sus_pourcentage = (ENV_Coeff / 16) * (OSC1.Env.Sus + 1); if (OSC1.Env.Atk) OSC1.Env.cur_env = ATK; else { OSC1.Env.cur_env = DEC; OSC1.Env.pourcentage = ENV_Coeff; } if (OSC1.presetOnde != TRI) OSC1.pos = 0; else OSC1.pos = 353; OSC2.Env.compteur = 0; OSC2.Env.pourcentage = 0; OSC2.Env.sus_pourcentage = (ENV_Coeff / 16) * (OSC2.Env.Sus + 1); if (OSC2.Env.Atk) OSC2.Env.cur_env = ATK; else { OSC2.Env.cur_env = DEC; OSC2.Env.pourcentage = ENV_Coeff; } if (OSC2.presetOnde != TRI) OSC2.pos = 0; else OSC2.pos = 353; } notesON++; if (midi_data1 >= midi_note) //La note la plus aigue est jouee midi_note = midi_data1; calculatePitch(read_period_preset(&OSC1), &OSC1); calculatePitch(read_period_preset(&OSC2), &OSC2); } resetMIDIMessage(); }
AMAction3* BioXASMirrorRollControl::createMoveAction(double setpoint) { AMAction3 *result = 0; if (isConnected()) { AMListAction3 *move = new AMListAction3(new AMListActionInfo3(name()+" move", name()+" move"), AMListAction3::Parallel); double pitch = calculatePitch(upstreamInboard_->xPosition(), upstreamInboard_->yPosition(), upstreamInboard_->zPositionSetpoint(), upstreamOutboard_->xPosition(), upstreamOutboard_->yPosition(), upstreamOutboard_->zPositionSetpoint(), downstream_->xPosition(), downstream_->yPosition(), downstream_->zPositionSetpoint()); double height = calculateHeight(upstreamInboard_->xPosition(), upstreamInboard_->yPosition(), upstreamInboard_->zPositionSetpoint(), upstreamOutboard_->xPosition(), upstreamOutboard_->yPosition(), upstreamOutboard_->zPositionSetpoint(), downstream_->xPosition(), downstream_->yPosition(), downstream_->zPositionSetpoint()); double upstreamInboardDestination = calculateUpstreamInboardPosition(upstreamInboard_->xPosition(), upstreamInboard_->yPosition(), pitch, setpoint, height); move->addSubAction(AMActionSupport::buildControlMoveAction(upstreamInboard_, upstreamInboardDestination)); double upstreamOutboardDestination = calculateUpstreamOutboardPosition(upstreamOutboard_->xPosition(), upstreamOutboard_->yPosition(), pitch, setpoint, height); move->addSubAction(AMActionSupport::buildControlMoveAction(upstreamOutboard_, upstreamOutboardDestination)); double downstreamDestination = calculateDownstreamPosition(downstream_->xPosition(), downstream_->yPosition(), pitch, setpoint, height); move->addSubAction(AMActionSupport::buildControlMoveAction(downstream_, downstreamDestination)); result = move; } return result; }
void Camera::move() { calculateZoom(); calculatePitch(); calculateAngleAroundPlayer(); float horizontalDistance = calculateHorizontalDistance(); float verticalDistance = calculateVerticalDistance(); calculateCameraPosition(horizontalDistance, verticalDistance); _yaw = 180 - (_player->getRotation().y + _angleAroundPlayer); }
void processMIDINoteON(void) { if (midi_data2 && !midi_notesON[midi_data1]) { midi_notesON[midi_data1] = midi_data2; if (!notesON) { OSC1.Env.cur_env = ATK; OSC1.Env.cur_amplitude = 0; OSC1.Env.compteur = 0; OSC2.Env.cur_env = ATK; OSC2.Env.cur_amplitude = 0; OSC2.Env.compteur = 0; } notesON++; if (midi_data1 >= midi_note) //La note la plus aigue est jouee midi_note = midi_data1; calculatePitch(); } resetMIDIMessage(); }
void SonicDog::startPlaying() { // find out if the client wants the sound to play bool can_play, once, removed; removed = false; pthread_mutex_lock( &play_lock_ ); can_play = playing_; pthread_mutex_unlock( &play_lock_ ); while ( can_play ) { pthread_mutex_lock( &q_lock_ ); while ( play_q_.size() == 0 && !exit_ ) { pthread_cond_wait( &empty_q_lock_, &q_lock_ ); } // check that we can keep playing after being woken up if ( exit_ ) { pthread_mutex_unlock( &q_lock_ ); pthread_exit( 0 ); } // there's stuff in the queue so pop off a source SoundSrc *src = play_q_.front(); play_q_.pop(); pthread_mutex_unlock( &q_lock_ ); once = src->once; do { // play the sound at least once if ( once ) pthread_mutex_lock( &turns_lock_ ); alSourcePlay( src->source ); alutSleep( src->pause ); if ( once ) pthread_mutex_unlock( &turns_lock_ ); if ( !once ) alSourcef( src->source, AL_PITCH, calculatePitch( src->source ) ); // check that we can keep playing pthread_mutex_lock( &play_lock_ ); can_play = playing_; pthread_mutex_unlock( &play_lock_ ); if ( !once ) { bool paused; // check if we're paused pthread_mutex_lock( &pause_lock_ ); BoolMap::iterator p = paused_.find( src->id ); assert( p != paused_.end() ); paused = p->second; while ( paused ) { pthread_cond_wait( &pause_cond_lock_, &pause_lock_ ); BoolMap::iterator p = paused_.find( src->id ); assert( p != paused_.end() ); paused = p->second; } pthread_mutex_unlock( &pause_lock_ ); // check if we've been removed pthread_mutex_lock( &remove_lock_ ); BoolMap::iterator cont = removed_.find( src->id ); if ( cont != removed_.end() ) { removed = cont->second; } pthread_mutex_unlock( &remove_lock_ ); } } while ( can_play && !once && !removed ); // remove this source if wasn't meant to be played only once if ( !src->once ) { // remove this source from the source map if it's in there pthread_mutex_lock( &sources_lock_ ); SoundMap::iterator itr = sources_.find( src->id ); if ( itr != sources_.end() ) { sources_.erase( itr ); } pthread_mutex_unlock( &sources_lock_ ); } // we're done with the source so clean it up alDeleteSources( 1, &(src->source) ); alDeleteBuffers( 1, &(src->buffer) ); delete src; } // we've been stopped, so exit the thread pthread_exit( 0 ); }
/** * @brief System starts here and delegates different actions. * @param None * @retval None */ void acc_thread(void const *argument){ st_system_state state = ST_INIT ; err_type error = NONE; float pitchRadians, rollRadians, pitchDegrees, rollDegrees; /* global variable */ int init_time = 0; filterState accPitchFilter; filterState accRollFilter; float filteredPitch=0.0; float filteredRoll=0.0; /* Main function */ while (1) { /* The system can be in multiple states, this is just good coding practice */ switch ( state ){ /* Initialization state */ case ST_INIT : /**************************************/ /************ initialization **********/ /**************************************/ //acc_init(); acc_ext_init(); initializeFilter(&accPitchFilter, 35); initializeFilter(&accRollFilter, 35); /**************************************/ state = ST_IDLE ; break ; /* Idle State */ case ST_IDLE : /**************************************/ /**************** idle ****************/ /**************************************/ delay(init_time); /**************************************/ state = ST_RUNNING ; break ; /* The system is running here the majority of the time */ case ST_RUNNING : /**************************************/ /***************** run ****************/ /**************************************/ /* Accelerometer Interrupt. When high run the following: */ //if(interrupt_EXTI0 == 1){ osSignalWait(0x1,osWaitForever); /* Reset flag */ interrupt_EXTI0 = 0; /* Read accelerometer data X,Y,Z into */ float data[3]; //LIS3DSH_ReadACC(data); //LSM9DS1_ReadACC(data); LSM9DS1_ReadGYRO(data); offsetAccData(data); //printf("%f\t%f\t%f\n", data[0]/*x*/, data[1]/*y*/, data[2]/*z*/); /* Calculate the pitch and roll in radians based on the following equation: */ /* Pitch = arctan(Ax1/sqrt((Ay1)^2+(Az1)^2 */ /* Roll = arctan(Ay1/sqrt((Ax1)^2+(Az1)^2 */ pitchRadians = calculatePitch(data); rollRadians = calculateRoll(data); /* Converting pitch and roll to degrees */ pitchDegrees = convertToDegrees(pitchRadians); rollDegrees = convertToDegrees(rollRadians); /* Filtering the pitch and roll angles in degrees using a moving average filter*/ filteredPitch = modify_filterState(&accPitchFilter, pitchDegrees); filteredRoll = modify_filterState(&accRollFilter, rollDegrees); /* Create message */ message_acc* acc_message = (message_acc*) osPoolAlloc(acc_mpool); acc_message->pitch = filteredPitch; acc_message->roll = filteredRoll; osMessagePut(acc_mqueue, (uint32_t)acc_message, osWaitForever); printf("%lf\t%f\t%lf\t%f\n", pitchDegrees, filteredPitch, rollDegrees, filteredRoll); //} /**************************************/ break ; case ST_ERROR : /**************************************/ /**************** error ***************/ /**************************************/ switch ( error ){ case NONE : //You didn't set error type... break ; case ERR_ERROR_1 : break ; case ERR_ERROR_2 : break ; case ERR_ERROR_3 : break ; case ERR_ERROR_4 : break ; } /**************************************/ break ; } //osDelay(250); } }