fluidsynth/test
Tom M 0d98c47545
Revise the sequencer's event queue (#604)
Proposing a new event queue for the sequencer, based on prior discussion:
https://lists.nongnu.org/archive/html/fluid-dev/2019-12/msg00001.html

With this change fluidsynth will require a C++98 compliant compiler.

Consider this as RFC, feedback is welcome.

The "pain-points" from the discussion:

#### 1. It is slow.

Done (thanks to heap sort), see runtime of `test_seq_event_queue_sort`.

#### 2. A meaningful ordering for events with the same tick has not been considered.

Done, see comments in `fluid_seq_queue.cpp`.

#### 3. Complicated implementation

Now uses one single event queue, which requires C++98. Implemented similarly to std::priority_queue by using heap sort.

The "queue" I use currently is of type `std::deque`. `deque` does not provide preallocation. `std::vector` does provide it. However, `std::deque` has the huge advantage that appending additional elements is cheap. For `std::vector` appending new elements would require to reallocate all the memory and copy it to the new array. So,

* either use `std::deque` with the risk that memory allocation may occur during `fluid_sequencer_send_at()`, or
* use `std::vector` with a preallocated pool of events and make `fluid_sequencer_send_at()` when the `vector` runs out of capacity.

Comments?

#### 4. Events that have been processed are deleted and gone.

After having thought about this more, this is the correct behavior. After events have been dispatched, they must be released to free underlying memory, see point 3. For the very rare case that a client (e.g. fluid_player) may require those events in the future, the client should be responsible for storing the events somewhere.

#### 5. The sequencer supports the system timer as alternative time source.

The conclusion from the mailing list was that the system timer can be removed. This has been done.

#### 6. Time Scaling

Time scaling can now be used for arbitrary tempo changes. The previous implementation was capable of that as well, however, the time-scale was limited to 1000. The only limitation for the scale is now >0, see `test_seq_scale`.

### Other Points

* `fluid_sequencer_remove_events()` turned out to be broken before, as it did not remove all events from the queue. This has been fixed, see `test_seq_event_queue_remove`.

* Consider the following code executed by `threadA`:

```c
fluid_sequencer_send_at(event0);
fluid_sequencer_set_time_scale(); // new scale
fluid_sequencer_send_at(event1);
```

The new scale will be definitely applied to `event1`. However, if another concurrently running `threadB` executes `fluid_sequencer_process()`, it was previously not clear, whether the new scale was also applied to event0. This depends on whether `event0` was still in the `preQueue`, and this depends on `event0.time` and the tick count that `fluid_sequencer_process()` is being called with. This has been changed. As of now, events are queued with their timestamp AS-IS. And only the latest call to `fluid_sequencer_set_time_scale()` is being considered during `fluid_sequencer_process()`. This makes the implementation very simple, i.e. no events need to be changed and the sequencer doesn't have to be locked down. On the other hand, it means that `fluid_sequencer_set_time_scale()` can only be used for tempo changes when called from the sequencer callback. In other words, if `threadA` executes the code above followed by `fluid_sequencer_process()`, `event0` and `event1` will be executed with the same tempo, which is the latest scale provided to the seq. Is this acceptable? The old implementation had the same limitation. And when looking through the internet, I only find users who call `fluid_sequencer_set_time_scale()` from the sequencer callback. Still, this is a point I'm raising for discussion.
2020-05-26 17:16:22 +02:00
..
CMakeLists.txt Revise the sequencer's event queue (#604) 2020-05-26 17:16:22 +02:00
README.md remove cmake option enable-tests 2018-08-05 20:50:41 +02:00
test.h Suppress abort() dialog on windows (#549) 2019-08-06 17:29:49 +02:00
test_bug_635.c Add regression test for #635 2020-05-23 15:30:27 +02:00
test_ct2hz.c More efficient implementation of fluid_ct2hz() (#569) 2019-10-22 13:09:42 +02:00
test_jack_obtaining_synth.c Workaround for jack sample rate mismatch (#607) 2020-01-19 15:36:15 +01:00
test_pointer_alignment.c enforce coding style guide 2018-06-24 13:13:18 +02:00
test_preset_sample_loading.c Reactivate test_preset_sample_loading 2020-05-23 14:40:41 +02:00
test_sample_cache.c fix building CoreAudio on OSX 10.4 2019-02-15 17:55:02 +01:00
test_sample_rate_change.c fix building CoreAudio on OSX 10.4 2019-02-15 17:55:02 +01:00
test_sample_validate.c Add a unit test for fluid_sample_validate() 2020-01-24 15:57:08 +01:00
test_seq_event_queue_remove.c Revise the sequencer's event queue (#604) 2020-05-26 17:16:22 +02:00
test_seq_event_queue_sort.c Revise the sequencer's event queue (#604) 2020-05-26 17:16:22 +02:00
test_seq_evt_order.c Revise the sequencer's event queue (#604) 2020-05-26 17:16:22 +02:00
test_seq_scale.c Revise the sequencer's event queue (#604) 2020-05-26 17:16:22 +02:00
test_seqbind_unregister.c Update unregistering unit test 2020-01-18 09:51:19 +01:00
test_sf3_sfont_loading.c fix building CoreAudio on OSX 10.4 2019-02-15 17:55:02 +01:00
test_sfont_loading.c Slightly extend test_sfont_loading.c 2020-01-24 13:33:41 +01:00
test_snprintf.c fix building CoreAudio on OSX 10.4 2019-02-15 17:55:02 +01:00
test_synth_chorus_reverb.c enforce coding style guide 2018-06-24 13:13:18 +02:00
test_synth_process.c Add a unit test for fluid_synth_write_float 2019-10-22 16:08:41 +02:00

README.md

This directory contains small executables to verify fluidsynths correct behaviour, i.e. unit tests.

Do not blindly use the tests as template for your application!

Although some tests might serve as educational demonstration of how to use certain parts of fluidsynth, they are not intended to do so! It is most likely that those tests will consist of many hacky parts that are necessary to test fluidsynth (e.g. including fluidsynth's private headers to access internal data types and functions). For user applications this programming style is strongly discouraged! Keep referring to the documentation and code examples listed in the API documentation.

Developers

To add a unit test just duplicate an existing one, give it a unique name and update the CMakeLists.txt by

  • adding a call to ADD_FLUID_TEST() and
  • a dependency to the custom check target.

Execute the tests via make check. Unit tests should use the VintageDreamsWaves-v2.sf2 as test soundfont. Use the TEST_SOUNDFONT macro to access it.