Solved

Need a FIFO in Java

Posted on 2004-08-03
8
1,466 Views
Last Modified: 2008-02-01
Hi!

I've a audio stream whichI get via udp....

When the stream arrives as packet in 400 bytes, I need a FIFO where I can put more into it in the same time as I can playback it... Anybody got  a solution for that???
0
Comment
Question by:mamruoc
8 Comments
 
LVL 35

Expert Comment

by:girionis
Comment Utility
Use two threads. One to play the audio and the other to store it in an ArrayList or another collection object.
0
 
LVL 9

Expert Comment

by:mmuruganandam
Comment Utility
use one of the list implementation... putting more on the same or playback, you have to implement on your own.
There is no built in support of that in Java as I know
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 125 total points
Comment Utility
List fifo = Collections.synchronizedList(new ArrayList());


...


public void play() {
      if (fifo.isEmpty() == false) {
            byte[] bytes = (byte[])fifo.remove(0);
            playAudio(bytes);
      }
}      

public void queueForPlayback(byte[] bytes) {
      fifo.add(bytes);
}
0
 

Author Comment

by:mamruoc
Comment Utility
Thanks again...

Maybe you should be the person how's doing this Java application.. :D
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
8-)
0
 

Author Comment

by:mamruoc
Comment Utility
Hi!!

Hope you're still there...

Can your FIFO store binary data?

Seems like it don't play back that well... But if I send a file with content:

\x0A, it seems to store and playback well....

regards
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
>>Can your FIFO store binary data?

Yes, as you can see, i assumed using a byte[]. Playback is another thing of course ...
0
 

Author Comment

by:mamruoc
Comment Utility
Well,,

I just dropped using ArrayList and used Vector, seems like Vetor is more efficient....

0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now