This code was being duplicated across three different playback functions
which basically did most of the same things.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
Check all audio chain elements for allocation failures, and also dispose
of all of the previous handles in reverse order, including nulling the
final node handle so the output does not attempt to poll for audio while
the chain is being rebuilt.
Also set up output node to handle the new null finalNode state, and
return an empty chunk to the caller.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
Play Count cannot be updated for tracks which have been deleted before
the update was added to them. This was another cause of a rare crash.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
We should not be processing a potential playback restart when the chain
is being torn down for shutdown.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
This should be perfectly safe to use in all situations now. It may have
been unstable due to mishandling return values, or not supporting
requesting more sample data from the library without feeding in more
input first.
Also, still signaling the End of Stream flag on chunk reading should be
correct, as downstream processors only react to it when the buffer runs
empty.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
The Downmixer wasn't updating its output format correctly, so it was
prone to outputting the wrong format for a while, which could confuse
the output device and produce garbage output.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
The delay value should be scaled by the resampling ratio, similar to
how it already is when allocating the impulse buffer. This went
undetected, as it scribbled over other memory without causing immediate
crashes, but instead later heap corruption.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
Check for paused processing state in various places, so that startup
playback works properly, and resume playback at seek offset works
properly and doesn't hang the player.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
The samples available function returns a signed integer, so it can
apparently return negative on error, and the DSP was incorrectly casting
this to an unsigned type, and thus attempting to buffer an inordinate
number of samples and crashing.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
The merge function should be able to tell when the caller has no audio
left to process, such as on end of stream.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
FreeSurround needs more buffering from its input, so increase buffering
of previous node to 100ms.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
Fixes timestamps in several cases where they were being processed
incorrectly, which was causing some chunked audio files to mis-report
timestamps into the past or the future, which caused the seekbar to jump
around in an unpredictable way.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
Stream timestamps were correctly being converted from the monotonically
increasing frame count, but the AudioChunk parameter was being set from
the frame count rather than the converted seconds count.
Fixes#418
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
Timed wait for 500us is kind of stupid and makes the threads wake up way
too much, and use way more CPU time. Reduce this, as the semaphores are
signaled appropriately, and the waiter should not wake up constantly.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
Visualization now buffers in the audio output pipeline, and uses a
container system to delay multiple buffer chains from emitting
visualization data over top of each other. This should stabilize
display output significantly, while introducing minimal lag before
DSP configuration changes take effect.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
The latency should not be incremented when writing sample data to the
buffer, but rather be posted by the output.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
Upstream functions which return empty chunks on error do not return nil,
so the caller should check for an empty duration instead.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
Impulses should be gain scaled roughly based on the sample ratio
relative to the original impulses. Lower target sample rate means less
impulses means gain goes up, higher target sample rate means more
impulses so gain goes down. Somewhat simple, seems to work.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
We were forcing a resampling ratio to match the HRTF filter supplied
with the app, now we resample the HRTF to match the input audio, which
will be resampled to match the output device settings.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
This prepares the filter to be the same as the rest of the filters, in
that they support flexible sample rates to match the output device.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
And disable it by default in new installations, otherwise leave the
setting alone. The disablement setting is shared with the engine
setting, so the default should not really change anything, except for
new installs.
Also, the time/pitch shifting dialog disables itself and displays an
obvious notice button, which opens the Rubber Band settings.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
These should have been defined already, but now they're the safe
defaults that should spring the dialog on startup, and doesn't grant
consent by default.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
It's more like the output monitor thread, since it only monitors output,
rather than actually handing the output callbacks.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
Sample block merging code should not be duplicated across the DSPs that
require it, but instead should be a common function. Also added some
optimizations to the Float32 converter function, to bypass conversion if
the audio format needs no conversion.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
Attempt to completely fill the input buffer of the Rubber Band library
between each call to the process function, instead of processing in
as small an increment as the source node provides. May reduce processing
power required.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
Audio Chunks now have full timestamp accounting, including DSP playback
speed ratio for the one DSP that can change play ratio, Rubber Band.
Inputs which support looping and actually reporting the absolute play
position now do so.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
In case multiple playlist entries are left marked as "current" in the
playlist database, resume playback on the first one, and unmark all the
rest of them.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
FreeSurround, like the Equalizer, which attempt to coalesce Audio Chunks
into larger blocks of 4096 samples, must check if the audio format has
changed between blocks, and stop stacking chunks together when a new
format is detected. They will continue processing with less sample data
than expected, as necessary.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
The last of the built-in processors is now in the threaded processing
chain, and all DSPs are marked high priority and with short buffers.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
Change one remaining semaphore wait to 500us, and change the buffering
so that it can always overflow the requested duration by one chunk, so
that at least one chunk will always fit in the buffer. This also allows
the DSP nodes to flush at the end of the stream without losing their
output.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
The end of stream flushing should only request remaining samples once,
as should the rest of the process. The problem with the Rubber Band code
in this case is that it will wrap the remaining samples pointer after it
has been flushed, and emit a really huge number.
Also, add code to try to equalize the samples output with the samples
input, relative to the tempo stretching, as Rubber Band seems to flush
entirely too much data at end of stream, which can create noticeable
gaps in the output. This solves that as well.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
This should be guarded, so that no other thread tries to free the DSP
while it is potentially writing to the Rubber Band instance.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>