Closed abegehr closed 2 years ago
Actually, it looks like the bites are all 0:
// Render the waveform (3 seconds)
final buf16 = ArrayInt16.zeros(numShorts: sampleRate * 3);
synth.renderMonoInt16(buf16);
final bytes = buf16.bytes.buffer.asUint8List();
debugPrint("bytes are 0? ${bytes.every((e) => e == 0)}");
=> flutter: bytes are 0? true
Debugging a bit, it seems the reason for this is that synth._voices is empty because in the noteOn() calls, the presetId evaluates to 0 whereas _presetLookup only has values for keys 115 and 8388656 and the noteOn() returns on preset == null
.
I've tried the soundfont from the readme akai_steinway.sf2 and it works! Before I was trying metronom.sf and it produced values in _presetLookup of 115 and 8388656 which non of the values 0..16 for channel produce. Looking at the code, all channel values have bank_number 0 except for channel 9 which has bank_number 128 (see here). Am I missing something for how to use metronom.sf? 🤔
This code is pretty new! There definitely could be some bugs.
Do other synths work with metronom.sf? Importantly, does C# MeltySynth work with it?
If you figure out the issue, please open a PR!
On Sat, Mar 5, 2022 at 6:53 AM Anton Begehr @.***> wrote:
I've tried the soundfont from the readme akai_steinway.sf2 https://www.polyphone-soundfonts.com/documents/10-pianos/303-akai-steinway-iii and it works! Before I was trying metronom.sf http://www.mirbsd.org/~tg/soundfont/ and it produced values in _presetLookup of 115 and 8388656 which non of the values 0..16 for channel produce. Looking at the code, all channel values have bank_number 0 except for channel 9 which has bank_number 128 (see here https://github.com/chipweinberger/DartMeltySoundFont/blob/main/lib/channel.dart#L95 ). Am I missing something for how to use metronom.sf? 🤔
— Reply to this email directly, view it on GitHub https://github.com/chipweinberger/DartMeltySoundFont/issues/5#issuecomment-1059778039, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOHB7RVDXKL2VBXVUAGQUTU6NYNZANCNFSM5P7XGNYQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>
C# MeltySynth works with the following code.
// Create the synthesizer.
var sampleRate = 44100;
var synthesizer = new Synthesizer("Metronom.sf2", sampleRate);
// Change the instrument to the metronome (preset #115).
synthesizer.ProcessMidiMessage(0, 0xC0, 115, 0);
// Play a note (the metronome supports only two keys, 76 or 77).
synthesizer.NoteOn(0, 76, 100);
// The output buffer (1 seconds).
var left = new float[1 * sampleRate];
var right = new float[1 * sampleRate];
// Render the waveform.
synthesizer.Render(left, right);
Appreciate your input @sinshu!! Were you able to see how your code differs from
"produced values in _presetLookup of 115 and 8388656 which non of the values 0..16 for channel produce."
@abegehr, I wont be able to debug this for 1-3 weeks or so. But if you find the issue happy to merge.
Oh, perhaps the issue was needing to set this line?
// Change the instrument to the metronome (preset #115).
synthesizer.ProcessMidiMessage(0, 0xC0, 115, 0);
Does setting that line work with DartMeltySoundFont?
In the C# version, the keys of presetLookup
were 115 and 8388656 as in the Dart version. These values should be correct, since Metronom.sf2 has the following two presets.
You therefore have to set the instrument to #115 via the program change command (0xC0) to use the metronome.
akai_steinway.sf2 works without this process because the piano is assigned to #0, the default instrument for normal channels.
Ya that makes sense. Thanks for looking into it =)
Pushed a readme change to make this more clear.
@sinshu , you should consider this readme change too =)
How can I play the rendered ArrayInt16 in a player like flutter_sounds?
I've tried the following but it doesn't work:
DO zou have an example for how to play the ArrayInt16?