搜尋套件、儲存庫與 APP 分類

套件詳情v2.0.0

dart_melty_soundfont

一個用純 Dart 編寫的音色庫合成器(也就是 '.sf2' 播放器)。

AndroidiOSmacOSWindowsLinux
近 30 天下載
2060
喜歡數
51
Pub 分數
140

安裝套件

flutter pub add dart_melty_soundfont

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個純 Dart 實現的 Soundfont 合成器,可播放 .sf2 音頻樣本,讓 Flutter 應用實現跨平台音樂播放。專為希望在不依賴原生程式碼的情況下整合高品質樂器音色的開發者設計。該套件支援 Android、iOS、macOS、Windows 和 Linux 多個平台,非常適合需要可攜式聲音合成的音樂應用。它利用 Dart 的強大功能,實現低設定要求的即時音頻渲染。

適用情境

  • 使用自定樂器聲音播放MIDI檔案
  • 建構音樂教育應用
  • 在 Flutter 中創建互動式樂器
  • 整合採樣樂器庫
  • 開發跨平台音頻應用程式

主要特色

  • 純 Dart 實現
  • 支援 .sf2 Soundfont 檔案
  • 跨平台相容性
  • 即時音訊合成
  • 輕量且易於整合
  • 無需原生程式碼

適合對象

  • Flutter 開發人員建構音樂應用
  • 帶有互動音訊的教育軟體
  • 需要便攜式樂器音色的應用程式
  • 避免使用平台特定音訊庫的項目
  • 開發者優先考慮程式碼的簡潔性和可移植性

使用建議

  • 效能可能在低階設備上有所差異
  • 大型 .sf2 檔案會增加記憶體使用量
  • 僅限 SoundFont 2.0 格式
  • 需要仔細管理音訊資源
  • 未針對複雜的多音軌或進階效果進行優化

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

dart_melty_soundfont is a SoundFont synthesizer (i.e. '.sf2' player) written in pure Dart.

It is a port of MeltySynth (C#, MIT License) written by Nobuaki Tanaka, to Dart.

https://github.com/sinshu/meltysynth

Dependencies

This package has no dependencies.

Maintanence

This project was specifically designed to not require maintanence, in large part by not having any dependencies. Apart from breaking changes to the Dart language (rare), it should be solid code that works for decades. It will work on any Dart SDK sdk>=2.12 indefinitely.

This package was written against Dart SDK 2.16.1.

Example

Synthesize a simple chord:

// Necessary Imports
import 'package:dart_melty_soundfont/dart_melty_soundfont.dart';
import 'package:flutter/services.dart' show rootBundle;

// load sf2
ByteData bytes = await rootBundle.load('assets/akai_steinway.sf2');

// Create the synthesizer.
Synthesizer synth = Synthesizer.loadByteData(bytes, 
    SynthesizerSettings(
        sampleRate: 44100, 
        blockSize: 64, 
        maximumPolyphony: 64, 
        enableReverbAndChorus: true,
    ));

// optional: print available instruments (aka presets)
List<Preset> p = synth.soundFont.presets;
for (int i = 0; i < p.length; i++) {
  String instrumentName = p[i].regions.isNotEmpty ? p[i].regions[0].instrument.name : "N/A";
  print('[preset $i] name: ${p[i].name} instrument: $instrumentName');
}

//  optional: select first instrument (aka preset)
synth.selectPreset(channel: 0, preset: 0);

// turn on some notes
synth.noteOn(channel: 0, key: 72, velocity: 120);
synth.noteOn(channel: 0, key: 76, velocity: 120);
synth.noteOn(channel: 0, key: 79, velocity: 120);
synth.noteOn(channel: 0, key: 82, velocity: 120);

// create a pcm buffer
ArrayInt16 buf16 = ArrayInt16.zeros(numShorts: 44100 * 3);

// render the waveform (1 second)
synth.renderMonoInt16(buf16);

// turn off a note
synth.noteOff(channel: 0, key: 72, velocity: 120);

// render another second
synth.renderMonoInt16(buf16);

Synthesize notes from a MIDI file playback:

// Necessary imports
import 'package:dart_melty_soundfont/dart_melty_soundfont.dart';
import 'package:flutter/services.dart' show rootBundle;

// Load the soundfont file
ByteData bytes = await rootBundle.load('assets/akai_steinway.sf2');

// Create the synthesizer
Synthesizer synth = Synthesizer.loadByteData(bytes);

// Load MIDI file from asset
ByteData midiBytes = await rootBundle.load('assets/arabesque.mid');
MidiFile midiFile = MidiFile.fromByteData(midiBytes);

// Start MIDI playback
MidiFileSequencer sequencer = MidiFileSequencer(synth);
sequencer.play(midiFile, loop: false);

// Change the playback speed.
sequencer.speed = 1.5;

// Render 10 seconds of playback into PCM buffer
ArrayInt16 buf16 = ArrayInt16.zeros(numShorts: 44100 * 10);
sequencer.renderMonoInt16(buf16);

Playing Sound

This library does not audibly make sound, it only generates the PCM waveform.

To actually hear something, you need to pass the generated PCM waveform to your device's speakers using PCM.

See the Example App for a flutter_pcm_sound + dart_melty_soundfont example.

Isolates

It is recommended to do your audio rendering in isolates or using compute. This will keep your UI fast & prevent audio stuttering.

Features

  • No memory allocation in the rendering process.

  • Wave synthesis

    • [x] SoundFont reader
    • [x] Waveform generator
    • [x] Envelope generator
    • [x] Low-pass filter
    • [x] Vibrato LFO
    • [x] Modulation LFO
  • MIDI message processing

    • [x] Note on/off
    • [x] Bank selection
    • [x] Modulation
    • [x] Volume control
    • [x] Pan
    • [x] Expression
    • [x] Hold pedal
    • [x] Program change
    • [x] Pitch bend
    • [x] Tuning
  • Effects

    • [x] Reverb
    • [x] Chorus
  • Other things

    • [x] Standard MIDI file support
    • [x] Loop extension support
    • [x] Performance optimization

License

DartMeltySoundFont is available under the MIT license.

References

  • SoundFont® Technical Specification
    http://www.synthfont.com/SFSPEC21.PDF

  • Polyphone Soundfont Editor
    Some of the test cases were generated with Polyphone.
    https://www.polyphone-soundfonts.com/

  • Freeverb by Jezar at Dreampoint
    The implementation of the reverb effect is based on Freeverb.
    https://music.columbia.edu/pipermail/music-dsp/2001-October/045433.html

所屬分類

原始碼儲存庫

使用此套件的專案