Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1] 2 3 ... 33
1  Game Development / Newbie & Debugging Questions / requst for newbie overview tutorial on porting options on: 2014-07-28 23:13:32
It would be nice to have in one place a tutorial on the current porting options (java to android, java to ios).

I'm seeing, for example, in going from Java to ios:

 - hand write code yourself (maybe not a terrible option, given Obj-C has a fair bit structurally in common with Java due to SmallTalk roots, but of course depends on the scale of the game and the use of libraries)
 - Avian
 - RoboVM
 - LibGDX
 - java2objc
 - multistep sort of thing: java to javascript/android, then javascript to obj-c as there are possibly more JavaScript to iOS options than from Java?

But for a Newbie, there is a lot of issues and steps involved that aren't immediately made clear by going to the various home pages for these resources. For example, if an embeddable VM has a reduced set of Java implemented, how are graphics and other IO (sound, mouse, touchpads, etc.) dealt with in each option?

Just an overview would be good, no need to get too detailed.

I'd write it myself if I were capable, but I don't have the needed knowledge. I'm pretty sure there are folks here that are well acquainted with the options and pros & cons of each.

I can guarantee I'd be one of the first to "appreciate" this if it were available. (Maybe there is already link at JGO I've overlooked?)
2  Game Development / Newbie & Debugging Questions / Re: Can someone teach me Perlin Noise? for my 2d game? on: 2014-07-28 22:59:11
Roquen has a great tutorial post here on JGO.
http://www.java-gaming.org/topics/noise-bandpassed-white/27071/view.html

SiVi is an open-source project of mine that uses Ken Perlin's 3rd version of random noise (known as Simplex Noise). There is not a lot of explanation, but it does have examples of different outputs (including a topo map), and a hands-on interface where you can vary parameters and see what effect they have.

SiVi also has a pretty simple working code example in the "help" area with lots of comments, including some notes on how to make a topo map. You can download a jar and get immediate access to this via the following link. http://hexara.com/SiVi.jar

In the below image (not the greatest terrain example, I'll admit), is an example of a mapping to a color bar with 256 increments (on the right) to get terrain. The number ranges and colors I choose are arbitrary. You can define your own for game purposes (e.g., 0 to 63 = water, 64 to 127 = forest, etc., and map to graphics used for those topo features, rather than to color gradients.




More SiVi info & examples, but will eventually expire:
http://www.java-gaming.org/topics/wip-reel/33731/msg/317526/view.html#msg317526
This post also has a link to an interesting slide show by Ken Perlin.

Since the project is open source, you can also sign up on github (http://github.com/philfrei/SiVi) and poke around the code that way.
3  Discussions / Miscellaneous Topics / Re: Game art for programmers with non-existent budgets on: 2014-07-27 05:18:55
You can use SiVi to make some interesting textures. Either use the app settings to write code to recreate the textures procedurally or export them as pngs and import them as assets. Once in, you could, say, fiddle with their alpha channel and overlay them on other graphics, perhaps. The ColorBar that is used can be something simple like a progression from on solid color to another. Clouds, of course, but also certain waxy crayon-like texturing is also easy to do.
http://www.java-gaming.org/topics/wip-reel/33731/msg/317526/view.html#msg317526
4  Game Development / Newbie & Debugging Questions / Re: Runnable jar doesn't play WAV formats on: 2014-07-25 23:42:40
FYI, just in case you aren't aware of this, there are a lot of issues pertaining to audio formats besides whether something is a WAV or not. I apologize if I am mentioning something you already know, but the posts you gave allow an ambiguous interpretation.

It can be stereo or mono, and the bytes can be in either little-endian or big-endian order. It can be 16, 24, or 32 bits encoding. And concerning frame rates, I think (I could be wrong) that 44100 is the maximum supported by Java, but some DAWs are now working at 48000 or 96000 fps. If any of these parameters are varying between the samples, then the formats could be an issue.

I think I also had some trouble once when I designated the 'compression' option when generating a jar in Eclipse for the resource files. This might make a difference as well, though admittedly WAV files are pretty large if they aren't compressed, and this might make using some sort of compression (at some stage or another) mandatory.
5  Game Development / Newbie & Debugging Questions / Re: Java Metronome | Visual Display Sync Problem on: 2014-07-18 01:33:07
I’m not sure I understand what you mean by the “standard technique of calculating the varying amounts of compensating Sleep”...do you mean calculating the delay by checking the system time and then sleeping for that amount of time, or something else?

It's a way of getting a "fixed time" loop. At the start of the loop, obtain the current nanotime. Do the loop's tasks: the update and render, then check the time again. If the "fixed time" amount has not elapsed yet, calculate and sleep the amount of time required to fill out the interval. Even fancier if you want to code it: if you have previously gone over in terms of processing time for a given frame, a fixed time loop algorithm can be written to "play catch up" by going a bit shorter (if there is time left over this iteration) than the required fixed time amount, until the frame loop is back at the correct time slot.

To a large extent, the timing issues that are discussed on that past thread that you quoted are no longer so important. AFAIK, the new Microsoft OS's use a faster system clock now. At that time, it only updated every 15 or 16 milliseconds. In other words, if you aren't expecting to market to Windows XP users, not to worry.

IMHO, the scheduleAtFixedRate type scheduling is perfectly adequate. Regardless of method, if the update and render takes longer than the scheduled time, you are going to get slippage in the frame rate. I don't see how the distinction "heavy lifting" actually means anything useful in this context. Either the tasks can be done within the designated frame rate or they can't. The wrapper for that code should have little or no influence on the execution speed of the tasks being wrapped.

A little slippage in frame rate may not even matter, as long as you are cleanly updating and reporting the metronome state at the time that the frame executes.

I continue to suspect that you might get more accurate scheduling with the scheduleAtFixedRate use of the util.Timer, versus calculating the variable sleep interval yourself, depending on how the Java engineers have implemented this internally. (I assume they know what they are doing.)

Maybe someone with a different opinion will speak up. Usually we hear something if I make an inaccurate remark. But given my tendency to tl;dr posts, perhaps my controversial statements are just be being overlooked.  Smiley

If you want to, you can also look at the ScheduledThreadPoolExecutor as an upgrade to the util.Timer. This gives you some additional exception handling capabilities (in case the TimeTask throws an unchecked exception). Learning about ExecutorServices and what Brian Goetz ("Java Concurrency in Practice") describes as "exploitable parallelism" is probably overkill. It would certainly be an interesting and very involved side trip! I'm in no position to evaluate the pros and cons.
6  Game Development / Newbie & Debugging Questions / Re: Java Metronome | Visual Display Sync Problem on: 2014-07-17 05:02:50
There's a lot of Java to learn, to do what you wish to do. You seem to me to be making good progress.

When you say "game engine", I think you mean to "game loop". An "engine" implies a whole slew of features that will enable a user to build a game via various templates and tools, not just the visual display loop.

It is my guess that if you have a visual display fps that is fine-grained enough, and supporting code that updates and reports the metronome state as cleanly as possible, that this will suffice. 60 fps is considered a good target for games. (Film is often 24 fps, or they do something like use 72 fps but show each frame 3 times. People don't usually notice synching discrepancies in the theaters, do they?)

Part of the reason I think a lack of precision (relative to that needed to make audio work) for sound/visual coordination is that the brain is biased towards fuzzing together sound and visuals as unified events. I'm not sure how to account for this. Maybe it has to do with the fact that the synching happens "higher up" in the nervous system, at some point where visual and aural systems meet, rather than at the more "mechanical" point of contact in the eye or ear. Or maybe it has something to do with sound travelling slower in air than light, thus lagging by varying amounts depending upon distance, i.e., inherently unreliable beyond a certain degree of precision anyway.

Looping the visual display at fixed time amounts by the standard technique of calculating the varying amounts of compensating Sleep will probably work okay. I think you just have to try it and see. I prefer using a util.Timer, as it is just as accurate (I cite "Killer Game Programming" as evidence) and somewhat simpler to code. There is a scheduling command that actively tries to keep the timer locked on a fixed schedule, making adjustments as best as it can if scheduling tasks run either slow or fast. To me that beats calculating sleep intervals, both in terms of the coding involved, and in the hope that the implementers know what they are doing and are handling this task at a level closer to native code. I could be wrong though and the util.Timer scheduling management could be implemented via higher level code similar to what we would write.

You're not doing a lot of "motion" animation are you? More like there are things blinking on and off, right?

The idea of "time stamping" with the audio frame count will only contribute to the extent that the visual frame loop is super solid. If it is, then you could also count visual frames and work out a calculation as to what audio frame range should be reported within a given visual frame. (Main issue would be figuring out a good "0" reference frame.)

But I don't think visual frames are displayed with as much precision as for playing back sound. You are getting into new territory for me. I've been able to be helpful because I'm a step or two ahead in a few regards, but that is all. There is much about the graphics system that I do not know.
7  Game Development / Newbie & Debugging Questions / Re: Java Metronome | Visual Display Sync Problem on: 2014-07-14 10:52:20
Quote
Currently, I don’t update the visual at a specific frame rate. It loop through and checks the system time to see when the visual needs to change, when it needs to change then it just goes and immediately updates the JLabels. Should I be updating these JLabel at a specific frame rate instead? I’m not doing any animations or anything at this point, but are there still benefits of using a frame rate even in my simple example just using JLabels? If so, then maybe this is part of my problem?

Most screen monitors are set to around 60Hz or maybe a little faster, and most game animation is done at 60 fps as well. There's a diminishing returns aspect of trying to update visuals faster than that, especially when the update out paces the screen refresh. Game animation at 60 fps is considered to be quite decent and should be sufficient for your metronome, it seems to me. It might be possible to get even more precise coordination with the sound but that would be moot since displays update very infrequently in comparison to audio frame rates.

It could very well work to write code to update visually "on demand". I've never tried it on anything with continuous animation. I strongly suspect getting a proper game loop structure going will be sufficient and simpler. Have you written one before?

The simplest game loop coding would be to use a util.Timer. You can put any needed updates and renders in a "TimerTask" and set the TimerTask to loop every 15 millis. The rendering code can branch on the boolean that handles the state of the JLabel, using that to decide what to show. (Most game loops use while loops instead, but if you don't have one to pull as a template from other code you've written, I doubt the trouble to write a first one of that form, from scratch, is justified for the scant amount of visuals or state updating you are doing.)

Handing off information between threads via variables is an important technique. It helps keep objects from getting too enmeshed and codependent, and helps with multi-threading. I think the proper term is "loosely coupled", for this sort of communication. If it works, great! If not, I am thinking of trying a strategy where the audio thread "time stamps" those requests to draw, but uses the audio frame number as the stamp value, not the actual processing moment of the audio. But hopefully you won't have to go there.

Are you familiar with the term "volatile"? Make the state boolean for the JLabel volatile, to help ensure timely and non-blocking communication between the audio and game-loop/visual threads.
8  Game Development / Newbie & Debugging Questions / Re: Libgdx sound lag? [solved] on: 2014-07-14 10:16:46
Congratulations!

Did the same code on the PC run clips with a sample rate of 96000? I didn't know Java on PCs could manage 96000Hz. Is this new to Java? Did you do anything special to allow this? Is there something built into LIBGDX that allows it to do this?
9  Game Development / Newbie & Debugging Questions / Re: Java Metronome | Visual Display Sync Problem on: 2014-07-13 23:27:42
Gulp. That's a lot of code to read.

Are you familiar with Java "listeners"? I think the concept is also known as the "Observer" design pattern.

Try this:

(1) On the audio thread, on the very sample that starts a tone, also flag the label for display. Do nothing more than toggle a boolean (the boolean should be volatile), as we don't want the audio processing thread to block with extraneous activities.

(2) I am assuming that you have a 'game loop' of some sort, for showing visual frames at some fixed rate (e.g., 60 fps is a popular choice for games). In your game loop, consult the boolean and use that to decide whether to display or not.

In effect, the item being displayed is an observer or listener to the audio event, and is "registered" in the audio thread.

Since the visual frames occur at a much slower rate than the audio samples (60 fps versus 44100 fps), an additional layer of lag time will be built in (besides the end stage graphics and audio renderings). Perhaps that will suffice?

I'm curious what results you get, if you try this method. I use it in an app that only has gradual sounds, and it looks fine. There are variably glowing lights that are "listening" to the evolving audio volume envelopes of individually associated synth notes, and the synth is set to have a slowish attack and long decay. Your usage will be a better test of the method.
10  Game Development / Newbie & Debugging Questions / Re: Libgdx sound lag? on: 2014-07-12 12:51:42
You could well be right. Is there a way to profile the program and verify that?
11  Game Development / Newbie & Debugging Questions / Re: Libgdx sound lag? on: 2014-07-12 00:06:45
My first guess is that your Android device has considerably less processing power than your PC, and that this accounts for the difference in performance.

Decoding a compressed file takes much more processing than running a wav. If you are trying to do both at the same time, or even just trying to play more than one ogg at once, that could very well be "too much" for your Android device while still being within the capabilities of your PC. (My old PC, from 2004, starts to bog down even with two compressed files playing at the same time. I assume a newer PC can handle considerably more than that.) I don't know what to suggest beyond either trying to create a less ambitious score, or trying to find some way of using less compression, e.g., decompressing and working from the unpacked file stored in memory (uses a lot of memory, yes).

Another remote possibility is that using some sort of mixer rather than running all the files individually might add some efficiency. But I've only done this using Java on PCs, not on Android. I do not know if, for example, the TinySound library could be wrappered or revised to run on Android, or if doing so would help.

Warning: my lack of experience with Android sound means that I could well be overlooking an Android-specific bug. But my general experience with sound leads me to suspect you are trying to do "too much".
12  Game Development / Newbie & Debugging Questions / Re: Libgdx sound lag? on: 2014-07-10 20:03:19
I'd be interested in seeing the code.

You might find the following article interesting, in terms of understanding basic issues pertaining to Java & Sound. Though, it doesn't specifically go into differences in implementation for Android & Java.

"Real Time Low Latency Audio Processing in Java"
http://quod.lib.umich.edu/cgi/p/pod/dod-idx?c=icmc;idno=bbp2372.2007.131
13  Games Center / WIP games, tools & toy projects / Re: WIP Publication Reel on: 2014-07-03 07:14:03
I managed to spend the last two days working on a new feature for the Simplex Noise Visualization Tool project. The result: it is now possible to use the tool to create simple Z-axis animations of noise textures, and to export them as animated gifs.

http://hexara.com/Images/plasma.gif

The gif export coding was very much helped by this posting from Riven:
http://www.java-gaming.org/topics/generate-animated-gifs/24196/view.html
 and from another example that came from the following Oracle Community post:
https://community.oracle.com/thread/1264385
It is unclear to me who the exact authors were on this second example. The following names are some but probably not all the contributors:  Brian Burkhalter, Geoff Titmus, Andrew Thompson.

In any event, my considerably stripped down version, for making an animated gif from an array of BufferedImages, is viewable as part of the open source SiVi project, which can be seen at http://github.com/philfrei/SiVi

Any interest in joining in and adding more features? The original goal was to make a tool to allow one to figure out, in a hands-on fashion, the parameters needed to make various texture effects using Perlin noise (the "Simplex Noise" flavor, in this case, though the principles would tend to apply to his other noise algorithms as well). But it is starting to accumulate ways to export various graphics, too.

As I said, the animation at this point is only on the Z-axis. It would be nice to add animation to other parameters, such as translation or scaling. Not sure when I'm going to be able to get to it. My next Java-coding priority is to get back to a Tanpura that is in the works.

Here's another gif that I made today, trying to approximate Ken Perlin's animated cloud example from his slide show: http://www.noisemachine.com/talk1

http://hexara.com/Images/perlinClouds.gif

If you look at his, you will notice that I didn't quite manage to match his color mapping, and his animation includes considerable horizontal translation (looks like a wind blowing the clouds to the east). I probably should have given my example a faster frame rate, too.

Here is Ken Perlin's cloud gif, from the above cited slide show:
http://www.noisemachine.com/talk1/imgs/clouds200.gif

I'm going to post one more, built from one of the images in the SiVi "Gallery". If it doesn't animate at first, it's because the file is rather large (5MB).
http://hexara.com/Images/tendrils.gif

If you wish to play with the tool, you can try the following URL:
http://hexara.com/SimplexVisualizer.html
but I have done nothing in terms of making certificates and such. Running and supporting Applets has become too much of a headache. If you don't want to build via the github project, you can download a jar with today's build from here:
http://hexara.com/SiVi.jar

To use: first select a graphic from the Gallery (menubar: View/Gallery) or build your own image. Then, select the Animator tool from the same View tab of the menubar. A form comes up where parameters are entered.

If you have trouble with setting the parameters and having the controls become enabled, try hitting <Enter> in each field where you have put a number. That is kind of annoying, the need to do this--any advice on how to better handle JTextFields so that <Enter> is not needed? Something has to trigger the intake of the value. Maybe someone could help improve this form. It really could use some help.

Last thing, I'm wondering if I can get credited for this as a 2nd project? Now that we have the WIP including "tools" and "toys" I think this project qualifies.
14  Java Game APIs & Engines / Java Sound & OpenAL / Re: Java Audio Metronome | Timing and Speed Problems on: 2014-07-01 19:41:27
Hi philfrei,

I realize it's a small delay and different software...but I've moved recorded music tracks around between different software and computers before with no shift in the timing. A friend and I used to bounce tracks back and forth between his Mac laptop and my PC desktop (he used Logic and I use Magix Samplitude) and there wasn't any timing drift problems as long as my project's tempo matched his project's tempo (or vice versa). But maybe any difference between them would have been too small to notice with instrument tracks?...it's very easy to tell exactly where the start of my metronome tone begins since everything surrounding it is all zero's, but that wouldn't be the case with instrument tracks.

I just added in a print statement for tickBufferSize and it does come back out to equal exactly 44100. The tempo I tested was 60bpm, which I did to avoid any weird cascading rounding errors as you mentioned just to see if it would stay "spot on".

I love your idea of trying to play a sound file in Java and recording that. I'll record 10 minutes of the metronome within my recording software Samplitude so that its easy to compare the difference between the Java playback version and the original. I'll need to figure out how to load the wave file into my program, because I'd like to use the same SourceDataLine method I'm using for my metronome.

Thanks again for all your help! Smiley

Interesting!

I think it is very likely that if you go back to some of those tracks you swapped, there might indeed be some drift. Ears have to be really good, and circumstances very clear to hear imprecisions when only a few millis are involved. I recall once trying to improvise against a friend's track and having the feeling be slightly uncomfortable, unable to get a sense of being "in the pocket". We took a closer look at the rhythms and found one of the drums offset by 4 millis. Straightening that out did a lot to settle my nerves. But I didn't hear it as a mistake, but rather just experienced some tension that I couldn't really explain. It could also have been an example of me just being nervous, and the fix working as a sort of placebo. But my experience was that the fix did feel more solid. (And yes, non-percussive sounds would be next to impossible to detect as being off at this level.)

I tested the idea of the int cast truncation, as well, and found that the "correct" number of frames was being generated, to the nearest frame. Later on, it occurred to me: what if a proper DAW is even more accurate than the sample rate? In order to handle a plethora of sample rates, maybe the DAWs work at a finer granularity than 44100 fps, and the metronomes naturally are tied to the highest level of precision available in that DAW. (My Cakewalk Sonar also handles 48000 sample rate, so it has to have something that is more precise than 44100 fps, but aren't there 96000 tracks now, as well?)

If a DAW's metronome is more accurate than the 44100 sample rate, then the fraction of the frame that is getting truncated in Java, but is handled in the DAW's metronome could cause some drift that is in the ballpark for what you are getting. Maybe?

I'm not sure how the fractions would be handled in the DAW. Maybe something like a Leap Year, adding or taking away an extra frame every now and then? As far as Java is concerned, there is no way I know of to take nanosecond readings at the precise time the frame is run through the digital-to-analog-converter, and the lack of real-time guarantees means the point when the frame is processed in the while loop could vary considerably!

In any event, your demonstration that the metronome is as or more accurate than other commercial metronomes seems like a good reality check. I wonder how your metronome, when running in Android, will compare.

Last bit of musing: if the DAW's metronome IS more accurate (to fractions of a sample), then a recording made from a DAW would most likely be a tiny bit longer than the calculated number of frames (using the truncation that Java does with the int cast). Perhaps that led to the drift in the plus, instead of minus direction, for that test?

I forgot about that post you dug up. I was contradicting the answer of one of my Java heros, Kay Horstmann! I was also doing a bit of venting. Maybe if you like that answer, and found it helpful, you'll give it a +?

Sometimes I wish I had minored in mathematics and/or sound engineering. I have a friend that is an engineer and used to work for Pro Tools. I'll run the idea of the metronome vs sample rate accuracy issue by him next chance I get.
15  Java Game APIs & Engines / Java Sound & OpenAL / Re: Java Audio Metronome | Timing and Speed Problems on: 2014-06-30 01:00:45
You are talking about less than 1/100th of a second after 10 minutes, when comparing the timing mechanisms of two entirely different pieces of software.

Maybe this is normal, I don't know. Perhaps this is why we have things like SMPTE code, and other mechanisms for maintaining synchronization?

Is tickBufferSize calculating out to what you expect? Bouncing back and forth between doubles and ints is worrisome. You only need to have the denominator of the division be a double (I don't know if making the sample rate a double adds to the error or not). Maybe test for a simple tempo like 60bpm or 120bpm, and eliminate this calculation -- hard code in 44100 or 22050 as your tickBufferSize and see if the error still occurs.

It occurs to me the (int) cast at the end could be causing a slight truncation in the tickBufferSize, which would create a slightly faster than expected rendition.

How many seconds in 10 minutes? 600? How many tickBuffers in 10 minutes? (Depends on tempo.) Are you testing a tempo (e.g., slower than 60bpm, or some "awkward" number) that would create the shown error if the tickBufferSize was off by one due to the int cast?

Another thought: take a piece of music, a wav that you have in your DAW, and play it back with Java, and record that in the DAW and compare. Or compare with other software that can play back.
16  Java Game APIs & Engines / Java Sound & OpenAL / Re: Java Audio Metronome | Timing and Speed Problems on: 2014-06-20 21:55:13
Quote
Am I on the right track here?...
Yes,

Quote
BTW, have you had any luck getting my Random Chord Progression Generator to load? I can't load that either via the web browser.
I haven't tried yet. Something about the way I'm wired, I will burn all sorts of time writing answers to questions and then get even further behind in everything else I am doing. Tongue Next window of opportunity will be Sunday. Will be looking forward to it!
17  Java Game APIs & Engines / Java Sound & OpenAL / Re: Java Audio Metronome | Timing and Speed Problems on: 2014-06-20 12:42:44
Thanks for elucidating this, Riven.

Tekkerue, as to the question about blocking: if the BlockingQueue is asked to do something that it can do, then the code executes. If it can't do it, then it blocks. So, I pick your scenario (b). But the lack of real time guarantees in Java makes this moot if you want metronomic accuracy.

The article I cited earlier goes into this: "Real Time Low Latency Audio Processing". It's going to be vital that you understand the nature of Java's lack of real time guarantees if you are going to use javax.sound.sampled for this.

For accuracy on par with Java's MIDI sequencer, the only way I know of is to calculate the actual sound frame a note should play, count frames, and start the note on that frame (when the while loop is processing that frame). The moment in time at which sound data is loaded into the buffer is too variable relative to when it is actually heard to do otherwise.

Example: 44100 fps stereo, 16-bit ("CD Quality"). Let's say you want the metronome to play 120 bpm. I would calculate the interval in frames ( = 22050 ) and have the while loop count frames as it processes the buffers of PCM bytes, and start the metronome click sound on that actual frame. So, in the middle of some buffer when you get to frame number N * 22050, you start the loading of the PCM data for the click sound.

I'm guessing you may have to hear for yourself before taking the trouble to use the frame counting method. I first ran into the 'lack of real time guarantees' issue with the Theremin, trying to get the sound to accurately track the mouse movements via a MouseMotionListener. My rude awakening (and considerable resistance to the truth) can be viewed on an old JGO thread. Eventually I got a reasonable solution.

Java's MIDI package and sequencer can provide the needed accuracy--so maybe you should just use that, and schedule Midi 'control messages' to trigger your visuals.

Doesn't NetBeans or your other IDE have a way to run Applets? I use Eclipse.
Doh!  Clueless I forgot to give you the entry point:
Here's the HTML code that is used for that jar:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
<script src="http://www.java.com/js/deployJava.js"></script>
<script>
    var attributes = {code:'jTheremin.ThereminApplet.class',
                      archive:'JThereminApplet.jar',
                      width:810, height:400} ;
    var parameters = {fontSize:10} ;
    var version = '1.6' ;
 
    deployJava.runApplet(attributes, parameters, version);
</script>


You know, there is the program "appletviewer.exe" that is in the bin file of your JDK, probably.
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/appletviewer.html
http://en.wikipedia.org/wiki/AppletViewer
I haven't tested this, but I think if you put the above html in a valid html file, and put it in the same directory as the jar, you can run it via a command line.
18  Java Game APIs & Engines / Java Sound & OpenAL / Re: Java Audio Metronome | Timing and Speed Problems on: 2014-06-19 19:55:25
I'm not entirely sure of the implementation, but I think SourceDataLine and TargetDataLine both rely on a BlockingQueue or something very similar. Basically, the audio loop proceeds in its own thread. The write method for SourceDataLine blocks until the underlying code has had a chance to process the previous buffer's data and it is able to accept the new buffer array of data.

Yes, the loading of data into the buffer array should be significantly faster than the rate at which the sound data is played! The audio while loop basically should be spending most of its time in a blocked state (at the point where SourceDataLine is writing). If the loading of the buffer array ever takes longer than the write command blocks, you will probably hear drop-outs.

The api for SourceDataLine's write method refers to the blocking:
http://docs.oracle.com/javase/7/docs/api/javax/sound/sampled/SourceDataLine.html

There are methods to check availability on the line, but there is usually no need to do this. Mostly we just keep shovelling buffer arrays into the line as fast as it is willing to accept them.

This should answer all 4 of your questions!

**********

Yes, the whole deal with applets is messed up. I gave up trying to deal with it. I leave it to the user to figure out what they have to do with their browser & plugins to allow the applets to play. As far as I know, my programs are okay to trust. They've just been sitting on my website and protected from tampering by whatever security the provider (startlogic.com) has going.

Some of the links are downloads of jars. You might have more luck with them. Should I dig up the link to the theremin applet's jar file?
Here it is:
http://Hexara/VSL/JThereminApplet.jar
But you will probably have to run it in your IDE as an Applet, not as an Application. Be sure to try the Echo effect. I've been meaning to add a control for vibrato, but haven't managed this yet. Vibrato via a mouse is hard to make sound good.
19  Java Game APIs & Engines / Java Sound & OpenAL / Re: Java Audio Metronome | Timing and Speed Problems on: 2014-06-18 20:41:52
It's kind of funny when we say "self taught", since we have the best teacher you can ask for at our finger tips...the Internet. Smiley

Good point!

Quote
I did go to university for programming, but it was a "liberal arts" college that was mostly known for theater, so it was definitely NOT a tech school by any stretch of the imagination. LOL I feel like I've learned far more online than I learned in college as most of the teachers were "so-so".

I was at UC Berkeley as a Music Major, but took "breadth" courses in Comp Sci and in Psychology (emphasis Cognitive & Psychoacoustics--worked at a Hearing Lab for work-study). Did a bit of composing and sound design for the Dance Department, and the Drama Department and the Educational TV Office. The CompSci teachers were great, no complaints. But the material I chose: Pascal, Assembly (via PDP-11), Logic Design (e.g., TTL chips to make a Pong game!), are all pretty out of date now. I was there in the 1970-s & 1980's. (Dating myself!)

Quote
I created a music related MIDI applet for my final project and my teachers couldn't even help me with it since none of them worked with MIDI...after a couple months of trying to figure it out, got lucky and found an example that was similar enough to what I needed and I was able to make it work. I uploaded my finished app online and since you're also a musician, I'll go ahead and share the link here...it's a random chord progression generator that creates chord progressions using music theory and then plays them via MIDI.
http://www.guitarforbeginners.com/tekker/Chord%20Progression%20Generator%20V3/ProgressionGenerator.html

Cool! I'm looking forward to checking it out. By the way, you might check out krasse's related work, posted on JGO.
http://www.java-gaming.org/topics/some-reasonable-output-from-my-generative-music-system/27309/view.html

Quote
What sound programs have you made? Have you made any kind of tools for musicians?

I made a Theremin applet, with a real-time touchpad control for volume and pitch.
http://www.java-gaming.org/topics/java-theremin/24646/view.html
I made another touchpad that let's you play sounds forwards or backwards at varying speeds. Another tool (based on a friend's idea) makes semi-random sine waves that are harmonically related (whole-number-ratios), creating a kind of evolving cloud--sounds spacy--involved figuring out envelopes.

After getting the basic mixer working, I wrote my own version of the Java Clip that can play at varying speeds, but also can support multiple cursors, so you can do things like trigger multiple gunshots and not have the newest shot squelch the previous. I wrote an improved tool for looping these clips, in that one can specify that the ends overlap or not, and cross-fade or not.

I have yet another Clip variant that plays random slices of a sound. There's an example posted somewhere here, where a 4-second recording of a brook is broken into something like 200msec random slices that are played with a bit of overlap, creating the illusion of a continual, non-repeating sound from a small source file.
http://www.java-gaming.org/topics/what-music-do-you-listen-to-while-you-code/27824/msg/275109/view.html#msg275109

Related, a "SoundField" construction that lets one select a number of Clips and play them semi-randomly, at a certain probability for given time period. This was also used in the above link, but the current version has a much more efficient way of generating the random bells than using Perlin's algorithm.

There was a soundscape sort of piece involving wav files from an old analog synth that I own. There are five volume sliders that can be manipulated or left to drift randomly. I was attempting to use ogg compression, initially, but couldn't get it to work without memory leakage. So the file is a bit bulky as the resources are raw wav files.
http://hexara.com/ffw/ffway.jar

I have been delving more deeply into frequency modulation, as I am a big fan of the Yamaha DX7 (vintage 1980's synth, again dating myself). I've written an FM synthesizer, and have converted something like 8 of the DX7 patches to real-time Java synthesis, some bells, and pads and a keyboard so far.

I have an echo tool working, and a flanger/chorus algorithm working. Haven't gotten to filters yet, nor reverb.

The "sound field", FM and flanger can be heard in the puzzle game project I started but have yet to finish: Hexara.
http://www.java-gaming.org/topics/hexara-work-in-progress/23676/view.html

Making a listing like this (first time in a long time!) I see that I've been at it for a while now, but also have a definite tendency to R&D over completing and bringing products to market. I am in awe of programmers like nsigma who have accomplished so much that is practical and commercially/publicly available.

Quote
I've also been looking at finding the mobile equivalents to SourceDataLine as well, I believe AudioTrack is the equivalent for Android...
Bingo! I agree. I just haven't attempted a proof-of-concept example yet.

Quote
...iOS has so ridiculously complicated that I actually haven't found the equivalent there yet. I've looked at several tutorials for iOS sound and it is insane the amount of overhead you have to do when working with lower level audio. Ugh!

A good friend of mine is a contract iOS programmer, and he recently said he found the hook. But this is a case where we have to successfully port Java to Object-C. There are a couple tools that seem plausible, one that goes directly, another path that uses an intermediate JavaScript conversion. Whether the code I wrote is basic enough Java to allow this conversion and runs efficiently, remains to be seen! I don't know enough about this hook yet to pass on info to you. I only heard about it from him two weeks ago and am frustrated that I have to work on other things and can't get to this immediately. The electronic tanpura project I'm working on (also stalled) has some potential to be a neat little iOS app.

Quote
When mixing the sounds, wouldn't you also need to have some kind of DSP limiter to make sure you don't clip when combining multiple sounds?

Yes. But simple can be effective for 90% of the situations: just use a Math.min and Math.max function. That prevents overflow. As to clipping, I use my ears for diagnosis, and just turn down the volume of the contributing sounds. Again, crude but simple. A limiter/compressor is not something I've dealt with yet. Like filtering, it involve understanding things like convolution (I have a tenuous grip on this--understand the basic concept but weak on appropriateness of where/how to implement), is a bit more advanced than I can handle.

Quote
I will definitely take a look at the article you mentioned and the code you posted. I have downloaded the TinySound source code and quickly glanced through it, but I'll definitely have to dedicate more time to really studying it to see what all I can get out of it.

Thanks again for your help, you've definitely given me some new directions to look into and creating my own audio mixer sounds intriguing for sure...got more studying to do there!

It's endless, and easy to get continually distracted! Good that you have a concrete project (the metronome) to help provide focus.
20  Java Game APIs & Engines / Java Sound & OpenAL / Re: Java Audio Metronome | Timing and Speed Problems on: 2014-06-18 08:26:49
I am also a musician first. I got into Java only four or five years ago, am self taught, and am also new to DSP. I've managed to teach myself a few things but also have had lots of help!

I also preferred to write things myself, in order to learn and understand, so I appreciate your wanting to do so as well. I'm in the process of working on the problem of converting my Java sound programs to iOS and Android, also. So maybe there is room to put heads together on this, down the road. (I think I've located the equivalent of the SourceDataLine output in both realms, so my framework code (all core Java) should run on these other system, but haven't tried testing this yet.)

Do read the article I recommended! Many issues pertain to what Java can and can't do. I prefer not to get into specifics about handling latency issues until you at least give it a go. It wasn't the easiest read, but having it to refer to will be helpful.

A simple mixer is definitely feasible. The DSP being about as easy as DSP gets. The main task is the combining of PCM values, and that is just addition! Converting to and from bytes has to be done. There's some tweaking to make sure you don't overflow. Handling volume and panning can be kept very simple/stupid, at least initially.

Another excellent audio programmer will probably reply soon as well (he's in Australia): nsigma. He has an excellent set of tools written and repeatedly given great advice as well as being generous in opening up his source code.

I just remembered, I started this thread when I started my second pass on a mixer:
http://www.java-gaming.org/topics/simple-audio-mixer-2nd-pass/27943/view.html
The first post has a link with a jar with source code. The project has evolved a bit since then, and some of the decisions I made have not had unanimous support (!) but the code might still be helpful for you to look over.
21  Java Game APIs & Engines / Java Sound & OpenAL / Re: Java Audio Metronome | Timing and Speed Problems on: 2014-06-18 03:16:09
Check out this really useful article on Java timing for music and sound:

http://quod.lib.umich.edu/cgi/p/pod/dod-idx?c=icmc;idno=bbp2372.2007.131
Quote
REAL-TIME, LOW LATENCY AUDIO PROCESSING IN JAVA
Nicolas Juillerat, Stefan Muller Arisona, Simon Schubiger-Banz
ETH Zurich
Computer Systems Institute

Secondly, you will probably want to keep a SourceDataLine open and running constantly, for use as the output for a "mixer," in the studio audio sense of the word mixer, not the Java sense. Have it play "silence" when there is nothing going else to play.

If you don't want to write your own audio mixer, TinySound (on github, but also has posts here on JGO) has been written and already does this. With this library (pretty small, easy to read) you'll be able to overlap sounds.

I wrote my own audio playback library also, but haven't made it available, and added an "event system" for it a couple months ago. It checks a queue every frame for "trigger" commands. Something like this would be ideal for your use. To code this, you have to play your sounds one frame at a time, and check if on that frame count there's another sound that is scheduled to be played. This is the only way I know to be really accurate, as Java does a good job of keeping sounds playing correctly (when you are at the stage of progressively loading the SourceDataLine), but is less accurate (doesn't make real time guarantees) about issues that pertain to multiple threads or other issues mentioned in the article I cited.

There's a trick for improving the accuracy of the sleep timer in windows. If you run it the command Thread.sleep(Long.MAX_VALUE) (on its own thread, of course!) the Windows OS will use its higher resolution clock (same one used for nanotime) for sleep and getmillis. But issues pertaining to the buffer used for playback and to thread management guarantees will still hinder accuracy.
22  Discussions / General Discussions / Re: This is one of the worst feelings i ever had on: 2014-06-16 20:32:25
I just wanted to reinforce what Riven (and Roquen) are saying. Laws don't always match intent. "Possession" in some cases can be sufficient to get you in trouble, even though you dropped it like a hot potato.

The only related case I know about involved a local (San Francisco Bay Area) popular talk show host, Bernie Ward, who's career was destroyed. He was very critical of the Bush administration, and was taken off the air when child pornography was found on AOL servers (not his computer, but the AOL account used for emailing the photos to a sex-chat dominatrix) and he was indicted by a Federal Jury. His defence was that the material was "for research purposes" on a book about hypocrisy in America. This defence didn't fly with either the general public or the jury. He ended up plea bargaining guilty to a single count of emailing files. Most probably this was not an act of political recrimination, and he was indeed guilty. I'm not a lawyer either, but I don't find it hard to extrapolate from that example to any sort of witch hunt, and mere presence of certain types of files being legally incriminating.

Quote
the first thing i noticed is that people doesn't react seriously to the problem, some even laughed
I agree, the lack of a serious response can be pretty upsetting on its own. I am reminded of a close woman friend who, as a child, was the victim of molestation from her uncle. She went to her mother with it and the mother's response was to dismiss it as being "as common as weeds." The only repercussion for the uncle was to try to avoid him as much as possible and never be alone with him again. Things like that can leave scars! (And he did go on to molest other victims.)

How could her own mother be so callous? My speculation was that she had also been a victim in her youth and received the same response when she reported the problem. Behaviors can be passed down for generations, with certain immoral acts rationalized or "swept under the rug" rather than confronted. At some point with these cycles of evil, people need to take a stand and stop them, rather than being cynical and allowing them to continue.

A couple other historical examples: slavery, pedophilia in the Church, a culture/mindset that blames women when they are raped...

Quote
i surely need someone to talk with about these things
Quote
it literally got into my mind from no where, it's very chocking, i can't find a stronger word to explain it.
"choking" or "shocking"?
Quote
the images that i saw are very very very disturbing for someone like me, and if they doesn't go away, i will think about consulting a therapist
Absolutely, it makes sense to look into this further, it seems to me. There's nothing to lose. I'd want to understand more about why and what in the world is being done about it. There are various people that can be consulted will have varying degrees of expertise. I'd try to find someone where the individual has direct training, knows the literature and appreciates the reality and seriousness.
23  Discussions / General Discussions / Re: This is one of the worst feelings i ever had on: 2014-06-16 08:48:39
Actually I am studying for a PhD in Psychology, and my statement still stands. There's nothing wrong with this kid, he's just after validation of his feelings about the situation, and he wants a little attention on the side, thus the very hyperbolic statements to get a reaction from us.

If he is truly deeply bothered by the imagery (and I don't believe he is), unless he if going to harm himself or others, he shouldn't just run off and get therapy anyway. He should try to handle it himself first. You don't run off to a therapist every time you see something a little scary or disturbing, you learn to handle it like an adult. If you can't, then you need the therapist. I'm sure he's going to be just fine without anyone's help.

Psychology is a very broad field, most of which does not pertain to this situation. So, that answer was kind of ambiguous. Are you in fact studying to be a mental health practitioner of some sort?

I acknowledge you wish to let your comment stand, but my concern about it stands on two counts.

(1) We don't know everything that is going in in the OP's head. We don't know that it was merely "a little scary or disturbing." (I'm not as willing as you are to make that conclusion, based on scant evidence.)
 
(2) Your attitude towards consulting a mental health professional seems to me to have a negative stigma on it. A consultation can go a long way to getting context and perspective. A consultation is not years of Freudian analysis, nor is it some sort of admission of moral weakness nor a giving away of one's own power. If the situation is as "minor" you assume it to be, a single meeting would suffice and be informative.


@Jimmt, sure it is good to be self-sufficient. But a lot of times, friends, colleagues, specialists, knowledgeable people can be a huge help. And moral questions have both a personal and a social part, and on occasion can be difficult and deep.

"There's messed up stuff all over the world" and we all have to deal with our own consciences as to the extent to which we lift a finger to try and do something or not. Sometimes "being the best you can" means allowing yourself to be affected, and channelling the outrage or disgust into positive motivation and actions.
24  Discussions / General Discussions / Re: This is one of the worst feelings i ever had on: 2014-06-16 06:15:56
Quote
I know what you mean, and actually i think that i may need a therapist.
No, you don't. Wink

Rayvolution, are you an actual mental health professional, or are you just confusing yourself with your avatar?

I think checking in with a mental health pro to talk about some of this crazy stuff makes a lot of sense. For one thing, a professional should know something about the legal context as well as the health issues. If you were in the USA, with the new ACA law, health plans now include mental health coverage.

I have no idea what the situation is in Tunisia.

I would take Riven's advice seriously.
25  Game Development / Newbie & Debugging Questions / Re: Trouble with text boxes on: 2014-06-05 23:20:52
What part are you having trouble with?

This String method lastIndexOf(int ch,  int fromIndex) should be helpful. You can use it to look backwards from the maximum number of chars that can fit, for a space, and then use the return value when you extract the "next" substring.
http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#lastIndexOf%28int,%20int%29

If you haven't already done so, maybe check out the descriptions and methods for both String and StringBuffer. They are fundamental knowledge, very helpful to know about! (Good to know how they are different, when to use which one.)

Have you looked at the java tutorials on String and StringBuilder?
http://docs.oracle.com/javase/tutorial/java/data/manipstrings.html
http://docs.oracle.com/javase/tutorial/java/data/buffers.html

The StringBuilder would be something you'd use to store results of appending if you used the algorithm of adding "words" progressively. But an algorithm using the lastIndexOf() method seems like a better choice to me. Maybe either approach is fine. An I/O stream approach would make more sense if the data for the boxes were stored as assets in files?
26  Game Development / Newbie & Debugging Questions / Re: Trouble with text boxes on: 2014-06-05 20:49:32
Can you use a MouseListener on the text box or enclosing rectangle bounds to check for clicks?

It should be possible to write a reusable function to extract the "next" text from a larger text block. No need to store individual words.

The function would need an index or cursor to hold the position of the last character currently visible, and the length of the text to be extracted. Within the method there should be a way to work backwards to find the nearest space character so that you don't break words in half.

Or, write or use a stream that breaks at spaces--isn't there a stream that already does that?--and add 'words' to a StringBuffer until the "next" one would pass the limit.

A "wrapper" object could hold the last displayed char in an instance variable.

Do you need a code sample, or can you write this yourself?
27  Discussions / Miscellaneous Topics / Re: Infatuated on: 2014-06-02 20:23:10
Quote
She's the only girl in the school i like. The first to give me a chance. She slow danced and hugged me twice. Never happened to me before.I'm not a confident guy either.

Some thoughts that spring to my mind which may or may not apply:

Your class size will increase by an order of magnitude in college. the chance of only liking one person from such a larger pool is significantly reduced. Plus, there is a greater age differential that is considered acceptable, which bumps up odds of meeting interesting potential partners by another factor . This age differential factor increasingly works to your benefit as you progress through school.

True, the fact that older men with younger women is more generally accepted than younger men with older women gives male freshman slightly worse odds than freshmen women. Even so, odds are still significantly better than most High School situations.

Many people approach things in a try-and-buy fashion, or are simply out to enjoy themselves or "learn more about life and people" before getting into deeper commitments. There's an inevitable risk/reward ratio in meeting people. More likely than not, a match does not result (or only lasts a very short time) and one side experiences rejection. A decent person will try to minimize hurting others.
28  Game Development / Newbie & Debugging Questions / Re: interacting with source from an event on: 2014-05-30 04:53:44
FIFO array? CircularQueue?

An idea: use an ArrayList.

use add() to add an item, then test the size
if larger than 6, remove the head item and uncheck it

with an ArrayList, any uncheck can also be removed from the list pretty easily

since its only 6 items, the exact implementation is not so crucial

29  Game Development / Newbie & Debugging Questions / Re: How to change and image transparency on: 2014-05-29 20:45:48
Slyth2727's link looks good.

Here is where I first learned how to do this, from a JGO post by StumpyStrust:
http://www.java-gaming.org/topics/java2d-clearing-up-the-air/27506/msg/246444/view.html#msg246444

There are a bunch of nifty suggestions there, including resizing/scaling, in addition to the info about changing transparency levels.
30  Game Development / Newbie & Debugging Questions / Re: Is it possible to check if a Runnable's State is State.RUNNING in a thread pool? on: 2014-05-29 18:52:24
Quote
Was thrown off by <?>. Have no idea if I should keep it or not?

In case you haven't read about wildcards before, here is the Java Tutorials explanation:

http://docs.oracle.com/javase/tutorial/extra/generics/wildcards.html

ags1 suggestion to use a Future sounds good, but I'd also consider just letting the i/o task be a runnable thread that simply expires when done, and drop the Executor part. However there are things that an Executor provides that you may be wanting. I don't have a lot of experience here, but I read that with the Executor you can get better error handling than with a raw thread.

There are lots of ways to have the thread notify other components of its completion. Have you ever built your own Listener? The design pattern called "Observer" would be another keyword for a method to search for ideas.

But the ExecutorService does include provisions for shutting it down. For example, if you have just one task, or are giving it the last task, after doing so you can run it's shutdown() method: "no new tasks are accepted but previously submitted tasks are allowed to complete." (Goetz, "Java Concurrency in Practice" pg. 121, 6.2.4 Executor lifecycle)

Great book! I am reading that ExecutorService has an awaitTermination() method as well. Maybe overkill for a single i/o task, but still pretty cool.
Pages: [1] 2 3 ... 33
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (13 views)
2014-07-30 21:08:39

Riven (21 views)
2014-07-29 18:09:19

Riven (14 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (32 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (42 views)
2014-07-24 01:59:36

Riven (42 views)
2014-07-23 21:16:32

Riven (29 views)
2014-07-23 21:07:15

Riven (30 views)
2014-07-23 20:56:16
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!