35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
import os
|
|
import json
|
|
import pytest
|
|
from app.core.render_engine import PythonRenderEngine
|
|
|
|
def test_render_engine_init():
|
|
engine = PythonRenderEngine()
|
|
assert engine.sample_rate == 44100
|
|
|
|
def test_bars_to_samples():
|
|
engine = PythonRenderEngine()
|
|
samples = engine.bars_to_samples(4.0, 120.0, 4)
|
|
assert samples == 352800
|
|
|
|
def test_render_session_container_empty():
|
|
engine = PythonRenderEngine()
|
|
session = {"tracks": []}
|
|
buf = engine.render_session_container(session, {}, 120.0, 4, 1000)
|
|
assert buf.shape == (2, 1000)
|
|
assert (buf == 0.0).all()
|
|
|
|
def test_render_project_bit_depth(tmp_path):
|
|
"""bit_depth 24/32 → WAV PCM_24/PCM_32; mặc định vẫn PCM_16."""
|
|
import soundfile as sf
|
|
engine = PythonRenderEngine()
|
|
project = {
|
|
"metadata": {"bpm": 120, "time_signature_numerator": 4},
|
|
"main_session": {"length_bars": 1.0, "tracks": []},
|
|
"section_store": {},
|
|
}
|
|
for bd, subtype in [(16, "PCM_16"), (24, "PCM_24"), (32, "PCM_32")]:
|
|
out = str(tmp_path / f"render_{bd}.wav")
|
|
engine.render_project(project, out, bit_depth=bd)
|
|
assert sf.info(out).subtype == subtype
|