Skip to content

Commit

Permalink
Simplify download function
Browse files Browse the repository at this point in the history
  • Loading branch information
AkiyukiOkayasu committed Aug 21, 2024
1 parent c23a6da commit 445fb62
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ reqwest = { version = "0.12.7", features = ["blocking"] }
cpal = "0.15.3"
approx = "0.5.1"
criterion = "0.4.0"
tempfile = "3.12.0"

[[bench]]
name = "bench"
Expand Down
23 changes: 8 additions & 15 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use pacmog::{
AudioFormat, PcmPlayer, PcmReaderBuilder,
};
use reqwest::blocking::get;
use std::io::{self, Read, Write};
use tempfile::NamedTempFile;

const SINEWAVE: [f32; 3000] = [
0f32,
Expand Down Expand Up @@ -3010,6 +3008,12 @@ const SINEWAVE: [f32; 3000] = [
0.05130394f32,
];

fn download_audio_file(url: &str) -> Result<Vec<u8>, reqwest::Error> {
let response = get(url)?;
let bytes = response.bytes()?;
Ok(bytes.to_vec())
}

#[test]
fn fixed_test() {
let hoge = I1F15::from_num(0.5);
Expand Down Expand Up @@ -3053,19 +3057,10 @@ fn aiff_linearpcm_specs() {
}

#[test]
fn wav_float32_specs() -> io::Result<()> {
fn wav_float32_specs() {
// Download the wave file using reqwest
let url = "https://github.com/AkiyukiOkayasu/TestToneSet/raw/main/Sine440Hz_1ch48000HzFP32.wav";
let response = get(url).expect("Failed to download file");
let content = response.bytes().expect("Failed to read response bytes");

// Create a temporary file
let mut temp_file = NamedTempFile::new()?;
temp_file.write_all(&content)?;

// Read the downloaded file into a byte array
let mut wav = Vec::new();
temp_file.reopen()?.read_to_end(&mut wav)?;
let wav = download_audio_file(url).unwrap();

// Use PcmReaderBuilder to read the PCM specs
let reader = PcmReaderBuilder::new(&wav).build().unwrap();
Expand All @@ -3077,8 +3072,6 @@ fn wav_float32_specs() -> io::Result<()> {
assert_eq!(spec.num_channels, 1);
assert_eq!(spec.sample_rate, 48000);
assert_eq!(spec.num_samples, 240000);

Ok(())
}

#[test]
Expand Down

0 comments on commit 445fb62

Please sign in to comment.