coast_audio
1.0.0


coast_audio是用DART编写的高性能音频处理库。
该软件包的目的是提供低级音频功能,而无需扑动依赖性。
| 安卓 | ios | macos | 视窗 | Linux | 网络 |
|---|---|---|---|---|---|
| ✅ | ✅ | ✅ | ✅ |
coast_audio建在dart:ffi的顶部。
因此,它可以在支持FFI的任何飞镖环境中使用。
某些功能是在使用Miniaudio的本机代码中实现的。
该存储库包含每个受支持平台的预构建二进制文件。
将以下内容添加到您的pubspec.yaml :
coast_audio : ^1.0.0android/src/main/jniLibs 。{ABI}/libcoast_audio.so从native/prebuilt/android目录复制到jniLibs目录。将以下内容添加到您的Podfile :
target 'Runner' do
...
pod 'CoastAudio' , :git => 'https://github.com/SKKbySSK/coast_audio.git' , :tag => '1.0.0'
end打开AppDelegate.swift文件,并添加以下Import和CoastAudioSymbolKeeper.keep()致电:
import CoastAudio // 1. Add import
@ UIApplicationMain
@ objc class AppDelegate : FlutterAppDelegate {
override func application (
_ application : UIApplication ,
didFinishLaunchingWithOptions launchOptions : [ UIApplication . LaunchOptionsKey : Any ] ?
) -> Bool {
CoastAudioSymbolKeeper . keep ( ) // 2. Add this line to prevent native symbols from being stripped (You can place this anywhere inside your iOS/macOS code)
GeneratedPluginRegistrant . register ( with : self )
return super . application ( application , didFinishLaunchingWithOptions : launchOptions )
}
}{ARCH}/libcoast_audio.so从native/prebuilt/linux目录中的文件复制到项目中的linux/libs目录。linux/CMakeLists.txt : install ( FILES "linux/libs/ ${CMAKE_SYSTEM_PROCESSOR} /libcoast_audio.so" DESTINATION " ${INSTALL_BUNDLE_LIB_DIR} " COMPONENT Runtime)托多
Windows还没有预先构建的本地库。
您需要手动构建它。
coast_audio提供了各种音频节点,可轻松生成/过程音频数据。
此示例代码使用FunctionNode生成440Hz正弦波。
// define the audio format with 48khz sample rate and stereo channels.
final format = AudioFormat (sampleRate : 48000 , channels : 1 , sampleFormat : SampleFormat .int16);
// create a sine wave function node with 440hz frequency.
final functionNode = FunctionNode (
function : const SineFunction (),
frequency : 440 ,
);
AllocatedAudioFrames (length : 1024 , format : format). acquireBuffer ((buffer) {
// read the audio data from the function node to the buffer.
functionNode.outputBus. read (buffer);
// floatList contains sine wave audio data.
final floatList = buffer. asFloat32ListView ();
});您可以使用WavAudioEncoder编码音频数据。
// define the audio format with 48khz sample rate and stereo channels.
final format = AudioFormat (sampleRate : 48000 , channels : 1 , sampleFormat : SampleFormat .int16);
// create a sine wave function node with 440hz frequency.
final functionNode = FunctionNode (
function : const SineFunction (),
frequency : 440 ,
);
final fileOutput = AudioFileDataSource (
file : File ( 'output.wav' ),
mode : FileMode .write,
);
// create a wav audio encoder.
final encoder = WavAudioEncoder (dataSource : fileOutput, inputFormat : format);
encoder. start ();
final duration = AudioTime ( 10 );
AllocatedAudioFrames (length : duration. computeFrames (format), format : format). acquireBuffer ((buffer) {
// read the audio data from the function node to the buffer.
final result = functionNode.outputBus. read (buffer);
// encode the audio data to the wav file.
encoder. encode (buffer. limit (result.frameCount));
});
encoder. finalize ();AudioNode可以连接到其他节点以构建音频图。
此示例代码演示了如何混合两个正弦波并写入WAV文件。
const format = AudioFormat (sampleRate : 48000 , channels : 1 );
final mixerNode = MixerNode (format : format);
// Initialize sine wave nodes and connect them to mixer's input
for ( final freq in [ 264.0 , 330.0 , 396.0 ]) {
final sineNode = FunctionNode (function : const SineFunction (), format : format, frequency : freq);
final mixerInputBus = mixerNode. appendInputBus ();
sineNode.outputBus. connect (mixerInputBus);
}
AllocatedAudioFrames (length : 1024 , format : format).bufferFrames. acquireBuffer ((buffer) {
// read the audio data from the function node to the buffer.
functionNode.outputBus. read (buffer);
// floatList contains mixed sine wave audio data.
final floatList = buffer. asFloat32ListView ();
});coast_audio提供AudioDevice类来处理音频设备I/O。
请参阅以下示例:
是的,您可以将coast_audio在扑朔迷离中使用。
coast_audio大部分操作都是同步的,它可能会阻止扑飞的主要分离株。
因此,建议在单独的分离株中使用coast_audio 。
请参阅示例应用程序实现以获取更多详细信息。
coast_audio吗?简而言之,不,
您应该使用dart:web_audio 。
但是,如果在Web平台上支持FFI,它可能会可用。