chipweinberger / dart_melty_soundfont

A port of Melty Synth by Nobuaki Tanaka (C#) to Dart
Other
33 stars 8 forks source link

Render function fails with exception #11

Closed postacik closed 2 years ago

postacik commented 2 years ago

Thanks for this great port of MeltySynth which I use in my C# project.

I'm trying to create a Flutter version of my project but the library has a weird problem which does not exist in the C# version.

Here's the sample application which demonstrates the problem:

DartMeltySoundFontTest.zip

My real application feeds the sound output with synthesized midi data.

The sample application simulates this with the following loop:

image

However after a few seconds, an exception occurs in the following function:

image

If I encapsulate this part in a try/catch block everything seems to work fine but I'm not sure if it has any side effects or creates performance problems.

Can you please check what's wrong here?

chipweinberger commented 2 years ago

Can you screenshot the exception backtrace? and what are the values of the variables block, block.length and t?

chipweinberger commented 2 years ago

I just tried your code and, and also tried your SF2 file in my own Flutter Project. No repro. The piano sounded decent! Perhaps your project configuration is somehow causing an issue? Not sure.

Mine:

flutter doctor
[✓] Flutter (Channel stable, 2.10.5, on macOS 12.1 21C52 darwin-arm, locale en-US)
[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
postacik commented 2 years ago

Can it be because I'm on Windows?

[√] Flutter (Channel stable, 2.10.4, on Microsoft Windows [Version 10.0.19042.1645], locale tr-TR)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Professional 2019 16.11.7)
[√] Android Studio (version 2020.3)
[√] VS Code (version 1.65.1)

image

image

After I added try/catch like this...

image

...these are the values which cause exception:

image

chipweinberger commented 2 years ago

Thanks for the screenshots!

This is actually a bug! I mixed up that List.fillRange wants the end index and not a length.

In the original implementation is using: definition: public static void Clear (Array array, int index, int length); code: Array.Clear(block, t, block.Length - t);

Whereas I'm using definition: void List.fillRange ([int] start,[int] end, [E fillValue]) code: block.fillRange(t, block.length - t, 0.0);

Note that it is end and not length.

In other words, the dart code should be:

block.fillRange(t, block.length, 0.0);

I'll push a fix. I have no idea why this has not repro'd on my side though. Maybe I have bounds checking disabled. It's interesting that this bug does not cause any noticeable problems for me. But it is definitely a bug.

chipweinberger commented 2 years ago

fixed. try updating.

914b72fbe09fe8e6918bf4c37ca4968ecc2db6aa

postacik commented 2 years ago

Thanks. It does not raise an exception now.