mirror of
https://github.com/iluvcapra/bwavfile.git
synced 2025-12-31 08:50:44 +00:00
clippy: Use Avoid unnecessary indexing in for loops
This commit is contained in:
18
src/fmt.rs
18
src/fmt.rs
@@ -328,12 +328,12 @@ impl WaveFmt {
|
|||||||
"frames buffer does not contain a number of samples % channel_count == 0"
|
"frames buffer does not contain a number of samples % channel_count == 0"
|
||||||
);
|
);
|
||||||
|
|
||||||
for n in 0..from_frames.len() {
|
for frame in from_frames {
|
||||||
match (self.valid_bits_per_sample(), self.bits_per_sample) {
|
match (self.valid_bits_per_sample(), self.bits_per_sample) {
|
||||||
(0..=8,8) => write_cursor.write_u8((from_frames[n] + 0x80) as u8 ).unwrap(), // EBU 3285 §A2.2
|
(0..=8,8) => write_cursor.write_u8((frame + 0x80) as u8 ).unwrap(), // EBU 3285 §A2.2
|
||||||
(9..=16,16) => write_cursor.write_i16::<LittleEndian>(from_frames[n] as i16).unwrap(),
|
(9..=16,16) => write_cursor.write_i16::<LittleEndian>(*frame as i16).unwrap(),
|
||||||
(10..=24,24) => write_cursor.write_i24::<LittleEndian>(from_frames[n]).unwrap(),
|
(10..=24,24) => write_cursor.write_i24::<LittleEndian>(*frame).unwrap(),
|
||||||
(25..=32,32) => write_cursor.write_i32::<LittleEndian>(from_frames[n]).unwrap(),
|
(25..=32,32) => write_cursor.write_i32::<LittleEndian>(*frame).unwrap(),
|
||||||
(b,_)=> panic!("Unrecognized integer format, bits per sample {}, channels {}, block_alignment {}",
|
(b,_)=> panic!("Unrecognized integer format, bits per sample {}, channels {}, block_alignment {}",
|
||||||
b, self.channel_count, self.block_alignment)
|
b, self.channel_count, self.block_alignment)
|
||||||
}
|
}
|
||||||
@@ -344,8 +344,8 @@ impl WaveFmt {
|
|||||||
/// Read bytes into frames
|
/// Read bytes into frames
|
||||||
pub fn unpack_frames(&self, from_bytes: &[u8], into_frames: &mut [i32]) -> () {
|
pub fn unpack_frames(&self, from_bytes: &[u8], into_frames: &mut [i32]) -> () {
|
||||||
let mut rdr = Cursor::new(from_bytes);
|
let mut rdr = Cursor::new(from_bytes);
|
||||||
for n in 0..(into_frames.len()) {
|
for frame in into_frames {
|
||||||
into_frames[n] = match (self.valid_bits_per_sample(), self.bits_per_sample) {
|
*frame = match (self.valid_bits_per_sample(), self.bits_per_sample) {
|
||||||
(0..=8,8) => rdr.read_u8().unwrap() as i32 - 0x80_i32, // EBU 3285 §A2.2
|
(0..=8,8) => rdr.read_u8().unwrap() as i32 - 0x80_i32, // EBU 3285 §A2.2
|
||||||
(9..=16,16) => rdr.read_i16::<LittleEndian>().unwrap() as i32,
|
(9..=16,16) => rdr.read_i16::<LittleEndian>().unwrap() as i32,
|
||||||
(10..=24,24) => rdr.read_i24::<LittleEndian>().unwrap(),
|
(10..=24,24) => rdr.read_i24::<LittleEndian>().unwrap(),
|
||||||
@@ -421,8 +421,8 @@ where
|
|||||||
) -> Result<usize, std::io::Error> {
|
) -> Result<usize, std::io::Error> {
|
||||||
assert!(into.len() % format.channel_count as usize == 0);
|
assert!(into.len() % format.channel_count as usize == 0);
|
||||||
|
|
||||||
for n in 0..(into.len()) {
|
for frame in into {
|
||||||
into[n] = match (format.valid_bits_per_sample(), format.bits_per_sample) {
|
*frame = match (format.valid_bits_per_sample(), format.bits_per_sample) {
|
||||||
(0..=8,8) => self.read_u8().unwrap() as i32 - 0x80_i32, // EBU 3285 §A2.2
|
(0..=8,8) => self.read_u8().unwrap() as i32 - 0x80_i32, // EBU 3285 §A2.2
|
||||||
(9..=16,16) => self.read_i16::<LittleEndian>().unwrap() as i32,
|
(9..=16,16) => self.read_i16::<LittleEndian>().unwrap() as i32,
|
||||||
(10..=24,24) => self.read_i24::<LittleEndian>().unwrap(),
|
(10..=24,24) => self.read_i24::<LittleEndian>().unwrap(),
|
||||||
|
|||||||
@@ -119,8 +119,8 @@ impl<R: Read + Seek> AudioFrameReader<R> {
|
|||||||
let tell = self.inner.stream_position()?;
|
let tell = self.inner.stream_position()?;
|
||||||
|
|
||||||
if (tell - self.start) < self.length {
|
if (tell - self.start) < self.length {
|
||||||
for n in 0..(self.format.channel_count as usize) {
|
for sample in buffer.iter_mut().take(self.format.channel_count as usize) {
|
||||||
buffer[n] = match (self.format.bits_per_sample, framed_bits_per_sample) {
|
*sample = match (self.format.bits_per_sample, framed_bits_per_sample) {
|
||||||
(0..=8,8) => self.inner.read_u8()? as i32 - 0x80_i32, // EBU 3285 §A2.2
|
(0..=8,8) => self.inner.read_u8()? as i32 - 0x80_i32, // EBU 3285 §A2.2
|
||||||
(9..=16,16) => self.inner.read_i16::<LittleEndian>()? as i32,
|
(9..=16,16) => self.inner.read_i16::<LittleEndian>()? as i32,
|
||||||
(10..=24,24) => self.inner.read_i24::<LittleEndian>()?,
|
(10..=24,24) => self.inner.read_i24::<LittleEndian>()?,
|
||||||
@@ -148,8 +148,8 @@ impl<R: Read + Seek> AudioFrameReader<R> {
|
|||||||
let tell = self.inner.stream_position()?;
|
let tell = self.inner.stream_position()?;
|
||||||
|
|
||||||
if (tell - self.start) < self.length {
|
if (tell - self.start) < self.length {
|
||||||
for n in 0..(self.format.channel_count as usize) {
|
for sample in buffer.iter_mut().take(self.format.channel_count as usize) {
|
||||||
buffer[n] = match (self.format.bits_per_sample, framed_bits_per_sample) {
|
*sample = match (self.format.bits_per_sample, framed_bits_per_sample) {
|
||||||
(25..=32,32) => self.inner.read_f32::<LittleEndian>()?,
|
(25..=32,32) => self.inner.read_f32::<LittleEndian>()?,
|
||||||
(b,_)=> panic!("Unrecognized integer format, bits per sample {}, channels {}, block_alignment {}",
|
(b,_)=> panic!("Unrecognized integer format, bits per sample {}, channels {}, block_alignment {}",
|
||||||
b, self.format.channel_count, self.format.block_alignment)
|
b, self.format.channel_count, self.format.block_alignment)
|
||||||
|
|||||||
Reference in New Issue
Block a user