gpt4 book ai didi

ios - Music TrackSetDestNode 重置旧音乐轨道的采样器声音

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:14:37 25 4
gpt4 key购买 nike

我正在制作一个音乐应用程序,您可以在其中向现有音序器添加新乐器。这些乐器是单独的 AudioUnitSampler,存储在一个数组中,因此当加载新乐器和音轨时,它会加载该音轨将要使用的声音。

这就是我目前向 AUGraph 添加轨道的方式。

// Return count as an id for the new track
- (int) addMusicTrack: (MusicTrack)musicTrack withNode:(AUNode)newSamplerNode withAudioUnit:(AudioUnit)newSamplerUnit {

tracksCount++;
int trackId = tracksCount;

MusicPlayerStop(_musicPlayer);
status = MusicSequenceNewTrack(sequence, &tracks[trackId]);
MusicSequenceSetAUGraph(sequence, graph);

if(status){
printf("Error adding main track: %d", (int)status);
status = 0;
}

timeDiff = 32.f/_tempo;

[self setLoopDuration:DEFAULT_LOOP_DURATION forTrack:trackId];
currentOctaveNumber = 59;

AudioComponentDescription samplerNodeDesc;
samplerNodeDesc.componentManufacturer = (OSType)kAudioUnitManufacturer_Apple;
samplerNodeDesc.componentType = (OSType)kAudioUnitType_MusicDevice;
samplerNodeDesc.componentSubType = (OSType)kAudioUnitSubType_Sampler;
samplerNodeDesc.componentFlags = 0;
samplerNodeDesc.componentFlagsMask = 0;
status = AUGraphAddNode(graph, &samplerNodeDesc, &auSampleNodes[trackId]);

AudioComponentDescription splitterNodeDesc;
splitterNodeDesc.componentManufacturer = (OSType)kAudioUnitManufacturer_Apple;
splitterNodeDesc.componentType = (OSType)kAudioUnitType_FormatConverter;
splitterNodeDesc.componentSubType = (OSType)kAudioUnitSubType_Splitter;
splitterNodeDesc.componentFlags = 0;
splitterNodeDesc.componentFlagsMask = 0;
status = AUGraphAddNode(graph, &splitterNodeDesc, &splitterNodes[trackId]);

// node info
status = AUGraphNodeInfo(graph, auSampleNodes[trackId], 0, &auSampleUnits[trackId]);
status = AUGraphNodeInfo(graph, splitterNodes[trackId], 0, &splitterUnits[trackId]);

// connecting nodes samplernode ==> Splitter ==> Mixer
status = AUGraphConnectNodeInput(graph, auSampleNodes[trackId], 0, splitterNodes[trackId], 0);
status = AUGraphConnectNodeInput(graph, splitterNodes[trackId], 0, mixerNode, trackId);

status = MusicTrackSetDestNode(tracks[trackId], auSampleNodes[trackId]);

status = AUGraphUpdate(graph, NULL);
if (status) {printf("Error updating graph: %ld\n", status);}

MusicPlayerStart(_musicPlayer);

return trackId;
}

这就是我为该轨道加载声音的方式:

[self samplerUnit:auSampleUnits[trackId] loadFromDLSOrSoundFont:url withPatch:patchNumber];

声音字体加载:

- (OSStatus)samplerUnit:(AudioUnit)sampler loadFromDLSOrSoundFont:(NSURL *)bankURL withPatch:(int)presetNumber{

OSStatus result = noErr;

// Fill out the sampler instrument data structure
AUSamplerInstrumentData insdata;
insdata.fileURL = (__bridge CFURLRef) bankURL;
insdata.bankMSB = kAUSampler_DefaultMelodicBankMSB;
insdata.bankLSB = (UInt8)0;
insdata.presetID = (UInt8) presetNumber;
insdata.instrumentType = kInstrumentType_DLSPreset; // DLS and SF2 are the same enum values

// Load the instrument
result = AudioUnitSetProperty(sampler,
kAUSamplerProperty_LoadInstrument,
kAudioUnitScope_Global,
0,
&insdata,
sizeof(insdata));

NSCAssert (result == noErr,
@"Unable to set the preset property on the Sampler. Error code: %d",
(int) result);

return result;
}

因此,当前会为最近添加的音轨加载适当的声音,但旧音轨的声音现在是默认的 AudioUnitSampler 正弦波声音。

我已经尝试解决这个问题大约一天了,但还没有找到解决方法,是否有解决方案?

干杯!!!

最佳答案

您是否将 trackCount 与 MusicSequenceGetTrackCount 进行了比较?

查看 MusicSequenceSetAUGraph 的文档。“默认情况下,序列中的所有音乐轨道都指向图中的第一个节点,该节点是乐器单元(类型为 DLSMusicDevice”

你想让拆分器做什么?它现在没有做太多事情。

关于ios - Music TrackSetDestNode 重置旧音乐轨道的采样器声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30997612/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com