Commit Graph

110 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
phantomsoldierking
8ffe7e6ae1 Docs: changed description of the length parameter
Fixes #134117

Pull Request: https://projects.blender.org/blender/blender/pulls/135958
2025-03-14 21:45:18 +01: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
2ec719447e Cmake: Add Pipewire support
Pull Request: https://projects.blender.org/blender/blender/pulls/126091
2024-12-03 16:26:01 +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
Ray molenkamp
0edfe46fc0 CMake: Fix Deprecation Warning in audaspace
CMake 3.31 has begun to emit the following warning:

```
CMake Deprecation Warning at extern/audaspace/CMakeLists.txt:17
Compatibility with CMake < 3.10 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.

```

The main blender CMakeLists has a `cmake_minimum_required(VERSION 3.10)`
already so it's likely the one in audaspace isn't needed. given it is there
however and i'm not entirely sure about the history why it is there i bumped
it to `3.10` so it aligns with the main blender one.

Pull Request: https://projects.blender.org/blender/blender/pulls/130566
2024-11-21 02:23:08 +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
Thomas Dinges
65762c880f Add license and copyright information for external dependencies
This is being added straight to 4.2, prior to the `make license` command
which will use this to generate a more complete license file.

Licenses information and ambiguities worked with Dalai Felinto.

Part of !129018.
2024-10-18 17:08:33 +02:00
Campbell Barton
c6afb0e270 Core: remove sdlew/WITH_SDL_DYNLOAD & disable SDL by default
Disable dynamic SDL loading as well as disable SDL for release builds.

This was only used for audio output which can already use OpenAL
if there are back-ends not natively supported by Blender.

- Remove extern/sdlew/
- Remove the WITH_SDL_DYNLOAD build option.
- Remove `bpy.app.sdl.available`.

Ref !127554
2024-09-13 22:44:35 +10:00
Jörg Müller
fae2195553 Audaspace: merge changes from upstream. 2024-08-06 17:59:20 +02:00
Jörg Müller
a235a18aca Audaspace: port changes from upstream. 2024-08-03 11:19:34 +02:00
Sergey Sharybin
9125fb868e Merge branch 'blender-v4.2-release' 2024-07-09 15:21:35 +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
Nathan Burnham
c810d1413d PyAPI Doc: fix doc gen warning wrt loadLeftHrtfSet
Pull Request: https://projects.blender.org/blender/blender/pulls/123147
2024-06-13 21:22:25 +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
Campbell Barton
03e68e5d9b Merge branch 'blender-v4.1-release' 2024-03-01 16:23:34 +11:00
Campbell Barton
5d08927eda Build: forward SDL defines to audaspace
audaspace used undefined SDL library & include variables.
2024-03-01 16:14:47 +11: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
Aras Pranckevicius
986f493812 Audaspace: faster audio resampling
Previously in Audaspace there was choice between linear resampler (okay
for preview, but not great for final mix), or "extremely high quality
preset" for rendering the final mix; with nothing in between. I have just
landed "medium" and "low" resampler quality levels in upstream Audaspace
(see https://github.com/audaspace/audaspace/pull/18 with details and
quality spectograms, also comparison with Audacity resampler).

This PR updates Audaspace to latest upstream, and switches to use the newly
added "medium" quality resampler. There's no audible difference (nor visible
one in spectrograms), as far as I can tell.

Timings, rendering out frames 1000-3000 of Sprite Fright Edit blender
studio data set:
- Windows (Ryzen 5950X, VS2022): 92 -> 73 sec
- Mac (M1 Max, clang 15): 70 -> 62 sec

i.e. using a faster audio resampler makes the _whole render process_ be
10-20% faster (however, this from VSE where it combines already pre-rendered
image strips).

Pull Request: https://projects.blender.org/blender/blender/pulls/116059
2024-01-03 21:23:24 +01:00
Campbell Barton
0e8e8fa462 CMake: mark WITH_COMPILER_ASAN_EXTERN as advanced, quiet warning 2023-10-31 10:42:06 +11:00
Marcos Perez
1015bed2fd VSE: Sound equalizer modifier
The sound equalizer is using the Audaspace FFT Convolver.
The blender part creates an array of descriptions of power per "band"
and orders the creation of Equalizer (ISound) in the Audaspace.

Modifier can be created on sound strips. It lets you define
amplification or attenuation over frequency range from 30Hz to 20 kHz.
The power is limited to -30 db - 30 db. This is done using curve
mapping widget.

Co-authored-by: menda <alguien@aqui.es>
Co-authored-by: Richard Antalik <richardantalik@gmail.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/105613
2023-08-30 22:36:36 +02:00
Campbell Barton
af16faf5d7 CMake: quiet AUDASPACE warning setting an old minimum_version
PR submitted upstream.
2023-08-17 11:53:59 +10:00
Jörg Müller
7c3a779bc2 Fix #110336 Regression: Speaker ignoring of the starting position in NLA track
Porting fix from upstream:

Bugfix for reading an animated property with a negative time value.

This can now happen in SequenceHandle::seek.
2023-07-24 16:44:05 +02:00
Jörg Müller
e98c26dece Audaspace: porting changes from upstream. 2023-05-25 23:00:22 +02:00
Jörg Müller
68af6f6836 Audaspace: porting changes from upstream. 2023-04-08 10:36:40 +02:00
Jörg Müller
cc332264ae Audaspace: porting changes from upstream. 2023-01-14 22:18:39 +01:00
Ray Molenkamp
7c1ab77fa6 audaspace: Fix build error with MSVC 17.4+
`DeviceManager.h` uses `std::string` without explicitly including
the `<string>` header. While older MSVC implicitly included this
header somewhere, the headers for 17.4+ do not leading to a build
error.
2022-11-09 14:39:15 -07: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
d136a996ca Audaspace: minor formatting fix for last commit. 2022-07-16 22:20:08 +02:00
Colin Basnett
1e4c557d82 Fix T99039: bpy.ops.sound.mixdown returns indecipherable error
Fix for {T99039}.

The problem was that `AUD_mixdown` and `AUD_mixdown_per_channel` were returning pointers to freed memory.

Two key changes are made:
1. The return value of those functions now simply return a bool as to whether the operation succeeded, instead of an optional error string pointer.
2. The error string buffer is now passed into the function to be filled in case an error occurs. In this way, the onus of memory ownership is unamibiguously on the caller.

Differential Revision: https://developer.blender.org/D15260
2022-07-16 22:14:19 +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
Campbell Barton
42a6c226d0 CMake: fix AUDASPACE disabling WITH_PYTHON for Blender
When AUDASPACE couldn't find NUMPY, it would disable WITH_PYTHON for
the rest of Blender. Now setting the value globally is only done for
standalone AUDASPACE builds. Now it's possible to build Blender with
AUDASPACE & PYTHON but without NUMPY.

While this isn't an especially important configuration to support,
having Python mysteriously disabled is a hassle to troubleshoot.

NOTE: extern/audaspace/CMakeLists.txt has become out sync with the
original [0], it seems this is being maintained in our repository.

[0]: https://github.com/neXyon/audaspace/blob/master/CMakeLists.txt
2022-05-20 11:18:49 +10: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