有谁有在iPhone上通过midi->wav转换或类似方式播放.midi文件的经验吗?

发布于 2024-07-26 11:22:37 字数 53 浏览 4 评论 0原文

有谁有在iPhone上通过midi->wav转换或类似方式播放.midi文件的经验吗?

Does anyone have any experience with playing .midi files through midi->wav conversion or the like on the iPhone?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

や三分注定 2024-08-02 11:22:37

iPhone 需要声音采用某些有效格式。 不确定是否直接支持 midi,但 MacOSX 附带了一个命令行工具来转换声音。

我会对我的声音文件运行以下命令,将它们转换为我知道有效的格式。

afconvert -v -f caff -d ima4 -c 1 filename.ext

并播放音效或环境声音,如下所示

+ (void)PlaySFX:(NSString*)name
{
    NSUserDefaults* savedState = [NSUserDefaults standardUserDefaults]; 

    if ([savedState boolForKey:SFX])
    {
        UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
        AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (sessionCategory), &sessionCategory); 

        SystemSoundID sound;  
        AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:name ofType:@"caf"]], &sound);  
        AudioServicesPlaySystemSound (sound);   
    }
}

+ (void)StartAmbientSound
{
    NSUserDefaults* savedState = [NSUserDefaults standardUserDefaults]; 

    player = [[AVAudioPlayer alloc] initWithContentsOfURL: [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Volcano Erupting" ofType:@"caf"]] error: nil];
    player.numberOfLoops = -1;
    player.currentTime = 0;
    player.volume = [savedState floatForKey:MUSICVOL];
    [player play];  
}

Iphone needs sounds to be in certain valid formats. Not sure if midi is supported directly but MacOSX comes with a command line tool to convert sounds.

I would run the following command on my sound files to convert them to a format I know works.

afconvert -v -f caff -d ima4 -c 1 filename.ext

and play either sound effects or ambient sound as follows

+ (void)PlaySFX:(NSString*)name
{
    NSUserDefaults* savedState = [NSUserDefaults standardUserDefaults]; 

    if ([savedState boolForKey:SFX])
    {
        UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
        AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (sessionCategory), &sessionCategory); 

        SystemSoundID sound;  
        AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:name ofType:@"caf"]], &sound);  
        AudioServicesPlaySystemSound (sound);   
    }
}

+ (void)StartAmbientSound
{
    NSUserDefaults* savedState = [NSUserDefaults standardUserDefaults]; 

    player = [[AVAudioPlayer alloc] initWithContentsOfURL: [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Volcano Erupting" ofType:@"caf"]] error: nil];
    player.numberOfLoops = -1;
    player.currentTime = 0;
    player.volume = [savedState floatForKey:MUSICVOL];
    [player play];  
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文