// Copyright (C) 2026 Yusuke Oda // SPDX-License-Identifier: AGPL-3.0-only //! 通常の演奏・音色・オートメーションを固定した性能回帰スイート。 #![allow(dead_code)] // ABI・保存処理など、計測対象以外の既存定義も読み込む。 #[path = "../src/abi.rs"] mod abi; #[path = "../src/chorus.rs"] mod chorus; #[path = "../src/compressor.rs"] mod compressor; #[path = "../src/delay.rs"] mod delay; #[path = "../src/distortion.rs"] mod distortion; #[path = "../src/effects.rs"] mod effects; #[path = "../src/envelope.rs"] mod envelope; #[path = "../src/eq.rs"] mod eq; #[path = "../src/filter.rs"] mod filter; #[path = "../src/float_mode.rs"] mod float_mode; #[path = "../src/limiter.rs"] mod limiter; #[path = "../src/oscillator.rs"] mod oscillator; #[path = "../src/parameters.rs"] mod parameters; #[path = "../src/phaser.rs"] mod phaser; #[path = "../src/random.rs"] mod random; #[path = "../src/reverb.rs"] mod reverb; #[path = "../src/synth.rs"] mod synth; #[path = "../src/voice.rs"] mod voice; #[path = "../src/volume.rs"] mod volume; #[cfg(after)] use parameters::state::{read_state, write_state}; use abi::*; use parameters::*; use std::{ptr, io::Write}; const STATE_SIZE: usize = 1076; fn main() { let mut bytes = Vec::new(); let default = defaults(); let preset = sine_preset(); for i in 0..COUNT { bytes.extend_from_slice(&IDS[i].to_le_bytes()); bytes.extend_from_slice(NAMES[i].as_bytes()); bytes.push(0); bytes.extend_from_slice(unit(i).as_bytes()); bytes.push(0); bytes.extend_from_slice(&default[i].to_bits().to_le_bytes()); bytes.extend_from_slice(&preset[i].to_bits().to_le_bytes()); bytes.extend_from_slice(&max_tick(i).to_le_bytes()); bytes.push(holds_between_points(i) as u8); for name in choices(i) { bytes.extend_from_slice(name.as_bytes()); bytes.push(0); } for tick in 0..=max_tick(i) { bytes.extend_from_slice(&tick_to_plain(i,tick).to_bits().to_le_bytes()); } for step in 0..=1000 { let x = f64::from(step) / 1000.0; bytes.extend_from_slice(&to_plain(i,x).to_bits().to_le_bytes()); bytes.extend_from_slice(&canonical(i,x).to_bits().to_le_bytes()); bytes.extend_from_slice(&to_tick(i,x).to_le_bytes()); } } for values in [default, preset, std::array::from_fn(|i| canonical(i,0.625))] { let mut stream = Stream {vtable:&STREAM_TABLE,bytes:[0;STATE_SIZE],length:0,position:0}; let raw = ptr::from_mut(&mut stream).cast(); assert_eq!(unsafe { write_state(raw,values) }, OK); bytes.extend_from_slice(&stream.bytes); unsafe { (*raw.cast::()).position=0; } for value in unsafe {read_state(raw)}.unwrap() {bytes.extend_from_slice(&value.to_bits().to_le_bytes());} } std::io::stdout().lock().write_all(&bytes).unwrap(); } #[repr(C)] struct Stream { /// このテストだけで使うIBStream関数表。 vtable: &'static StreamVTable, /// 形式の最大長だけを用意したテスト用領域。 bytes: [u8; STATE_SIZE], /// 初期化済みデータの長さ。 length: usize, /// 次の読み書き位置。 position: usize, } unsafe extern "system" fn query(_: This, _: *const Tuid, _: *mut This) -> TResult { NO_INTERFACE } unsafe extern "system" fn retain(_: This) -> u32 { panic!("stream is borrowed") } unsafe extern "system" fn read(this: This, out: This, size: i32, actual: *mut i32) -> TResult { // SAFETY: テストのStreamと、呼び出し元が確保した出力領域。両者は重ならない。 unsafe { let stream = &mut *this.cast::(); let count = (size as usize).min(3).min(stream.length - stream.position); ptr::copy_nonoverlapping( stream.bytes.as_ptr().add(stream.position), out.cast(), count, ); stream.position += count; actual.write(count as i32); } OK } unsafe extern "system" fn write( this: This, input: This, size: i32, actual: *mut i32, ) -> TResult { // SAFETY: テストのStreamと、呼び出し元が確保した入力領域。両者は重ならない。 unsafe { let stream = &mut *this.cast::(); let count = (size as usize) .min(2) .min(stream.bytes.len() - stream.position); ptr::copy_nonoverlapping( input.cast(), stream.bytes.as_mut_ptr().add(stream.position), count, ); stream.position += count; stream.length = stream.position; actual.write(count as i32); } OK } unsafe extern "system" fn seek(_: This, _: i64, _: i32, _: *mut i64) -> TResult { panic!("unexpected seek") } unsafe extern "system" fn tell(_: This, _: *mut i64) -> TResult { panic!("unexpected tell") } static STREAM_TABLE: StreamVTable = StreamVTable { unknown: UnknownVTable { query_interface: query, add_ref: retain, release: retain, }, read, write, seek, tell, };