rusty-jeep: init
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -9,3 +9,4 @@ result
|
|||||||
input.txt
|
input.txt
|
||||||
greek.csv
|
greek.csv
|
||||||
node_modules
|
node_modules
|
||||||
|
target
|
||||||
|
|||||||
1066
rusty-jeep/Cargo.lock
generated
Normal file
1066
rusty-jeep/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
6
rusty-jeep/Cargo.toml
Normal file
6
rusty-jeep/Cargo.toml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "rusty-jeep"
|
||||||
|
version = "1.0.0"
|
||||||
|
edition = "2021"
|
||||||
|
[dependencies]
|
||||||
|
rodio = "0.16.0"
|
||||||
22
rusty-jeep/alarm
Executable file
22
rusty-jeep/alarm
Executable file
@@ -0,0 +1,22 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
#
|
||||||
|
# //Kübelwagen/alarm SLEEPARGS...
|
||||||
|
#
|
||||||
|
# where SLEEPARGS are passed to sleep(3)
|
||||||
|
#
|
||||||
|
set -euf
|
||||||
|
cd $(dirname $(readlink -f $0))
|
||||||
|
exec >&2
|
||||||
|
|
||||||
|
for i in `seq 8000 1000 10000`; do
|
||||||
|
echo $i 100
|
||||||
|
done | ./target/debug/rusty-jeep 1
|
||||||
|
echo 'if you heard that sound, then goto sleep..^_^'
|
||||||
|
|
||||||
|
echo sleep "$@"
|
||||||
|
sleep "$@"
|
||||||
|
|
||||||
|
echo 'wake up!'
|
||||||
|
while :; do
|
||||||
|
echo $(echo "($(od -tu -An -N 2 /dev/urandom)%1000)+500"|bc) $(echo "($(od -tu -An -N 2 /dev/urandom)%500)+100"|bc)
|
||||||
|
done | ./target/debug/rusty-jeep 1
|
||||||
10
rusty-jeep/shell.nix
Normal file
10
rusty-jeep/shell.nix
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{pkgs ? import <nixpkgs> {}}:
|
||||||
|
pkgs.mkShell {
|
||||||
|
packages = [
|
||||||
|
pkgs.rustc
|
||||||
|
pkgs.cargo
|
||||||
|
pkgs.rustfmt
|
||||||
|
pkgs.pkg-config
|
||||||
|
pkgs.alsa-lib
|
||||||
|
];
|
||||||
|
}
|
||||||
29
rusty-jeep/src/main.rs
Normal file
29
rusty-jeep/src/main.rs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
use rodio::source::{SineWave, Source};
|
||||||
|
use rodio::{OutputStream, Sink};
|
||||||
|
use std::io;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let (_stream, stream_handle) = OutputStream::try_default().unwrap();
|
||||||
|
let sink = Sink::try_new(&stream_handle).unwrap();
|
||||||
|
|
||||||
|
for input_line in io::stdin().lines() {
|
||||||
|
if let [frequency_str, duration_str] = input_line
|
||||||
|
.expect("Input empty?")
|
||||||
|
.trim()
|
||||||
|
.split_whitespace()
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.as_slice()
|
||||||
|
{
|
||||||
|
let frequency: u32 = frequency_str.parse().expect("Input not an integer");
|
||||||
|
let duration: u32 = duration_str.parse().expect("Input not an integer");
|
||||||
|
|
||||||
|
let sound = SineWave::new(frequency as f32)
|
||||||
|
.take_duration(Duration::from_millis(duration as u64));
|
||||||
|
sink.append(sound);
|
||||||
|
} else {
|
||||||
|
panic!("Expected two integers: FREQUENCY DURATION")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sink.sleep_until_end();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user