Allow scopes to request any audio format #1906

Merged
bmatherly opened 12:47pm on August 29, 2026 wanted to merge 60 ฮ” into mltframework/shotcut master from
audio_scope_format

Pull Request Overview

  • Opened on August 29, 2026
  • Status Merged
  • Commit count 1 with first commit August 29, 2026

Total Delta

60 Total Diff Delta

Open Days

Open 15 weekdays

Test Delta

0 Diff Delta in Test Files
Breakdown by Phase

How long has this pull request spent in each phase of its lifecycle?

Fraction of total time Business days Phase
 
0.0 days Authoring 0 commits before pull request opened for review
 
0.0 days Awaiting first review
Set up deploy tracking to begin tracking full PR start-to-deploy times

Total time for pull request 0.0 business days from first commit authored to merge
Deploy tracking has not been set up

Author avatar

Allow scopes to request any audio format

The scopes all assumed that the shared frame is rendered in S16. This change will cause the audio to be converted and cached if a format is requested that is not the rendered format.

Comments Threads Pending Resolution

ljharb reviewed on August 29, 2026
ljharb left a comment

## Pull request overview

This PR updates `SharedFrame` to support requesting audio buffers in an arbitrary `mlt_audio_format`, converting and caching audio on-demand when the requested format differs from the frameโ€™s native rendered format. This enables scopes (and other consumers) to reliably read S16 (or other formats) without assuming the render pipelineโ€™s native audio format.

**Changes:**
- Changed `SharedFrame::get_audio()` to accept a requested `mlt_audio_format` and return audio either natively or via a cached converted frame.
- Updated multiple audio scope widgets to explicitly request `mlt_audio_s16` audio buffers.
- Updated `SharedFrame` header/copyright to reflect the new API.

### Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file

| File | Description |
| ---- | ----------- |
| src/widgets/scopes/audiowaveformscopewidget.cpp | Requests S16 audio explicitly when reading waveform samples. |
| src/widgets/scopes/audiovectorscopewidget.cpp | Requests S16 audio explicitly for vector scope calculations. |
| src/widgets/scopes/audiosurroundscopewidget.cpp | Requests S16 audio explicitly for surround level calculations. |
| src/widgets/scopes/audiopeakmeterscopewidget.cpp | Requests S16 audio explicitly for peak meter level calculations. |
| src/sharedframe.h | Updates `SharedFrame::get_audio` API to accept a format parameter. |
| src/sharedframe.cpp | Implements audio conversion + caching behavior for requested non-native formats. |

Suppressed comments (2)

**src/widgets/scopes/audiowaveformscopewidget.cpp:260**
* Avoid casting away constness when reading audio from SharedFrame. `SharedFrame::get_audio()` returns read-only data; use a `const int16_t*` here to reflect that.
```
int16_t *audio = (int16_t *) m_frame.get_audio(mlt_audio_s16);
```
**src/widgets/scopes/audiovectorscopewidget.cpp:195**
* This cast drops const and is inconsistent with the `const int16_t*` variable type. Use a const-qualified cast to reflect that the audio buffer is read-only.
```
a = (int16_t *) m_frame.get_audio(mlt_audio_s16);
```

---

๐Ÿ’ก Add a `code-review` agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

src/sharedframe.cpp
296
        // Get the audio from the cache frame.
297
        // This will cause a conversion if it was just created.
298
        audio = cacheFrame->get_audio(format, frequency, channels, sample_count);
299
300
        nonConstData->m.unlock();

Resolved Comment Threads

No resolved comments have been left on this PR.