From f4ddf5bf594092599e1a21cf9ebe79ee8fc1b3ce Mon Sep 17 00:00:00 2001 From: AkiyukiOkayasu Date: Thu, 8 Jun 2023 15:07:28 +0900 Subject: [PATCH] Rewrite comments in English --- src/imaadpcm.rs | 17 +++++++++-------- src/lib.rs | 17 ++++++++++------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/imaadpcm.rs b/src/imaadpcm.rs index 2efe5c8..aa41eff 100644 --- a/src/imaadpcm.rs +++ b/src/imaadpcm.rs @@ -107,7 +107,7 @@ fn decode_sample( (predicted_sample, step_size_table_index) } -/// step_sizeの更新 +/// Update step_size of IMA-ADPCM table fn compute_step_size(nibble: u4, mut step_size_table_index: i8) -> i8 { // adjust index into step_size lookup table using original_sample step_size_table_index += INDEX_TABLE[nibble.value() as usize]; @@ -115,7 +115,7 @@ fn compute_step_size(nibble: u4, mut step_size_table_index: i8) -> i8 { step_size_table_index } -/// サンプル数を計算する. +/// Calculate the number of samples per channel for IMA-ADPCM files. pub(crate) fn calc_num_samples_per_channel( data_chunk_size_in_bytes: u32, spec: &PcmSpecs, @@ -136,16 +136,17 @@ pub(crate) fn calc_num_samples_per_channel( pub struct ImaAdpcmPlayer<'a> { /// A reader to access basic information about the PCM file. pub reader: PcmReader<'a>, - /// 現在読んでいるサンプル位置. + /// Frame index of the current block. frame_index: u32, - /// デコードされた直近の値. + /// The last decoded sample value. last_predicted_sample: [I1F15; MAX_NUM_CHANNELS], - /// STEP_SIZE_TABLEのindex. + /// The current index of STEP_SIZE_TABLE. step_size_table_index: [i8; MAX_NUM_CHANNELS], - /// 現在読み込み中のIMA-ADPCMのブロック. + /// The current block of IMA-ADPCM being read. reading_block: &'a [u8], - /// Data word読み込み時のnibble配列を保管するqueue. - nibble_queue: [Queue; MAX_NUM_CHANNELS], //todo Queueサイズは2の冪乗の方がパフォーマンスよい。 + /// A queue that stores nibble arrays when reading data words. + /// TODO: Queue size is better to be a power of 2 for performance. + nibble_queue: [Queue; MAX_NUM_CHANNELS], } impl<'a> ImaAdpcmPlayer<'a> { diff --git a/src/lib.rs b/src/lib.rs index ebdbeb4..0f98bcd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -180,13 +180,15 @@ impl<'a> PcmReader<'a> { Ok((input, &[])) } + /// PCMReader is a struct that reads PCM data from a byte array. + /// It supports Linear PCM and IEEE Float. /// * 'input' - PCM data byte array pub fn new(input: &'a [u8]) -> Self { let file_length = input.len(); let mut reader: PcmReader = Default::default(); - //WAVの場合 + //WAVE if let Ok((input, riff)) = wav::parse_riff_header(input) { assert_eq!((file_length - 8) as u32, riff.size); if let Ok((_, _)) = reader.parse_wav(input) { @@ -194,7 +196,7 @@ impl<'a> PcmReader<'a> { } }; - //AIFFの場合 + //AIFF if let Ok((input, _aiff)) = aiff::parse_aiff_header(input) { // assert_eq!((file_length - 8) as u32, aiff.size); if let Ok((_, _)) = reader.parse_aiff(input) { @@ -203,6 +205,7 @@ impl<'a> PcmReader<'a> { }; //WAVでもAIFFでもなかった場合 + panic!(); } @@ -226,11 +229,11 @@ impl<'a> PcmReader<'a> { } } -/// DATAチャンクを読んでサンプルを読みだす -/// フォーマットに関わらず+/-1の範囲に正規化された数を返す -/// TODO f32以外Q15やQ23, f64などでも返せるようにしたい -/// もしくはf32かf64を選択できるようにする -/// 固定小数点の取得はread_raw_sample()的な関数とそのジェネリスクで対応するのがいいかもしれない +/// Decode a sample from a byte array. +/// Returns a normalized value in the range +/-1.0 regardless of AudioFormat. +/// TODO return not only f32 but also Q15, Q23, f64, etc. +/// Or make it possible to select f32 or f64. +/// It may be better to use a function like read_raw_sample() to get fixed-point numbers. fn decode_sample(specs: &PcmSpecs, data: &[u8]) -> anyhow::Result { match specs.audio_format { AudioFormat::Unknown => {