Skip to content

Commit

Permalink
fix compilation error (#528)
Browse files Browse the repository at this point in the history
  • Loading branch information
typester authored Dec 17, 2024
1 parent e04a3cc commit ca95b54
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions examples/save_to_disk/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const FILE_PATH: &str = "record.wav";

#[derive(Debug, Clone, Copy)]
pub struct WavHeader {
pub sample_rate: u32,
pub sample_rate: i32,
pub bit_depth: u16,
pub num_channels: u32,
pub num_channels: i32,
}

pub struct WavWriter {
Expand Down Expand Up @@ -43,8 +43,8 @@ impl WavWriter {

fn write_header(&mut self) -> Result<(), std::io::Error> {
let byte_rate = self.header.sample_rate
* self.header.bit_depth as u32
* self.header.num_channels as u32;
* self.header.bit_depth as i32
* self.header.num_channels;

let block_align = byte_rate as u16 / self.header.sample_rate as u16;

Expand All @@ -55,8 +55,8 @@ impl WavWriter {
self.data.put_u32_le(16); // Subchunk1Size (16 for PCM)
self.data.put_u16_le(1); // AudioFormat (1 for PCM)
self.data.put_u16_le(self.header.num_channels as u16);
self.data.put_u32_le(self.header.sample_rate);
self.data.put_u32_le(byte_rate);
self.data.put_i32_le(self.header.sample_rate);
self.data.put_i32_le(byte_rate);
self.data.put_u16_le(block_align);
self.data.put_u16_le(self.header.bit_depth);
self.data.put_slice(b"data");
Expand Down Expand Up @@ -118,15 +118,18 @@ async fn record_track(audio_track: RemoteAudioTrack) -> Result<(), std::io::Erro
println!("Recording track {:?}", audio_track.sid());
let rtc_track = audio_track.rtc_track();

let sample_rate = 48000;
let num_channels = 2;

let header = WavHeader {
sample_rate: 48000,
sample_rate,
bit_depth: 16,
num_channels: 2,
num_channels,
};

let mut resampler = audio_resampler::AudioResampler::default();
let mut wav_writer = WavWriter::create(FILE_PATH, header).await?;
let mut audio_stream = NativeAudioStream::new(rtc_track);
let mut audio_stream = NativeAudioStream::new(rtc_track, sample_rate, num_channels);

let max_record = 5 * header.sample_rate * header.num_channels;
let mut sample_count = 0;
Expand All @@ -136,8 +139,8 @@ async fn record_track(audio_track: RemoteAudioTrack) -> Result<(), std::io::Erro
frame.samples_per_channel,
frame.num_channels,
frame.sample_rate,
header.num_channels,
header.sample_rate,
header.num_channels as u32,
header.sample_rate as u32,
);

for sample in data {
Expand Down

0 comments on commit ca95b54

Please sign in to comment.