在OSX上的Nim中播放.wav文件的简单方法是什么? [英] What is a simple way to play a .wav file in Nim on OSX?

查看:93
本文介绍了在OSX上的Nim中播放.wav文件的简单方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用一个非常简单的程序来播放wav文件,该程序看起来像这样,目前正在尝试使用

I am trying to play a wav file in a very simple program that looks like this, currently attempting to use nim-csfml:

import csfml_audio

var alarmsong = newMusic("alarm.wav")
alarmsong.play()

,但是它似乎依赖于libcsfml.audi o的存在,虽然我的程序编译得很好,但是当我尝试实际运行它时却出现了错误

but it appears to be relying on the existence of libcsfml.audio, and while my program compiles just fine, when I try to actually run it I get an error

| => ./alarm
could not load: libcsfml-audio.so 

(相反,我有一个libcsfml-audio.dylib,因为我将OSX共享库用于csfml/sfml)

(I have a libcsfml-audio.dylib instead, being that I used the OSX shared libraries for csfml/sfml)

还有其他方法可以在Nim中播放.wav文件吗?

Is there some other way to play a .wav file in Nim?

在@ def-进行PR之后,我现在得到一个不同的,稍微令人欣慰的错误,这可能是由于对nim如何处理共享库的理解不足所致:

After the PR made by @def-, I now get a different, slightly more comforting error, which is probably due to some poor understanding of how nim deals with shared libraries:

| => ./alarm
could not load: libcsfml-audio.dylib

我在nim.cfg文件中添加了path = "/usr/local/lib",但似乎没有任何影响.我还导出了$LD_LIBRARY_PATH="/usr/local/lib"(/usr/local/bin所在的位置是/usr/local/bin.),并尝试通过

I added path = "/usr/local/lib" to my nim.cfg file, but it didn't seem to be affect anything. I also exported $LD_LIBRARY_PATH="/usr/local/lib" (/usr/local/bin is where libcsfml-audio.dylib is.), and tried compilation through

nim c alarm.nim --clib:/usr/local/lib/libcsfml-audio.dylib

感谢您的帮助!

推荐答案

为使nim-csfml正常工作,您需要SFML 2.1和CSFML 2.1.另外,似乎nim-csfml对于Mac OS X实际上已损坏,因此我提出了具有修复的请求请求:

For nim-csfml to work you'll need SFML 2.1 and CSFML 2.1. Also, it seems that nim-csfml is actually broken for Mac OS X, so I've made a pull request with a fix: https://github.com/BlaXpirit/nim-csfml/pull/4

其他可以播放声音的模块是 sdl_mixer

Other modules that could play sound are sdl_mixer, sdl2/audio and allegro5.

通过调用afplay二进制文件,作为不使用任何库的仅OSX替代方案:

As an OSX-only alternative without using any libraries, by calling the afplay binary:

import osproc
discard execProcess("afplay", ["file.wav"])

当Nim报告无法加载:libcs​​fml-audio.dynlib"时,这也可能意味着该库的依赖项之一丢失或版本错误.特别是SFML 2.2不能与CSFML 2.1一起使用.确保libsfml-audio.dynlib也位于您的LD_LIBRARY_PATH中.如果这也不起作用,您可以尝试编译并运行像这样的常规C CSFML示例: https://gist.github.com/def-/fee8bb041719337c8812

When Nim reports "could not load: libcsfml-audio.dynlib" that could also mean that one of the dependencies of that library are missing or in a wrong version. Especially SFML 2.2 doesn't work with CSFML 2.1. Make sure libsfml-audio.dynlib is in your LD_LIBRARY_PATH as well. If that doesn't work either, you could try to compile and run a regular C CSFML example like this one: https://gist.github.com/def-/fee8bb041719337c8812

使用clang -o mainpage -lcsfml-graphics -lcsfml-audio -lGL -lGLEW mainpage.c进行编译,以查看有关缺少库的错误/警告.

Compile it with clang -o mainpage -lcsfml-graphics -lcsfml-audio -lGL -lGLEW mainpage.c to see the errors/warnings about missing libraries.

这篇关于在OSX上的Nim中播放.wav文件的简单方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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