     func render(buffer:AVAudioPCMBuffer) -> Bool {
         let sampleCount = Int(self.length * UInt64(SampleRate) / 1000)
 
-        if (self.frequencies.count == sampleCount) {
+        if (self.frequencyBuffer != nil) {
             for (var i = Int(0); i < sampleCount; i++) {
-                let value = volumes[i] * sin(Float(i) * 2 * π * self.frequencies[i] / SampleRate)
+                let value = (volumeBuffer?.floatChannelData.memory[i])! * sin(Float(i) * 2 * π * (self.frequencyBuffer?.floatChannelData.memory[i])! / SampleRate)
                 buffer.floatChannelData.memory[i] = value
                 // second channel
                 buffer.floatChannelData.memory[sampleCount + i] = value

    private func renderFrequencies() {
        let sampleCount = UInt32(self.length * UInt64(SampleRate) / 1000)

        self.frequencies = Array<Float>()

        let sectionLength = lengthOfSections(sampleCount, sequence: self.toneSequence)

        for (var i = 0; i < sectionLength.count; i++) {
            let length = sectionLength[i]
            let frequency = self.toneSequence[i].frequency()

            renderFadeIn(UInt32(frequencies.count))
            renderFadeOut(UInt32(frequencies.count) + length)

            for (var j:UInt32 = 0; j < length; j++) {
                frequencies.append(frequency)
            }
        }
    }

    private func resetVolume() {
        let sampleCount = UInt32(self.length * UInt64(SampleRate) / 1000)

        self.volumeBuffer = getBuffer()

        for (var i:Int = 0; i < Int(sampleCount); i++) {
            self.volumeBuffer?.floatChannelData.memory[i] = Float(1)
        }
    }

    private func renderFadeIn(wantedStart:UInt32) {
        let sampleCount = UInt32(self.length * UInt64(SampleRate) / 1000)

        if (self.volumeBuffer?.frameLength < sampleCount) {
            resetVolume()
        }

