Saturday, November 8, 2008

Notes class 5 october 8

Lolcats is a phenomenon to check out.


Sound in flash by default streams. So don’t put it in your library. You don’t wait for the whole thing to download. As soon as it can it will play. They are too big for the library.
Video works the same way as audio.

58 streaming sound is small. All it does is play the sound.

Sound event has a couple of properties. It has a play command. That’s what gets the sound to play.

59. streaming 2
2 commands. snd.play(0,3) will be (milliseconds, number of repeats)

60. buffered sound
var context:SoundLoaderContext = new SoundLoaderContext(5000, false);
= wait till there is 5 seconds of the file downloaded into memory.


61. sound channel
Each sound when played is assigned to a sound channel. If you have 1 sound it’s ok or if you don’t care. If you want control of the sound you create a sound channel. Sound object cannot stop itself. It can start itself. The sound channel can control the flow and turn off the sound. Always start it with the sound object. Always stop it with the channel.

private var box : black_box;
private var snd:Sound;
private var mychannel:SoundChannel; // create a sound channel for this sound

above, it passes the sound to the channel. Then you can use the channel to stop it.




62. sound channel 2

Snd. Object is like a hose. It doesn’t know about the data going through it. The sound channel is smart. It knows when the sound completes. Like water in a hose. When it’s done, it knows.

It will be able to set a variable and clear it to 0 when the sound stops and then when it hits the variable you can then allow the sound to play again so you don’t end up layering the same sound over itself again and again.


63. id tags
Id3 built into flash, when pulling in an mpg it reads the metadata tags inside the file and you can pull out artist, song name, album cover, etc. from the file. It streams the song and then the id3 data comes in. it fires the event when the stream has started. See the help to get more id3 functions.

63 seeking sound
Make a box; make a sound and put it in a channel. “Position” shows where we are in the sound at this minute. Reads full song length in ms. Then Brian’s file traces the place in the play at the moment of the click.
Position is a property of channel
Length is a property of snd

Video will seek –jump to a place in the file. By adding + 3000 it adds 3000 ms to the number the click traces.



64. sound transform

Transformation object you pass to a sound object. When the button is clicked it will run the transform object. Pass it 2 numbers. It has a channel mychannel.soundTransform = transform

First number is volume. 0=none 1= full vol .5 is half volume.
Second is pan left speaker is 0 right speaker is 1


Default is full vol and .5 in the middle

private function whenClicked(e:Event) // this function is called by the CLICK listener above
{
// create a sound transform and pass it to the sound channel
var transform:SoundTransform = new SoundTransform(0.5, 1.0); // #1 is volume, #2 is panning
mychannel.soundTransform = transform; // only a soundchannel can stop the sound
}


65. microphone 1
Can’t save microphone data or create wave forms in microphone data in flash. Can get activity level. Can gauge how much sound is coming into the mic at any time. Lots of work is made using this feature.

Cut and paste this code if you use anything using a mic. Flash won’t turn on mic or camera on without that user knowing about it.

Use this to find out if they allow it:

public function mictest()
{
mic = Microphone.getMicrophone();
mic.addEventListener(StatusEvent.STATUS, this.onMicStatus);
mic.addEventListener(ActivityEvent.ACTIVITY, this.onMicActivity);

// set mic properties
mic.gain = 60; // how mic amplifies sound // 50 is default
mic.rate = 11; // capture rate in Khz // 11 is default
mic.setUseEchoSuppression(true);
mic.setLoopBack(true); // send through speakers
mic.setSilenceLevel(5, 500); // how loud to register event? // how long between sounds to register silence
}



function onMicStatus(event:StatusEvent):void
{
if (event.code == "Microphone.Unmuted")
{
trace("Microphone access was allowed.");
}
else if (event.code == "Microphone.Muted")
{
trace("Microphone access was denied.");
}
}



66. mic 2

If activitylevel is >1 set the box to scale. Makes a simple sensor that gets data from the outside world.



Wii talks to the wii and maybe your computer. It sees the infrared lights to track the dots the wiimote projects toward the screen. Using infrared and projected light you can track objects on a screen or in space.

Download wiiflash from the web site to get this file to work.

66. wiiflash demo.
Make sure in preferences that no wii remotes are paired. In Bluetooth. Wiiflash serverj opens an app that lets you connect to the wiimote via holding down 1 and 2 buttons.

Org folder is wiimote flash libraries. Needs to be in the same folder as the flash file. Use it to check that the wiimote is working. It has all the sensore, pitch yaw roll and battery level. It’s the accelerometers.

67 wiimote buttons
Has the import code to get the wiimote info in.
Public function connects to the wiimote. Listeners listen for when the wiimote connects to the file and if it goes away.
Are custom events written for the wiimote. They are a lot like all the other listeners and codes used up till now. The listeners work just like you were using a mouse. The trace lets you know it’s working. There are events for all the willmote buttons. Easy to send that info to flash.


68. wiimote control
New event here : wiimote event update. New position data to flash is update event. New square sprite and box is drawn in this case. On update
Turn on trace actions here to see what happens. Look at pitch and roll. Now it follows the movement of the wiimote in both directions. 1.5 to -1.5 are the range and 0 is the middle.

Inside the events is data we want to use for stuff.

With xtemp variable, adding 1.5 to a number it will now go from 0 to 3 so the math is easier. Changes the range. The number will amplify (normalize) so multipl the x by (1000 / 3);

Same with the y but divide 700 (screen height) / 3;


Makes x and y position based on roll and yaw.


69. wiimote music 1
Bad samples from garage band.

Now it will play with the buttons pressed.


70. wiimote music 2

Panmultiplier is a normalizer same as the amplify code in 68. it works on the roll.
Padvolume adds 1.5 to it’s 0-3 range instead of -1.5 – 1.5. the other divides by 3 for some reason.

Transformation object will change the volume and change the pan.


71. wiimote crossfade

Changes the panning
Plays all the 3 music elements at once.
Immediately passes transform objects that set 2 to half volume. Roll adds 1.5 to go from -3 as normalized pan. Goes from 0 – 1 then subtract that from 1.0 so it changes positive to negative so when it plays it will get louder when the other gets quieter and the opposite. The drums are always playing. The sound really all always plays but the volume changes.


Pc version of wii server can talk to the wii balance board. Cool. New version of wii flash server for the mac.

The server is open source, free download and is written in java. Can get flash wii games online that people have posted.


Think about what you want to make. Work in teams ok.

No comments: