- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我已经成功创建了一些函数来获取 SNSpeechSynthesizer.startSpeakingString(string, url)
并通过闭包将生成的 .aiff 文件附加到 SCNAudioPlayer
并附加整个事情到 SCNNode
。
这将运行具有给定 SCNNode.position(x, y, z)
的音频片段。
一切都很好,但没有与 SCNAudioSource
相关的效果,除了音量、速率和混响本身什么都不做。
我想添加音频单元效果,如延迟回声法兰等,但我找不到相关信息,除了 AVAudioEngine
和 AVAudioFile
类似乎是SCNAudioSource
的父类(super class),AVAudioEngine
包含 AudioUnitPitc
h 等类。但是,我无法弄清楚SCNAudioSource
、SCNAudioPlayer
、AVAudioEngine
和AVAudioFile
之间有什么联系。没有在子类或父类(super class)中引用另一个,并且任何教程(例如下面)仅在 AVFoundation
中讲,而不是在 SceneKit
中讲。 http://www.jawadrashid.com/swift-tutorial-udacity-7/
非常感谢对我可以阅读更多相关内容的任何链接的任何帮助
编辑:我找到了另一个链接,该链接显示了使用 AVAudioNode
的 SCNAudioPlayer
构造函数。也许我可以通过以下方式扩展它:
class CustomAudioPlayer:SCNAudioPlayer{}
然后通过将 AudioUnit 附加到 AudioNode 来覆盖父类(super class) init?但是,这似乎不会出现在 AudioEngine 中。
这是 objective-c 中的以下链接:
编辑2:我找到了对音频单元的引用并执行了以下操作,但现在我遇到了段错误
命令因信号而失败:段错误:11
code:
let source = prepareSynth(welcome, url: URL)
source.volume = 500.0
source.reverbBlend = 30.0
source.rate = 0.8
let clip = SCNAudioPlayer(source: source)
let mixer = clip.audioNode as AVAudioNode!?
distortion.loadFactoryPreset(AVAudioUnitDistortionPreset.SpeechRadioTower)
mixer?.engine?.attachNode(distortion)
mixer?.engine?.connect(mixer!, to: distortion, format: nil)
return clip
最佳答案
因此,在进行了大量研究以将任何可用的 AVAudioUnitEffec* 效果放入 SceneKit 场景之后,我终于找到了一个解决方案,经过测试、尝试和尝试。
AVAudioEngine 的以下子类将1-实例化具有特定配置的AVAudioEngine2-添加了一些方法来封装错误处理和效果预设加载3-使用连线方法将每个播放器和效果器节点放入音频引擎图中4-创建 AVAudioPCMBuffer 实例,配置帧数,文件格式作为辅助方法,以简化从 SceneKit 调用这些函数
注意:多声道代码未包含在内,因为我没有环绕声 5.1 系统,并且我已经对从 AVAudioEnvironmentNode 类公开的 HRTF(头部相关传输函数)算法感到非常满意。请注意,尽管此算法是双耳格式,但它是计算 secret 集度最高的算法。
可能的补充:1-添加一个混响区域预设切换器,这需要断开音频引擎,将环境节点重新连接到新的混响预设(大厅、小房间等)2-从 SceneKit SCNNode 列表中创建一个基于 RayCast 的回声传输维度以添加更逼真的效果,即:你在 T 形路口的中央栏,一个敌人在路口顶部栏的左侧滑行,声音穿过 RayCast 离开敌人并反弹到面对你的墙上。 AVAudioUnitDelay 类具有内部函数来更改早期延迟以创建所需的回声效果,而无需在任何地方使用相同的效果清洗节点。
代码在这里:
import Foundation
import SceneKit
import AVFoundation
class AudioLayerEngine:AVAudioEngine{
var engine:AVAudioEngine!
var environment:AVAudioEnvironmentNode!
var outputBuffer:AVAudioPCMBuffer!
var voicePlayer:AVAudioPlayerNode!
var multiChannelEnabled:Bool!
//audio effects
let delay = AVAudioUnitDelay()
let distortion = AVAudioUnitDistortion()
let reverb = AVAudioUnitReverb()
override init(){
super.init()
engine = AVAudioEngine()
environment = AVAudioEnvironmentNode()
engine.attachNode(self.environment)
voicePlayer = AVAudioPlayerNode()
engine.attachNode(voicePlayer)
voicePlayer.volume = 1.0
outputBuffer = loadVoice()
wireEngine()
startEngine()
voicePlayer.scheduleBuffer(self.outputBuffer, completionHandler: nil)
voicePlayer.play()
}
func startEngine(){
do{
try engine.start()
}catch{
print("error loading engine")
}
}
func loadVoice()->AVAudioPCMBuffer{
let URL = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("art.scnassets/sounds/interface/test", ofType: "aiff")!)
do{
let soundFile = try AVAudioFile(forReading: URL, commonFormat: AVAudioCommonFormat.PCMFormatFloat32, interleaved: false)
outputBuffer = AVAudioPCMBuffer(PCMFormat: soundFile.processingFormat, frameCapacity: AVAudioFrameCount(soundFile.length))
do{
try soundFile.readIntoBuffer(outputBuffer)
}catch{
print("somethign went wrong with loading the buffer into the sound fiel")
}
print("returning buffer")
return outputBuffer
}catch{
}
return outputBuffer
}
func wireEngine(){
loadDistortionPreset(AVAudioUnitDistortionPreset.MultiCellphoneConcert)
engine.attachNode(distortion)
engine.attachNode(delay)
engine.connect(voicePlayer, to: distortion, format: self.outputBuffer.format)
engine.connect(distortion, to: delay, format: self.outputBuffer.format)
engine.connect(delay, to: environment, format: self.outputBuffer.format)
engine.connect(environment, to: engine.outputNode, format: constructOutputFormatForEnvironment())
}
func constructOutputFormatForEnvironment()->AVAudioFormat{
let outputChannelCount = self.engine.outputNode.outputFormatForBus(1).channelCount
let hardwareSampleRate = self.engine.outputNode.outputFormatForBus(1).sampleRate
let environmentOutputConnectionFormat = AVAudioFormat(standardFormatWithSampleRate: hardwareSampleRate, channels: outputChannelCount)
multiChannelEnabled = false
return environmentOutputConnectionFormat
}
func loadDistortionPreset(preset: AVAudioUnitDistortionPreset){
distortion.loadFactoryPreset(preset)
}
func createPlayer(node: SCNNode){
let player = AVAudioPlayerNode()
distortion.loadFactoryPreset(AVAudioUnitDistortionPreset.SpeechCosmicInterference)
engine.attachNode(player)
engine.attachNode(distortion)
engine.connect(player, to: distortion, format: outputBuffer.format)
engine.connect(distortion, to: environment, format: constructOutputFormatForEnvironment())
let algo = AVAudio3DMixingRenderingAlgorithm.HRTF
player.renderingAlgorithm = algo
player.reverbBlend = 0.3
player.renderingAlgorithm = AVAudio3DMixingRenderingAlgorithm.HRTF
}
}
e
关于swift - 将 AudioUnit 效果附加到 SceneKit 中的 SCNAudioSource 节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33984205/
目标是创建无限的棋盘图案。 使用SCNFloor和附加的图像,我们可以生成接近但不太像棋盘的东西。一些黑色正方形在不应该合并的位置合并。 我们尝试了Scale,WrapS,WrapT,Min filt
这看起来很简单,但我就是无法缩小!使用这些搜索词的所有在线内容都是关于在应用程序中编写效果的。我的问题不在应用程序中;我只想在用户界面中评估和编辑 SceneKit 场景中的所有对象,并在我可以看到整
我在这里遗漏了什么吗?在各种向量/矩阵函数中here ,我看不到任何简单地将 SCNMatrix4 变换应用于 SCNVector4 的函数。我当然可以通过直接写出矩阵/向量乘法来做到这一点,但这肯定
我试图了解 ArKit 中引入的不同元素与 SceneKit 中可能的等价物之间的区别: SCNNode.simdTransform对比 SCNNode.transform .在 ARKit 中,似乎
我已经实现了向 ARKit 和 SceneKit 场景添加阴影平面的多种方法之一。它工作得很好,阴影看起来很好。 问题是大部分时间这架飞机也有灰白色。换句话说,它不是完全透明的。另一方面,有时灰色的类
我在游戏执行过程中随机弹出以下错误: 我正在随机时刻创建 carNode 的多个实例,并且所有实例都具有从场景中删除节点的操作。大多数情况下,这不是问题,但在某些情况下,应用程序会崩溃并显示照片中的错
我正在使用 Metal 计算内核生成网格数据(目前是三角汤)。 是否可以高效(无需任何复制)将网格数据导入 SceneKit 以利用 SceneKit 的渲染器?网格数据会经常更新,因此避免数据复制非
我想使用 Metal 计算着色器来计算一些位置,然后将这些位置输入到 Metal 着色器中。听起来很简单,但我无法将 MTLBuffer 数据导入基于 Metal 的 SCNProgram。 计算内核
在 Xcode 8 中,SceneKit 编辑器 允许您在使用 SCNLightingModelPhysicallyBased 时为 metalness 属性设置浮点值。选项包括金属、电介质、浮点值或
我注意到,如果您有一个空场景,然后在其中加载具有基于物理照明的 3D 模型,则在对象出现时会出现一些卡顿。如果之后我再添加一个不同的对象,就不会发生口吃。 查看分析器,似乎默认 PBR 着色器正在第一
我有一个 SceneKit 游戏,我正在尝试将其与 GameplayKit 集成。 为了让 GameplayKit 正常工作,我需要通过调用 updateWithDeltaTime(seconds:)
我正在 iOS SceneKit 中使用 SCNMorpher 在从 Blender 导出为 DAE 文件的 3D 面部模型上的不同面部表情之间进行变形。变形本身效果很好。 在我第一次在变形器上调用
文档 states GameplayKit also works well for 3D games built with the SceneKit framework 但是,似乎没有提及使用Scen
我通过使用 Interface Builder 将 3D 文本拖到场景中创建了这个 SceneKit 文本。 它是这样创建的: 轴在左下方。有没有一种方法可以使用界面生成器使轴在该文本上居中? 最佳答
我正在尝试将 SwiftUI 路径添加到 Scenekit 场景(作为 SCNShape)。 我创建了:Scenekit View (图片 1)SwiftUI 路径(图 2) 然后我尝试根据以下方法调
我想之前一定有人问过这个问题,但我现在找不到,所以暂时先问一下。 当 SceneKit 动画停止时,SpriteKit 的动画覆盖在 SceneKit 上。这是出乎意料的。这就像整个 SCNView
如何绘制边框以突出显示 SCNNode 并向用户指示该节点已被选中? 在我的项目中,用户可以放置多个虚拟对象,用户可以随时选择任何对象。选择后,我应该向用户显示突出显示的 3D 对象。有没有办法直接实
我正在 Scenekit 中加载一个 .obj 模型。当我尝试加载像(水瓶)这样的小模型时,它工作得很好。但是当我尝试加载更大的模型(如沙发、 table )时,它加载完美,但超出了场景的边界。 在S
我正在编写一个 iOS 应用程序,它使用自定义几何体在 SceneKit 中渲染点云。 This post对我实现这一目标非常有帮助(尽管我将其翻译为 Objective-C),David Rönnq
必须使用什么 orthographicProjection 才能在 SceneKit 中以 1:1 SceneKit 点与屏幕点/像素比率制作 2D 应用程序? 例子:我想在屏幕上的 (200, 20
我是一名优秀的程序员,十分优秀!