clarify sample index calculation with channel_count
This commit is contained in:
parent
c22eb1cd8f
commit
e441ed634f
1 changed files with 6 additions and 6 deletions
|
@ -29,12 +29,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
.register();
|
.register();
|
||||||
|
|
||||||
let sample_rate = 48000;
|
let sample_rate = 48000;
|
||||||
let channel_count = 2;
|
let channel_count : usize = 2;
|
||||||
|
|
||||||
let mut audio_info = AudioInfoRaw::new();
|
let mut audio_info = AudioInfoRaw::new();
|
||||||
audio_info.set_format(AudioFormat::F32LE);
|
audio_info.set_format(AudioFormat::F32LE);
|
||||||
audio_info.set_rate(sample_rate);
|
audio_info.set_rate(sample_rate);
|
||||||
audio_info.set_channels(channel_count);
|
audio_info.set_channels(channel_count as u32);
|
||||||
|
|
||||||
let param_bytes = PodSerializer::serialize(
|
let param_bytes = PodSerializer::serialize(
|
||||||
Cursor::new(vec![]),
|
Cursor::new(vec![]),
|
||||||
|
@ -83,7 +83,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let stride = std::mem::size_of::<f32>() * (channel_count as usize);
|
let stride = std::mem::size_of::<f32>() * channel_count;
|
||||||
let datas = buffer.datas_mut();
|
let datas = buffer.datas_mut();
|
||||||
|
|
||||||
let data = &mut datas[0];
|
let data = &mut datas[0];
|
||||||
|
@ -104,9 +104,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let phi = pi2 * time_secs * sine_freq;
|
let phi = pi2 * time_secs * sine_freq;
|
||||||
let value = 0.5 + 0.5 * f32::sin(phi);
|
let value = 0.5 + 0.5 * f32::sin(phi);
|
||||||
|
|
||||||
slice[2 * i] = value;
|
slice[channel_count*i + 0] = value;
|
||||||
slice[2 * i + 1] = value;
|
slice[channel_count*i + 1] = value;
|
||||||
samples_written += 2;
|
samples_written += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue