 
     func render(buffer:AVAudioPCMBuffer) -> Bool {
         let sampleCount = Int(self.length * UInt64(SampleRate) / 1000)
+
+        if (buffer.format.channelCount != 2) {
+            return false;
+        }
+
+        if (Int(buffer.frameCapacity) < sampleCount) {
+            return false;
+        }
 
         if (self.frequencyBuffer != nil) {
             for (var i = Int(0); i < sampleCount; i++) {

        for (var i = 0; i < count; i++) {
            self.volumeBuffer?.floatChannelData.memory[start +  i] *= Float(1) - (Float(i) / Float(count))
        }

    }

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

        self.frequencyBuffer = getBuffer()

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


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

        let start:Int = wantedStart > fadeSampleCount ? Int(wantedStart - fadeSampleCount) : 0
        var count:Int = wantedStart > fadeSampleCount ? Int(fadeSampleCount) : Int(start)

