Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6860201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:22:45+00:00 2026-05-27T02:22:45+00:00

I’m working on a virtual piano keyboard that processes imported mp3 sound samples. I’ve

  • 0

I’m working on a virtual piano keyboard that processes imported mp3 sound samples. I’ve come to a solution with this question, but as I run this test code below, the sound loops its last data chunk of each sound source forever, and obviously, I want it to stop at the end of the extracted sound data. The same happens with any extracted sample data, I don’t even have to mix it. I added a dynamically drawn graphic waveform so you can visually check what happens. This is my first time using the ByteArray class, so I don’t know how to solve this issue.

import flash.media.Sound;
import flash.utils.ByteArray;
import flash.geom.Point;
import flash.display.Sprite;
import flash.net.URLRequest;
import flash.events.MouseEvent;

var t0:Sound = new Sound(new URLRequest("5_C.mp3")); //sound imported
var t1:Sound = new Sound(new URLRequest("5_E.mp3")); //other sound imported
//var t0:Sound = new C4(); //sound in library
//var t1:Sound = new E4(); //other sound in library
var t0p:Point = new Point();
var t1p:Point = new Point();
var t0a:ByteArray = new ByteArray();
var t1a:ByteArray = new ByteArray();
var mix:Sound = new Sound();

var spr:Sprite = new Sprite();
addChild(spr);
spr.y = 10;
var lx:Number = 0;
var ly:Number = 0;
spr.graphics.lineStyle(1,0,1,true);

mix.addEventListener(SampleDataEvent.SAMPLE_DATA, onSampleData);

stage.addEventListener(MouseEvent.CLICK, mce);
function mce(e:MouseEvent) {
    mix.play();
}

function onSampleData(e:SampleDataEvent):void {

    t0a.position = 0;
    t1a.position = 0;

    t0.extract(t0a, 3072);
    t1.extract(t1a, 3072);

    t0a.position = 0;
    t1a.position = 0;

    for(var i:int = 0; i < 3072; i++) {

        t0p.x = t0a.readFloat();
        t0p.y = t0a.readFloat();
        t1p.x = t1a.readFloat();
        t1p.y = t1a.readFloat();

        var tmp:Point = new Point(Math.max(Math.min(t0p.x + t1p.x, 1), -1), Math.max(Math.min(t0p.y + t1p.y, 1), -1));

        e.data.writeFloat(tmp.x); // left
        e.data.writeFloat(tmp.y); // right

        if (lx > 549) {
            lx = 0;
            ly += 10;
            if (ly > 399) {
                spr.graphics.clear();
                ly = 0;
                spr.graphics.lineStyle(1,0,1,true);
            }
            spr.graphics.moveTo(lx, (tmp.x + tmp.y) * 4 + ly);
        } else {
            spr.graphics.lineTo(lx, (tmp.x + tmp.y) * 4 + ly);
        }
        lx += 0.05;

    }
}

There must be a very simple solution for this, I just don’t have experience with handling raw data, so I’d be really thankful if you could help me out with anything.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:22:45+00:00Added an answer on May 27, 2026 at 2:22 am

    Okay, I’ve come up with a solution a few days ago, I just didn’t have time to post it here.

    An easy way to calculate a sound’s ByteArray sample length is samplesLength = sound.length * 44.1;.

    This is because a sound displays its length in milliseconds, which are 1000 stereo sample-pairs per second, and the sampling resolution for sounds in flash is 44100 Hz (also sample-pairs per second), so there are 44.1 sample-pairs rendered over a brief millisecond.

    Also, a sample is a 32-bit Float value, and a sample-pair is 64 bits (8 bytes) long, so if I’m correct, it’s samplesLength = soundExtract.length / 8;.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.