It is possible to use at the same time two players with jFugue - real-time-updates

I'm trying to make a musical game (a bit like "Guitar Hero") and I'm having some issues to notify the player when he/she is getting a wrong 'note' played. Now is just a basic system but for example if the player has to push Up Arrow and missed it (no matter if the player clicks another one or didn't click any key at all), I want to make a noise or play an out of tune note.
I'm trying two ways:
a) to use a second player that, when the miss is detected, plays an out of tune chord.
b) to modify the volume of the pattern which is already being played.
With the first one I think it is just not possible to play 2 players at the same time and I'm gonna try this weekend to use a second thread. Nevertheless in theory I think it shouldn't work due to both players will use the same PC sound board for different instructions. This is the head of the error I get in return when I try this option:
Exception in thread "Thread-2" java.lang.NumberFormatException: Value
out of range. Value:"200" Radix:10
("200" is the volume value I gave to the miss note, but it doesn't matter how much I put because it always fails.)
With the second one I found no example of any pattern which is being reproduced and modified, or any question here that confirm it is possible.
Any idea of what should I try?

A Player plays music by connecting to a MIDI Sequencer, and there is only one of those on your system, so you can really have only one Player. (I'm realizing now that the JFugue API doesn't enforce that, and perhaps it should.)
MIDI has 16 channels, which JFugue calls Voices. Instead of having two Players, you could play the main melody of your song in Voice 0, and the player's feedback in, say, Voice 5. Notes in each of those voices could use different instruments. If the player gets the note right, the Voice 0 and Voice 5 notes will sound together. If they get it wrong, you can play something different in Voice 5, or if they don't play anything at all, you could play nothing on Voice 5.
If you are playing the Voice 0 and Voice 5 notes one at a time (instead of sending a full pattern at the beginning of the game), you could also modify the on velocity and off velocity of the note on Voice 0 to make it sound fainter.
(Voice 9 is the percussion track, so don't play on that!)
We would need to see some source code to see why you're getting that error with the volume.

Related

Can you isolate audio data given two mics?

So I had an idea for a program, but I really have no idea if it would work, and I didn't really know where to post this question. I used which computer science programming stack exchange sites do I post on in order to determine, that since this is an algorithmic question (can this algorithm be written), I thought this would be the best place.
So the idea is this. Imagine you are sitting at a table with someone else each of you have a mic, as if you're doing a podcast or something. Your voice is being heard by your mic, and the other mic, albeit faintly.
The question is, can you use the distance between the two mics to act as a filter on your voice only?
Your voice is heard by the mic in front of you first, then by the mic further away from you at a very specific interval, since they are stationary. Any audio elsewhere in the room reaches the two mics at different interval signatures, for instance, if at a perpendicular angle the audio would reach the two mics at the same time.
It seems to me that this relationship could be used to isolate audio coming from a certain angle and filter out all the rest. Is this possible? Is it done already?

Relative Sorting Algorithm Based On 2 Related Variables

I have a bunch of video games I like, but I like some more than others. I have assigned them all a ranking 1 - 100 inclusive (not necessarily all integers are used and some may be used twice, although this can be changed if needed).
I have a list in excel with three columns: name of video game, rating (1-100), date last played, and a VBA macro button that says "kick" to bottom (more on this below).
When I assign a video game a ranking of 1, I want to be reminded to play it ideally every week.
When I assign a video game a ranking of 100, I want to be reminded to play it ideally every 52 weeks.
I defined reminded as "floating" to the top of this list in excel. So all games are slowly floating to the top (highly rated ones just faster than others) to remind me to play them. If I "kick" one to the bottom because I was reminded to play it, the counter/date on that video game starts over.
I'd imagine for this to work games will have to "pile up" at top, because many of them may have their due dates at a closely related times.
I think a perfect solution exists but it doesn't have to even be perfect.
How can I go about solving this problem?

Mac OS X: Audio frequency shift by change of sample rate?

I want to change the frequency of a voice recording by changing sample rate on Mac OS X.
This is a research project aimed at people who stutter. It's essential that the latency is very low – this is, for instance, why I'm not considering Fast Fourier Transforms. Instead, I want to collect samples at a rate of, say, 44kHz, then do one of two things:
1) Play the samples back twice as slowly (i.e. 22kHz). This will result in increasing asynchrony with the source. It would be useful if I can restart the sampling every 1 second or so to prevent the asynchrony from becoming too noticeable.
2) Play the samples back twice as quickly. Obviously, it's impossible to do this continuously (i.e. can't play back samples which haven't been collected yet). To get around this, I'm intending to gate the playback with a square wave. Samples will be played back twice as quickly as they were recorded during the peak of the square wave. Nothing will be heard (but samples will still be collected) during the trough of the square wave.
I've prepared a PDF which describes the project in more detail here:
https://www.dropbox.com/s/8u3tz7d9hhxd3t9/Frequency%20shift%20techniques.pdf?dl=0
A friend has helped me with some of the programming for this using PortAudio. Unfortunately, we're getting very long latencies. I think this might be because PortAudio is working at too high a level. From the code, it looks to me as if PortAudio is buffering the incoming audio stream and then making alterations which are prima facie similar to the ones I've described above, but which are in fact operations on the buffered stream.
This isn't what I want at all. It's essential that the processing unit does as little as possible. Referring to the conditions (1) and (2) above, all the computer should do is to (1) play back the samples without any manipulation but twice as slowly; or (2) store the incoming samples then play them back twice as quickly. There should be no other processing whatsoever. I think this is the only way I'll get the very low latencies I'm looking for.
I wondered if it would be better to try doing this directly in Core Audio for OS X, rather than using PortAudio? This would limit platform compatibility. But the low latency is much more important than compatibility.
Am I likely to be able to do what I want using a mid-level service, such as Audio Units? Or would I need to write directly for a low-level service such as I/O Kit? How would I go about it?
It looks like the best thing for you would be to use something like Max/MSP or Pure Data. This will allow you to avoid working with text-based languages and should be good for you rapidly develop what you're looking to do. I/O kit is a bit too low-level for what you're trying to do.
Since max is not a text based language, sharing the code itself is a bit tricky on sites like stack overflow. I've included a screengrab. You can copy and paste max code, but it's a bit ugly and innappropiate for this.
here's a quick description. The box that says rect~ 1 is generating a square wave at Hz. The snapshot~ box is capturing the values this spits out. The if boxes check when it's greater than zero or less than zeros (peaks and troughs). If it gets a trough, the record~ box records the signal from the microphone box and stores it in a buffer. the groove~ box is a sampler that plays back the audio in this buffer, when it recives a bang from the if box, it plays back the audio. The sig~ box is being used to control the playback rate.
Also, you may not know this but the .PDF you're trying to share is unavailable.
One other thing, if latency is important, you should learn about something called a click train. This is basically where you send a signal with a single 1 at the start and time how long it takes for that value to get through your system.

Google Play Games Services unlocking multiple achievements with the same increment counter

I have a game and would like to add some achievements.
In this example lets say there are the following:
Won 5 Games
Won 10 Games
Won 100 Games
These 3 achievements share the same counter. But as far as I understand I need to create 3 different incremental achievements and post each of them if a game was won.
The only other alternative I see is, don't make incremental achievements and count locally.
Any other suggestions?
Your first assumption is correct. You would need to create three different incremental achievements and increment each one of them separately.
That said, this is normal and expected behavior. If you're worried about being throttled for hitting the service too much, the "increment three different achievements at once" quota is much more lenient than the "increment the same achievement three times in a row", so you should be fine. Plus, the Play Games library might be smart enough to submit this as a single batch call on your behalf.

Artificial Intelligence for card battle based game

I want to make a game card battle based game. In this cards have specific attributes which can increase player's hp/attack/defense or attack an enemy to reduce his hp/attack/defense
I am trying to make an AI for this game. AI has to predict which card it will select on the basis of current situations like AI's hp/attack/defense and Enemy's hp/attack/defense. Since AI cannot see enemy's card hence it cannot predict future moves.
I searched few techniques of AI like minmax but I think minmax will not be suitable since AI cannot predict any future moves.
I am searching for a technique which is very flexible so that i can add a large variety of cards later.
Can you please suggest a technique for such game.
Thanks
This isn't an ActionScript 3 topic per se but I do think it's rather interesting.
First I'd suggest picking up Yu-Gi-Oh's Stardust Accelerator World Championship 2009 for the Nintendo DS or a comparable game.
The game has a fairly advanced computer AI system that not only deals with expected advantage or disadvantage in terms of hit points but also card advantage and combos. If you're taking on a challenge like this, I definately recommend you do the required research (plus, when playing video games is research, who can complain?)
My suggestion for building an AI is as follows:
As the computer decides its move, create an array of Move objects. Then have it create a new Move object for each possible Move that it can see.
For each move object, calculate how much less HP the opponent will have, how many cards they will still have, how many creatures,etc.
Have the computer decide what's most important (more damage, more card advantage) and have it play that move.
More sophisticated AI's will also think several turns in advance and perhaps "see" moves that others do not.
I suggest you look at this game of Reversi I built a few weeks back for fun in Flash. This has a very basic AI implemented, but the basics could be applied to your situation.
Basically, the way that game works is after each move (player or CPU, so I can determine if the player made the right move in comparison to what the CPU would have made), I create a Vector of each possible legal move. I then decide which move provides the highest score change, and set that as best move. However, I also check to see if the move would result in the other player having access to a corner (if you've never played, the player who grabs the corners generally wins). If it does, I tell the CPU to avoid that move and check the second best move and so on. The end result is a CPU who can actually put up a fight.
Keep in mind that this is just a single afternoon of work (for the entire game, from the crappy GUI to the functionality to the AI) so it is very basic and I could do things like run future possible moves through the check sequence as well. Fun fact, though, my moves (which I based the AI on obviously) are the ones the CPU would make nearly 80% of the time. The only time that does not hold true is when I play the game like you would Chess, where your move is made solely to position a move four turns down the line
For your game, you have a ton of variables to consider and not a single point scale as I had. I would suggest listing out each thing and applying a point value to each thing so you can apply importance values to each one. I did something similar for a caching system that automatically determines what is the most important file to keep based on age, usage, size, etc. You then look at each card in the CPU's hand, calculate what each card's value is and play that card (assuming it is legal to do so, of course).
Once you figure that out, you can look into things like what each move could do in the next turn (i.e. "damage" values for each move). And once that is done, you could add functionality to it that would let the CPU make strategic moves that would allow them to use a more powerful card or perform a "finishing" move or however it works in the end.
Again, though, keep it to a simple point based system and keep going from there. You need something you can physically compare, so sticking to a point based system makes that simple.
I apologize for the length of this answer, but I hope it helps in some way.

Resources