Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (581)
Games in Android Showcase (163)
games submitted by our members
Games in WIP (632)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Pew Pew Pew! Sound synthesis  (Read 9522 times)
0 Members and 1 Guest are viewing this topic.
Offline ryanm

Senior Devvie

Projects: 1
Exp: 15 years

Used to be bleb

« Posted 2008-01-23 21:55:12 »

I started out trying to make a straight port of the excellent SFXR, but quickly got tired of picking through opaquely-named variables, and so made my own sound synthesis doodad instead.


Download the jar here.

A rundown of what does what:
The black panels control the value of some variable over time. Left click on them to add a point, right click to remove the closest point, and the points are draggable too. The top 4 panels should be self-explanatory, the fifth shows the effect of the vibrato on the final sound frequency, the final two control the delightfully-named flange effect.
Used to great effect by Hendrix and Procol Harum, flanging overlays the signal with a delayed version of itself, creating some weird effects.
The delay panel controls how delayed the overlay is, while the alpha panel controls how much of the delayed signal is added.

The "Signal" combobox controls the waveform of the sound, the "Vibrato" combobox controls the waveform of the vibrato that's added to the base frequency, length controls the duration of the sound, in seconds.
"Export" saves the sound as a wav, "Play" plays the sound, and "Save" saves the data needed to recreate the sound if you want to generate it at runtime, like so:

TerrainSound ts = new TerrainSound( getClass().getClassLoader().getResourceAsStream( mySoundFilename ) );
ByteBuffer littleEndian16BitPCMData = ts.generate( 44100 );

All the code is available here.

If you're hardcore and want to define the sound in code, you can do that too:
SoundSpec ss = new SoundSpec();

ss.volumeEnvelope = new Variable() {
   public float getValue( float time )
      return the volume at that time;
ss.waveform = new Waveform( ) {
   public float valueForPhase( float phase )
      return the value at this point in a wave, eg sin( 2*PI*phase);
ss.waveform.frequency = new Variable( ) {
   public float getValue( float time )
      return the frequency at that time;
ss.length = foo;
ss.postProcess = new PostProcess( ) {
   public void process( ShortBuffer data, int sampleRate )
      postprocesses are optional, but feel free to monkey with the data samples how you like
ByteBuffer littleEndian16bitPCMData = ss.generate( 44100 );

Offline Orangy Tang

JGO Kernel

Medals: 57
Projects: 11

Monkey for a head

« Reply #1 - Posted 2008-01-23 23:20:37 »

Awesomeness! /me saves next to SFXR  Grin

Any chance of adding some random and mutate buttons? They were the best features of SFXR for a non-sound-inclined person like me.

[ - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline jojoh

JGO Knight

Medals: 5
Projects: 7

« Reply #2 - Posted 2008-01-23 23:21:14 »

Wow that is just soo brilliant!   Cool

Both great to be able to create some own sounds and I guess that is also makes it possible to compress sounds heavily (if you generate at runtime) for web based stuff or anywhere that size really matters. Especially if one wants some pac-man style sounds. Could you share some presets of different types if you have some? I am specifically looking for vehicle sounds that would be possible change revs in realtime or something that can be pregenerated that one can then slide between in realtime. An accelerating car for example. Is that what one can do with the code example? (Haven't tried it yet)

Sfxr also has the autogenerate certain types of sounds and mutate and randomize which was really great for me since I don't quite know what I am doing, but, can then start with a good idea and then mutate or try and error til it is good enough. Load would also be useful.

Thanks for sharing!

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ryanm

Senior Devvie

Projects: 1
Exp: 15 years

Used to be bleb

« Reply #3 - Posted 2008-01-24 00:36:55 »

Usability stuff like load/random/mutate/presets/space to play will probably appear tomorrow, unless I know what's good for me and I work on my thesis instead (depressingly unlikely Undecided ).

File sizes if you're generating at runtime are tiny - 36 bytes + 8 bytes for every point you define versus tens of kilobytes for the generated pcm data. They could certainly be reduced more, but is it worth it? I'll leave it to the 4K-ers.

As to vehicle sounds: nothing presents itself off the top of my head, but I'd start by looking at low frequency noise, or perhaps a low hum with a noise vibrato.
Offline brackeen

Junior Devvie

« Reply #4 - Posted 2008-01-24 02:38:27 »

This is awesome! I'd like to second the idea of adding 'random' and 'mutate' buttons and also some presets Smiley

The code looks good, too. I'll definitely be keeping an eye on this.
Offline ryanm

Senior Devvie

Projects: 1
Exp: 15 years

Used to be bleb

« Reply #5 - Posted 2008-01-24 17:56:09 »

Alrighty then, that's random/mutate/presets/loading added. Again, get the jar here.

I'm currently torn over whether to implement incremental sound generation. On one hand it's going to be a minor pain in the bum to do, on the other hand it would be nice not to have the delay when you click "play"...
Maybe later...
Offline kappa
« League of Dukes »

JGO Kernel

Medals: 85
Projects: 15


« Reply #6 - Posted 2008-01-24 18:01:00 »

this is very cool, amazingly useful for indie games.
Offline moogie

JGO Ninja

Medals: 16
Projects: 6
Exp: 10 years

Java games rock!

« Reply #7 - Posted 2008-01-24 20:31:33 »

heh, this brings me back to my Amstrad CPC664 days and passing random values thru its 3 channel sound generator until i found something that sounded good and used it for a simple crappy games! (well i was about 9-10 at the time Smiley )

good work!

Java4k RIP 2014
Offline darkprophet

Senior Devvie

Go Go Gadget Arms

« Reply #8 - Posted 2008-01-24 20:43:04 »

The explosion sounds *exactly* like the explosion from MGS1 on the PSX with the grenades....


DP Smiley

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
Offline brackeen

Junior Devvie

« Reply #9 - Posted 2008-01-25 03:34:39 »

Brilliant. The new version works on Mac OS X Java 5, too. Cheers!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ryanm

Senior Devvie

Projects: 1
Exp: 15 years

Used to be bleb

« Reply #10 - Posted 2008-01-25 07:13:42 »

Brilliant. The new version works on Mac OS X Java 5, too. Cheers!

Good stuff! I was mildly worried about endian issues there. I had a bash at incremental generation, but it was difficult to apply postprocesses correctly and the SourceDataLine didn't seem to want to cooperate, so I rolled back the changes.

On to actually writing a game now I suppose...
Offline CommanderKeith
« Reply #11 - Posted 2008-01-28 08:32:21 »

Cool program, it's really quite funny!

Thanks for making it so easy to export stuff into a wav file  Smiley

PS: what's your thesis about (80's sound effects?!)

Offline ryanm

Senior Devvie

Projects: 1
Exp: 15 years

Used to be bleb

« Reply #12 - Posted 2008-01-28 09:23:31 »

I wish. It's on location algorithms for wireless sensor networks.
After four years, and now deep in a writing-up deathmarch, I'm desperate for diversions. Hence the recent burst of activity here as I finally get round to writing some gaming stuff: the sound generation, the texture packer and the font rendering. Coming next - a stupidly over-specified game of asteroids.
Offline CommanderKeith
« Reply #13 - Posted 2008-01-28 14:31:42 »

Hehe, well it's said that if you want something done, give it to a busy person  Tongue

I was the same when I was doing my honours thesis last year, I would just sit in the computer labs and stuff around in these forums, mostly watching what other people were looking at and checking it out... pretty sad but sometimes pretty interesting seeing the funny old things that people used to have heated discussions about!  I'd also lament how many cool things I could do if only I didn't have to do my thesis. At least you're actually making the cool things!

Apologies for the thread hijack, but is the 'location algorithms for wireless sensor networks' about finding people who are on their mobile phone?  Sounds cool enough.  My fun-packed thesis was 'The price and volume effects of off-market share buy backs in Australia'  Cry Sad

Offline ryanm

Senior Devvie

Projects: 1
Exp: 15 years

Used to be bleb

« Reply #14 - Posted 2008-01-28 18:57:47 »

Apologies for the thread hijack, but is the 'location algorithms for wireless sensor networks' about finding people who are on their mobile phone?

Similar, but much, much harder. In the particular flavour of WSN that I've been looking at, the nodes are very small (and so completely crap from a capability and reliability point of view), potentially mobile, and extremely numerous. I also can't rely on any infrastructure like cellphone masts, gps satellites or compute servers.
So it's all error-tolerant distributed algorithms, each node working out its location with respect to its neighbours, emergent behaviour, that kind of thing.
Offline kaoD

Senior Newbie

« Reply #15 - Posted 2010-08-20 15:04:39 »

I'm sorry for the bump, but SoundGen is exactly what I was looking for. Awesome stuff, I hope you're still around here! I love sound synthesis, so you made me want to set up a multi-instrument enviroment for my applet game Smiley

I want to buffer some random output for little sounds effects (like coin, powerup...) and pre-generate a tune. What would be better in each case, keeping ByteBuffers or Clips cached? I mean, the little wait time when clicking play in your app is caused by SoundSpec generation or in the Clip player? Is Clip much bigger in memory?
Offline ryanm

Senior Devvie

Projects: 1
Exp: 15 years

Used to be bleb

« Reply #16 - Posted 2010-08-20 17:00:04 »


The time for generation depends on the duration of the sound as you would expect, and it's always a good idea to avoid work when you can, so I would keep hold of the generated buffers.
I don't have enough experience with the javasound APIs to say much about clip objects, but I would be surprised if they were much more than a wrapper on top of the buffer.
Does anyone else know? Are Clip objects a limited resource like OpenAL sources?
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

theagentd (19 views)
2015-05-27 22:21:17

theagentd (23 views)
2015-05-27 22:21:08

CopyableCougar4 (18 views)
2015-05-27 19:24:50

MrMapcom (24 views)
2015-05-23 20:26:16

MrMapcom (32 views)
2015-05-23 20:23:34

Waterwolf (37 views)
2015-05-20 15:01:45

chrislo27 (44 views)
2015-05-20 03:42:21

BurntPizza (79 views)
2015-05-10 15:53:18

FrozenShade (63 views)
2015-05-07 09:11:21

TheLopais (227 views)
2015-05-06 13:36:48
List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00 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‑
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!