Matt Gallagher's iOS Tone Generator

陌路散爱 提交于 2019-12-02 12:00:42

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!