A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 24

Thread: [Resolved] [Resolved] [Resolved] [Resolved] [Resolved] [Resolved] [Resolved] [Resolved] [Resolved] [

  1. #1
    cre8ive
    Guest
    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]

  2. #2
    Junior Member
    Join Date
    Oct 2001
    Location
    Los Angeles
    Posts
    24
    hi, cre8ive

    this post is nice. Finaly something that everyone can really use. You only have a mistake on it, which gave me a headache...

    To "Tracking the time.":
    those formulars are wrong. correct is:

    current time in sec = _curentframe * (1/framerate)
    total time = _totalframes * (1/framerate)
    maximum t.c.a. = _framesloaded * (1/framerate)

    And I don't quite understand in which way to use these properties....

    check out my 1$-Million Question...have an answer`?
    hoelle


  3. #3
    Great post cre8ive!

    You mention "third-party software" that generates the flahtrak data.swf. What's the name of that third-party software? Where can I download/order it? Thanx!

  4. #4

    Got it!

    Ah,... after googling about for a few hours, I found a thread on chinwag.com that solves the riddle surrounding the creation of your own flashtrak::

    Check this: I found this on www.chinwag.com:

    "But how do you get the variables (data, fulllen, etc) into data.swf that
    the player requires? I think they must be created by some (undoubtedly
    proprietary) program based on the music to get the info for the
    equalizer, so just using another plain music swf wouldn't work as far as
    I can see. "

    We created a custom program that we use, it takes any sound file, (wav,
    aiff, mp3) creates the text data (peaks), makes the conversions and then
    builds the flashtrak using swift generator :)

    Its a sweet little engine, and we are looking for more players!!!! So feel
    free to make one up!

    The catch is it only works with the loops in our archive at the minute :)
    But this grows daily anyways!

    Regards Mark Fennell
    Flashkit.com Webmaster



    So.... what does that mean for us Flashers?
    Well, it means that we can't generate our own flashtraks...
    a shame realy, 'cause what if you have a certain loop you want to use, and you can't because it's not on flashkit.com?

    Well, the only solution to that problem is uploading the loop to flashkit, pray that they pop it online, and download the flashtrak you needed.

    It would be better though, if the fine people of flashkit would either sell or give us the proggy's they use for generating flashtraks.

    Any chance of that idea seeing daylight?

    I, and I bet everybody else in hear, sure hope so! :)

    Regards,
    Emil

  5. #5
    cre8ive
    Guest
    fruitjuice

    There is little chance that the application will be released.

    That leaves us 3 options.

    1. using flashtracks and extracting the variables.

    2. using swiftmp3.

    3 or finding someone who can write a proggy to take spectrum readings from an audio file in time intervals.



    option 1:

    Sometimes you just want to use the audio file and not the flashtrak swf, but you still want to have a spectrum display.

    It is possible to extract the variable encoding from a flash track swf. You'll need "step" "fullen" "rows" and all the data# variables (use "rows" to determine the number of data# variables) Just load the flashtrak into a movie that displays the variables with formatting. The formatting can be in actionscript or variables for a textfile.


    option 2:

    Swiftmp3 encodes spectrum variables from mp3 files. The result is a streaming audio swf with 18 bands of audio.

    Because the resulting swf is set to stream the variables are easier to handle. The bands are individual variables s0-s17 unline the string that must be disected in flashtrack. Each frame has declarations for new variable values that haven't changed since the previous frame. Values that are constant remain the same but aren't declared on the frame to reduce filesize.

    Unfortunatly, a streaming file isn't the result one always needs, but you can use the streaming swf to harvest the spectrum data for any sound clip. Load the swf into another movie level. Have it play and log the variables s0-s17 from the level into an array as it plays.

    Drawback. Swiftmp3 runs on a command line dos prompt. 18 bands of data is overkill.


    Option 3: If you find this person. Get in touch with me or send me the proggy.



  6. #6
    Senior Moderator ®
    FK´s Banning Machine ™
    GMF ™'s Avatar
    Join Date
    Feb 2000
    Location
    Oslo, Norway
    Posts
    5,697
    Will have this in mine and I will put it back up when its down in the line. Great work Jason

  7. #7
    Junior Member
    Join Date
    Feb 2002
    Posts
    14
    thank you

  8. #8
    Senior Mender trionik's Avatar
    Join Date
    Nov 2000
    Location
    Montréal,Canada
    Posts
    1,077
    thanx for this awesome explanation....

    Guys like you that give so much of their time just for the benefits of other should get a medals or something ...

    I'll put a credit for you everytime i'll use your method...

    Thanks very much cre8ive....

  9. #9
    Junior Member
    Join Date
    Oct 2000
    Posts
    12
    Hi Cre8ive,

    I have a question regarding streaming and bandwidth that I'm not sure is anwered in this thread yet. I have a music Flash/Swish website, http://www.angrychiwawah.com, where for each song, the user has the option to press a play button for low-fi (dial-up) or hi-fi (broadband). Both options load a swf with an MP3 set to stream in Flash. The low-fi was created using a bitrate of 24 and the hi-fi was created at a 128 bitrate. I want to be able to let broadband users hear the highest quality sound, but of course want the lo-fi users to hear the songs too without interruption. Is there a way that Flash, or some other tool, can automatically detect the modem/bandwidth and then serve the appropriate stream (i.e., highest possible quality stream given the bandwidth)? Is this best done with Quicktime, and if so, do you know of a thread that describes that method? Also, if so, do you then need to worry if the user has Quicktime installed locally?

    What is the best tool right now to easily take a song and turn it into a swf set to stream; one that you can load into another swf? Is this the best method for streaming?

    Thanks!

    Bill

  10. #10
    Registered User
    Join Date
    Apr 2001
    Location
    Akron OH, USA
    Posts
    4,841
    Here are some approaches for bandwidth detection:

    F4:
    load an external swf with a 5k gif.
    use a getTimer loop to track how long it takes to load.
    if the swf loads in less than 1 second the user has broad band, otherwise the user has narrowband.
    (load the swf with a random number in query string to work around file caching in case someone revists the site with narrow band connection - you dont want them getting the broad band version because they loaded the 5k swf immediately from cache)

    F5:
    check getBytesLoaded() over a period of time like 1 second to get a rough idea of user's data transfer rate.

    see Remixology #19 for a bandwidth detection script:
    http://www.sonify.org/home/feature/r...idthdetection/
    Last edited by hp3; 03-11-2003 at 09:15 AM.

  11. #11
    cre8ive
    Guest
    bump

  12. #12
    Junior Member
    Join Date
    Oct 2002
    Location
    RI
    Posts
    3

    eBilly??

    Hey, I was wondering if EBILLY would be willing to send me a copy of the FLA he used for his flash music site. Im looking for a good way to list music on my site as well. Please drop me a line. Thanks

  13. #13
    Hey, is there anyway to get flashtraks to automatically play when it starts up. I have just spent about 3 hours and I know that it's probably something really easy but I guess my brain just isn't thinking at 2:30 in the morning. Thanks I appreciate it.

  14. #14
    Junior Member
    Join Date
    Sep 2000
    Location
    Kingsport, TN
    Posts
    14
    First of all, let me say that I'm relatively new to the FlashKit boards, so, if I'm posting this in the wrong place, please be gentle, and tell where I should be posting.

    I just finished reading cre8ive's great posting explaining about streaming audio in general and how to do it in Flash. I have read a lot about Flash and done lots of "lessons" and "tutorials" but now it's time to do something for real. My need is to be able to incorporate audio into some corporate training pieces.

    Am I understanding correctly that the only way to have Flash truly stream an external audio file is to have it encoded as an SWF file? If I try to load an external MP3 file that is not saved as SWF, will I be forced to wait until the whole file downloads before it plays?

    Thanks.
    Dave Carter

  15. #15
    Registered User
    Join Date
    Apr 2001
    Location
    Akron OH, USA
    Posts
    4,841
    Flash supports both downloading and progressive loading of audio. Progressive loading means that the audio plays as it loads, which is like streaming except that the file accumulates in user's RAM and is eventually moved onto the hard drive for subsequent use.

    Unlike true streaming, the advantage of progressive download is that the file plays from hard drive and does not need to re-stream for subsequent playback. A disadvantage, also unlike streaming, is that Flash does not handle large files well because they can use too much RAM. Another disadvantage is that the after playback there is a copy of the file on the user's computer. This is not the case with true streaming.

    All vesions of flash progressively load sounds in SWF set to stream sync.

    Flash 6+ can either progressively load or download native mp3. You do not need to create sound only SWF for audio streaming in Flash 6+.

    Make sure you require Flash 6r40 or greater to avoid mp3 streaming bugs. Earlier versions did not support the sound object start method and also did not terminate download unless you actually quit the browser, causing bandwidth clog.

    Also Flash cannot play just any old MP3, the sample rates must be 44,22,11, the bitrate must be one of the supported rates listed in the Sound Properties window and the file must be encded with CBR not VBR.

  16. #16
    Junior Member
    Join Date
    Sep 2000
    Location
    Kingsport, TN
    Posts
    14
    Thank you for the information. I tried to do this one early last year and ran into the bugs with the early version of the Flash 6 Player. I ended using Windows Media Player instead. However, for various reasons, I need to revisit the option of using Flash. I don't have a problem requiring the latest Flash Player as I have a somewhat captive corporate audience, and I'd prefer to use MP3's so that we don't have convert all our audio files.

    Three questions that I still have after reading your reply are:

    1. Since this "progressive download" concept does not require anything special on the server end, it should work equally well pulling MP3 files from file servers using \\servername\filename.mp3 instead of using an http://servername/filename.mp3 URL. Am I right on this?

    2. Do we know for a fact that later versions of the Flash Player correctly terminate the download of the MP3 file if the user interrupts it before the download is complete? This was one of my biggest concerns when I looked into this last year.

    3. Are there differences in the amount of control I can have over the sound (play, stop, pause, FF, rew, etc.) if the streamed sound is a MP3 file vs. a SWF file?

    Thanks again for all your help. This will save me lots of trial and error!
    Dave Carter

  17. #17
    Junior Member
    Join Date
    Sep 2000
    Location
    Kingsport, TN
    Posts
    14
    One other thing I forgot:

    Can I detect download progress for both streamed MP3 files and SWF-encoded MP3's? Is it significantly easier to do for one vs. the other?

    Thanks.
    Dave Carter

  18. #18
    Registered User
    Join Date
    Apr 2001
    Location
    Akron OH, USA
    Posts
    4,841
    no need for special server.

    as far as I know the download termination error is fixed.

    they both offer the same amount of control but require different ActionScript, though I have not tested FF and RW with streaming mp3. You might not be able to FF with streamed mp3. You can do this with SWF, using gotoAndPlay(). Generally it is more complicated to navigate an MP3 than a SWF.

    for mp3 you can compare the sound object's getBytesLoaded() vs. getBytesTotal() to calculate a download percentage. For sound only SWF you compare its movie clip getBytesLoaded() vs. getBytesTotal(). Same scripting technique but different object.

    Code:
    // mp3
    mp3 = new Sound();
    mp3.loadSound("urlto.mp3",true);
    if(mp3.getBytesLoaded() == mp3.getBytesTotal()){
       // sound is loaded
    }
    
    ... compared to SWF ...
    
    // swf
    swfcontainer.loadMovie("urlto.swf");
    if(swfcontainer.getBytesLoaded() == swfcontainer.getBytesTotal()){
      // sound is loaded
    }

  19. #19
    Registered User
    Join Date
    Apr 2001
    Location
    Akron OH, USA
    Posts
    4,841
    Not that this relates to David's project but Flash 6r40 can parse ID tags from MP3. However, the entire mp3 must load before you can read the values. So, instead many folks use a server side script to parse the ID3 tags from mp3 into an xml file. Then load the xml file before streaming the song to display title, copyright, author information.

    below is a link to a php script at sourceforge that can parse meta data from many audio formats including mp3. It does not automatically create the xml data though, you will have to do that yourself.

    http://sonify.org/cgi-bin/tutoriallinks/jump.cgi?ID=211

  20. #20
    Junior Member
    Join Date
    Mar 2002
    Posts
    7
    this thread is great, except i'm looking for a way of getting numerical data from a online radio source - so streamed as real audio or windows audio or something, any ideas?

    any help would be amazing

    matt

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center