Update and added ReadMe

This commit is contained in:
Andre Henriques 2021-10-06 17:46:18 +01:00
parent f45a9cf312
commit a51b69ad7c
5 changed files with 176 additions and 816 deletions

101
Cargo.lock generated
View File

@ -66,9 +66,9 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
[[package]]
name = "backtrace"
version = "0.3.55"
version = "0.3.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef5140344c85b01f9bbb4d4b7288a8aa4b3287ccef913a14bcc78a1063623598"
checksum = "9d117600f438b1707d4e4ae15d3595657288f8235a0eb593e80ecc98ab34e1bc"
dependencies = [
"addr2line",
"cfg-if 1.0.0",
@ -117,9 +117,9 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]]
name = "bumpalo"
version = "3.4.0"
version = "3.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820"
checksum = "f07aa6688c702439a1be0307b6a94dffe1168569e45b9500c1372bc580740d59"
[[package]]
name = "bytemuck"
@ -403,9 +403,9 @@ dependencies = [
[[package]]
name = "derivative"
version = "2.1.3"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eaed5874effa6cde088c644ddcdcb4ffd1511391c5be4fdd7a5ccd02c7e4a183"
checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b"
dependencies = [
"proc-macro2",
"quote",
@ -447,13 +447,13 @@ dependencies = [
[[package]]
name = "filetime"
version = "0.2.13"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c122a393ea57648015bf06fbd3d372378992e86b9ff5a7a497b076a28c79efe"
checksum = "1d34cfa13a63ae058bfa601fe9e313bbdb3746427c1459185464ce0fcf62e1e8"
dependencies = [
"cfg-if 1.0.0",
"libc",
"redox_syscall",
"redox_syscall 0.2.4",
"winapi",
]
@ -591,19 +591,18 @@ checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130"
[[package]]
name = "jpeg-decoder"
version = "0.1.20"
version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc797adac5f083b8ff0ca6f6294a999393d76e197c36488e2ef732c4715f6fa3"
checksum = "d6187dc218616c3a222bae7b78938f5af5e7c27d9cbef4c30ebca709cd680bf8"
dependencies = [
"byteorder",
"rayon",
]
[[package]]
name = "js-sys"
version = "0.3.46"
version = "0.3.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf3d7383929f7c9c7c2d0fa596f325832df98c3704f2c60553080f7127a58175"
checksum = "5cfb73131c35423a367daf8cbd24100af0d077668c8c2943f0e7dd775fef0f65"
dependencies = [
"wasm-bindgen",
]
@ -622,9 +621,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
[[package]]
name = "libc"
version = "0.2.82"
version = "0.2.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89203f3fba0a3795506acaad8ebce3c80c0af93f994d5a1d7a0b1eeb23271929"
checksum = "7eb0c4e9c72ee9d69b767adebc5f4788462a3b45624acd919475c92597bcaf4f"
[[package]]
name = "libflate"
@ -665,11 +664,11 @@ dependencies = [
[[package]]
name = "log"
version = "0.4.13"
version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcf3805d4480bb5b86070dcfeb9e2cb2ebc148adb753c5cca5f884d1d65a42b2"
checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
dependencies = [
"cfg-if 0.1.10",
"cfg-if 1.0.0",
]
[[package]]
@ -884,9 +883,9 @@ dependencies = [
[[package]]
name = "object"
version = "0.22.0"
version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d3b63360ec3cb337817c2dbd47ab4a0f170d285d8e5a2064600f3def1402397"
checksum = "a9a7ab5d64814df0fe4a4b5ead45ed6c5f181ee3ff04ba344313a6c80446c5d4"
[[package]]
name = "oboe"
@ -937,7 +936,7 @@ dependencies = [
"cfg-if 1.0.0",
"instant",
"libc",
"redox_syscall",
"redox_syscall 0.1.57",
"smallvec",
"winapi",
]
@ -1058,6 +1057,15 @@ version = "0.1.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce"
[[package]]
name = "redox_syscall"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05ec8ca9416c5ea37062b502703cd7fcb207736bc294f6e0cf367ac6fc234570"
dependencies = [
"bitflags",
]
[[package]]
name = "regex"
version = "1.4.3"
@ -1182,18 +1190,18 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
[[package]]
name = "serde"
version = "1.0.119"
version = "1.0.123"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9bdd36f49e35b61d49efd8aa7fc068fd295961fd2286d0b2ee9a4c7a14e99cc3"
checksum = "92d5161132722baa40d802cc70b15262b98258453e85e5d1d365c757c73869ae"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.119"
version = "1.0.123"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "552954ce79a059ddd5fd68c271592374bd15cab2274970380c000118aeffe1cd"
checksum = "9391c295d64fc0abb2c556bad848f33cb8296276b1ad2677d1ae1ace4f258f31"
dependencies = [
"proc-macro2",
"quote",
@ -1307,9 +1315,9 @@ checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c"
[[package]]
name = "syn"
version = "1.0.58"
version = "1.0.60"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc60a3d73ea6594cd712d830cc1f0390fd71542d8c8cd24e70cc54cdfd5e05d5"
checksum = "c700597eca8a5a762beb35753ef6b94df201c81cca676604f547495a0d7f0081"
dependencies = [
"proc-macro2",
"quote",
@ -1318,13 +1326,12 @@ dependencies = [
[[package]]
name = "tar"
version = "0.4.30"
version = "0.4.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "489997b7557e9a43e192c527face4feacc78bfbe6eed67fd55c4c9e381cba290"
checksum = "0313546c01d59e29be4f09687bcb4fb6690cec931cc3607b6aec7a0e417f4cc6"
dependencies = [
"filetime",
"libc",
"redox_syscall",
"xattr",
]
@ -1361,9 +1368,9 @@ dependencies = [
[[package]]
name = "time"
version = "0.2.24"
version = "0.2.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "273d3ed44dca264b0d6b3665e8d48fb515042d42466fad93d2a45b90ec4058f7"
checksum = "1195b046942c221454c2539395f85413b33383a067449d78aab2b7b052a142f7"
dependencies = [
"const_fn",
"libc",
@ -1399,9 +1406,9 @@ dependencies = [
[[package]]
name = "tinyvec"
version = "1.1.0"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccf8dbc19eb42fba10e8feaaec282fb50e2c14b2726d6301dbfeed0f73306a6f"
checksum = "317cca572a0e89c3ce0ca1f1bdc9369547fe318a683418e42ac8f59d14701023"
dependencies = [
"tinyvec_macros",
]
@ -1516,9 +1523,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen"
version = "0.2.69"
version = "0.2.70"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3cd364751395ca0f68cafb17666eee36b63077fb5ecd972bbcd74c90c4bf736e"
checksum = "55c0f7123de74f0dab9b7d00fd614e7b19349cd1e2f5252bbe9b1754b59433be"
dependencies = [
"cfg-if 1.0.0",
"wasm-bindgen-macro",
@ -1526,9 +1533,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.69"
version = "0.2.70"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1114f89ab1f4106e5b55e688b828c0ab0ea593a1ea7c094b141b14cbaaec2d62"
checksum = "7bc45447f0d4573f3d65720f636bbcc3dd6ce920ed704670118650bcd47764c7"
dependencies = [
"bumpalo",
"lazy_static",
@ -1541,9 +1548,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.69"
version = "0.2.70"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a6ac8995ead1f084a8dea1e65f194d0973800c7f571f6edd70adf06ecf77084"
checksum = "3b8853882eef39593ad4174dd26fc9865a64e84026d223f63bb2c42affcbba2c"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
@ -1551,9 +1558,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.69"
version = "0.2.70"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5a48c72f299d80557c7c62e37e7225369ecc0c963964059509fbafe917c7549"
checksum = "4133b5e7f2a531fa413b3a1695e925038a05a71cf67e87dafa295cb645a01385"
dependencies = [
"proc-macro2",
"quote",
@ -1564,15 +1571,15 @@ dependencies = [
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.69"
version = "0.2.70"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e7811dd7f9398f14cc76efd356f98f03aa30419dea46aa810d71e819fc97158"
checksum = "dd4945e4943ae02d15c13962b38a5b1e81eadd4b71214eee75af64a4d6a4fd64"
[[package]]
name = "web-sys"
version = "0.3.46"
version = "0.3.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "222b1ef9334f92a21d3fb53dc3fd80f30836959a90f9274a626d7e06315ba3c3"
checksum = "c40dc691fc48003eba817c38da7113c15698142da971298003cac3ef175680b3"
dependencies = [
"js-sys",
"wasm-bindgen",

15
README.md Normal file
View File

@ -0,0 +1,15 @@
# Frequency detector written in rust
This project started out as a simple humming detector written in rust but, ended up becoming a frequency analyser that uses a Fourier transform to obtain the frequencies of the sound that is being recorded.
But the main goals of the project were still accomplished:
- Improve rust skills
- Learn how to record audio using rust (in Linux)
- Learn the mathematical bases of a Fourier transform
#How to run
```bash
cargo run
```

690
run.txt
View File

@ -1,690 +0,0 @@
Audio Test:
Geting audio input:
Got config: StreamConfig { channels: 1, sample_rate: SampleRate(384000), buffer_size: Default }
Starting len: 0
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: 2031.1113
center: 2320.9202
center: 26923.928
center: 117546.72
center: 18371.844
center: 89.2022
center: 500.3014
center: 22334.268
center: 39480.168
center: 5655.695
center: 4710.687
center: 643.5967
center: 2011.2443
center: 2986.1655
center: 5707.3687
center: 4728.5767
center: 6896.886
center: 57073.06
center: 324.83862
center: 10413.74
center: 22430.717
center: 3857.2686
center: 4640.9155
center: 406.69818
center: 15993.602
center: 7389.506
center: 9092.286
center: 4103.5547
center: 10718.313
center: 8854.663
center: 1268.1268
center: 18428.066
center: 2430.1287
center: 51975.824
center: 618.8661
center: 12986.857
center: 1457.4575
center: 7627.938
center: 888.3817
center: 2750.2568
center: 5426.428
center: 20452.42
center: 84379.33
center: 14416.17
center: 9933.385
center: 11257.673
center: 158.01053
center: 24689.518
center: 4015.0176
center: 12129.81
center: 1696.017
center: 5762.913
center: 2036.8901
center: 82121.305
center: 548.1412
center: 5557.4233
center: 2453.202
center: 28790.023
center: 2578.658
center: 3519.55
center: 934.0422
center: 112734.75
center: 105091.766
center: 1436.033
center: 1040.6259
center: 6223.329
center: 4617.11
center: 400.06595
center: 20380.111
center: 12726.654
center: 1855.0885
center: 2882.1733
center: 22924.059
center: 101310.195
center: 15793.605
center: 12800.167
center: 690.21704
center: 49025.35
center: 637.9289
center: 4027.347
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: 1161.8999
center: 105139.23
center: 1358.9448
center: 892.5615
center: 2260.65
center: 1107.7091
center: 170.60666
center: 2300.7803
center: 987.9872
center: 89.85326
center: 135.57477
center: 2423.6494
center: 843.7888
center: 2348.6252
center: 330.20633
center: 1851.1389
center: 1237.345
center: 1023.59955
center: 1302.2617
center: 2779.6648
center: 354.6044
center: 509.48483
center: 2377.6167
center: 1876.2759
center: 1918.5946
center: 1391.6147
center: 2707.9502
center: 752.9018
center: 3187.3745
center: 2869.126
center: 5193.3364
center: 70.19446
center: 273.9206
center: 276.0692
center: 3269.9712
center: 1701.6759
center: 1131.254
center: 994.9833
center: 2480.564
center: 2228.843
center: 2151.8235
center: 1375.6486
center: 378.76782
center: 58.56343
center: 535.1102
center: 704.05774
center: 1049.728
center: 2519.3691
center: 3385.6526
center: 3957.8855
center: 4754.4434
center: 43.17607
center: 1963.65
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: 1121.8591
center: 3014.0725
center: 3388.4263
center: 792.8876
center: 154.16129
center: 2378.1804
center: 85.2204
center: 166.37509
center: 2521.1577
center: 415.94843
center: 2161.8943
center: 616.03595
center: 7650.4023
center: 122.93094
center: 1850.946
center: 2078.6584
center: 335.71027
center: 2317.7039
center: 4042.0342
center: 1898.307
center: 1838.5259
center: 176.44273
center: 625.3767
center: 1927.7709
center: 639.6147
center: 312.7572
center: 1946.7892
center: 647.61426
center: 3277.1233
center: 466.34064
center: 1108.7056
center: 4496.6587
center: 159.33643
center: 809.46796
center: 1009.162
center: 388.80566
center: 1178.3425
center: 748.15216
center: 319.1537
center: 362.24866
center: 3914.8008
center: 757.17474
center: 797.702
center: 9607.199
center: 1434.6464
center: 631.1357
center: 2396.3643
center: 2317.1404
center: 3770.143
center: 440.52762
center: 86.75669
center: 2688.924
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN
center: NaN

View File

@ -1,10 +1,10 @@
use cpal::traits::{HostTrait, DeviceTrait, StreamTrait};
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
use cpal::StreamInstant;
use std::{thread, time};
use std::sync::{Arc, Mutex};
use std::sync::mpsc;
use num_complex::Complex;
use image::{ImageBuffer, RgbImage};
use num_complex::Complex;
use std::sync::mpsc;
use std::sync::{Arc, Mutex};
use std::{thread, time};
#[derive(Debug)]
struct MyRecData {
@ -17,39 +17,26 @@ struct ProcessData {
data: Vec<f32>,
}
const IMAGEX: u32 = 500;
const IMAGEY: u32 = 500;
const IMAGEX: u32 = 200;
const IMAGEY: u32 = 100;
const STEP: f32 = 20.0;
const START_FREC: f32 = 200.0;
fn generate_buffer() -> RgbImage {
let mut imgbuf: RgbImage = ImageBuffer::new(IMAGEX, IMAGEY);
for i in 0..IMAGEX {
*imgbuf.get_pixel_mut(i, 250) = image::Rgb([255,255,255]);
}
//imgbuf.save("test.png").unwrap();
imgbuf
ImageBuffer::new(IMAGEX, IMAGEY)
}
fn process(p_data: ProcessData, x: u32) {
let time = p_data.duration.as_nanos() as f32 / (10.0_f32).powf(9.0);
let mut sum: Complex<f32> = Complex::new(0.0, 0.0);
let test_frec = 440.0f32;
let data_size = p_data.data.len() as u32;
let gragh_step = (data_size as f64 / (IMAGEX as f64 - 1.0f64)).floor() as u32;
println!("gs:{}", gragh_step);
let gragh_step = 20 as u32;
let step = (time as f32 / data_size as f32) * gragh_step as f32;
let mut i: u32 = 0;
let mut max = 0.0f64;
while i < data_size && i/gragh_step < IMAGEX - 1 {
while i < data_size {
if max < *p_data.data.get(i as usize).unwrap() as f64 {
max = *p_data.data.get(i as usize).unwrap() as f64;
}
@ -60,29 +47,51 @@ fn process(p_data: ProcessData, x: u32) {
let mut img_buff: RgbImage = generate_buffer();
i = 0;
let mut sum_vec: Vec<Complex<f32>> = vec![];
while i < data_size && i/gragh_step < IMAGEX - 1 {
let y = (250.0f64 - (*p_data.data.get(i as usize).unwrap() as f64 * scale).floor()) as u32;
let to_sum = Complex::from_polar(*p_data.data.get(i as usize).unwrap() as f32 * scale as f32, - 2.0 * std::f32::consts::PI * test_frec * ( i as f32/gragh_step as f32) * step);
sum += to_sum;
if y < 500 && y > 0 {
*img_buff.get_pixel_mut((i/gragh_step) as u32, y ) = image::Rgb([0, 255, 255]);
for j in 0..(IMAGEX + 1) {
let test_frec: f32 = j as f32 * STEP + START_FREC;
i = 0;
while i < data_size {
let to_sum = Complex::from_polar(
*p_data.data.get(i as usize).unwrap() as f32 * scale as f32,
-2.0 * std::f32::consts::PI * test_frec * (i as f32 / gragh_step as f32) * step,
);
if sum_vec.get(j as usize).is_none() {
sum_vec.push(to_sum);
} else {
let a = *sum_vec.get(j as usize).unwrap();
let _ = std::mem::replace(&mut sum_vec[j as usize], a + to_sum);
}
i += gragh_step;
}
// sum = sum.scale(1.0f32 / (data_size as f32 /gragh_step as f32));
if !sum.re.is_nan() && !sum.im.is_nan() {
println!("center: {}", (sum.im.powf(2.0) + sum.im.powf(2.0)).sqrt() )
}
let x1 = sum.re + (IMAGEX/2) as f32;
let y1 = sum.im + 250.0;
if x1 > 0.0 && x1 < IMAGEX as f32 && y1 > 0.0 && y1 < 500.0 {
*img_buff.get_pixel_mut( x1 as u32, y1 as u32 ) = image::Rgb([255, 255, 255]);
//println!("center");
let mut max = 0.0f32;
let mut average = 0.0f32;
let mut possible = 0.0f32;
for i in 0..IMAGEX {
let v: Complex<f32> = *sum_vec.get(i as usize).unwrap();
if !v.is_nan() {
let v = (v.re.powf(2.0) + v.im.powf(2.0)).sqrt();
if max < v {
max = v;
possible = START_FREC + STEP * i as f32;
}
average += v;
}
}
average = IMAGEY as f32 - (average / IMAGEX as f32) / max * (IMAGEY - 10) as f32;
for i in 0..IMAGEX {
let v: Complex<f32> = *sum_vec.get(i as usize).unwrap();
if !v.is_nan() {
let j = IMAGEY as f32
- ((v.re.powf(2.0) + v.im.powf(2.0)).sqrt() / max) * (IMAGEY - 10) as f32;
*img_buff.get_pixel_mut(i as u32, j.floor() as u32) = image::Rgb([255, 0, 255]);
*img_buff.get_pixel_mut(i as u32, average as u32) = image::Rgb([255, 0, 0]);
}
}
println!("Processed {}", x);
println!("Processed {} {}", x, possible);
img_buff.save(format!("run/process{}.png", x)).unwrap();
}
@ -94,7 +103,6 @@ fn process(p_data: ProcessData, x: u32) {
//}
fn main() {
println!("Audio Test:");
let host = cpal::default_host();
@ -106,23 +114,38 @@ fn main() {
println!("Geting audio input:");
let device = host.default_input_device().expect("no output device available!");
let device = host
.default_input_device()
.expect("no output device available!");
let mut supported_configs_range = device.supported_input_configs().expect("Error while geting the configs");
let supported_config = supported_configs_range.next().expect("no supported config").with_max_sample_rate().into();
let mut supported_configs_range = device
.supported_input_configs()
.expect("Error while geting the configs");
let supported_config = supported_configs_range
.next()
.expect("no supported config")
.with_max_sample_rate()
.into();
println!("Got config: {:?}", supported_config);
let stream = device.build_input_stream(&supported_config,
let stream = device
.build_input_stream(
&supported_config,
move |data: &[f32], input_info: &cpal::InputCallbackInfo| {
// println!("Data:\n Input info:{:?}", input_info.timestamp().capture);
let mdata = MyRecData {instant: input_info.timestamp().capture, data: data.to_vec()};
let mdata = MyRecData {
instant: input_info.timestamp().capture,
data: data.to_vec(),
};
rec_data_c.lock().ok().unwrap().insert(0, mdata);
()
},
move |err| {
println!("Error: {:?}", err);
}).expect("Failed to build stream");
},
)
.expect("Failed to build stream");
stream.play().expect("faild to play");
@ -165,7 +188,13 @@ fn main() {
last = Some(mdata.instant);
} else {
let instant = mdata.instant.duration_since(&last.unwrap()).unwrap();
process(ProcessData {duration: instant, data: mdata.data}, x);
process(
ProcessData {
duration: instant,
data: mdata.data,
},
x,
);
last = Some(mdata.instant);
// println!("time:{:?}", instant);
}
@ -174,12 +203,11 @@ fn main() {
println!("Stoped processing");
});
thread::sleep(time::Duration::from_secs(2));
thread::sleep(time::Duration::from_secs(30));
stream.pause().expect("faild to close");
println!("stoping");
m_t.send(false).ok();
t.join().unwrap();
}

BIN
test.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB