def uniform_white_noise_wave(wave_out, amplitude, seed, duration): """ Plays a uniform white noise wave with the parameters you specify. Args: wave_out(:any:`DoubleValue`): variable onto which the white noise wave plays. amplitude(:any:`DoubleValue`): amplitude of the white noise wave. seed(:any:`I32Value`): seed for random number generator. duration(:any:`DoubleValue`): duration, in seconds, to play the white noise wave. """ x_seed = I32Value(0) y_seed = I32Value(0) z_seed = I32Value(0) init_time = DoubleValue(0) seed_sum = DoubleValue(0) x_seed.value = seed.value y_seed.value = (seed.value * 8191) & 16383 z_seed.value = (y_seed.value * 8191) & 16383 init_time.value = seqtime() while seqtime() - init_time.value < duration.value: x_seed.value = rem(x_seed.value * 171.0, 30269.0) y_seed.value = rem(x_seed.value * 172.0, 30307.0) z_seed.value = rem(x_seed.value * 170.0, 30323.0) seed_sum.value = (x_seed.value / 30269.0) + ( y_seed.value / 30307.0) + (z_seed.value / 30323.0) wave_out.value = amplitude.value * ( (seed_sum - floor(seed_sum.value)) - 0.5) * 2.0 localhost_wait(deltat()) nivs_yield()
def sawtooth_wave(wave_out, amplitude, freq, phase, bias, duration): """ Plays a sawtooth wave with the parameters you specify. Args: wave_out(:any:`DoubleValue`): variable onto which the sawtooth wave plays. amplitude(:any:`DoubleValue`): amplitude of the sawtooth wave. freq(:any:`DoubleValue`): frequency, in Hz, of the sawtooth wave. phase(:any:`DoubleValue`): phase, in degrees, of the sawtooth wave. bias(:any:`DoubleValue`): offset to add to the sawtooth wave. duration(:any:`DoubleValue`): duration, in seconds, to play the sawtooth wave. """ init_time = DoubleValue(0) curr_phase = DoubleValue(0) init_time.value = seqtime() while seqtime() - init_time.value < duration.value: curr_phase.value = rem( (freq.value * 360.0 * (seqtime() - init_time.value)) + phase.value, 360.0) if curr_phase.value < 180.0: wave_out.value = ( (curr_phase.value / 180.0) * amplitude.value) + bias.value else: wave_out.value = (((curr_phase.value / 180.0) - 2.0) * amplitude.value) + bias.value localhost_wait(deltat()) nivs_yield()
def square_wave(wave_out, amplitude, freq, phase, bias, duty_cycle, duration): """ Plays a square wave with the parameters you specify. Args: wave_out(:any:`DoubleValue`): variable onto which the square wave plays. amplitude(:any:`DoubleValue`): amplitude of the square wave. freq(:any:`DoubleValue`): frequency, in Hz, of the square wave. phase(:any:`DoubleValue`): phase, in degrees, of the square wave. bias(:any:`DoubleValue`): offset to add to the square wave. duty_cycle(:any:`DoubleValue`): percentage of time the square wave remains high versus low over one period. duration(:any:`DoubleValue`): time, in seconds, to play the square wave. """ init_time = DoubleValue(0) curr_phase = DoubleValue(0) init_time.value = seqtime() while seqtime() - init_time.value < duration.value: curr_phase.value = rem(((freq.value * 360.0 * (seqtime() - init_time.value)) + phase.value), 360.0) if curr_phase.value < (duty_cycle.value * 3.6): wave_out.value = amplitude.value + bias.value else: wave_out.value = -amplitude.value + bias.value localhost_wait(deltat()) nivs_yield()