Ok, here's what everyones looking for...a resource for Flash streaming audio and graphical equalizer displays.

Everyone please use this thread for all related inquiries and feedback. Much of this information is already available in other threads but is buried under a pile of repeated questions.

I'll be updating this main post to summarize additions to the thread. Be advised some post may be deleted in the future to reduce the overall posts to the thread.

Let's begin

What is streaming audio?

Anyone familiar with digital audio knows the file sizes are huge. One can spend minutes waiting for the file to download, just to hear it. Streaming audio is essentially one huge audio file broken up into ten of thousands smaller audio files. These files are commonly refered to as packets. Individual packets can be played as soon as they are downloaded. As long as packets download faster than the song plays the playback will be seamless.

Types of streaming.

The main difference between flash streaming and other forms is where the stream occurs, either server side or client side.

Server Side

With Real, Shoutcast and others place the processing strain on server software. The server creates a dialog with the player and packets audio to be sent. Once a packet is played the player dumps it and move onto the next packet buffered. The two-way dialog allows the server to adjust packet quality to compensate for bandwidth.

In server-side streaming each simultaneous user requires a software node, and an allocation of the servers processor. The number of nodes are limited by the software license and hardware resources.

Client Side

Flash, Beatnik, and some Quicktime files do not require software on the server to packet the file. The frames in flash are actually packets that allow the file to playback while downloading. Normally an entire file must download before it can be accessed. In client side streaming packeting information is already encoded into the file. This allows the player to decode and access parts of the file before the download is complete. All the strain is placed on the client and the server handles the file like any other.

In client side streaming there is no two way dialog to compensate for changes in bandwidth, and the entire file must remain active to play any of its parts.

Each method has advantages and disadvantage.
Code:
Advantages 
  Server Side 
    live broadcasts 
    active bandwidth compensation 
    low client side resource requirements 

  Client Side 
     no cost for server software 
     interactivity 

Disadvantages 

  Server Side 
    cost per node 
    server intensive 
    limited interactivity 

  Client side 
    no active compensation for net congestion 
    client resource requirements 
    smooth playback is difficult to calculate
Basics of Flash Streaming Audio

The basic model for streaming audio in flash consists of a player.swf and seperate swf files for each audio sample.

The audio swf files are simply a timeline with a sound set to stream. The timeline is generally a few thousand frames long. It is usefull to add a stop action on the first and last frame.

The player has two functions. One, to load audio files as requested. Two, monitor audio playback and allow functionality.

Generally the audio file is loaded into a level of the player. Tracking _framesloaded, _currentframe, and _totalframes of the level gives most of the functionality to a player.

Tracking the time.

current time in sec = _currentframe / framerate of audio swf

total time = _totalframes / framerate of audio swf

maximum time currently available = _framesloaded / framerate of audio swf

Audio Control

Functions such as fast-forward, rewind, and pause are all done by targeting the timeline of the level where the audio is load.

Pause
_level#.stop()

Fast-forward, rewind
_level#.gotoandplay(frame number)

Change song
unload _level# and load new swf into the level

Buffering in flash

Flash has natural ability to handle buffering of a streaming sound. It is the Sound Buffer Time global property. By default the value is 5. Meaning 5 seconds of a streaming sound must be loaded before flash will start playing it.

For better results override the sound buffer time and set it to 0. Using action script to check the _framesloaded or bytesloaded in the level serves as a better buffer. The audio swf should have a stop action in the first frame for this to work. Once conditions are satisfied the script must tell the level timeline to play.

Optimizing audio compression for Client Streaming

The following numbers are for the bandwidth needed to stream mp3's of different compression bitrates. (first number bitrate/second number bandwidth kb/s) Calulations where made using CBR (constant bitrate) not VBR (variable bitrate)

8bit / 1.09kb/s
16bit / 1.99kb/s
20bit / 2.50kb/s
24bit / 2.99kb/s
32bit / 3.99kb/s
48bit / 4.98kb/s
64bit / 7.974kb/s
80bit / 10.10 kb/s
112bit / 13.99kb/s
128bit / 16.11kb/s

There is a minor variance to add to these base numbers depending on the framerate used in flash. Since the streaming sound must be packeted. The more packets(frames) the greater the file size. This number is 0.01kb/s times the framerate.

By choosing a compression and adding a little for framerate you can easily calulate the bandwidth needed to stream any sound.

The modem speed are 9600-14.4 baud (telecom devices 0.96 kb/2- 1.44 kb/s), 24.4 baud (2.44 kb/s), 36.6 (3.66 kb/s), 56.6 (5.66kb/s), ISDN (8-11.2 kb/s), and DSL/cable modem (ranging).

The problem is user bandwidth varies by modem, net congestions, isp congestion, and host congestion. This means the user rarely has the bandwidth they are capable of. It should be assumed that a users bandwidth isn't the peak value.

Using one stream that all users can hear results in poor sound quality. Dial-up modem users aren't used to sound with their internet, and the sound they normally hear is poor quality anyway. They won't mind. Broadband users expect more.

Upgrading to support multiple bandwidths requires duplicate audio swfs at different compressions and bandwidth checking capability in the player.

Quality obviously depends on the compression rate, but it also varies by the mp3 codec used. The Fraunhofer Institute invented and owns the rights to mp3. Their version 2 codec is the one used in Flash. There are also knock-off freware codecs; LAME and Blaze to name a couple. These are the codecs used in freeware and shareware mp3 programs. Each codec will make files identical in size but with varying sound qualities.

For the best quality go with the Fraunhofer version 3 codec. The only program I know of the includes this codec is the MP3 add-on to Cool Edit Pro $200US. There is also a tricky command line from Fraunhofer $200US.

http://www.swifftools.com makes a mp3 to flash converter called SwiffPEG. Very handy.

Flashtraks and graphical audio diplays

The flashtraks are actual interpretations of the sound; however, this ability is simulated since flash doesn't have capabilities to interpret sound.

A flashtrak movie is not made using flash. The movie is generated by a third party program that, takes an audio file, analyzes the audio spectrum, creates a set of variables, and generates a flashtrak swf.

Each flashtrak has a unique set of variables that are used for the graphic equalizer display. Programs like winamp actively interpret the sound data whereas in a flashtrak the data is stored.

The flashtrak has the following vaiables.

"load" used to check if the file is fully loaded

"length" Length of audio sample in seconds. For display purpose only

Below are the usefull ones

"fulllen" The full length of the song. A value of time in msec. 1 second = 1000 msec

"step" The amount of time between each sample of the audio spectrum. value in msec

"rows" The number of samples taken from the audio data. Equal to the integer of fulllen/steps.

"data1", "data2"...."datan" A variable containing the spectrum data for each spectrum sample. The number of data variables is equal to the value of "rows".

A data variable is 16 digits long. '0102030405060708' This string represents 8 bands of audio. Breaking the string up by 2's gives 8 numbers ranging from 00-99. Low bands at the beginning of the string. High bands at the end.

Each data variable represents a reading of the 8 bands at a specific point in time. data1 is the first sample and following data#'s are taken at time intervals equal to "step".

The trick is tracking the time to know which data variable to use. I'm not in the mood to code at the moment so hopefully someone will help and translate this. Or you can see a good version 4 fla here.

http://www.flashkit.com/movies/Third...07/index.shtml

The data.swf flashtrak file has a stop command in the first frame. To start tell the instance where it is loaded to play. Also tell an instance with a looping frame to play. It is important to use the gettimer function to set a starttime at the same time you start the sound.

The starttime is equal to time zero for the audio. Data1 holds the info to be displayed. Break the data1 string up by 2's. The value will be from zero to 99.

For a simple eq create a mc with a vertical rectangle. Place the bottom left corner of the rectangle to the center point of the mc. Set the height of the rectangle equal to the maximum height for a peak audio response. Create 8 instances of this mc for each band.

Having pulled the band variables from the data1 string you can use these numbers as a percent to set the y% property of each band mc instance.

Since audio time equals 0 and starttime this is the easy one. Moving into the next frame (the looping frame) the main problem is to track the audio time and pull the proper data# to display.

Use gettimer to update current time. By subtacting the starttime and an offset time (for loops) you can get the audio time. Divide the audio time by "step" and take the integer of the result to calculate the data# to use. If this value is greater than "rows" or if audio time is greater than "fulllen" then the audio has looped. Set the offset time equal to offset time plus "fulllen".

FlashAmp http://www.marmalademedia.com.au/flashamp/ is a program that will generate variables for the overall amplitude.

Using a string for the bands and a timer is kinda complicated. There is a program called swiftmp3 from http://www.swift-tools.com that will create a custom swf for streaming. With these you only need to read a variable from a level. The variable automatically updates as the song plays. No need to use sub-strings or timers.


Hope this helps someone.
[Edited by cre8ive on 12-07-2001 at 02:18 AM]