Adobe
Products

Top destinations

  • Adobe Creative Cloud
  • Creative Suite
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • SiteCatalyst
  • Students
  • Elements family

Adobe Creative Cloud

  • What is Adobe Creative Cloud?
  • Design
  • Web
  • Photography
  • Video
  • Students
  • Teams
  • Enterprise
  • Educational institutions

Design and photography

  • Photoshop
  • Illustrator
  • InDesign
  • Adobe Muse
  • Lightroom

Video

  • Adobe Premiere
  • After Effects

Web development and HTML5

  • Edge Tools & Services [opens in a new window]
  • Dreamweaver
  • Gaming [opens in a new window]

Adobe Marketing Cloud

  • What is Adobe Marketing Cloud?
  • Digital analytics
  • Social marketing
  • Web experience management
  • Testing and targeting
  • Media optimization

Analytics

  • SiteCatalyst
  • Adobe Discover
  • Insight

Social

  • Adobe Social

Experience Manager

  • CQ
  • Scene7

Target

  • Test&Target
  • Recommendations
  • Search&Promote

Media Optimizer

  • AdLens
  • AudienceManager
  • AudienceResearch

Document services

  • Acrobat
  • EchoSign [opens in a new window]
  • FormsCentral [opens in a new window]
  • SendNow [opens in a new window]
  • Acrobat.com [opens in a new window]

Publishing

  • Digital Publishing Suite

  • See all products
Business solutions

By business need

  • Digital analytics
  • Digital publishing
  • Document management
  • Media optimization
  • Social marketing
  • Testing and targeting
  • Video editing and serving
  • Web development [opens in a new window]
  • Web experience management
  • See all business needs

By industry

  • Broadcast
  • Education
  • Financial services
  • Government
  • Publishing
  • Retail
  • See all industries
Support & Learning

I need help

  • Products
  • Adobe Creative Cloud
  • Adobe Marketing Cloud
  • Forums [opens in a new window]

I want to learn

  • Training and tutorials
  • Certification [opens in a new window]
  • Adobe Developer Connection
  • Adobe Design Center
  • Adobe TV [opens in a new window]
  • Adobe Marketing Center
  • Adobe Labs [opens in a new window]
Download
  • Product trials
  • Adobe Flash Player
  • Adobe Reader
  • Adobe AIR
  • See all downloads
Company
  • Careers at Adobe
  • Investor Relations
  • Newsroom
  • Privacy
  • Corporate Social Responsibility
  • Customer Showcase
  • Contact us
  • More company info
Buy
  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers
  • Adobe Marketing Cloud sales [opens in a new window]
Search
 
Info Sign in
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Welcome,
My Adobe
My orders
My information
My preferences
My products and services
Sign out
My cart
Privacy My Adobe
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out Privacy My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Promotions
Estimated shipping
Tax
Calculated at checkout
Total
Review and Checkout
Adobe Developer Connection / Flash Developer Center /

Displaying the audio waveform captured from a microphone

by Fumio Nonaka

Fumio Nonaka
  • fumiononaka.com
  • jactionscripters.com

Created

4 October 2010

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
Flash Player 10.1Flash Professional CS5
Was this helpful?
Yes   No

By clicking Submit, you accept the Adobe Terms of Use.

 
Thanks for your feedback.

Requirements

Prerequisite knowledge

Some prior experience working with ActionScript 3 is recommended. Familiarity with the Flash authoring environment is also helpful.

User level

Beginning

Required products

  • Flash Professional CS5 (Download trial)
  • Flash Player 10.1

This article is the fifth of seven in a series highlighting examples of programming strategies that make it easier than ever before to create rich content in Adobe Flash CS5 Professional. There are several new events that are available in Flash Professional CS5. The first event is the Microphone.sampleData event, which captures audio samples from the input of a microphone. You can use event to record audio samples and dynamically draw the recorded sound waves.

To capture input of a microphone, you'll follow these steps:

  1. Create a Microphone instance using the Microphone.getMicrophone() method.
  2. Specify its sample rate and gain by setting the Microphone.rate and Microphone.gain properties.
  3. Add a listener for the Microphone.sampleData event (using the SampleDataEvent.SAMPLE_DATA constant) that is registered to the Microphone instance.
  4. The captured audio samples are stored in the ByteArray object. You can access them by using the SampleDataEvent.data property of the event object received by the  listener function, as shown in the code example below:
import flash.media.Microphone; import flash.events.SampleDataEvent; var my_mic:Microphone = Microphone.getMicrophone(); my_mic.rate = 22; my_mic.gain = 100; my_mic.addEventListener(SampleDataEvent.SAMPLE_DATA, drawSampleData); function drawSampleData(eventObject:SampleDataEvent):void { var myData:ByteArray = eventObject.data; // dealing with audio samples

You can draw the audio waveforms by accessing the sample's data captured from a microphone by an event listener function. Data is a collection of floating point numbers with values between −1 and 1. Use the ByteArray.readFloat() method to retrieve the numbers.

You can get the total bytes of a ByteArray object using the ByteArray.length property. And the current position of the pointer is indicated by the ByteArray.position property.

The script below draws visual interpretations of the audio waveforms of samples captured from a microphone. In the code below, the sequential values are processed in a while loop until the value of the ByteArray.bytesAvailable property is zero:

// frame action import flash.media.Microphone; import flash.events.SampleDataEvent; import flash.utils.ByteArray; import flash.display.Graphics; var nWidth:Number = stage.stageWidth; var nCenter:Number = stage.stageHeight / 2; var nScale:Number = 100; var myGraphics:Graphics = graphics; var my_mic:Microphone = Microphone.getMicrophone(); my_mic.rate = 22; my_mic.gain = 100; my_mic.addEventListener(SampleDataEvent.SAMPLE_DATA, drawSampleData); function drawSampleData(eventObject:SampleDataEvent):void { var myData:ByteArray = eventObject.data; myGraphics.clear(); myGraphics.lineStyle(0, 0x000000); myGraphics.moveTo(0, nCenter); var nPitch:Number = nWidth / myData.length; while (myData.bytesAvailable > 0) { var nX:Number = myData.position * nPitch; var nY:Number = myData.readFloat() * nScale + nCenter; myGraphics.lineTo(nX, nY); } }

Every time the microphone captures audio samples, the script draws lines like a graph. The x axis is the pointer position and the y axis displays the value of the floating numbers. The wave of the graph visually describes the characteristics of the audio samples (see Figure 1).

The audio waveforms are drawn based on the data of the samples captured from a microphone.
Figure 1. The audio waveforms are drawn based on the data of the samples captured from a microphone.

The graph created by the code shown above simply draws the values retrieved from the captured audio samples. However, depending on the needs of your project, you could programmatically manipulate the captured audio values in a variety of ways to achieve different effects.

Where to go from here

As you can see from these examples, there are many new possibilities to explore when developing ActionScript 3 projects in Flash Professional CS5. Hopefully the scripts provided in these examples will serve as the starting point as you begin experimenting with the new events and capabilities for delivering rich content with interactivity.

Be sure to check out my other articles in this series:

  • Working with TLF Text to control the appearance of text elements
  • Manipulating springs of an IK Bone for animations
  • Leveraging code snippets and using enhanced code hinting
  • Dynamically drawing a vector instance that contains elements
  • Deploying projects on devices with touch panels
  • Catching errors globally to facilitate troubleshooting

To learn more about developing with ActionScript 3, see the following online resources:

  • ActionScript Technology Center
  • ActionScript 3.0 Reference for the Adobe Flash Platform
  • Adobe ActionScript Cookbook

Also be sure to visit the Flash Developer Center to find more articles and sample files to help you take your Flash projects to the next level.

Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License

Products

  • Adobe Creative Cloud
  • Creative Suite
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • Digital Publishing Suite
  • Elements family
  • SiteCatalyst
  • For education

Download

  • Product trials
  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR

Support & Learning

  • Product help
  • Forums

Buy

  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2013 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy | Cookies

Ad Choices

Reviewed by TRUSTe: site privacy statement