0

I'm trying to load a sample into AKWavetable and get this error:

Thread 1: EXC_BAD_ACCESS (code=1, address=0x20)

It cant be the sample itself, because I have tried the whole thing with AKPlayer and it worked fine.. any ideas?

var sampler = AKWaveTable()

do
{
    //sampler load sample
    var audiofile = try AKAudioFile(readFileName: "SAUCE4.wav")
    sampler = AKWaveTable(file: audiofile,
                          startPoint: 0,
                          endPoint: Sample(audiofile.length),
                          rate: 1,
                          volume: 1,
                          maximumSamples: Int(audiofile.samplesCount),
                          completionHandler: {print("completed")},
                          loadCompletionHandler: {print("loadcompleted")}
                        )

}
catch
{
    print("No Such File...")
}

Output:

loadcompleted

(lldb)

Thread 1: EXC_BAD_ACCESS (code=1, address=0x20)

Community
  • 1
  • 1
  • follow this: https://code.tutsplus.com/tutorials/what-is-exc_bad_access-and-how-to-debug-it--cms-24544 esp. zombies part – timbre timbre Feb 27 '20 at 20:55

1 Answers1

1

This has something to do with initing the wavetable empty, and then trying to init it again. I was able to fix it by making sampler optional, then initing that:

var wavetable: AKWaveTable?
        do
        {
            //sampler load sample
            var audiofile = try AKAudioFile(readFileName: "SAUCE4.wav")
            wavetable = AKWaveTable(file: audiofile,
                                  startPoint: 0,
                                  endPoint: Sample(audiofile.length),
                                  rate: 1,
                                  volume: 1,
                                  maximumSamples: Int(audiofile.samplesCount),
                                  completionHandler: {print("completed")},
                                  loadCompletionHandler: {print("loadcompleted")}
                                )

        }
        catch
        {
            print("No Such File...")
        }
audiocoder
  • 76
  • 4