Friday, September 5, 2008

Controlling sound volume and panning in flash cs3

Controlling sound volume and panning
An individual SoundChannel object controls both the left and the right stereo channels for a sound. If an mp3 sound is a monaural sound, the left and right stereo channels of the SoundChannel object will contain identical waveforms.

You can find out the amplitude of each stereo channel of the sound being played using the leftPeak and rightPeak properties of the SoundChannel object. These properties show the peak amplitude of the sound waveform itself. They do not represent the actual playback volume. The actual playback volume is a function of the amplitude of the sound wave and the volume values set in the SoundChannel object and the SoundMixer class.

The pan property of a SoundChannel object can be used to specify a different volume level for each of the left and right channels during playback. The pan property can have a value ranging from -1 to 1, where -1 means the left channel plays at top volume while the right channel is silent, and 1 means the right channel plays at top volume while the left channel is silent. Numeric values in between -1 and 1 set proportional values for the left and right channel values, and a value of 0 means that both channels play at a balanced, mid-volume level.

The following code example creates a SoundTransform object with a volume value of 0.6 and a pan value of -1 (top left channel volume and no right channel volume). It passes the SoundTransform object as a parameter to the play() method, which applies that SoundTransform object to the new SoundChannel object that is created to control the playback.

var snd:Sound = new Sound(new URLRequest("bigSound.mp3"));
var trans:SoundTransform = new SoundTransform(0.6, -1);
var channel:SoundChannel = snd.play(0, 1, trans);
You can alter the volume and panning while a sound is playing by setting the pan or volume properties of a SoundTransform object and then applying that object as the soundTransform property of a SoundChannel object.

You can also set global volume and pan values for all sounds at once using the soundTransform property of the SoundMixer class, as the following example shows:

SoundMixer.soundTransform = new SoundTransform(1, -1);
You can also use a SoundTransform object to set volume and pan values for a Microphone object (see Capturing sound input) and for Sprite objects and SimpleButton objects.

The following example alternates the panning of the sound from the left channel to the right channel and back while the sound plays.

import flash.events.Event;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundMixer;
import flash.net.URLRequest;

var snd:Sound = new Sound();
var req:URLRequest = new URLRequest("bigSound.mp3");
snd.load(req);

var panCounter:Number = 0;

var trans:SoundTransform;
trans = new SoundTransform(1, 0);
var channel:SoundChannel = snd.play(0, 1, trans);
channel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);

addEventListener(Event.ENTER_FRAME, onEnterFrame);

function onEnterFrame(event:Event):void
{
trans.pan = Math.sin(panCounter);
channel.soundTransform = trans; // or SoundMixer.soundTransform = trans;
panCounter += 0.05;
}

function onPlaybackComplete(event:Event):void
{
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
}
This code starts by loading a sound file and then creating a new SoundTransform object with volume set to 1 (full volume) and pan set to 0 (evenly balanced between left and right). Then it calls the snd.play() method, passing the SoundTransform object as a parameter.

While the sound plays, the onEnterFrame() method executes repeatedly. The onEnterFrame() method uses the Math.sin() function to generate a value between -1 and 1, a range that corresponds to the acceptable values of the SoundTransform.pan property. The SoundTransform object's pan property is set to the new value, and then the channel's soundTransform property is set to use the altered SoundTransform object.

To run this example, replace the filename bigSound.mp3 with the name of a local mp3 file. Then run the example. You should hear the left channel volume getting louder while the right channel volume gets softer, and vice versa.

In this example, the same effect could be achieved by setting the soundTransform property of the SoundMixer class. However, that would affect the panning of all sounds currently playing, not just the single sound being played by this SoundChannel object.

Working with streaming sound files in flash

Working with streaming sound files
When a sound file or video file is playing back while its data is still being loaded, it is said to be streaming. External sound files that are loaded from a remote server are often streamed so that the user doesn't have to wait for all the sound data to load before listening to the sound.

The SoundMixer.bufferTime property represents the number of milliseconds of sound data that Flash Player should gather before letting the sound play. In other words, if the bufferTime property is set to 5000, Flash Player loads at least 5000 milliseconds worth of data from the sound file before the sound begins to play. The default SoundMixer.bufferTime value is 1000.

Your application can override the global SoundMixer.bufferTime value for an individual sound by explicitly specifying a new bufferTime value when loading the sound. To override the default buffer time, first create a new instance of the SoundLoaderContext class, set its bufferTime property, and then pass it as a parameter to the Sound.load() method, as shown below:

import flash.media.Sound;
import flash.media.SoundLoaderContext;
import flash.net.URLRequest;

var s:Sound = new Sound();
var req:URLRequest = new URLRequest("bigSound.mp3");
var context:SoundLoaderContext = new SoundLoaderContext(8000, true);
s.load(req, context);
s.play();
As playback continues, Flash Player tries to keep the sound buffer at the same size or greater. If the sound data loads faster than the playback speed, playback will continue without interruption. However, if the data loading rate slows down because of network limitations, the playhead could reach the end of the sound buffer. If this happens, playback is suspended, though it automatically resumes once more sound data has been loaded.

To find out if playback is suspended because Flash Player is waiting for data to load, use the Sound.isBuffering property.

Friday, August 22, 2008

Vista Hibernation off

1. Click Start, All Programs, and then right click on "Command Prompt".
2. From the context menu click on "Run as administrator".
3. If User Account Control prompts you to allow the action, click on Continue.
4. In the command prompt window, type "powercfg –h off" (or "on" without the quotes) followed by Enter button.
4. Close the Command Prompt window and you're done :)

Tuesday, July 1, 2008

File Upload

Label1.Text = "File Name : " & FileUpload1.FileName
Dim i As Integer = FileUpload1.PostedFile.ContentLength
Label2.Text = Math.Round(i / 1024, 2) & "KB"
FileUpload1.PostedFile.SaveAs(Server.MapPath("~/images/") & FileUpload1.FileName)

Friday, June 20, 2008

Oracle Codings

exp 80 - to export database
imp 80 - to import database

Thursday, June 19, 2008

Print first 10 prime numbers

To print first 10 Prime Number

Void main()
{
Int I, count=1;
For(i=1;i<=100;i++)
{
For(j=1;j<=I;j++)
{
If(j%2==0)
{
Continue;
}
If(j==i)
{
Cout<<”Number is prime”< Count=count+1;
}
If (count==10)
{
Break;
}
}

Lan Cable Colour Coding

1. White of Orange
2. Orange
3. White of Green
4. Blue
5. White of Blue
6. Green
7. White of Brown
8. Brown

Wednesday, April 2, 2008

making flash movie transparent

param value="transparent" name="wmode" param name="wmode" value="transparent" close tag here

Now, find the embed tag and add the following tags along with the other embed tags:
wmode="transparent"

Tuesday, April 1, 2008

changing listview according to change in treeview and listbox

ListView1.Items.Clear()
Dim a, b As String
a = ListBox1.SelectedItem
If File.Exists(TreeView1.SelectedNode.Text & "\" & a) Then
b = TreeView1.SelectedNode.Text & "\" & a
Dim y As FileInfo = New FileInfo(b)
ListView1.Items.Add(y.Length / 1024 & " KB")
ListView1.Items(0).SubItems.Add(y.CreationTime)
ListView1.Items(0).SubItems.Add(y.LastAccessTime)
ListView1.Items(0).SubItems.Add(y.IsReadOnly)
Else
ListView1.Items.Add("This is a directory")
End If

Running Any process in vb.net

Dim p As New Process
Dim pi As New ProcessStartInfo
pi.FileName = TreeView1.SelectedNode.Text & "\" & ListBox1.SelectedItem
pi.UseShellExecute = True
p.StartInfo = pi
p.Start()

Wednesday, March 19, 2008

Birthday Reminder VB.net

Dim a As DateTime
a = Now

vconn = New OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=c:\friends.mdb")
vconn.Open()

vadapter = New OleDbDataAdapter("select * from birthdays", vconn)
vdataset = New DataSet
vadapter.Fill(vdataset, "birthdays")
vdatatable = vdataset.Tables(0)

Dim x As Integer

Dim y As Integer = 0
For x = 0 To vdatatable.Rows.Count - 1
If DatePart("m", vdatatable.Rows(x).Item(2)) = Now.Month Then

ListView1.Items.Add(vdatatable.Rows(x).Item(1))
ListView1.Items(y).SubItems.Add(vdatatable.Rows(x).Item(2))
ListView1.Items(y).SubItems.Add(vdatatable.Rows(x).Item(3))
ListView1.GridLines = True
y += 1

End If
Next

Sunday, March 16, 2008

autosuggest & data binding

dim oproducts as new autocompletestringcollection
for each product as productdataset.productrow in me. productdataset.product
if product.name.startswith("O") then
oproducts.add (product.name)
end if
me.combobox.autocompletecustomsource= oproducts

Wednesday, January 2, 2008

To select only datepart from date column in sqlserver2005

To select only datepart from date column in sqlserver2005

select datepart(m,dob) from customers