PORT4K

Thanks, thinking about cutting the aim and add a new level instead.
The music do contain a fair bit of high frequencies and noise. But if you use headphones or ‘real’ speakers it shouldn’t be too noisy. You need to be able to hear the base tones to appreciate it :wink:

Hint: On Level 5 you need to shoot a portal midair.

It would be too bad to cut this music. You should better consider how to fix it. You may give a look at the source code of Rick Townsend’s Mazer 4K, which includes a rather good synth. Thanks for the tip for level 5. I’ll try my best to pass it.

What i meant is that if you for example listen on it trough the laptop speakers you will only hear the high frequencies.

But yeah, the noise in the song is there by design :slight_smile: For instance the lead is using a square wave oscillator and the drum track is, of course, just noise with a fast envelope and a delay effect. But I’ll review the sound settings for the published song later today. If it’s too much noise I’ll lower the delay effect or volume on that track a bit.

For those interested, here’s the synth itself. As you can see there are plenty of room for bit loss in the calculations, but it’s very compact!
It features three oscillators, a delay effect, envelope, transpose on each track.

I’ll publish the complete code including the tracker, with more comments, in a few days.


		final int[][] wave = new int[3][WAVE_BUFFER];
		for (index = 0; index < WAVE_BUFFER; index++) {
			wave[0][index] = (int) (FP_S1 * (float) Math.sin(index * (2f * PI / WAVE_BUFFER)));
			wave[1][index] = index < (WAVE_BUFFER >> 1) ? FP_S1 : -FP_S1;
			wave[2][index] = (int) (FP_U1 * (float) Math.random()) - FP_S1;
		}
		while (true) {
			for (int track = 0; track < NUM_TRACKS; track++) {
				final int[] ins = song[INSTRUMENT_OFFSET + track];
				ins[ENV_LEVEL + 1] = FP_U1;
				final int pattern = song[SEQUENCE_OFFSET + (track >> 1)][((track & 1) * SEQ_LENGTH) + (sequence >> 5)];
				final int note = song[PATTERN_OFFSET + pattern][sequence & 0x1f];
				if (note == 1 && ins[ENV_STAGE] < (2 << FP)) {
				ins[ENV_STAGE] = (2 << FP);
				}
				if (note > 1) {
					ins[OSC1_RATE] = frequencies.charAt((note - 2 + ins[PITCH]) & 0xf) << ((note - 2 + ins[PITCH]) >> 4);
					ins[ENV_STAGE] = 0;
				}
				for (index = 0, offset = 0; index < SAMPLES_PER_TICK; index++, offset += 2) {
					if (track == 0) {
						out[offset] = 0;
						out[offset + 1] = 0;
					}
					final int stage = ins[ENV_STAGE] >> FP;
					ins[ENV_STAGE] += ins[ENV_RATE + stage];
					ins[OSC1_PHASE] += ins[OSC1_RATE];
					int value = wave[ins[OSC_TYPE]][ins[OSC1_PHASE] & WAVE_BUFFER_MASK];
					final int env = ins[ENV_LEVEL + stage]
							+ (int) ((long) (ins[ENV_LEVEL + stage + 1] - ins[ENV_LEVEL + stage]) * (ins[ENV_STAGE] & FP_U1) >> FP);
					value = (((value * env) >> (FP + 2)) * ins[VOLUME]) >> 6;
					value += ((delay[track][(ins[DELAY_POS] - ((ins[DELAY] * SAMPLES_PER_TICK >> 1))) & DELAY_MASK]) * ins[DELAY_MIX]) / 128;
					delay[track][ins[DELAY_POS]] = (value * ins[DELAY_FEEDBACK]) / 128;
					out[offset + 0] += (byte) value;
					out[offset + 1] += (byte) (value >> 8);
					ins[DELAY_POS] = (ins[DELAY_POS] + 1) & DELAY_MASK;
				}
			}
			index = 0;
			while (index < BUFFER_SIZE) {
				index += line.write(out, index, BUFFER_SIZE - index);
			}
			sequence = (sequence + 1) & SEQ_WRAP;
		}

Great improvement over the first itteration.
I personally would like to alter the keys so that the arrow keys could be used
instead of the A-D keys.

Best regards from
M.E.

Here is the source release for TinySynth which is the tracker and player i use in PORT4K.

Ok, i’ve removed the aim and added the last super hard level :slight_smile:

How many levels, Bysse ? You may add the option to go to the next level, so everyone could see them all. Without it, I’m not sure I will be able to see this last super hard one.

It’s only eight levels so it shouldn’t take too long :wink:
I don’t have enough space for a level skip, trying to squeeze in the aim again… I’ll think about it

Tests complete ! Finally… This eighth level was tricky but passing it was very satisfactory. Really a great game. And thanks for all the informations about your 800 bytes synth.

Good job!
Check out http://www.java-gaming.org/topics/music-player-for-4k-games/25845/view.html for the complete source.

Hi, is it possible to have a look into the portal source? It would be nice to study it, especially since the java decompiler screwed the decompilation completely up :slight_smile:

Peter

I’ll upload the source on the entry soon :slight_smile:

This sounds great :slight_smile:

I’ve upped the code on the game page, it was to large to paste here.
If you have any questions don’t hesitate to ask.