马特·加拉格尔(Matt Gallagher)的iOS音源 [英] Matt Gallagher's iOS Tone Generator

查看:67
本文介绍了马特·加拉格尔(Matt Gallagher)的iOS音源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以指出我是Matt Gallagher的Tone Generator的工作版本吗?

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

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

正如Matt所说,它尚未更新,显然已被较新的API破坏.我更新了我可以确定需要更新的内容,现在它仅使用弃用警告进行编译和运行,但所做的只是在触摸播放"和停止"按钮时发出咔嗒声.我遍历了代码,并查看了Xcode中关于API的文档,但这是一个艰难的学习过程.我希望有一个工作版本,以便我可以进行修改以了解更多信息.有人更新过吗?还是类似的声音发生器?

As Matt says, it hasn't been updated and apparently got broken by newer APIs. I updated what I could figure out needed updating and now it compiles and runs with only deprecation warnings but all it does is make clicking sounds when the "Play" and "Stop" button are touched. I've gone through the code and looked at the documentation in Xcode for the API but it's a steep learning curve. I would love to have a working version so I could tinker with it to learn more. Has anyone updated it? Or a similar tone generator?

我尝试通过以下方式调用hotpaw2中的ToneOutputUnit类.

I tried using the ToneOutputUnit class from hotpaw2 by calling it as follows.

class ViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    let unit = ToneOutputUnit()
    unit.toneCount = 64000
    unit.setFrequency(1000.0)
    unit.setToneVolume(0.5)
    unit.startToneForDuration(2.0)
    unit.enableSpeaker()
    print("ok")
}

}

我可以看到ToneOutputUnit代码正在被调用,并且正在逐步执行各种功能,但是没有产生声音.我还尝试在"startToneForDuration"之前调用"enableSpeaker",但也没有声音.我想念什么?

I could see that the ToneOutputUnit code was being called and was stepping through the various functions but no sound was produced. I also tried calling 'enableSpeaker' before 'startToneForDuration' but also no sound. What am I missing?

推荐答案

Gene De Lisa当然是正确的.需要在viewDidLoad之外声明"unit"变量,以便不会立即将其释放.另外,"unit.enableSpeaker()"必须位于"unit.startToneForDuration(0.5)"之前.但是,即使进行了这两次更改,我也听不到声音.经过更多的抓挠之后,我在hotpaw2的ToneOutputUnit.swift(在github中)中发现了两个缩放错误.

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)在函数startToneForDuration中,"toneCount = Int32(round(time/sampleRate))"行应为"toneCount = Int32(time * sampleRate)".

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

2)在函数setToneVolume中,"v0 = vol/32768.0"行应为"v0 = vol * 32768.0".

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:希望您能在github中更新您的版本.这是一门写得很好的课程,可以帮助其他人.

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

这篇关于马特·加拉格尔(Matt Gallagher)的iOS音源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆