Error playing SoundEffects in MonoGame

Just a quick note for anyone that has this same problem in the future:

While making a game in MonoGame, I had problems playing SoundEffects. Basically, I would:

  1. create a SoundEffect variable
  2. do a Content.Load<SoundEffect>(“EffectFileName”)
  3. Later call soundEffect.Play() to try to play the sound

The above sequence ended up in silence – no exceptions, no indication that something went wrong. To fix this, I found a post here: https://monogame.codeplex.com/discussions/397588 mentioning to use Song rather than SoundEffect. So, I followed the instructions at here: http://rbwhitaker.wikidot.com/another-way-to-do-audio-in-xna to play the sound effect as a Song instead, and it’s worked so far.

FYI in case this helps someone out.

Categories: Uncategorized

When will we run out of new music?

December 2, 2013 Leave a comment

An (in my mind) interesting question I’ve thought about before is when humans will run out of new music to create. By that I mean, when will we reach a point where (within certain parameters) every possible combination of music has been tried? Let’s try to figure that out.

For the purpose of this post, I’m going to make some very conservative initial assumptions.

Assumptions

1) We’re only interested in discussing orchestral music. Thus, a rough upper bound on the length of the pieces produced will be ~40 minutes.
2) Since we’re only discussing orchestral music, we’ll only focus on a standard set of orchestral instruments. To keep things small, we’ll use Wikipedia’s definition of a Classical orchestra:

  • 2 Flutes
  • 2 Oboes
  • 2 Clarinets
  • 2 Bassoons
  • 2 French Horns
  • 2 Trumpets
  • 2 Timpani
  • 10 Violin 1s
  • 8 Violin 2s
  • 6 Violas
  • 4 Cellos
  • 2 Double basses

3) For further simplification, we’ll assume that each above instrument of the same type will be playing the same notes. That is, Cello 1 plays the same notes as Cello 2, as Cello 3, etc. So this means we have 12 “instruments” to choose from.
4) We assume that each instrument only plays the standard notes found on a piano (A through G, plus sharps/flats). No special effects (ie pizzicatto, rim shots on a snare drum, etc) are allowed.

Calculation

Now, our orchestra is made of 12 instruments. Let’s break time into a series of discrete points at which either a note can be played or not played by all of the 12 instruments. So, at any point in time, each instrument can play 13 possible notes (the 12 of the scale, or play nothing).

By this token, at any point in time, there are
13 * 13 * 13 * 13 * 13 * 13 * 13 * 13 * 13 * 13 * 13 * 13 = 13^12 combinations of notes that could be played. This is 23,298,085,122,481 (> 23 trillion!) possible note combinations.

How about the number of notes that could be played in two consecutive time slots? That would result in 13^12 * 13^12 = 13^24 possible notes. This is ~542 septillion note combinations.

Now, you might say, certain combinations of notes are very displeasing, and it’s unlikely that a composer would pick a certain combination of notes on multiple instruments at the same time.

If that’s the case, we’ll assume that each instrument can play only a single “good” note, or nothing, at any given time. So, at any time, there are 2*2*2*2*2*2*2*2*2*2*2*2 = 2^12 = 4096 notes possible.

In this case, after 4 time slots, we will have 2^12 * 2^12 * 2^12 * 2^12 = 2^(12*4) = 2^48 = ~281 trillion possible note combinations. Consider that, if we only let the orchestra play in units of 16th notes, we would have 281 trillion musical possibilities in a fourth of a single measure.

One sees that the number of note combinations that we have to work with grows extremely quickly with the length of music being played. And keep in mind that this is with somewhat conservative initial assumptions. If we wanted to let loose, we could use Wikipedia’s definition of a “Modern orchestra”, which would include 128 instruments (counting each instrument of each type individually). Which would mean there are 13^128 notes at any given time that the orchestra could play. And of course, this does not consider non-orchestral instruments, special effects on instruments, electronic music, etc etc.

So in regards to running out of new music, I think we’re safe for awhile.

=====

Note: I’m a Computer Science student, not a mathematician. Please correct me if there’s a flaw in the above
reasoning! This is what we’re discussing in a Discrete Mathematics course.

The debugger as interactive API browser

I’ve recently started my first job where I’m getting to do some software development (yay!) and one tool that I’ve picked up and come to love is the debugger.

Before working at this job, I had always wanted to pick up the debugger for my personal projects, as I’d read that it’s a very powerful tool. However, a lot of the documentation I read about the debugger didn’t make it clear exactly what benefit I would get out of learning to use it. Or rather, I was not excited about the idea of just being able to look at variable values.

I would like to add an extra reason for learning the debugger, in the hopes that it will entice some people to pick up this powerful tool.

===

One of the coolest things about using the debugger I’ve found is that it basically gives me interactive API documentation for what I’m working with. If I’m looking for a certain method, one option is to look up the API documentation for the library you’re using and search for a method that matches what you want. This works, but it makes us switch from our development environment to a web browser, which takes time, can be distracting, etc. Not ideal.

This is an image of a Visual Studio feature called the Watch Window:

Visual Studio's Watch Window feature

Visual Studio’s Watch Window feature

This feature’s also available with most other debuggers I think, so you’re not limited to Visual Studio. The Watch Window lets you enter variables that are used in your program and look at their values while the program is running. In the above image, the “Name” column tells you the names of the variables you’re looking at. Value tells you the value of those variables. And Type is the type of the variable. Simple enough.

The cool part though, I think, is what’s happening in the Name column. “current” is a struct in this program, and it has the fields “time”, “port”, and “analog”. “analog” is an array, and by clicking the +/- sign by its name, you can look at the values in the array while the program is paused.

Not only that, but if analog was an array of objects, and those objects had fields, you could look at the fields of each object in the array.

The best part of this feature, I think, is that if you are working with unfamiliar code (say you’re using a library), you can look at the objects and their fields in this same way to explore the objects that make up your program.

You can do the same thing by browsing through API documentation, but doing this process through a debugger is so much more convenient that I think it’s definitely worth learning to do, at least if you work with unfamiliar code somewhat often.

Also, the first 2.5 minutes of the following video provides a good demonstration of the Watch Window in action:  https://www.youtube.com/watch?v=3t8QUlp5kcs

First Aikido session

March 19, 2013 Leave a comment

Just went to my first Aikido session. I have been quite out of shape for the last while, which definitely showed through as I was practicing. I’m currently very confused – we ran over around 8 or 10 moves and I did not feel like I truly got the hang of any of them, although I did make some good progress with a few of them. My homework for this Friday: learning to properly fall and get back up. Confusing but very fun so far. Looking forward to getting over the initial learning curve and feeling comfortable executing moves. For now though, lots and lots of simple falling exercises.

Categories: Uncategorized

Soaking up job displacement from automation

November 18, 2012 Leave a comment

A major problem with automation is that, even though in the long term it is beneficial to automate the work of factory workers (we can produce more goods/services for reduced cost), it’s not obvious how displaced workers will make a living afterwards. Retraining for a higher-skilled career is possible, but maybe not desirable for everybody.

One possibility governments/organizations could consider would be creating lots of make-work jobs [make-work is probably an incorrect term here], in the form of data entry. There are tons of valuable crowd-sourced projects that could use more people to enter data. These projects usually have low learning curves, and require little skill but a lot of labor. Also, they can be very beneficial to humanity, rather than a waste of money. For example, Old Weather, Openstreetmap, or Project Gutenburg. The goals of these projects are often beneficial to society, and could probably eat up a lot of labor, at least temporarily. Just a thought.

Categories: Uncategorized

Slightly cleaner way of looping in Java

November 2, 2012 Leave a comment

Just a quick note about a somewhat handy little trick I came across (I’m sure this is well-known elsewhere, figured I would write it down though).

Problem: You want to do something repeatedly to a list of objects.

[My] Normal solution: Put those objects into an array, or similar data structure, and loop through that structure. The thing that annoys me with this approach is creating an array that is only used in a single loop. For example:


String[] strings = {"Hello", "there", "this", "is", "an", "array"};
for (String s : strings) {
    System.out.println(s);
}

As you can see, the strings array is created and only used for the loop. Rather than creating the strings array, an approach I like is the following:


for (String s : Arrays.asList("Hello", "there", "this", "is", "an", "array")) {
    System.out.println(s);
}

Makes it a bit more clear that you’re only using the array to loop, rather than potentially using it later. Of course, this looks a bit unwieldy when the array in question is large, but for a small number of items the approach seems to work nicely, for me.

Categories: Java, Tips

Nichomachaen ethics book 1 thoughts

October 16, 2012 Leave a comment

A few thoughts below on book 1 of Nichomachaen ethics, read for a class recently.

————————————

Very interesting thoughts going on.

I like the idea, and though I can’t prove its validity, think that it’s a good idea that things which are ends in themselves are the most valuable. For example, all the arts and sciences. In the arts, usually pleasure and the hope to create something great are the only goals. In sciences, the goal to understand is the main goal. In both cases, the purposes of the fields are not to make money, to gain advantage over your fellow citizens. The goals are to witness beauty and to know. These ends have some nice secondary effects (pleasure from the arts, practical knowledge from the sciences), but pursued in their most pure form they are a couple things that can be used to justify humanity’s efforts and existence. It would be depressing to think that the best we can do is create art that pleases us and gain knowledge so as to crush foes on the battlefield, and feel more comfortable at home. Gaining knowledge and creating great art are things worth doing in themselves – they give intrinsic pleasure. When listening to music, I almost never have ulterior motives. I just want to hear some cool stuff, and in some cases, some of the best works created by humans.

The idea that the goal of political science is to create virtuous citizens is very interesting to me, and so far off of what seems to be the norm today. The present situation seems to be that politics is a useful tool for gaining personal wealth and fame. The idea that you would go into politics with a goal to improve your fellow citizens is very noble and actually worth pursuing. This gives some more reason that law as a field could be justified. The goal of the field is to improve the behavior of everyone in your constituency, and have them exhibit virtuous behavior that we can be proud of as a species. This is the goal of the field, but I am currently caught up on the methods used to achieve this goal. The methods seem to be seriously harming (financially) a person who commits an action that we consider bad. Would it not be better to have a system that rewarded those who do well? You could argue that the people doing well do not need the extra help, which is probably true. However, incentives for normal citizens to behave better could be very valuable. For a toy example, a $5 reward to everyone who helps a person with an injury across a street. This would lead to more people getting help they need, more people acting in a virtuous way, and a small reward for the person who helps the other. The reward would allow the helper to slightly improve their financial situation, which might be a small bump that Aristotle discusses. Spread out over a whole society, this could result in net improvements to citizen and personal behavior. I wonder if/how far this idea has been taken in law. It seems like all laws are geared towards providing reprisal against negatives that people enact, but never towards guaranteeing positives for people who act well. For example, since almost everyone considers education and knowledge valuable goals for people to seek, guarantee by law a $500 reward each year a person attends a school.

This setup seems to be widespread privately, but it’s not an institution backed governmentally. For example, fields of endeavor provide rewards (medals, praise) for those who are at the top of their field. We congratulate people who achieve good things. But lawfully, there does not seem to be a mechanism in place to promote good behavior, at least not to the same extent as we punish bad behavior.

Categories: Uncategorized
Follow

Get every new post delivered to your Inbox.