// Use this for initialization
void Start () {
lowLevelSystem = RuntimeManager.LowlevelSystem;
channel = new FMOD.Channel();
lowLevelSystem.getMasterChannelGroup(out channelGroup);
soundInfo = new FMOD.CREATESOUNDEXINFO();
soundInfo.cbsize = Marshal.SizeOf(soundInfo);
soundInfo.decodebuffersize = (uint)sampleRate / 10;
soundInfo.length = (uint)(sampleRate * numberOfChannels * sizeof(short));
soundInfo.numchannels = numberOfChannels;
soundInfo.defaultfrequency = sampleRate;
soundInfo.format = FMOD.SOUND_FORMAT.PCM16;
soundInfo.pcmreadcallback = PCMReadCallback;
soundInfo.pcmsetposcallback = PCMSetPositionCallback;
lowLevelSystem.setStreamBufferSize(65536, FMOD.TIMEUNIT.RAWBYTES);
lowLevelSystem.createStream("SoundGeneratorStream", FMOD.MODE.OPENUSER, ref soundInfo, out generatedSound);
generatedSound.setMode(FMOD.MODE.OPENUSER | FMOD.MODE._3D | FMOD.MODE._3D_LINEARSQUAREROLLOFF);
lowLevelSystem.playSound(generatedSound, channelGroup, true, out channel);
channel.setLoopCount(-1);
channel.setMode(FMOD.MODE.LOOP_NORMAL);
channel.setPosition(0, FMOD.TIMEUNIT.MS);
channel.set3DMinMaxDistance(minDistance, maxDistance);
Update();
channel.setPaused(false);
}