Log In or Create Account
Back to Blog
DEVELOPMENT

0

1,475
Weekly Update - Music System Coding, Distracting Dog
3 years ago1,151 words
This week, I worked on combining three separate music systems in Atonal Dreams' code, but didn't do as much as I'd like due to a distracting dog!

My parents have been away on yet another holiday this week, so again I’ve been tasked with looking after the community hall thing that’s adjacent to this house, and - more annoyingly - the shih tzu they inherited after its elderly owner died a few months ago.

“Great!”, I thought, “I’ll have a lot of time to myself, to focus and get a lot done!”

Instead, though, the needy dog fidgets around and paws at me if I don’t sit with it, meaning I’ve been unable to sit and focus for more than about an hour or so at a time. Frustrating! I’ve done far less than I would have liked. (I’ve experimented with a bunch of positions where it could sit with me and I could work, but nothing really worked... though it seems relatively settled today, so maybe it was all just animal anxiety from a situation/routine change.)

Still, I've done some more work on the dynamic music system that I wrote about last week.



Originally, the game's music was just wav files that looped using Unity's built-in systems, meaning all I had to do was create an 'AudioSource', assign an 'AudioClip' to it, set it to looping, and have it Play(). That works fine, but it's limited to tracks which are composed such that the end blends seamlessly into the beginning.

For the recently-added intro, I added a system - using new code independent of the old music code - that plays music tracks divided into sections, which can be transitioned between depending on criteria.


This is data stored in a ScriptableObject in Unity. I'm using something called OdinInspector, which adds some convenience and prettifying features to the Inspector.


For example, here, an initial section with the id 'loop' will play a section with the id 'loop' - that is, the same again - on completion. An event would force it the next section, which has the id 'enc' here; this would play 'enc' again at the end normally, but if a variable to move on is set, it'd transition to 'kill' at the end instead, which transitions to 'hb1'... If that makes sense at all.

I got this working by chopping the music into separate wav files for each section, which I feel is sloppy, plus it's tedious to set up, and there were some issues with timing that meant there were sometimes short but noticeable gaps between sections, which I'd been wanting to correct for a while.

The new system I added last week added yet more independent code, which did very similar things to that one - it could transition between looping sections that were stored in separate wav files - but it kept track of the beat, meaning I had to specify data like tempo and time signature and code events that ensured everything happened exactly on a bar change.

I realised that having three separate, independent music systems was silly, though, and intended to spend Monday morning combining the three of them... only for the task to span the entire week - it always seems to turn out this way - and I still haven't finished thanks to the distracting dog.

I've mostly got it working, but I've essentially recoded everything three or four times, so now I've got this tangled web of code that I've been trying to clean up while retaining full functionality. It's not difficult - I feel I know how to do it - but it's time-consuming.



I did realise though that I don't need to chop up the files at all; I can just have them start and end at scheduled times calculated based on tempo and time signature. So that should save a lot of time and stress when adding future tracks.

One big thing I've learned from figuring out how to do this - which I didn't know while making Sindrel Song - is that binding music events to Unity's Time.time value and Update or FixedUpdate functions tends to be unreliable, and to produce gaps; instead it's more accurate to use the more precise AudioSettings.dspTime, which is the time since Unity started up rather than the time of the current session, and you need to tell AudioSources to PlayScheduled() - that is, to play at an exact time, specified in advance - rather than just to Play().

Though I don't know if anyone who reads this even uses Unity, so maybe that's not a very useful or interesting thing to mention!



My parents will be back on Monday, which I have mixed feelings about. Relief, since the dog will focus on them and I can hopefully sit down and concentrate on getting stuff done, but also frustration, since I'm enjoying the freedom and quiet without them here.

I talked a while ago about moving out, but haven't yet; my parents always try to talk me out of it since me being around means they can go on these holidays without getting someone else to look after the hall and dog (even though my step-dad has dozens of friends he could ask, but apparently dumping the responsibility on me is less imposing even though his sister and her husband are unemployed and do nothing all day, grumble grumble). And I'd be living alone, which might drive me even deeper into madness. Already I've been possessed by at least some hypochondria these past couple of days. And I'm not really earning enough reliably to pay for rent.

The end of the year's rapidly approaching, and I'll write about some general review of how this year's been creatively, financially, etc then. See where to go from there.



Other than that, I've been playing a couple of games this week.

One is Pokemon Brilliant Diamond, like a lot of people, which I'm currently doing post-Champion stuff in. Hopefully I'll be able to muster up the focus and energy to write about it at some point.

The other is Memody: Sindrel Song, which I pushed through anxious reluctance to start playing again for the first time in a year after I went in my Discord a week or so ago and it came up. I have lots of feelings and things to say about that! I started writing out a looking-back-on-it post about a year ago, apparently, but I never finished it; I'd like to write about that before the end of the year, if I can.


...And I still haven't got a new PC!! Ugh. Looks like I won't be getting one before the end of the year, which is annoying. Hopefully I can finally sort that when I'm not so distracted by the dog.

0 COMMENTS

Log in to comment!