Matt Gallagher's iOS Tone Generator

后端 未结 1 1226
遥遥无期
遥遥无期 2021-01-27 01:54

Can someone point me to a working version of Matt Gallagher\'s Tone Generator?

http://www.cocoawithlove.com/assets/objc-era/ToneGenerator.zip

As Matt says, it h

相关标签:
1条回答
  • 2021-01-27 02:21

    Of course Gene De Lisa is right. The "unit" variable needs to be declared outside of viewDidLoad so it doesn't get deallocated right away. Also, "unit.enableSpeaker()" needs to be before "unit.startToneForDuration(0.5)". However even with those 2 changes I got no sound. After more head scratching I found two scaling errors in hotpaw2's ToneOutputUnit.swift (in github).

    1) In the function startToneForDuration the line "toneCount = Int32(round( time / sampleRate ))" should be "toneCount = Int32(time * sampleRate)".

    2) And in the function setToneVolume the line "v0 = vol / 32768.0" should be "v0 = vol * 32768.0".

    With those two changes it works and produces a tone with volume and duration that seem reasonable.

    @Hotpaw2: I hope you will update your version in github. It's a nicely written class that will help others.

    0 讨论(0)
提交回复
热议问题