{"action":"created","issue":{"url":"https://api.github.com/repos/RustAudio/sample/issues/32","repository_url":"https://api.github.com/repos/RustAudio/sample","labels_url":"https://api.github.com/repos/RustAudio/sample/issues/32/labels{/name}","comments_url":"https://api.github.com/repos/RustAudio/sample/issues/32/comments","events_url":"https://api.github.com/repos/RustAudio/sample/issues/32/events","html_url":"https://github.com/RustAudio/sample/issues/32","id":145232988,"number":32,"title":"Add Window Iterators","user":{"login":"andrewcsmith","id":378677,"avatar_url":"https://avatars.githubusercontent.com/u/378677?v=3","gravatar_id":"","url":"https://api.github.com/users/andrewcsmith","html_url":"https://github.com/andrewcsmith","followers_url":"https://api.github.com/users/andrewcsmith/followers","following_url":"https://api.github.com/users/andrewcsmith/following{/other_user}","gists_url":"https://api.github.com/users/andrewcsmith/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewcsmith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewcsmith/subscriptions","organizations_url":"https://api.github.com/users/andrewcsmith/orgs","repos_url":"https://api.github.com/users/andrewcsmith/repos","events_url":"https://api.github.com/users/andrewcsmith/events{/privacy}","received_events_url":"https://api.github.com/users/andrewcsmith/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/RustAudio/sample/labels/draft","name":"draft","color":"e11d21"},{"url":"https://api.github.com/repos/RustAudio/sample/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-04-01T17:07:27Z","updated_at":"2016-05-11T02:17:49Z","closed_at":null,"body":"After [our brief discussion on /r/rust](https://www.reddit.com/r/rust/comments/4arjm8/sample_050_the_fundamentals_for_working_with/d13grzb), I thought that now is the time to move my `Window` functions to your `sample` crate. I'm having a hard time conceptualizing where to put this though. It seems like `sample` is focused on the time domain, and (in general) windowing is mostly used in the frequency domain. \r\n\r\nHere's a limited, first-steps proposal:\r\n\r\n* Implement `Window` as a `struct` implementing `Iterator`\r\n* `Window` will yield `Frame`s, allowing for a trivial impl of `Signal`\r\n* `Window` can be instantiated with a convenience function similar to `signal::sine` or `signal::saw`, with an argument of an `Iterator` that yields a `Phase`\r\n* Users can then call `mul_amp` on their own time to multiply the two signals\r\n\r\nThis is pretty simple. The catch is that this wouldn't actually implement *windowing* but only common window functions like Hanning/Hamming/Rectangular/etc. represented as oscillators.\r\n\r\nStep two would be to implement a sliding window that (given a bin and hop) yields up slices of `Frame`s. I believe this should be an `Iterator` called `Windower` where:\r\n\r\n```rust\r\n// WARNING: I haven't actually tried to compile any of this. Pseudo.\r\nstruct Windower<'a, F> {\r\n    window: Window<F>,\r\n    current_index: usize,\r\n    hop: usize,\r\n    input: &'a [F],\r\n    data: &'a mut [F]\r\n}\r\n\r\nimpl<'a, T: ToFrameSliceMut<'a, F>, F: Frame> Windower<'a, F> {\r\n    fn new<'a>(type: WindowType, input: &'a [F], data_store: &'a mut [F]) -> Windower<'a, F> {\r\n        // Create a `Window`-type `Signal` as outlined above, taking the `Phase` \r\n        // frequency from data_store.len()\r\n    }\r\n}\r\n\r\nimpl<'a, F: Frame> Iterator for Windower<'a, F> {\r\n    type Item = &[F];\r\n    fn next(&mut self) -> Self::Item {\r\n        // update self.data with the product of the window value and input[(self.current_index*self.hop)..(self.current_index*self.hop+self.data.len())]\r\n        // increment current_index by hop. (the bin is inferred from the size of self.data)\r\n        // yield the value of self.data as an immutable reference\r\n    }\r\n}\r\n```\r\n\r\nThis way, the `Windower` would be an iterator that would yield immutable slices of `Frame`s.\r\n\r\nLet me know if this looks like an all right implementation. I'm not quite sure what the state of spectral analysis in the `sample` crate is going to be, but it would be fantastic to at least have many of these functions be generalized over `Sample` and `Frame`."},"comment":{"url":"https://api.github.com/repos/RustAudio/sample/issues/comments/218344801","html_url":"https://github.com/RustAudio/sample/issues/32#issuecomment-218344801","issue_url":"https://api.github.com/repos/RustAudio/sample/issues/32","id":218344801,"user":{"login":"andrewcsmith","id":378677,"avatar_url":"https://avatars.githubusercontent.com/u/378677?v=3","gravatar_id":"","url":"https://api.github.com/users/andrewcsmith","html_url":"https://github.com/andrewcsmith","followers_url":"https://api.github.com/users/andrewcsmith/followers","following_url":"https://api.github.com/users/andrewcsmith/following{/other_user}","gists_url":"https://api.github.com/users/andrewcsmith/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewcsmith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewcsmith/subscriptions","organizations_url":"https://api.github.com/users/andrewcsmith/orgs","repos_url":"https://api.github.com/users/andrewcsmith/repos","events_url":"https://api.github.com/users/andrewcsmith/events{/privacy}","received_events_url":"https://api.github.com/users/andrewcsmith/received_events","type":"User","site_admin":false},"created_at":"2016-05-11T02:17:48Z","updated_at":"2016-05-11T02:17:48Z","body":"Okay, sorry it's been a while. I have an initial draft of what I'm thinking. Could you look it over and let me know if I'm:\r\n\r\n1. Making things as general as possible\r\n2. Adhering to the idiomatic conventions of the crate\r\n\r\nI decided on using empty structs instead of an enum to hold the `WindowType`. This will allow for static dispatch and minimal branches in the compiled code. Currently, `Window` is basically just another oscillator. I kind of like this as it allows us to reuse the same `Window`.\r\n\r\nI haven't actually used the `sample` crate myself (although I hope to soon) so give this a look and let me know if there's anything I'm missing about the design of the crate. It's not ready for a PR yet. \r\n\r\nhttps://github.com/andrewcsmith/sample/commit/216f3c44782d82b6005ea9c2506143cc1d3a0c0b"}}