Commit Graph

57 Commits

Author SHA1 Message Date
Sebastian Parborg
552a395952 Audaspace: Wait for the PulseAudio stream to be ready when initializing
Otherwise, the stream might be in an invalid state when we are trying to
start playback.

Pull Request: https://projects.blender.org/blender/blender/pulls/136845
2025-05-07 15:01:10 +02:00
Sebastian Parborg
b6a86a8fc9 Audaspace: Always free up the CoreAudio resources 2025-05-07 15:00:55 +02:00
Sebastian Parborg
df733ea3a7 Audaspace: Fix Core Audio sound playback 2025-05-07 15:00:55 +02:00
Sebastian Parborg
898877e8b3 Audaspace: Workaround Core Audio clock quirk 2025-05-07 15:00:55 +02:00
Sebastian Parborg
034478fe07 Audaspace: Cork the PulseAudio audio stream on creation
We uncork it when we start playback
2025-05-07 15:00:55 +02:00
Jörg Müller
e4792cb4e7 Audaspace: MixingThreadDevice
Fixes #135897 by introducing a mixing thread to coreaudio, making the callback lock free. At the same time these changes unify all devices that use a mixing thread (now that's jack, pulse, pipewire and coreaudio).

Pull Request: https://projects.blender.org/blender/blender/pulls/136711
2025-04-17 14:30:34 +02:00
Jörg Müller
57117497fe Audaspace: Synchronizer API change
Removes the playback handle from the synchronizer API and integrates it
into the device, removing the ISynchronizer interface completely.

This has been discussed in more detail in #126047 and its main purpose is to unify the handling of synchronizer events, especially seek which needed different logic for jack vs other backends.

OpenAL now needs a silence playback handle for synchronization but all
other backends are pretty straightforward just counting the mixed
samples in the SoftwareDevice with some specializations for specific
backends that had their own synchronizers before.

Note: CoreAudio changes are untested as I don't have a Mac.

Pull Request: https://projects.blender.org/blender/blender/pulls/133191
2025-04-01 11:28:08 +02:00
Jörg Müller
4c1c2f0280 Audaspace: update to version 1.6 for blender 4.4.
Pull Request: https://projects.blender.org/blender/blender/pulls/135475
2025-03-06 21:14:45 +01:00
Jörg Müller
41cbebe6d9 Audaspace: port CoreAudio closing fix from main. 2025-03-06 21:14:44 +01:00
Aras Pranckevicius
e705073f94 Fix #132905: High idle CPU usage with PulseAudio in Linux
Prevents the unnecessary calls to CPU intensive PulseAudio functions
while the stream is corked.

This is re-applying PR #129312 since during Audaspace upstream update
in bc39ee692d the previous fix got lost.

Co-authored-by: Jörg Müller <nexyon@gmail.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/132990
2025-01-13 14:33:15 +01:00
Aras Pranckevicius
64f1f29a50 Audio: add AAC and Opus to Render Audio operator
There's a "Render -> Render Audio" operator that pretty much calls into Audaspace functionality directly. This PR adds two new options in there, that boThere's a "Render -> Render Audio" operator that pretty much calls
into Audaspace functionality directly. This PR adds two new options in
there, that both feel like an oversight:

- There's an option for AAC container, when someone wants to render
  into .aac file. Previously you could render AAC audio, but only in
  MKV (Matroska) container. This is a user request #131980.
- When using MKV (Matroska) or Ogg container, it did not list Opus as
  an audio codec that can be used. This felt like an oversight; both
  the rest of Blender and Audaspace can handle that, jus the option
  was not spelled out in the RNA enums.

Pull Request: https://projects.blender.org/blender/blender/pulls/132877th feel like an oversight:

- There's an option for AAC container, when someone wants to render into `.aac` file. Previously you _could_ render AAC audio, but only in MKV (Matroska) container. This is a user request #131980.
- When using MKV (Matroska) or Ogg container, it did not list Opus as an audio codec that can be used. This felt like an oversight; both the rest of Blender and Audaspace can handle that, jus the option was not spelled out in the RNA enums. Note however that without fix in #132872 the Matroska container continues to be useless in that it produces wrong result.

Upstream Audaspace PR for the 2nd point: https://github.com/neXyon/audaspace/pull/47 (was just merged!)

Pull Request: https://projects.blender.org/blender/blender/pulls/132877
2025-01-10 12:26:24 +01:00
Aras Pranckevicius
6a865a2265 Fix #132214: wrong Render Audio result when using Matroska container format
Matroska container really really wants to internally keep on using
milliseconds as a time base. Even if at initialization time both the
m_stream and m_codecCtx are set to use {1, sample_rate} timebase,
later during the avformat_write_header call the audio stream gets set
to {1, 1000}.

Doing av_packet_rescale_ts for each packet after receiving it but
before writing it seems to do all the correct work. This is what is
being done inside Blender movie_write_audio.cc, and in official ffmpeg
mux.c example.

Pull Request: https://projects.blender.org/blender/blender/pulls/132872
2025-01-10 12:25:01 +01:00
Sebastian Parborg
bb53214661 Audaspace: Enforce minimal pipewire library version
While I implemented pipewire support I forgot that some of the functions I use is not available in older pipewire versions.

This adds proper library version sanity checks for pipewire.

Pull Request: https://projects.blender.org/blender/blender/pulls/131610
2025-01-06 18:19:08 +01:00
Sebastian Parborg
bc39ee692d Audaspace: merge changes from upstream.
Add the Pipewire backend and Pulseaudio fixes.
There are also some other minor changes.
2024-12-03 16:25:59 +01:00
Sebastian Parborg
b1ca2f09db Fix: FFmpeg deprecation warnings
Pull Request: https://projects.blender.org/blender/blender/pulls/127203
2024-11-18 17:46:04 +01:00
Jörg Müller
3b8bd516e9 Fix #129162: High idle CPU usage with PulseAudio in Linux 2024-10-21 00:53:14 +02:00
Jörg Müller
a235a18aca Audaspace: port changes from upstream. 2024-08-03 11:19:34 +02:00
Sergey Sharybin
6d3b4f1c32 Fix #121911: macOS: Interference with sound in other applications
Turns out closing AudioUnit handle could interfere with other software.

It is something Apple is investigating, to see if it is API not used
correctly, or whether there is something to be fixed in the Core Audio.

Until then disable the code which closes audio handles. It rolls back
to the situation when the computer might not be able to sleep properly,
but it is how the previous release was, and overall it is less annoying
than causing an interference.

Once the issue is looked into by Apple we will re-iterate over having
both issues (interference and power management) resolved.

Pull Request: https://projects.blender.org/blender/blender/pulls/124400
2024-07-09 15:20:49 +02:00
Sergey Sharybin
68a76c3c77 Fix #121719: Sound does not play when playback starts outside of strip
The issue was caused by an integer overflow in the `FFMPEGReader::seek`, which
lead to different results depending on an exact compiler version and platform.

The overflow happened in the equation which calculates `m_position`, in its
`packet.pts - st_time` part, which is effectively `int64_t - uint64_t` which is
expected to result in `uint64_t` due to the way how upcasting works in C++.

With the values `packet.pts=0` and `st_time=353600` from the test file the
calculation resulted in a negative value, which then wrapped around due to the
unsigned nature of the type, resulting in very big value on arm64. The value
was wrong, but it did not manifest itself as an error, since the seek code
believed it found the place.

However, when built on x86 platform, the result value was very large negative
value. It is possible that the type upcasting went different, due to the
multiplication with a double value later in the formula. And this large negative
value lead to the seeking code to read the entire file, trying to make it so
the `m_position` is not less than the requested position.

Fortunately, the `AVStream::start_time` is `int64_t`, which leads to a simple
fix which avoids signed/unsigned cast, making the seeking code to properly
calculate `m_position` on both arm64 and x64 platforms, regardless of the
compiler.

Pull Request: https://projects.blender.org/blender/blender/pulls/122149
2024-05-23 21:25:04 +02:00
Lalit Shankar Chowdhury
1456dafa27 Windows: Use COM smart pointers in WASAPI plugin
Use COM smart pointer (`ComPtr`) to simplify memory management in WASAPI driver.

This reduces chances of calling `Release()` when a COM object has not been allocated.

Pull Request: https://projects.blender.org/blender/blender/pulls/121828
2024-05-17 17:00:40 +02:00
Jörg Müller
a5ba4032e0 Audaspace: porting bugfixes for CoreAudioDevice from upstream. 2024-05-06 08:28:20 +02:00
Sebastian Parborg
6dfb1cdf22 Fix: Crash/Assert in the pusleaudio lib when pausing playback
After 91eb50ec2f, we would get random crashes/asserts from the pulseaudio library like:
`Assertion 'e->mainloop->n_enabled_defer_events > 0' failed at ../pulseaudio-17.0/src/pulse/mainloop.c:261, function mainloop_defer_enable(). Aborting.`

It seems like we would run into a race condition if we didn't guard the
pulseaudio flush command with the pulseaudio mutex.

This is probably because the pulseaudio thread would try to read the
buffer for a tiny bit even after pausing the playback.

Sadly the only way to reproduce this is to playback any scene (seem to happen more often if A/V sync is on) and spam play/pause.
Note that I could not reproduce this on every computer I tested this on.

But by expanding the main pulseaudio mutex lock, I can't seem to reproduce this anymore.
So I think that is the correct solution.

Pull Request: https://projects.blender.org/blender/blender/pulls/120072
2024-03-29 19:47:16 +01:00
Jörg Müller
91eb50ec2f Audaspace: Bugfix for PulseAudio ported from upstream. 2024-03-08 17:02:26 +01:00
Jörg Müller
43307b667d Audaspace: porting changes from upstream.
Developed in Blender, see: #107607
2024-03-05 18:22:17 +01:00
Aras Pranckevicius
79707c2ae8 Extern: update Audaspace to latest version
No behavior changes, but no need to have a local modification
that sets JOS resampler quality to Medium

This basically contains two PRs that got accepted upstream:
- https://github.com/audaspace/audaspace/pull/19
- https://github.com/audaspace/audaspace/pull/20

Pull Request: https://projects.blender.org/blender/blender/pulls/118896
2024-02-29 12:08:00 +01:00
Jörg Müller
e4fd2d5754 Fix T99812: Audio scrubbing freezes Blender 3.2.1
Bug was caused by a change in ffmpeg's API.
2022-08-02 20:17:46 +02:00
Jörg Müller
41a0411d79 Fix T99083: audio bad in command-line video player (blender -a)
There was a wrong sample size computation in PulseAudioDevice.
The sample format is switched to float32 for the command-line player.
2022-06-23 21:32:34 +02:00
Jörg Müller
ac8beb4fda Fix T97453: Blender crash when selecting Caching checkbox in VSE
Merge Audaspace fixes from upstream.
2022-04-22 22:36:04 +02:00
Sebastian Parborg
c2016feadc Merge branch 'blender-v3.1-release' 2022-02-18 18:25:31 +01:00
Sebastian Parborg
af6a1b08e3 VSE: Refactor our code to be compatible with ffmpeg 5.0
In ffmpeg 5.0, several variables were made const to try to prevent bad API usage.
Removed some dead code that wasn't used anymore as well.

Reviewed By: Richard Antalik

Differential Revision: http://developer.blender.org/D14063
2022-02-18 18:24:16 +01:00
Jörg Müller
4782713390 Fix T94994: Anim Player Stops working In Video Sequence Editor
Port from upstream: variable was unitialized when device initialization
failed when the WASAPI mixing thread is started.
2022-02-15 20:04:42 +01:00
Jörg Müller
2a095d8bfe Audaspace: port bugfixes from upstream.
Windows audio backend (WASAPI) now automatically switches to
the selected audio device in windows.
2022-01-14 22:51:35 +01:00
Jörg Müller
8324ac8457 Audaspace: porting upstream pulseaudio fixes.
Fixes T89045 and T91057.
2021-09-21 22:20:34 +02:00
Jörg Müller
bdbc7e12a0 Audaspace: added audio file streams functionality.
On the blender side this commit fixes importing video files with audio
and video streams that do not share the same start time and duration.

Differential Revision: https://developer.blender.org/D12353
2021-09-18 21:45:33 +02:00
Jörg Müller
a217e043be Audaspace: porting PulseAudio fixes from upstream. 2021-08-18 22:22:21 +02:00
Sebastian Parborg
ded68fb102 VSE: Fix audaspace not reading ffmpeg files with start offset correctly
The duration and start time for audio strips were not correctly read in
audaspace.

Some video files have a "lead in" section of audio that plays before the
video starts playing back. Before this patch, we would play this lead in
audio at the same time as the video started and thus the audio would not
be in sync anymore.

Now the lead in audio is cut off and the duration should be correctly
calculated with this in mind.

If the audio starts after the video, the audio strip is shifted to
account for this, but it will also lead to cut off audio which might not
be wanted. However we don't have a simple way to solve this at this
point.

Differential Revision: http://developer.blender.org/D11917
2021-08-16 15:10:58 +02:00
Jörg Müller
a112adf16a Audaspace: porting pulseaudio fixes from upstream. 2021-07-01 14:26:13 +02:00
Jörg Müller
19d19970e4 Fix T88887: Audio causes issues with Playback when PC put to Sleep, Hibernate or when Screensaver appears
Porting WASAPI device reinitialization from upstream.
2021-07-01 14:26:13 +02:00
Jörg Müller
530f2994e9 Fix T88614: Mixdown crashes Blender 2.92.0 and 3.0.0 Alpha
The problem is caused by the most recent ffmpeg version (4.4) which
needs channels to be set when submitting a frame for encoding.
2021-05-27 19:05:17 +02:00
Jörg Müller
35cf34de6d Fix T86851: PulseAudio randomly asserts in background rendering
Upstream fix from Audaspace with simplified PulseAudio code.

Maniphest Tasks: T86851

Differential Revision: https://developer.blender.org/D10840
2021-03-29 12:16:01 +02:00
Jörg Müller
250a69ee82 Fix T86728: Blender freezes when playhead is dragged in this .blend
Porting the deadlock bugfix in WASAPI from upstream Audaspace.
2021-03-19 21:42:55 +01:00
Jörg Müller
12c08ceee3 Audaspace: add support for CoreAudio on macOS
This adds CoreAudio as audio backend on macOS.
CoreAudio is the standard audio API on macOS.

Ref T86590
2021-03-16 23:21:45 +01:00
Jörg Müller
bc57985306 Audaspace: add support for WASAPI on Windows
This adds WASAPI as audio backend on Windows.
WASAPI is the modern standard audio API on
Windows introduced with Windows Vista.

Ref T86590
2021-03-16 23:21:45 +01:00
Jörg Müller
d33339ebf4 Audaspace: add support for PulseAudio on Linux
This adds PulseAudio as audio backend on Linux.
PulseAudio is the main audio engine used on most,
if not all, Linux distributions today.

Ref T86590
2021-03-16 23:21:45 +01:00
Jörg Müller
7b8fc307dc Audaspace: porting minor improvements from upstream
- NullDevice is now called None
- Automatic choice of best available device.
- Minor formatting, documentation and cmake fixes.
2021-03-16 23:21:45 +01:00
Jörg Müller
fe3ca3f6ce Fix T66786: Audio SDL: Video editor Sound muted without muting it
Porting fix for SDL 2 audio formats from audaspace upstream.
2020-06-13 15:19:03 +02:00
Jörg Müller
fe891d581d Audaspace: update from upstream
- Changing API for time values from float to double for better precision.
- Fixing minor mistakes in the documentation.
- Fixing minor unnecessary large memory allocation.
2020-05-03 15:30:35 +02:00
Joerg Mueller
e93aa9c0fc Fix T71621: VSE crashes when playing last frame of audio
Porting bug fix from audaspace upstream.
2019-11-22 10:34:01 +01:00
Sybren A. Stüvel
122ba774e0 Fix T71621: VSE crashes when playing last frame of audio
Due to some floating point errors the last frame of a VSE audio strip can
cause integer overflow and crash Blender. This overflow was caused by a
cast from `int64_t` to `int` without prior check. The crash is fixed by
keeping the variable as `int64_t` for as long as possible.
2019-11-21 10:01:12 +01:00
Jörg Müller
fb1cbbaf46 Fix T71322: Crash in Audaspace with some video file
Getting upstream audaspace fixes for audio files with more than 8
channels.
2019-11-17 09:02:18 +01:00