0

This is an AudioKit question:

I am really new to AudioKit and audio in general.

My question is: How could I use AudioKit to create a sound that changes as I move my phone around? I already know how to get the gyro information so lets say I can take the gyro values between 0-10, zero being no movement and 10 being a lot of movement of the phone. I want to translate that into sounds that corresponds to how hard/quickly the phone is being moved. To start just move the sound higher in pitch as the speed increase, low pitch down at zero. Sounds easy yes?

I'm just not experienced enough to know which AudioKit class to use or how to use it to achieve my results.

Thank you! Michael

MichaelG
  • 103
  • 1
  • 8
  • 2
    This is more of a sound design question than a programming question. You really have to think what a light saber sound is made of; the base sound (oscillators, samples), filter sweeps, etc etc. Go on youtube to research how the sound was created and then start trying to recreate it either through synthesis or sampling. In terms of how to use the gyro info with the sound, you have the right idea. – yun Oct 09 '17 at 16:36
  • Question is overly broad. Either ask for specific help to pitch sound up and down with AudioKit oscillator/sampler or ask for sound design of light saber. – mahal tertin Oct 09 '17 at 17:56
  • 1
    OK, to be more specific, which AudioKit class would I use that would allow me to change the pitch up and down easily based upon some parameter / magnitude such as the value of a gyro axis? I want to be able to change the pitch up and down in "real time" as the gyro values changes. Thanks. – MichaelG Oct 10 '17 at 14:19

1 Answers1

1

You have to write your own AKOperationGenerator.

enum PitchEnvVCOSynthParameter: Int {
    case frequency, gate
}

struct PitchEnvVCO {
    static var frequency: AKOperation {
        return AKOperation.parameters[PitchEnvVCOSynthParameter.frequency.rawValue]
    }
    static var gate: AKOperation {
        return AKOperation.parameters[PitchEnvVCOSynthParameter.gate.rawValue]
    }
}

extension AKOperationGenerator {
    var frequency: Double {
        get { return self.parameters[PitchEnvVCOSynthParameter.frequency.rawValue] }
        set(newValue) { self.parameters[PitchEnvVCOSynthParameter.frequency.rawValue] = newValue }
    }
    var gate: Double {
        get { return self.parameters[PitchEnvVCOSynthParameter.gate.rawValue] }
        set(newValue) { self.parameters[PitchEnvVCOSynthParameter.gate.rawValue] = newValue }
    }
}

and

let generator = AKOperationGenerator { parameters in
    let oscillator = AKOperation.squareWave(
        frequency: PitchEnvVCO.frequency
    )
    return oscillator
}

and then make your variable control the frequency

var vco1Freq: Double = 440.0
{
    didSet {
        generator.parameters[PitchEnvVCOSynthParameter.frequency.rawValue] = vco1Freq
    }
}

Fetch the gyro data and make it control your variable like describes here

headkit
  • 3,207
  • 4
  • 49
  • 99