← エンジン一覧に戻る ← Back to Engines Phase Vocoder & Phase Locking Engine | DS Soft
EN JP

フェーズボコーダ & 位相同期(Phase Locking)エンジン Phase Vocoder & Phase Locking Engine

「なぜピッチやテンポを変えても音質が濁りにくいのか?」時間伸縮の設計思想 Time Stretching & Pitch Shifting Artifact Reduction

概要と搭載アプリケーション Overview & Applications

フェーズボコーダ(Phase Vocoder)は、オーディオ信号の時間長(テンポ)と周波数(ピッチ)を互いに独立して変化させるDSPアルゴリズムです。
DS Softでは、従来の処理で発生しやすい「金属的なフランジャー音(Phasing Artifact)」、「ピッチの微小な不安定感・振幅リップル」、「超スロー再生時の波形荒れ」、「アタックの立ち上がりのにじみ・打ち消し合い」、「リサンプリング時の高域ノイズ」を抑えるため、位相ロックの精度向上、合成ホップ(hs)固定による振幅リップルの低減、トランジェント時の時間領域バイパス/OLAクロスフェード処理、負荷に応じたWSOLA等への段階的自動フォールバック、64タップKaiser窓付きSincリサンプリングによるリアルタイム・ストリーミングエンジンを構築しました。

【自作に至った開発の経緯】
当初は既存のサードパーティ製オーディオライブラリ(SoundTouch等)を導入していましたが、ピッチシフトやタイムストレッチ時の音質の曇りや輪郭の劣化がどうしても拭えず、音響的クオリティに納得がいかないという課題に直面しました。
そこで、ライブラリ依存を脱却し、独自に「Phase Vocoder + Phase Locking(位相同期)」を一から設計・実装。さらにユーザーフィードバックをもとに再合成アーキテクチャの数学的見直しを重ね、原音のハリと透明感を可能な限り保つエンジンへと改良を重ねてきました。

The Phase Vocoder decouples pitch and tempo adjustments. DS Soft designed a C++ multi-threaded and real-time streaming engine for mobile devices, featuring refined phase locking, fixed synthesis hop (hs) OLA reconstruction to suppress amplitude ripples, transient time-domain bypass & OLA crossfading to preserve attack sheen, load-adaptive tiered fallback (PV Lite / WSOLA / Cubic) for stable real-time playback, and 64-tap Kaiser-windowed sinc resampling to reduce metallic phasing, pitch wobble, and high-frequency noise.

[Development Background]
Initially utilizing third-party libraries such as SoundTouch, we encountered audio dullness and detail degradation during pitch and tempo scaling. To overcome these quality limitations, we built a custom Phase Vocoder with Phase Locking from scratch, continuously refining its mathematical reconstruction architecture based on user feedback to preserve sound crispness and transparency.
採用アプリ:Adopted Apps:
Pitch Tempo Changer Pitch Tempo Changer Flash Video Speed & Pitch Changer Notewise AutoTuner Odd-Time Beat Converter

1. 方式の使い分けとピッチ・テンポの独立制御 ➔ 2パス処理アーキテクチャ 1. Method Selection & Independent Pitch/Tempo Control ➔ Two-Pass Architecture

💬 開発者のつぶやき: 「”音が酷い”というレビューを受けて一念発起、エンジンを自作してみよう」 💬 Dev's Note: "Motivated by user reviews pointing out sound degradation, I decided to build a custom audio engine from scratch."

ピッチやテンポを変える方法には、PSOLAやWSOLAなど、素材や用途に応じて有効な手法があります。本エンジンでは、25%のスロー再生から400%の高速再生までのような大きなテンポ変更にも対応しやすい、周波数領域ベースのPhase Vocoderを中核に採用しています。

【問題】 音声波形をそのまま伸縮させると、テンポの変更に伴ってピッチ(音程)まで一緒に上下してしまうため、テンポとピッチを個別にコントロールすることができない。

【対処(アプローチ)】 処理を明確に2ステップに分離する「2パス戦略(Stretch ➔ Resample)」を採用しました。

  • Pass 1(STFT タイムストレッチ): 短時間フーリエ変換(STFT)を用い、周波数ドメイン上で時間軸(テンポ)のみを正確に伸縮。
  • Pass 2(リサンプリングによるピッチ変換): 伸縮後の時間波形に対し、用途や負荷に応じて「64タップ Kaiser窓付き Sinc リサンプリング」(リアルタイム通常時・オフライン高音質モード)と「Catmull-Rom型 3次スプライン補間」(オフライン標準モード・高負荷フォールバック時)を使い分けて目的のピッチへ着地。
この分離アプローチにより、処理の数学的独立性と軽量な処理負荷、およびリアルタイムでの滑らかなパラメーター追従を実現しています。

PSOLA and WSOLA are effective options depending on the source material and use case. This engine centers on a frequency-domain Phase Vocoder, which is well suited to large tempo changes such as 25% slow playback through 400% fast playback.

[Problem] Directly stretching time waveforms inherently alters pitch alongside tempo, making independent control impossible.

[Solution] A clear 2-pass strategy (Stretch ➔ Resample): Pass 1 stretches the time axis via STFT in the frequency domain; Pass 2 resamples the waveform to reach the target pitch—using 64-tap Kaiser-windowed sinc in HQ offline and normal real-time playback, or lightweight Catmull-Rom cubic spline interpolation in standard offline mode and Tier 3 load fallback.

入力 PCM 元テンポ・元ピッチ (44.1kHz Stereo) Pass 1: STFT 伸縮 周波数ドメインで時間軸伸縮 伸縮率 = Pitch ÷ Tempo ピッチを変えずに長さだけ調整 Pass 2: リサンプリング 時間波形の再生レート変換 64-tap Kaiser-Sinc / Cubic 目的のピッチ・テンポへ同時着地 出力 PCM 独立制御された ピッチ × テンポ
Input PCM Original Tempo/Pitch (44.1kHz Stereo) Pass 1: STFT Stretch Frequency-domain time scaling Ratio = Pitch ÷ Tempo Alters length, keeps pitch fixed Pass 2: Resampling Time-domain rate conversion 64-tap Kaiser-Sinc / Cubic Lands on target Pitch & Tempo Output PCM Independent Pitch & Tempo

2. 金属的フランジャーノイズの発生 ➔ ピーク検出型 Phase Locking(位相同期) 2. Metallic Phasing Artifacts ➔ Peak-Tracking Phase Locking

💬 開発者のつぶやき: 「え・・・・フェーズボコーダって音良いんじゃないの?」 💬 Dev's Note: "Wait... isn't a Phase Vocoder supposed to sound great...?"

【問題】 ナイーブな(単純な)フェーズボコーダでは、時間軸を引き伸ばした際に「隣り合う周波数ビン(Bin)どうしの位相関係がバラバラ」になり、波形が相互干渉することでコーラスがかかったようなキンキンした金属音(Phasing Artifact)や濁りが発生する。

【対処(アプローチ)】 ピーク追跡型のPhase Locked Bins(位相同期機構)を精度向上しました。主音・倍音成分の局所的ピークをサブビン精度で推定し、各周波数ビンを最も近いピークへ割り当てて位相回転を同期。さらに、微小なノイズ成分は不要にロックしないことで、波形の位相コヒーレンスを保ちながら、金属的な響きやシュワシュワした濁りを抑制します。

【さらなる進化(HQモード)】 PGHI型ヒープ位相積分 & パーシャル・リンキング
  • パーシャル・リンキング(Partial Linking): 前フレームのピークと現フレームのピークを ±1.5 ビン以内で対応付け、連続した倍音軌跡として位相を積分することで、音程の滑らかさと透明感を向上。
  • PGHI型 Max-Heap 位相伝播 & 垂直位相コヒーレンス: 従来の単純な最近傍割り当てに代わり、ピークを起点として対数振幅の大きい順(Max-Heap)に隣接ビンへ位相を順次伝播。さらに分析時のビン間位相差(垂直位相コヒーレンス)をそのまま保存して伝播させることで、音色の輪郭を保ちます。
  • 聴覚心理学的しきい値 & コンフォートノイズ補間: フレームピークから −60dB 未満の微小ビンでは無意味な位相アンラップを省き、−70dB 相当の極微小コンフォートノイズでスペクトルギャップを自然に埋めることで、無音〜極小音域の水っぽいノイズ(Musical Noise)を抑制しています。

[Problem] Naive STFT time-stretching disrupts relative phase coherence between adjacent frequency bins, causing unnatural metallic phasing/flanging noise.

[Solution] Refined peak-tracking Phase Locking. The algorithm estimates local spectral peaks with sub-bin precision, assigns each bin to its nearest peak, and synchronizes phase rotation while leaving very low-level noise bins unlocked. This preserves phase coherence while reducing metallic and watery artifacts.

[HQ Evolution] PGHI-Based Heap Phase Integration & Partial Linking
  • Partial Linking Across Frames: Links current spectral peaks to the previous frame's peaks within ±1.5 bins and integrates phase along continuous harmonic trajectories.
  • PGHI Max-Heap Propagation & Vertical Phase Coherence: Instead of flat nearest-peak assignment, HQ mode propagates phases outward from peaks in descending log-magnitude order via a max-heap, preserving the true inter-bin phase gradient from analysis.
  • Psychoacoustic Quiet Threshold & Comfort Noise Floor: Skips phase unwrapping on bins below −60dB relative to the frame peak and fills spectral gaps with a subtle −70dB comfort noise floor, preventing watery musical-noise artifacts in quiet passages.

3. スロー再生時の波形荒れ & 残存ノイズの抑制 ➔ 定常OLA再合成 3. Slow-Tempo Artifacts & Residual Phasing Reduction ➔ Constant OLA

💬 開発者のつぶやき: 「なんか、トレモロ掛かってない?」 💬 Dev's Note: "Wait, why does this sound like a tremolo effect is turned on...?"

【問題】 25%のような極端なスロー再生では、分析フレーム間隔が開いて窓関数の重ね合わせ密度が疎になり、波形の荒れやブツ切りノイズ(トレモロ現象)が生じやすくなる。

【対処(アプローチ)】
  • 動的オーバーラップ(Dynamic Overlap Adjustment): テンポ減速量に応じて内部オーバーラップ倍率を動的に自動制御。どのような超スロー再生でも重ね合わせ密度を常に高く維持。
  • WOLA(Weighted Overlap-Add)再合成: 窓関数による加重Overlap-Addと正規化処理を適用し、フレーム境界の振幅リップルやブツ切り音を物理的に消去。

[Problem] At extreme slow-down rates such as 25%, wider analysis hop sizes can make overlap-add synthesis sparse, producing frame clicks and amplitude flutter (tremolo).

[Solution]
  • Dynamic Overlap Adjustment: Automatically scales internal overlap factors up during slow-tempo playback to ensure continuous window density.
  • WOLA Synthesis: Applies windowing and weight normalization to physically eliminate boundary amplitude clicks.
💬 ユーザーの声: 「なんか、まだトレモロ掛かってない?(金属的なノイズや、ピッチが不自然に歪む感じがある)」 💬 User's Feedback: "Wait, isn't there still a tremolo effect? (Subtle metallic harshness and pitch drift remain...)"

【問題】 なぜWOLA正規化を行っても金属音やピッチ歪みが残るのか?
従来の設計では、分析ホップ $h_a$ を固定して合成ホップを $h_s = \lfloor h_a \times \text{timeStretch} \rfloor$ と整数変換していました。しかし合成ホップ $h_s$ が窓長の厳密な約数(例: $\text{FRAME\_SIZE} / 4$)で均一でないと、合成窓を足し合わせる瞬間に周期的な振幅の波打ち(リップル)が生じます。この局所的なAM変調によって発生した変調サイドバンド(金属音の正体)は、後から全体振幅を重みで割っても波形の中に焼き付いて消えません。さらに整数サンプル移動による微小な丸め誤差が、持続音でのピッチ揺らぎや不自然な歪みを引き起こしていました。

【対処(アプローチ)】 合成ホップ($h_s$)固定 & 倍精度連続解析(定常OLA再合成)
  • 合成ホップ $h_s$ の固定 & 2の累乗アライン: 合成ストライド $h_s = \text{FRAME\_SIZE} / \text{internalOverlap}$ を処理全体で固定し、4や8など「2の累乗」にアライン。Sine窓の二乗和が理論的定数値(4倍重複なら2.0)を満たすため、振幅リップルと変調サイドバンドを理論上抑え込むことができます。
  • 分析ホップの倍精度連続トラバース & サブサンプル線形補間: 分析側の移動量を倍精度浮動小数点 $h_a = h_s / \text{timeStretch}$ として連続計算し、小数部(frac)による線形補間(v0 * (1 - frac) + v1 * frac)で切り出すことで、位相理論値と波形のズレを1サンプル未満に抑えピッチの歪み・揺らぎを大幅に抑制。
  • 動的オーバーラップとの統合: スロー再生時にはオーバーラップ数を $4 \to 8 \to 16$ と2の累乗で動的に自動引き上げ、定数和(COLA)と十分な窓密度を同時に確保します。

[Problem] Why did metallic artifacts and pitch distortion remain despite WOLA?
Even with WOLA normalization, if the synthesis hop $h_s = \lfloor h_a \times \text{timeStretch} \rfloor$ is not a strict uniform divisor of the frame size, overlapping windows create periodic amplitude ripples. The spurious amplitude modulation (AM) generates modulation sidebands (the source of metallic noise) baked into the audio that cannot be removed by amplitude scaling. Furthermore, stepping in integer samples caused fractional timing jitter, producing noticeable pitch wobble and distortion on sustained notes.

[Solution] Fixed Synthesis Hop ($h_s$) & Double-Precision Continuous Analysis
  • Fixed Synthesis Hop ($h_s$) & Power-of-Two Alignment: Holding $h_s = \text{FRAME\_SIZE} / \text{internalOverlap}$ constant aligned to powers of two (4, 8, 16) maintains the theoretical constant sum of squared Sine windows (2.0 at 4x overlap), suppressing amplitude ripples and modulation sidebands.
  • Continuous Double-Precision Analysis & Sub-Sample Linear Interpolation: Evaluating analysis positions continuously via double precision $h_a = h_s / \text{timeStretch}$ with sub-sample linear interpolation (v0 * (1 - frac) + v1 * frac) keeps calculated phase advances aligned with the waveform, greatly reducing pitch drift and timing jitter.
  • Integration with Dynamic Overlap: Scales overlap factors ($4 \to 8 \to 16$) in powers of two during slow playback, ensuring both dense coverage and constant overlap-add (COLA).
従来設計:分析ホップ hₐ 固定 → 合成ホップ hₛ = ⌊hₐ × stretch⌋(端数・不均一) 合成窓の間隔が約数からズレる ➔ 窓の二乗和が周期的に波打つ ➔ 金属音・ピッチ揺らぎ DS Soft:合成ホップ hₛ = FRAME_SIZE / 2ᵏ 完全固定 + 倍精度連続解析 hₐ hₛ が常に2の累乗約数(4, 8, 16) ➔ Sine窓二乗和 = 定数(COLA 2.0) ➔ リップル抑制・透明感向上
Legacy: Fixed Analysis Hop hₐ → Integer Synthesis Hop hₛ = ⌊hₐ × stretch⌋ Non-uniform synthesis window spacing ➔ Periodic window-sum AM ripple ➔ Metallic Sidebands & Wobble DS Soft: Fixed Synthesis Hop hₛ = FRAME_SIZE / 2ᵏ + Double-Precision Analysis hₐ hₛ aligned to power-of-2 divisors ➔ Constant Sine² sum (COLA = 2.0) ➔ Minimal Ripple & Clarity

4. リサンプリング時の高域ノイズ ➔ アンチエイリアス付き高品質リサンプリング 4. High-Frequency Resampling Noise ➔ Anti-Aliased High-Quality Resampling

💬 開発者のつぶやき: 「ユーザー様からいただいた参考音源を聞き衝撃。え、こんな滑らかでシルキーにピッチ変えられるの?」 💬 Dev's Note: "Listening to a reference audio sample sent by a user, I was stunned: 'Wait, pitch can actually be shifted this smoothly and silkily?!'"

【問題】 ピッチ変更後のリサンプリングでは、処理条件によって不要な高域成分が折り返し、ザラつきや高音域のノイズとして聞こえることがある。

【対処(アプローチ)】 音質重視と軽量処理の2方式使い分け

アンチエイリアスフィルタを内包した64タップ Kaiser窓付き Sinc リサンプリング($\beta=9.0$)を主力としつつ、軽量性が必要な場面ではCatmull-Rom 3次スプライン補間へ切り替える2段構成としています。

  • 64タップ Kaiser-Sinc(オフラインHQ & リアルタイム通常時 Tier 0〜2): 不要な高域成分を抑えながら補間することで、高音域のザラつきや折り返し由来のノイズを低減し、滑らかで明瞭な再生を目指します。リアルタイム版では4096点LUTにより軽量に動作します。
  • Catmull-Rom 3次スプライン補間(オフライン標準 & 高負荷フォールバック Tier 3): 4点参照の高速な補間により、負荷を抑えて変換・再生を継続したい場面を担当します。

[Problem] During resampling after pitch adjustment, unwanted high-frequency content can fold back into the audible range, creating graininess and high-frequency noise.

[Solution] Dual Resampling Strategy (Quality vs. Speed)

The engine pairs 64-tap Kaiser-windowed sinc resampling ($\beta=9.0$) with lightweight Catmull-Rom cubic spline interpolation depending on the mode and CPU load:

  • 64-Tap Kaiser-Sinc (Offline HQ & Real-Time Tier 0–2): Integrates anti-alias filtering during interpolation to reduce graininess and aliasing noise for smoother highs (LUT-accelerated in real time).
  • Catmull-Rom Cubic Spline (Offline Standard & Tier 3 Fallback): Uses fast 4-point interpolation when prioritizing minimal CPU overhead or safeguarding real-time continuity under heavy load.

5. モバイルでの高計算負荷 ➔ C++マルチスレッド並列処理(Lock-Free) 5. Heavy Mobile Compute Load ➔ C++ Multi-Thread Parallel Processing

💬 開発者のつぶやき: 「さすがに1曲の変換に1分以上は長すぎるよな・・・」 💬 Dev's Note: "Converting one song taking over a minute is definitely too long..."

【問題】 長尺ファイルやステレオ音声を高精度なFFT/STFTフレーム分解・合成処理する際、重い複素数演算によってモバイル端末のCPU負荷が高まり、ファイル変換やリアルタイムプレビューに時間を要する。

【対処(アプローチ)】 C++のマルチスレッド機能を活用し、L/Rステレオ各チャンネルのSTFT処理を左右独立スレッドで並列実行するアーキテクチャを設計しました。
各スレッドが専用の演算リソースと状態バッファを個別保持することで、スレッド間のロック競合を排し(Lock-Free)、マルチコアCPUの並列性を活かした高速処理を行っています。

[Problem] High-resolution STFT/FFT frame processing over stereo channels incurs significant CPU load on mobile hardware.

[Solution] Multi-threaded execution via C++. Stereo channels process in parallel with isolated thread-local state buffers, eliminating lock contention and making effective use of multi-core CPUs.

6. アタックのにじみ・立ち上がりのもたつき抑制 ➔ トランジェント検出 & 時間領域バイパス/OLAクロスフェード 6. Reducing Attack Smearing & Cancellation ➔ Transient Detection & Time-Domain Bypass / OLA Crossfade

💬 開発者のつぶやき: 「ドラムやボーカルの出だしが、なんだかモタついて揺らぐ……アタック時に位相リセットした波形どうしが打ち消し合ってる!?」 💬 Dev's Note: "Why do drum hits and vocal attacks feel slightly sluggish or wobbly...? Wait—the phase-reset attack frame is actually cancelling out with the previous frame during OLA!"

【問題】 フェーズボコーダでは音の立ち上がり(アタック)を鋭く保つため、トランジェント検出時に位相をリセットします。しかし従来の設計には3つの弱点がありました。
(1) OLA加算による位相の打ち消し合い: 位相が連続している直前フレームと、位相をリセットした新しいアタックフレームをそのまま Overlap-Add(加算)すると、互いに逆相に近い成分が相殺(キャンセル)し合って立ち上がりがもたつく・濁る。
(2) 誤検出による揺らぎ: ゼロ交差率(ZCR)等による単純な判定では、サ行の子音やハイハットなどで連続トリガーが起き、持続音や明るい音色で位相が何度もリセットされて音が不安定に揺らぐ。
(3) 低域の音量ジャンプ: 全帯域の位相を一斉にリセットすると、ベースやキックなどの低周波帯域で不連続な音量段差が生じる。

【対処(アプローチ)】 3段階の位相干渉レス・アタック再合成
  • スペクトルフラックス × サブブロックエネルギー複合検出(detectSubBlockTransient): 直前フレームからの正のスペクトル変化量(Spectral Flux)と瞬間エネルギー上昇率に加え、128サンプル単位のサブブロック走査(プリエンファシス s - 0.65 * prevS 付き)を併用。高速テンポ(大きな ha)でもドラムのアタックを取りこぼさず、クールダウン制御(lastWasTransient / transientCooldownFrames_)によりビブラートや子音での誤発火を抑え、本物のアタックだけを正確に捕捉します。
  • 低域(〜500Hz以下)の位相連続性保護: トランジェント検出時であっても、500Hz以下の低域ビンは位相リセットを行わず連続軌跡を維持。ベースやキックの太い芯を崩さずに、中高域のアタックだけを鋭くリセットします。
  • トランジェントOLAコサイン・クロスフェード: アタックフレームを再合成する際、単純加算ではなく窓の立ち上がり区間(512〜1024サンプル付近)を滑らかなコサイン・クロスフェードで切り替え、後半を新フレームで上書き。これにより位相の打ち消し合いを抑え、原音に近いキレのある立ち上がりを保ちます。
  • 1:1 時間領域トランジェント・バイパス(transientBypassFrames_): リアルタイム処理(PhaseVocoder::Stream)で伸縮中(|timeStretch - 1.0| ≥ 0.03)に鋭いアタックを検出すると、FFT/IFFTを通さず同一2048点窓のまま 1:1 の時間領域波形へコサイン・クロスフェードでスプライスし、続く数フレームも時間領域のまま出力。周波数変換によるアタックの艶・粒立ちの劣化を抑えつつ計算負荷も削減し、PV復帰時には全ビンの位相を現在値へ再同期して滑らかに接続します。
  • 適応ホップ長制御によるアタック非伸縮(computeAdaptiveHop): ハイクオリティモードやバイパス復帰時の時間ドリフト(adaptiveDrift_)制御では、アタック直後の数フレームだけ分析ホップ ha を 1.0× 側(hs 付近)へ引き戻して原音の鋭さを維持し、後続の定常部で時間ドリフトを緩やかに吸収して全体のテンポを厳密に一致させます。

[Problem] To keep percussive attacks crisp, a Phase Vocoder resets synthesis phases on detected transients. However, naive phase resetting introduces three subtle artifacts:
(1) OLA Phase Cancellation: Simply adding a phase-reset attack frame onto the preceding continuous-phase frame causes partial destructive interference, smearing the attack and making it feel sluggish.
(2) False-Trigger Wobble: Simple ZCR or energy thresholds can fire repeatedly on sibilants, hi-hats, or vibrato, causing unstable warbling.
(3) Low-Frequency Volume Jumps: Resetting phases across all bins disrupts low-end fundamentals like kick and bass.

[Solution] Interference-Free Three-Stage Transient Synthesis
  • Spectral Flux × Sub-Block Energy Composite Detection (detectSubBlockTransient): Combines positive spectral flux and instantaneous energy rise with a 128-sample sub-block scan (with gentle pre-emphasis s - 0.65 * prevS) so fast tempos never skip drum hits, while cooldown logic (lastWasTransient / transientCooldownFrames_) prevents false triggers on vibrato or bright consonants.
  • Sub-500Hz Phase Continuity Protection: Keeps phase trajectories continuous below ~500Hz even during transients, resetting only mid-to-high frequencies so kick and bass fundamentals remain rock-solid.
  • Transient OLA Cosine Crossfading: Instead of summing conflicting phases during OLA, transient frames smoothly cosine-crossfade over the 512–1024 sample region and overwrite the remainder with the fresh attack frame—reducing destructive phase cancellation and keeping punchy transients.
  • 1:1 Time-Domain Transient Bypass Splice (transientBypassFrames_): In real-time streaming (PhaseVocoder::Stream), when a sharp transient arrives while stretching (|timeStretch - 1.0| ≥ 0.03), the engine skips FFT/IFFT and splices directly into a 1:1 time-domain 2048-sample window via cosine crossfade for the attack span—preserving natural attack sheen and cutting CPU cost, then resyncing all bin phases seamlessly on return to PV.
  • Transient-Preserving Adaptive Hop Control (computeAdaptiveHop): Temporarily blends the analysis hop ha toward 1.0× (hs) right after a transient so the attack itself is never smeared by slow stretching, then smoothly absorbs accumulated timing drift (adaptiveDrift_) during steady-state segments.
時間軸に沿った「定常部(PV)」⇔「アタック部(1:1 時間領域バイパス)」ハイブリッド遷移 通常定常部 Phase Vocoder PGHI 位相ロック 透明感のある持続音 アタック検出 128pt サブブロック走査 + スペクトルフラックス 512–1024 Cosine接続 1:1 時間領域バイパス FFT / IFFT をスキップ 原音波形を非伸縮で出力 アタックの艶・キレ維持 PVへシームレス復帰 全ビン位相を再同期 adaptiveDrift_ で 時間ズレを緩やかに吸収 同一2048点窓で境界をコサイン・クロスフェードするため、位相干渉による打ち消しやクリック音を抑えながら接続できます。
Timeline Hybrid Transition: Steady-State PV ⇔ 1:1 Time-Domain Attack Bypass Steady-State Phase Vocoder PGHI Phase Locking Transparent sustain Onset Detected 128-pt Sub-Block Scan + Spectral Flux 512–1024 Cosine Splice 1:1 Time-Domain Bypass Skips FFT / IFFT Unstretched 2048-pt frame Preserves attack sheen Return to PV Resync all bin phases Absorb adaptiveDrift_ smoothly in steady-state Cosine-crossfading across the identical 2048-sample window minimizes destructive interference and clicks.

7. 高品質エンジンのリアルタイム化 ➔ ストリーミングSTFT + 64タップKaiser-Sinc 7. Real-Time Engine Streaming ➔ Continuous STFT + 64-Tap Kaiser-Sinc

💬 開発者のつぶやき: 「このPhase Vocoderの高音質を、書き出しだけじゃなく再生中のスライダー操作でもリアルタイムに反映できたら最高なのに……!」 💬 Dev's Note: "What if we could bring this exact Phase Vocoder quality—not just to offline file export, but to live slider changes during playback?!"

【問題】 従来の「2パス処理(ファイル全体を一括でSTFT伸縮 ➔ 全体をリサンプリング)」はオフライン書き出しでは高い音質を得られる一方、曲全体をメモリに展開する必要があり、再生中にリアルタイムでピッチやテンポ、フォルマントを動かす用途にはそのまま適用できなかった。

【対処(アプローチ)】 逐次ストリーミングエンジン(PhaseVocoder::Stream)の構築
  • リング/FIFOベースの連続2パス・ストリーミング: 入力PCMを逐次受け取り、STFT解析位置(analysisPos_)とリサンプル位置(resamplePos_)を倍精度で連続トラッキング。フレーム間の位相状態(sumPhase / lastPhase)やOLAアキュムレータを保持したまま、スライダー操作を音切れ・フラッシュなしで即座にリアルタイム反映します。
  • LUT高速化 64タップ Kaiser窓付き Sinc リサンプラー: リアルタイム環境でもアンチエイリアス付き高品質リサンプリングを軽快に回すため、ベッセル関数($I_0$)ベースのKaiser窓($\beta=9.0$)とSinc重みを4096点ルックアップテーブル(LUT)化。ピッチ変更量に応じた適応型ローパス・カットオフにより、折りかえしノイズを抑えたシルキーな高域をリアルタイム出力します。
  • ゼロアロケーション & ソフトクリッピング保護 & 非対称ゲイン平滑化: 定常ループ内のメモリ再確保を排除し、オフライン版と同等のPGHI位相伝播・適応ホップ制御・フォルマント処理(過大ブーストを +1.9dB 上限に抑え、アタック即応・リリース緩慢で平滑化する非対称RMSゲイン正規化)と出力ソフトクリッパーを搭載。急激なパラメーター変更時でも破綻のない安定した低遅延再生を実現しています。

[Problem] While the original two-pass batch pipeline excelled for offline file conversion, holding entire tracks in memory prevented immediate real-time parameter updates during live playback.

[Solution] Continuous Streaming Architecture (PhaseVocoder::Stream)
  • Continuous FIFO-Based 2-Pass Streaming: Consumes incoming PCM chunks incrementally while tracking both STFT analysisPos_ and resampler resamplePos_ in double precision. Pitch, tempo, and formant sliders update live without pipeline flushes or audio dropouts.
  • LUT-Accelerated 64-Tap Kaiser-Windowed Sinc Resampler: Precomputes a 4096-entry lookup table for Kaiser-windowed ($\beta=9.0$) sinc interpolation with pitch-adaptive anti-alias cutoff, delivering silky, alias-free highs in real time on mobile CPUs.
  • Steady-State Zero Allocation, Asymmetric Gain Smoothing & Soft Clipping: Pre-allocated scratch buffers eliminate per-frame heap churn while sharing the offline engine's PGHI phase propagation, adaptive hop control, formant RMS normalization (capped at +1.9dB with fast-attack / smooth-release smoothing), and an output soft clipper for stable real-time modulation.

8. リアルタイム性の維持 ➔ 負荷監視 & 段階的自動フォールバック(WSOLAハイブリッド) 8. Maintaining Real-Time Playback ➔ Load Monitoring & Tiered Auto-Fallback (WSOLA Hybrid)

💬 開発者のつぶやき: 「端末が重くなった瞬間に音がプチプチ途切れるのは避けたい……リアルタイム負荷に応じて自動でアルゴリズムを切り替えられないか?」 💬 Dev's Note: "We want to avoid audio dropouts when the device gets busy... What if the engine monitors its own real-time load and steps down algorithms automatically?"

【問題】 モバイル端末では、他アプリのバックグラウンド動作や省電力モード(サーマルスロットリング)、あるいは超スロー再生による高倍率オーバーラップが重なると、STFT+64タップSinc処理の計算時間が実時間(オーディオ再生長)を超過し、バッファアンダーランによる音飛び・ブツ切れが発生するリスクがある。

【対処(アプローチ)】 リアルタイム負荷監視(loadFactorEma_)& ヒステリシス付き4段階フォールバック

PhaseVocoder::Stream 内でフレーム生成ごとに「実処理時間 ÷ 生成オーディオ長」の瞬間負荷率と指数移動平均(EMA)を常時計測し、音切れが起きる前に4段階(Tier 0〜3)で処理を自動的に軽量化・切り替えます。

  • Tier 0(通常運転 / HQ_PV or STD_PV): PGHI型HQ Phase Vocoder(または標準PV)+ 64タップ Kaiser-Sinc リサンプリングで動作。
  • Tier 1(PV_LITE / EMA > 0.70): HQモードの重いPGHI演算・適応ホップを標準PVへ落とし、さらに動的オーバーラップ上限を 8 に制限してSTFT回数を抑制(保持1.5秒)。
  • Tier 2(WSOLA 切り替え / 瞬間負荷 > 0.90 または EMA > 0.85): 重いFFT/IFFTをスキップし、1024サンプル窓・探索幅512サンプルの正規化相互相関による時間領域 WSOLA(Waveform Similarity Overlap-Add) へ自動切り替え(保持2.0秒)。PV ⇔ WSOLA 間の遷移時には128〜384サンプル区間でコサイン・クロスフェードと全ビン位相再同期を行い、切り替え時のクリック音を抑えています。
  • Tier 3(CUBIC 補間フォールバック / 瞬間負荷 > 1.05 または EMA > 1.00): WSOLA に加え、Pass 2 の 64タップ Kaiser-Sinc リサンプリングも軽量な 3次スプライン補間(Cubic Interpolation) へ切り替え、高負荷な状況でもリアルタイム再生の維持を図ります(保持2.0秒)。
  • ヒステリシス付き段階的復帰 & JNI状態公開: 負荷が EMA < 0.55 まで落ち着き保持時間が経過すると、Tier 3 → 2 → 1 → 0 へと1段階ずつ(1.0秒間隔)安全に元の高品質モードへ復帰(ハンチング防止)。さらに getActiveEngineMode() / getRealtimeLoadFactor() により、アプリ側UIでも稼働中のエンジン状態をリアルタイムに把握できます。

[Problem] On mobile devices, background tasks, thermal throttling, or high overlap factors during extreme slow playback can push STFT + 64-tap Sinc processing time past real-time audio duration, risking buffer underruns and audible dropouts.

[Solution] Real-Time Load Monitoring (loadFactorEma_) & Hysteretic 4-Tier Auto-Fallback

PhaseVocoder::Stream continuously measures instantaneous CPU load (processing time ÷ generated audio duration) and its exponential moving average (EMA), stepping through four tiers before underruns can occur:

  • Tier 0 (Normal / HQ_PV or STD_PV): Runs full PGHI-based HQ Phase Vocoder (or Standard PV) with 64-tap Kaiser-Sinc resampling.
  • Tier 1 (PV_LITE / EMA > 0.70): Steps down from HQ PGHI/adaptive hop to Standard PV and caps dynamic overlap at 8 to cut STFT iterations (1.5s hold).
  • Tier 2 (WSOLA / Instant > 0.90 or EMA > 0.85): Skips FFT/IFFT and switches to time-domain WSOLA (Waveform Similarity Overlap-Add) using a 1024-sample window and 512-sample normalized cross-correlation search (2.0s hold). Transitions between PV and WSOLA use a 128–384 sample cosine crossfade plus full-bin phase resync for smooth switching.
  • Tier 3 (CUBIC / Instant > 1.05 or EMA > 1.00): Combines WSOLA with lightweight Cubic Interpolation in Pass 2 instead of 64-tap Kaiser-Sinc, safeguarding continuous playback even under extreme CPU contention (2.0s hold).
  • Hysteretic Recovery & JNI Telemetry: Once load settles below EMA < 0.55 and hold timers expire, the engine steps back up one tier at a time (1.0s intervals) to prevent mode hunting, while exposing getActiveEngineMode() and getRealtimeLoadFactor() to the app UI.
リアルタイム負荷率(loadFactorEma_)に応じた4段階自動フォールバック & ヒステリシス復帰 Tier 0: 通常運転 HQ_PV / STD_PV PGHI型 Phase Vocoder + 64-tap Kaiser-Sinc 高音質モード Tier 1: 軽量PV PV_LITE (EMA > 0.70) PGHI演算を標準PVへ オーバーラップ上限 = 8 保持: 1.5秒 Tier 2: 時間領域 WSOLA (EMA > 0.85) FFT/IFFTをスキップ 128–384 Cosineクロスフェード 保持: 2.0秒(Inst > 0.90) Tier 3: 負荷保護 CUBIC (EMA > 1.00) WSOLA + Pass 2も 3次スプライン補間へ 保持: 2.0秒(Inst > 1.05) 負荷安定時(EMA < 0.55 & 保持タイマー満了)➔ 1.0秒間隔で1段階ずつ安全復帰 ※ getActiveEngineMode() / getRealtimeLoadFactor() によりアプリUIからもリアルタイム監視可能
4-Tier Load-Adaptive Auto-Fallback (loadFactorEma_) & Hysteretic Recovery Tier 0: Normal HQ_PV / STD_PV PGHI Phase Vocoder + 64-tap Kaiser-Sinc High Quality Tier 1: Lite PV PV_LITE (EMA > 0.70) Standard PV mode Overlap capped at 8 Hold: 1.5s Tier 2: Time-Domain WSOLA (EMA > 0.85) Skips FFT/IFFT 128–384 Cosine crossfade Hold: 2.0s (Inst > 0.90) Tier 3: Load Guard CUBIC (EMA > 1.00) WSOLA + Pass 2 Cubic Interpolation Hold: 2.0s (Inst > 1.05) Load Settled (EMA < 0.55 & Hold Expired) ➔ Step-Up Recovery Every 1.0s Live status exposed to App UI via getActiveEngineMode() & getRealtimeLoadFactor()

9. 技術の応用展開 ➔ 部分的なピッチ・時間伸縮が切り拓く新体験 9. Architectural Expansion ➔ Localized Pitch & Time Modulation

💬 ユーザーの声: 「Melodyneみたいに、特定の音だけ音程変えられるアプリ作れない?」
💬 開発者のつぶやき: 「ピンポイントに時間軸を伸縮できるなら……これ、拍ごとに伸縮させて変拍子変換とかいけるんじゃね?」
💬 User's Voice: "Can you build an app like Melodyne that edits specific notes on mobile?"
💬 Dev's Note: "Wait, if we can stretch localized time segments arbitrarily... couldn't we transform regular meters into odd time signatures or custom grooves on the fly?!"

フェーズボコーダの本質的な強みは、楽曲全体を一律にストレッチ・ピッチ変更するだけに留まりません。「時間軸上の特定区間」「特定の音符」だけをピンポイントに切り出し、局所的にパラメーターを動的コントロールできる柔軟性にあります。
DS Softではこの特性に着目し、「ピッチ領域」と「テンポ(時間)領域」のそれぞれにおいて、従来の常識を覆すユニークな応用アプリへと展開しました。

● ピッチ領域の応用 ➔ Notewise AutoTuner(メロディ補正・スケール再構築)

オーディオ波形から音符(ノート)単位のピッチ軌跡を検出し、ピンポイントで音程を操作。

  • 単一ノートの補正: ボーカルや管楽器メロディの「特定の1音だけ」をピッチシフトし、調外音や音程のズレを綺麗にリファイン。
  • スケール・調性のダイナミック変換: メロディ内の特定の構成音を半音単位で上下させることで、「短調(マイナー)の楽曲を長調(メジャー)にトランスフォーム」したり、教会旋法(ドリアン、フリジアン等)や民族音階へ楽曲のムードそのものを再構築。
● テンポ(時間)領域の応用 ➔ Odd-Time Beat Converter(変拍子化・グルーヴ変形)

曲全体を均一に速く/遅くするのではなく、自動ビート解析と連動して「リズムの特定の拍だけをミリ秒単位で個別に伸縮・削除」。

  • 変拍子へのトランスフォーム: 4/4拍子の楽曲から特定の拍を伸縮・挿入することで、自然な音質を保ったまま「5/4拍子や7/8拍子のプログレ楽曲」へと再構築。
  • グルーヴの自由自在なコントロール: イーブンな8ビートや16ビートの裏拍を局所的にタイムストレッチし、シャッフルやスウィング、バルカン風の複雑なポリリズムへとグルーヴ感を自在に変形。

The true strength of the Phase Vocoder extends far beyond uniform tempo or pitch shifts across an entire track. Its mathematical elegance allows for pinpoint, localized dynamic modulation applied to specific time intervals or individual notes.
DS Soft leveraged this unique characteristic to pioneer unconventional applications across both the pitch and time domains.

● Pitch Domain ➔ Notewise AutoTuner (Melody Tuning & Scale Re-Harmonization)

Tracks note-level pitch trajectories from audio waveforms and applies localized surgical frequency shifts.

  • Individual Note Correction: Pinpoint adjustment for single out-of-tune notes in vocal or melodic instrument recordings.
  • Dynamic Scale Transformation: Shifting specific notes in a melody allows converting minor-key songs to major keys, or morphing melodies into Dorian, Phrygian, or exotic modal scales.
● Time Domain ➔ Odd-Time Beat Converter (Odd-Meter Conversion & Groove Morphing)

Rather than uniformly changing song tempo, it pairs automatic beat analysis with millisecond-precision localized stretching or deletion of specific beats.

  • Odd-Meter Transformation: Stretches or alters designated beats in standard 4/4 songs to reconstruct them cleanly into 5/4 or 7/8 progressive rock rhythms.
  • Groove Control & Morphing: Localized time-stretching of off-beats transforms even 8th/16th note rhythms into swung, shuffled, or complex Balkan polyrhythms on the fly.

10. プロダクト設計における選択と進化 ➔ Media3再生基盤 × リアルタイムPhase Vocoder 10. Architectural Evolution ➔ Media3 Playback Foundation × Real-Time Phase Vocoder

💬 開発者のつぶやき: 「軽快なレスポンスとPhase Vocoderの音質、Media3と組み合わせれば両方手に入るんじゃ!?」 💬 Dev's Note: "Wait—if we combine Media3's reliable playback service with our real-time streaming Phase Vocoder, we can get both snappy responsiveness and clear sound!"

DS Softでは、すべてのアプリで同じ構成を盲目的に使うのではなく、「アプリが追求する体験の軸」に合わせて最適なアーキテクチャを選択しています。

Pitch Tempo Changer Flash における統合アプローチ
「Pitch Tempo Changer Flash」は「軽快な起動と素早いレスポンス」をコンセプトとして開発され、初期バージョンではAndroid標準のMedia3(ExoPlayer / Sonic系)によるピッチ・スピード処理を採用していました。
その後、リアルタイム・ストリーミング型Phase Vocoder(PhaseVocoder::Stream)の確立とアタック滲み抑制(OLAクロスフェード/時間領域バイパス)の実装を受け、Media3のフォアグラウンド再生・シーク・メディア通知基盤はそのまま活かしながら、音声処理コア(AudioProcessor)を自作Phase Vocoderへ刷新。
スライダー操作時のパイプライン再フラッシュを回避する制御と組み合わせることで、Flashならではの軽快な操作感を損なうことなく、高い音質とリアルタイム反映の両立を図っています。

Rather than forcing one rigid architecture onto every app, we align each product's audio stack with its core user experience goals:

Pitch Tempo Changer Flash Case Study
Designed around quick responsiveness and a lightweight footprint, "Pitch Tempo Changer Flash" initially relied on Android Media3's built-in Sonic pitch/speed processor.
With the completion of our low-latency PhaseVocoder::Stream engine and transient OLA crossfading / time-domain bypass, we replaced the internal AudioProcessor with our custom Phase Vocoder while retaining Media3's reliable background playback and notification architecture—delivering real-time, clean sound without sacrificing Flash's snappy feel.

おわりに:実際の音でお試しください Conclusion: Experience the Sound

これらの理論や仕組みが実際に音としてどのような効果をもたらしているか、ぜひご自身の耳でお試しください。
その上で、もしご意見やご感想をいただけましたら、それが今後の開発の原動力になります。

Experience how these algorithms and design ideas actually shape the sound in our applications.
If you have any feedback or thoughts, we would love to hear from you—it directly fuels our ongoing development!

搭載アプリ(Pitch Tempo Changer)を見る » View App (Pitch Tempo Changer) »