[HN Gopher] I made a guitar tuner app using Flutter and Rust
___________________________________________________________________
I made a guitar tuner app using Flutter and Rust
Author : zduny
Score : 183 points
Date : 2022-10-10 11:58 UTC (11 hours ago)
(HTM) web link (justune.eu)
(TXT) w3m dump (justune.eu)
| tonypags wrote:
| Assuming you're using A440. I do not see a way to change it to my
| preferred reference frequency A432.
| LocalPCGuy wrote:
| Purchased for Android, love Flutter and been trying to learn
| guitar off/on, so this could be helpful.
|
| Question re: web (where I have not been impressed with Flutter as
| a platform) - I just get "Failed to start listening thread." I
| tried both Firefox and Chrome, latest versions.
|
| Side note: Also noticed I can't highlight/copy the text (common
| usability/accessibility issue with Flutter Web. I believe it's
| not that hard to allow?)
| solatic wrote:
| The developer is supposed to use a SelectableText widget:
| https://api.flutter.dev/flutter/material/SelectableText-clas...
| slfnflctd wrote:
| You may already be aware, but having a small clip-on digital
| hardware tuner you can use anywhere without involving a phone
| is a life upgrade if you're playing guitar on a regular basis.
|
| Of course, this is a cool project for more insight into the
| technologies involved regardless.
| iwebdevfromhome wrote:
| This is very cool! Is there a way to contribute or something to
| have support for ukulele ? I'm just starting to learn the uke and
| this could be very useful.
| jaywalk wrote:
| There's a Ukulele switch at the bottom left of the window.
| iwebdevfromhome wrote:
| Oh man, somehow I missed this on desktop. Thanks a lot!
| phdelightful wrote:
| As an undergrad I made a guitar tuner using a PIC32
| microcontroller to do time-series correlation to figure out the
| frequency (FFT was too slow for real-time) and a state machine
| embodied in a stratix FPGA to control a stepper motor to turn the
| pegs. A different era of "mobile app" I guess.
| icapybara wrote:
| Correlation is calculated using FFTs, so wouldn't that be just
| as slow?
| karmakaze wrote:
| Computations can be reduced if you only care about
| frequencies near 6 particular ones (and maybe some
| harmonics).
| xani_ wrote:
| You'd get shit tuner if you do that. Ain't nobody got time
| to define scales on a fucking tuner
| karmakaze wrote:
| There's only 12 per octave, way fewer than doing FFT for
| all frequencies in Hz steps.
| rglover wrote:
| Nice work, going to put this to use tonight!
|
| P.S.: you've got a customer if you plan to port this to iOS.
| Narishma wrote:
| How do you scroll the list on the left? It doesn't have any
| scroll bar or scroll buttons that I can see.
| K0nserv wrote:
| With the mouse wheel/trackpad. Flutter Web doesn't actually
| generate proper DOM, instead it renders things (mostly) from
| scratch, hence no scroll bars.
| Narishma wrote:
| So if you don't have a scroll wheel the interface is broken.
| K0nserv wrote:
| Yes, AFAIK. Flutter web is pretty terrible, especially for
| any form of accessibility
| lvl102 wrote:
| iStrobosoft is the best tuning app. No contest.
| drukenemo wrote:
| It is. It's just a pity they haven't updated it in a while.
| account-5 wrote:
| Is there an Android/web version?
| copperx wrote:
| No. Although there is a 1.0 version APK floating around and
| that's what I use. It's pretty great.
| jibbit wrote:
| the idea of a 'virtual' strobe tuner is a curious one - a
| strobe tuner being such a material thing. I'm not contesting
| that Peterson's is the best, but the 'strobe' aspect of it has
| to be marketing guff, doesn't it?
| cge wrote:
| There was one strobe-like tuner for Android years ago that
| seemed to be something other than a visual representation of
| a standard digital tuner.
|
| My understanding of the way it worked is that it took the
| waveform over some set N/frequency time, converted it to a
| _1D_ horizontal line of black-white pixels, and then stacked
| subsequent lines to create a 2D image, with new lines being
| added at the top and moving down. In tune (or a multiple of
| the root frequency for the image), you 'd see a series of
| vertical black and white bars; out of tune, these bars would
| slant to the left or right, and move over time.
|
| This method _was_ actually somewhat like a strobe tuner in
| mechanism, replacing the persistence-of-vision appearance of
| the bars moving with a spatial representation of the audio
| waveform moving in comparison to the reference frequency.
| Presumably, this could also have been done without the
| stacked 2D representation, but that doesn 't seem to be what
| apps like iStroboSoft do, as the bars are far too clean and
| even. While the app didn't do it, harmonic partials could
| have been added by having multiple simultaneous 2D images,
| each with a different reference frequency.
|
| Unfortunately, the app and its developer disappeared years
| ago, and while I might still have the apk somewhere. I
| haven't seen anything like it since.
| andrewon wrote:
| This is surprisingly useful. Thanks!
|
| I used an iPhone app with similar interface but couldn't find one
| that's as intuitive on web until this one.
| RHSman2 wrote:
| As an alternate tuning person I'd love a simple 'this is the note
| you are playing' I hate having to pick the tuning as I just wanna
| know a c#, g#, c#, f, g#, c#
|
| Please :)
| vanillax wrote:
| Agree!
| titzer wrote:
| Snarks will do that automatically.
| audio_stuff wrote:
| Looks very nice, would you tell us a little bit about what you
| used to build this? I am just getting started with Rust and it
| would be cool to hear what approach you went and what you would
| recommend when starting today.
| zduny wrote:
| Flutter for the UI. Rust for the listening, and pitch detecting
| backend. Connected the former with the latter using
| flutter_rust_bridge.
|
| More details on Rust backend:
|
| For listening (getting audio signal from microphone) I used:
|
| - Android: https://crates.io/crates/oboe
|
| - native desktop/iOS (not currently released):
| https://crates.io/crates/clap
|
| - Web: https://crates.io/crates/web-sys (so basically JS Web
| Audio API called from Rust compiled to WASM).
|
| For pitch detection:
|
| - https://crates.io/crates/pitch-detection
| audio_stuff wrote:
| Awesome, thanks!
| bobajeff wrote:
| >Flutter for the UI. Rust for the listening, and pitch
| detecting backend. Connected the former with the latter using
| flutter_rust_bridge.
|
| It's good to see that there is a active project to help with
| making Android apps using rust.
| sodality2 wrote:
| > - native desktop/iOS (not currently released):
| https://crates.io/crates/clap
|
| I hope you didn't use a command line parser to stream
| audio...
| zduny wrote:
| I meant https://github.com/RustAudio/cpal (should've
| checked).
| sodality2 wrote:
| Haha, no worries :) "clap" does indeed sound audio-
| related, and "clap" is only one transposition from
| "cpal"!
| audio_stuff wrote:
| "clap" IS actually audio related too
| https://github.com/free-audio/clap :)
| frr149 wrote:
| Why not just dart?
| account-5 wrote:
| This might have an obvious answer for the more experienced here,
| but (potentially stupid question) why didn't you use dart for
| this?
|
| Nothing against rust, just interested is all considering the
| dart/flutter relationship.
| nu11ptr wrote:
| Speaking only for myself, I'm considering Flutter + Rust
| because I want to write everything in Rust, but there aren't
| great GUI options for Rust atm. I've heard good things about
| the rust<->dart bridge so it seems like a reasonable
| compromise, esp. given the Dart code to write Flutter UIs seems
| fairly declarative. Hoping to keep most of the logic in Rust
| and just the view in Flutter/Dart.
| UltimateEdge wrote:
| Do you mean this
| https://github.com/fzyzcjy/flutter_rust_bridge ?
| nu11ptr wrote:
| yes
| zduny wrote:
| Performance reasons, also wanted it to work on the web (Flutter
| web support is fairly recent, and dart/flutter libraries don't
| automatically work on the web, they have to support the
| platform).
| account-5 wrote:
| Thanks. Is dart performance that bad? I thought it compiled
| to machine code if needed.
|
| With the web support I was hoping the since dart can be
| transpiled to JS Flutter might do something similar. I'll
| have to look into this, I'm learning Dart due to its ability
| to run on most platforms.
| skybrian wrote:
| It's hard to say with performance (you need to measure),
| but I'll point out that for the web, Dart is compiled to
| JavaScript.
|
| Performance is pretty good, but as with JavaScript
| performance, there are performance cliffs depending on how
| well V8, SpiderMonkey, or JavaScriptCore is able to
| optimize the code. An audio worklet is pretty standalone
| and compute intensive, so it seems like a good place to use
| WebAssembly.
| n4bz0r wrote:
| zduny wrote:
| What is that anger about Rust on internet forums about?
|
| I started learning Rust because it's a language with
| interesting characteristics and welcoming documentation.
|
| Only then I've discovered it's apparently "controversial" for
| some reason...
| zdragnar wrote:
| Members of the rust community were often accused of being
| overly-enthusiastic in recommending that things be
| rewritten in rust, so much to the point it more or less
| became a meme unto itself.
|
| Now, visceral anti-rust gut reactions are more commonplace
| than inappropriate suggestions to use rust are. Even that
| is petering out, though.
| n4bz0r wrote:
| Dammit. Was writing a similar yet a bit more extensive
| elaboration on my phone, but accidentally refreshed the
| page a-a-and... it's gone :') Truly a
| RRRRREEEEEEEEEEEEEEE moment.
|
| Basically, 'this ^', but wanted to add that the post was
| a lighthearted jab and a comical insinuation. Which, by
| the way, according to the little rollercoaster of upvotes
| and downvotes, seem to have raised a micro controversy of
| it's own. Which adds another layer of comedy to the
| entire situation.
|
| A-A-ANYWAY. Since I was a bit upsetting, adding a
| (hopefully) evening out, on-topic suggestion.
|
| For tuning my guitars, I often use gStrings app [0]. For
| some reason it's much better at 'catching' freqencies
| than the alternatives. Can't recall all the names, but
| I've tried most of the popular ones (such as Guitar Tuna,
| the Fender's one, etc). Might wanna check it out and see
| if there are some tricks to borrow :)
|
| [0]: https://play.google.com/store/apps/details?id=org.co
| hortor.g...
| timeon wrote:
| psuedo_uuh wrote:
| I would love to see the source code, or at least a simplified
| version. Audio input in rust and rust talking with flutter on
| mobile device. Such a cool project.
| [deleted]
| tyingq wrote:
| I don't think it's related, but a post from someone showing a
| simplified version of the same idea (pitch detection with
| WASM/Rust), with detail and source:
| https://www.toptal.com/webassembly/webassembly-rust-tutorial...
| [deleted]
| zduny wrote:
| Well, all the Rust crates I've mentioned in other comment have
| comprehensive examples attached, so it's just a matter of
| connecting their functionality together :)
| copperx wrote:
| What algorithm are you using? I've been tempted to write a tuner
| using autocorrelation, because in my experience it picks up pitch
| wonderfully.
| its_bbq wrote:
| Beautiful!
|
| Can I request banjo and chromatic modes?
| renewiltord wrote:
| Enjoying humming the tune to make it hit haha
| j_m_b wrote:
| So how do you tune 7 string guitars? :)
| zduny wrote:
| Maybe in future version :)
| blobbers wrote:
| Hello Rust Music World!
| mgsk wrote:
| Cool! What's the deal with `DADGAd` being `D#ADGA#D#`?
| whispersnow wrote:
| Super cool! Also, love the UI!
| sirjaz wrote:
| Are you going to release it on Windows 11?
| zduny wrote:
| It's available free (and no ads) for desktop browsers and as a $1
| Android app (on mobile needs to be an app for performance reasons
| and I believe it's a fair price).
| bicarbonato wrote:
| Is the app the same as the desktop version feature wise?
| KMnO4 wrote:
| While $1 is certainly far less than the value this app
| provides, it's going to be a hard sell when there are several
| free apps which do the same thing.
| TylerE wrote:
| Or if you're paying, just spend the extra few books (it's
| $10) and get Petersen Strobosoft which is the absolute gold
| standard.
| groby_b wrote:
| Or skip the idea that your phone makes a good tuner, spend
| $35, and get the TC Electronic Unitune. It's by far the
| best tuner I've used so far, and it's small enough you can
| just throw it into your guitar case. (Or leave it
| permanently attached)
|
| Plus, it's much less fiddly to handle than balancing a
| phone and a guitar :)
|
| Ultimately, it's a matter of taste, and what you use them
| for.
| TylerE wrote:
| Lots of things to tune that aren't electric guitars ;)
| groby_b wrote:
| The TC works just fine w/ any number of string
| instruments that aren't guitars or electric :)
| LocalPCGuy wrote:
| I will pay anywhere from $1 to $5 to eliminate ads, so this
| is a good value, considering the free apps almost all have
| ads, if I recall. Or are provided by one of the larger guitar
| companies and promote their subscription/learning platforms?
|
| I find the idea that $1 is a "hard sell" laughable, but
| unfortunately for software devs that is the world we find
| ourselves in when trying to monetize an idea.
| paulgb wrote:
| Same. If I see a free app and a $1 app that does the same
| thing, I'll probably go for the $1 app.
| xani_ wrote:
| Well, there are also already at least dozen free ones that
| allow to buy ad-less versions
|
| > I find the idea that $1 is a "hard sell" laughable, but
| unfortunately for software devs that is the world we find
| ourselves in when trying to monetize an idea.
|
| and it's hard sell because you can just pick any of them,
| test to your liking and pay for one after using it.
| tyingq wrote:
| The intersection of "free", "no ads", and "works right" is
| often pretty bad. This at least has the web interface where
| you can see roughly what you would be getting.
| izietto wrote:
| Yes, but to be fair it's awfully hard to find a free app that
| does the same without bloat due to any kind of ads. I'm going
| to buy this app just because of frustration due to that.
| planede wrote:
| There are several such apps on f-droid.
| berkes wrote:
| F-droid often has nice apps, but too often, they are just
| not good enough for what I want or need[1]. In that case,
| I'll gladly pay on the play-store because the paid
| version is nearly always (but certainly not guaranteed
| to) have less or no trackers ads, and malware included.
| The free apps far too often do.
|
| I use https://exodus-privacy.eu.org/ to check for
| trackers, ads and "malware".
|
| [1] Far too often, the apps there are "OK, but...",
| clearly the work of a someone building a quick "works for
| me" or someone learning how to build apps. For some
| tasks, "just OK" is good enough. More often it just
| isn't.
| rock_artist wrote:
| Sometimes, But a similar "utility" (shameless promotion
| here) I've made a free open source metronome. No ads and
| cross-platform.
|
| https://tick.talaviram.com
|
| So if someone like me had incentive for free metronome. I'm
| pretty sure there are also tuners out there.
|
| Still, 1$ to support an app is really legitimate and
| sometimes gives more incentives for the developer to
| maintain it or add features.
| zduny wrote:
| Ok.
| cowtools wrote:
| I also will need to buy a guitar to use this app, so if
| anything you should be paying me to use it
| psychphysic wrote:
| I agree. Although this might be more about covering
| development costs than making OP money.
|
| An important distinction so many entrepreneurs fail to make.
| Don't enter a saturated market without anything new on the
| table _if you intend to make money_.
|
| The problem with this particular market is that musicians can
| mostly tune by ear. Most will have a dedicated tuner next to
| their instrument and worst of all these apps don't perform as
| well for a variety of reasons not least of all that the
| response of the device might be off.
| xwowsersx wrote:
| Musicians can tune by ear, but the vast majority of people
| who play guitar on a daily basis are novices or beginners
| and they all use tuners or tuner apps.
| rav wrote:
| Even if you can tune by ear, it can be faster to use a
| tuner, especially in a noisy environment. Also, if you
| listen to harmonics when tuning a guitar by ear, you'll
| get something like just intonation instead of the equal
| temperament tuning that you would get with typical tuner
| apps.
| ElijahLynn wrote:
| Even if tuning by ear, when you play with a band or
| especially are recording, it would be very silly to trust
| your ear alone because recording hours of takes in an
| expensive recording studio with many other people's time
| in a slightly out of tune key would be very disrespectful
| and wasteful.
|
| Most musicians can tune "relatively" okay, but do not
| have the ability to tune "absolutely" (perfect pitch).
|
| Here is an example of perfect/absolute pitch that very
| few musicians have. This is the skill one would need to
| be able to not use a tuner at all >
| https://www.youtube.com/watch?v=dw3-k9 (Jimmy Kimmel Puts
| Charlie Puth's Perfect Pitch to the Test).
| xwowsersx wrote:
| For sure. We always tuned by plugging into tuners when I
| played in a band. You might get it to closer than
| completely out of tune by ear, but when you're in close
| quarters and there's people talking or playing their
| music, you just plug in and get to the green light.
| criddell wrote:
| When I click through, all I get is a black screen that says
| "Failed to start listening thread."
| tyingq wrote:
| Firefox maybe? This bug:
| https://bugzilla.mozilla.org/show_bug.cgi?id=1572644
| zduny wrote:
| Android or Web?
|
| If web - well, it sadly requires modern browser on relatively
| modern hardware - it has some performance problems currently in
| browsers, I'm not happy about that fact, I am considering
| improving it if the app catches enough interest.
|
| If Android - please consider returning the app and getting your
| money back as long as you still can - I'm afraid I won't be
| able to solve it in quick fashion.
| mattmaroon wrote:
| Can you add Ukulele to the drop down? There are only a few common
| tunings.
| munro wrote:
| The movement is really choppy on my iPhone 13 Pro. Did you use
| requestAnimationFrame for the tuning movement? & CSS animations
| for switching instruments? Kinda just wondering how the
| performance could be so bad. Reminds me of PhoneGap circa 2013
| panzerboiler wrote:
| I can confirm. It is extremely choppy and resource hungry for
| what it does. Since they use Flutter, the UI is rendered using
| 119 canvas elements. The same thing could be implemented using
| the web platform (no flutter and no rust) with better results.
| [deleted]
| naet wrote:
| I was thinking the same thing- I've seen many mobile
| performant, web based tuners before, it's a very common
| personal project. If the intention was to make a web based
| tuner from the start, Flutter and Rust was a big step down
| from just using HTML and JS.
|
| I know the trend on HN is to upvote any project with Rust in
| the title, and to hate on native JS, but projects like this
| that have to use a bunch of tooling to eventually compile
| down to JS would have almost always been better just using JS
| in the first place IMO.
| alvarlagerlof wrote:
| Flutter is not web-based. It's all custom.
| veidr wrote:
| That is true (that Flutter builds natively on all platforms
| it supports, and controls every pixel on the screen, unlike
| React Native and similar).
|
| But I suspect these people were trying the _web_ version of
| this (pretty neat, IMO) app.
|
| Flutter does build for the web but then it does (of course)
| use web technologies to deliver the UI. To get the native
| experience on iOS, you'd have to download the iOS version
| from the App Store or something like that.
| RHSman2 wrote:
| Ben Howard and Nick Drake tunings. That's funny!
| RHSman2 wrote:
| And wow! He really does use it a lot!!!!
| throwaway019254 wrote:
| Nice!
|
| We're you inspired by the GuitarTuna iPhone app?
| zduny wrote:
| Yes, I did the app mostly for myself as I was getting
| disappointed with them adding too many unnecessary (IMO)
| features to it.
| boomskats wrote:
| This looks _very_ GuitarTuna. I've not come across another app
| which uses the (IMHO very effective) vertical scrolling pitch
| visualisation.
|
| This is great though OP. It's the best browser-based tuner I've
| ever used. I really hope you don't get sued.
| zduny wrote:
| I don't know if it is allowed here:
|
| Please reply if you would be interested in free promo codes for
| the Android app, I will post some.
| zduny wrote:
| 20 promo codes for the Android app:
|
| [all codes have been redeemed]
| stefanyas wrote:
| I redeemed 4PLTCBMWVANG2DSDK5L6J0U.
|
| Thank you!
| taylodl wrote:
| There are two Drop D tunings listed and one is actually Drop C.
| There is no Drop D, you call it Drop C# which while it's
| technically the same set of tones, it's now how guitar players
| think of it. You have the same issue with E Standard. Each of
| your notes in these tunings are listed as sharps instead of
| flats, which is not how guitar players think of the notes in
| these tunings.
|
| Also, you might want to consider polyphonic tuning. That's what
| would set you apart from everybody else. I bought a TC Electronic
| PolyTune earlier this year and it's been a game changer. It's
| much faster and easier to get tuned
| skybrian wrote:
| I'm interested in the algorithm for that, but it looks like for
| PolyTune, they just say "patented 'MonyPoly' algorithm."
|
| So that's out. I wonder what other research has been done into
| detecting multiple notes at once?
| skupig wrote:
| Fourier Transform, identify the fundamentals by loudness
| and/or presence of harmonics?
| dspig wrote:
| Each string has it's fundamental frequency and harmonics.
| Some of them coincide or are very close in frequency, but
| some are unique to one string so can be picked out and their
| frequency measured with a FFT of sufficient resolution and
| used to indicate the tuning of the string it must be a
| harmonic of.
|
| (Polytune is more robust than just doing this and does work
| really well, but if the guitar is really out of tune the
| method falls apart and you have to use its one-string-at-a-
| time mode)
| tomduncalf wrote:
| In general polyphonic pitch detection is a much harder problem
| to solve than monophonic. I guess focussing on guitar tuning
| only rather than trying to transcribe a whole song makes the
| problem a bit simpler but still is probably a lot more
| challenging than handling one note a time. Cool feature though,
| I had never thought of a polyphonic tuner!
| taylodl wrote:
| My Snark died and I was about to order another one when I saw
| the TC Electronic PolyTune. I splurged and bought it. I love
| it!
| RHSman2 wrote:
| Why is it good? Interested
| taylodl wrote:
| Because you can see the tuning of all the strings at once.
| You strum and they all show up. Then you can see which ones
| are more out of tune than others and tune them together.
| Prevents problems where changing the tuning (tension) of one
| string throws another string out of tune. I call it "global
| tuning." It gives you precise tuning extremely fast.
| someweirdperson wrote:
| Does the tuning of one string affect the others on guitars
| with hard tails, or is this mostly a tremolo induced issue?
| huehehue wrote:
| Interesting you mention guitarists thinking in terms of flats.
| Is that rooted in music theory, preference/convention, or
| something else?
|
| A sibling common mentions "c#, g#, c#, f, g#, c#" which is
| exactly how I would think of it. I'd guess that without a key
| signature to reference it doesn't really matter, but I'm a
| theory novice so curious about this.
| jcparkyn wrote:
| I would guess that it's to do with the fact that musicians
| generally use the key with fewer sharps/flats. E.g., Bb major
| (2 flats) instead of A# major (5 sharps). This also follows
| what's on the circle of fifths, where major keys clockwise
| from C use sharps, and vice versa.
|
| In the case of drop Db, I would also guess that people just
| think of it as "slightly lower than drop D", hence just
| adding a flat symbol.
| mrob wrote:
| I assume it's because tuning a string up can break it, while
| tuning it down is harmless.
| taylodl wrote:
| I really don't know why that's the convention. I always
| assumed it was due to the minor scale/modes having so many
| flats. The only mode with a sharp is Lydian - and that's a
| single sharp! Even the major mode Mixolydian has a flat!
| Natural minor has 3 flats.
| davidkuennen wrote:
| Very cool. Looks great.
| thatguyagain wrote:
| Cool, good job! :)
| taraparo wrote:
| The app looks great, but since no source code is provided knowing
| that it's made with Flutter and Rust isn't really of much use for
| anyone (esp. for learning purposes).
|
| For anyone interested, I found a nice open source tuner for
| Android https://github.com/thetwom/Tuner
| bibanez wrote:
| This is the tuner I use! It works great, definetely recommend
| it.
| notfed wrote:
| Evil plan:
|
| 1. Create closed-source app in some boring language
|
| 2. Promote on hacker news as "written in Rust"
| [deleted]
| vhanda wrote:
| Do you have any plans on open sourcing the code?
| zduny wrote:
| Not at the moment. Sorry.
|
| I'm planning to create a simpler free version of the app for
| the sake of cross-promotion, I may open source that one (but I
| can't make any promises currently, both regarding creating the
| actual app and open sourcing it).
___________________________________________________________________
(page generated 2022-10-10 23:00 UTC)