tone generator

38 views
Skip to first unread message

leathrum

unread,
Mar 5, 2011, 11:00:52 AM3/5/11
to gwt-voices
Has anyone written a basic sinusoid tone generator in GWT-voices (and
willing to share code)? What I have in mind is something that
generates its tone on the fly, based on something like A*Math.sin(B*x)
with sliders controlling values of A and B, so the tone needs to be
generated as the sound plays and updated whenever A or B values on the
sliders change. I want to use something like this (also showing a
graph of the sinusoid) to show trigonometry students about amplitude
and frequency of sinusoids. I just need some sample code for how to
handle the sound, I can build the rest of the app myself. From what I
can tell, GWT-voices is built around playing downloaded or streamed
sound files (referenced by URLs), not around playing tones as they are
generated within the GWT code.

Fred Sauer

unread,
Mar 7, 2011, 12:59:11 PM3/7/11
to gwt-v...@googlegroups.com, leathrum
You could create an array of bytes containing the samples. If you can then add the appropriate header bytes to turn these into wav/au/mp3/whatever files, then you can Base64 encode them into data URLs (http://en.wikipedia.org/wiki/Data_URI_scheme). Those can be played.


--
You received this message because you are subscribed to the Google Groups "gwt-voices" group.
To post to this group, send email to gwt-v...@googlegroups.com.
To unsubscribe from this group, send email to gwt-voices+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gwt-voices?hl=en.




--
Fred Sauer
Developer Advocate
G
ooglInc.
1600 Amphitheatre Parkway
Mountain View, CA 94043
fre...@google.com


Fred Sauer

unread,
Mar 7, 2011, 8:01:04 PM3/7/11
to gwt-v...@googlegroups.com, leathrum

leathrum

unread,
Mar 9, 2011, 10:35:23 AM3/9/11
to gwt-voices
I tested data: URL's with only limited success. For example, the MP3
example here:

http://www-archive.mozilla.org/quality/networking/testing/datatests.html

works fine as a plain HTML link, but if I try to use the same data URI
in the soundController.createSound(...) method, it doesn't work. I
checked the Sound.LoadState, and everything looked fine ("supported
and ready"), but play() didn't do anything.

I have also looked at what Mozilla is working on for FF4:

https://developer.mozilla.org/en/Introducing_the_Audio_API_Extension
https://developer.mozilla.org/en/Creating_a_Web_based_tone_generator

These are, at least in principle, similar to the chromakode example
you pointed out. But these don't really answer the question for GWT.
What I got used to using in plain Java was the
javax.sound.sampled.SourceDataLine object API, where I could put
together short bursts of the sound and keep them going onto an open
channel. I'm coming to the conclusion that there just isn't anything
like this available for GWT, at least not yet.

leathrum

unread,
Mar 10, 2011, 10:32:58 AM3/10/11
to gwt-voices
There is also this, from the Webkit camp (Chrome and Safari):

http://chromium.googlecode.com/svn/trunk/samples/audio/index.html
http://chromium.googlecode.com/svn/trunk/samples/audio/specification/specification.html

So it seems Gecko and Webkit are working on separate, incompatible
projects toward the same browser functionality. Go figure.

In any case, it looks like either of these approaches will do what I
want, but neither are available in production browsers yet, so there
is no point in even looking for a GWT library to handle this. The
features should be in production browsers by the end of the year, but
it will probably be another year after that before there are any
standards-based approaches available. I'm just ahead of the curve.

Fred Sauer

unread,
Mar 14, 2011, 12:18:38 PM3/14/11
to gwt-v...@googlegroups.com, leathrum
The data: URLs (including your example) work fine with gwt-voices. However, they won't play via Flash, so you have to play them via HTML5.

Using the attached version of gwt-voices, you can try it like this:
String url = "data:audio/mp3;base64,//tAxAAABvhjIgS...
SoundController sc = new SoundController();
sc.setPreferredSoundType(Html5Sound.class);
Sound sound = sc.createSound("audio/mpeg", url, false);

Be sure to use the full data URL, not the cut off one shown above.

Fred


--
You received this message because you are subscribed to the Google Groups "gwt-voices" group.
To post to this group, send email to gwt-v...@googlegroups.com.
To unsubscribe from this group, send email to gwt-voices+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gwt-voices?hl=en.

gwt-voices-r382.jar

Max Völkel

unread,
Jun 12, 2012, 4:55:48 PM6/12/12
to gwt-v...@googlegroups.com, leathrum
I cannot get this to run.
Using your current API this must look like this:

String url = "data:audio/mp3;base64,//tAxAAABvhjIgS...
SoundController sc = new SoundController();
Sound sound = sc.createSound(Sound.MIME_TYPE_AUDIO_MPEG_MP3, url, false, false);

I get a single LOAD_STATE_SUPPORTED_NOT_READY event, and no matter how long I wait or when I try to play() the sound, there is just silence or no other events come.

Here is the data URI that I use (a single short beep):

data:audio/mp3;base64,//tQwAA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AAAAAAAAAAAAAAP/7UsBXgAjZF2WkAG75IQhl9GwNUQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAg//tSwG4AAAABLAAAAAAAACWAAAAAACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACD/+1LAzAAAAAEsAAAAAAAAJYAAAAAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAAA==

Reply all
Reply to author
Forward
0 new messages