Java Forum / General / February 2007
Using sound files in programs
ThL - 11 Feb 2007 15:08 GMT Hi everyone, As an old Amos Pro basic for Amiga programmer, I've decided to go back to coding, after giving up, 12 years ago. I don't know which of the following languages would suit best my project
: Visual Basic (6 or .net), Java or even php. Here's what I have in mind : create a program that plays a short sound sampls (2 seconds max.) and the asks the user to match it with 4 possible sound files (he'd have to click on 4 icons, linked to a different sound sample). It's in fact a sort of music test. I'd like to know who could tell me which language would be best-suited (and would be the easiest to use), knowing that I'm a very rusty programmer (but a very strong-willed one too !). I'd also like to know if there's any coding available which could import and manipulate sound samples. I've even thought of plugins which would use external players like winamp or windows media player. Many thanks in advance for your kind and precious help or at least for your comments. Thierry
Andrew Thompson - 11 Feb 2007 16:21 GMT On Feb 12, 2:08 am, ThL <t-l-a-r-i-v-i-e-r-e-sanslestir...@n-o-r-d-n-e- t.ft> wrote: ...
> Here's what I have in mind : create a program that plays a short sound > sampls (2 seconds max.) and the asks the user to match it with 4 > possible sound files (he'd have to click on 4 icons, linked to a > different sound sample). What flavor? WAV, MID, MOD, WMV, MP3, AU, AIFF..?
This is an important question to resolve early on.
If you control the format that the sound is in, it becomes easier. Do you?
Core J2SE has inbuilt support for some WAV, AU, AIFF and MID (MIDI - sequenced music). For a limited range of other formats, you might look to (the now abandoned) JMF, or other Java based API's.
> ..there's any coding available which could > import and manipulate sound samples. Manipulate in the sense of play, and stop at a certain time?
Sure. An applet can do it within a handful of lines of code (most of which would be the GUI and event handling for starting and stopping the sound), an application in just a few more.
More sophistcated control can be achieved using the classes in the (core Java) javax.sound packages.
Andrew T.
ThL - 11 Feb 2007 18:25 GMT Hi Andrew,
Andrew Thompson a écrit :
> On Feb 12, 2:08 am, ThL <t-l-a-r-i-v-i-e-r-e-sanslestir...@n-o-r-d-n-e- > t.ft> wrote: [quoted text clipped - 6 lines] > What flavor? WAV, MID, MOD, WMV, MP3, > AU, AIFF..? Well, my contention is that wav files should be the easiest files to deal with. Considering the length, 1 or 2 seconds would only "weigh" 100 KB or so. Opting for compressed files is not really worht the candle and I'm afraid i'd have to deal with more complex structures (supposing I'd have to edit them, which is not the case), and then there are copyright issues to take into account.
> This is an important question to resolve > early on. So let's say "wav" or any other "easy" format.
> If you control the format that the sound is > in, it becomes easier. Do you? I suppose it does.
> Core J2SE has inbuilt support for some > WAV, AU, AIFF and MID (MIDI - sequenced > music). For a limited range of other > formats, you might look to (the now > abandoned) JMF, or other Java based > API's. As I need real sound samples, midi files are not my best option.
>> ..there's any coding available which could >> import and manipulate sound samples. > > Manipulate in the sense of play, and stop > at a certain time? Exactly. This does not sound hard for the experienced programmer, but believe me, for an "old person" like me, I really need to regain self-confidence.
> Sure. An applet can do it within a handful > of lines of code (most of which would be > the GUI and event handling for starting > and stopping the sound), an application > in just a few more. This is what I call "regain self-confidence" !
> More sophistcated control can be achieved > using the classes in the (core Java) > javax.sound packages. > > Andrew T. Not so long ago I bought Barry Burd's "Java 2 for Dummies". I suppose this is one of the guides to start with, right ?
One last question : as Java seems to be more popular among the coders'community than Visual Basic, do you think I'm making the right choice going for a more complex language such as Java ? After all, Visual basic.net has very little to do with former versions of basic, like the ones I used to know.
Thank you very much for your help, Andrew. Thierry
Andrew Thompson - 12 Feb 2007 08:11 GMT On Feb 12, 5:25 am, ThL <t-l-a-r-i-v-i-e-r-e-sanslestir...@n-o-r-d-n-e- t.ft> wrote: ...
> Not so long ago I bought Barry Burd's "Java 2 for Dummies". I suppose > this is one of the guides to start with, right ? I tend to avoid books. The Java Tutorial and the JavaDocs (both available freely from Sun) combined with a bit of searching for specific topics, tends to do for my purposes.
OTOH - I would avoid any book that ends with '..for Dummies' - Someone who's opinion I respect, loves books and has reviewed many - you might find just the right book at their review page.. <http://www.techbookreport.com/JavaIndex.html>
> One last question : as Java seems to be more popular among the > coders'community than Visual Basic, do you think I'm making the right > choice going for a more complex language such as Java ? After all, > Visual basic.net has very little to do with former versions of basic, > like the ones I used to know. I am no 'language expert' and have no experience with VB. It seems Lew went covered the entire area better than I ever could, in any case.
Having said that, I will add that I like Java for the following basic reasons.
- Cross-platform, or 'X-plat' (VB/.NET is supposed to be available on different platforms, AFAIU, but it is nowhere near as easy to produce an X-plat GUI). - Good documentation from the manufacturer (the JavaDocs and Java Tutorial alone make for good docs., but there is also available:- the language spec., the source..). - Lots of free tools for development (NetBeans, Eclipse, JBuilder community edition..) and the SDK itself is also free 'bar the bytes to download it'. - Huge repository of pluggable API's. - Huge repository of LGPL code. - The Plug-In required to run a Java based project is both supplied freely by Sun (for Windows, at least) and updated as a matter of priority, should a security bug be discovered. As a result, I can confidently recommend it to my end users. - Excellent usenet newsgroups devoted to discussing Java and Java based development.
Anything I forgot? Probably a great deal..
Andrew T.
Tris Orendorff - 13 Feb 2007 22:28 GMT > Not so long ago I bought Barry Burd's "Java 2 for Dummies". I suppose > this is one of the guides to start with, right ? I recommend one of Terry Terd's "Java 2 for Retentives," Carrie Curd's "Java 2 for Telepaths," or Bruce Eckel's "Thinking in Java."
 Signature Tris Orendorff [Q: What kind of modem did Jimi Hendrix use? A: A purple Hayes.]
Lew - 13 Feb 2007 23:13 GMT > ThL burped up : >> Not so long ago I bought Barry Burd's "Java 2 for Dummies". >> I suppose this is one of the guides to start with, right ?
> I recommend one of Terry Terd's "Java 2 for Retentives," Carrie > Curd's "Java 2 for Telepaths," or Bruce Eckel's "Thinking in > Java." Just in case: the third book, unlike the first two, actually exists and its earlier editions are available for free online. It is an excellent beginner's book, and not bad for intermediate Java programmers, either. It won't cover everything, but it lives up to its title - it really does help one "think in Java".
"Java 2 for Telepaths" can only be read in your mind. :-)
FWIW, Java 2 is obsolete. Java 4 is the current "grandparent" version, Java 5 is two-and-a-half years old, more or less, and Java 6 is the current version.
That said, most of what you learn for Java 2 is still valid for Java 6.
(However, Java 2 references will probably still talk about "Hashtable", "Vector" and "Enumeration" where a modern reference would probably recommend "Map", "List" and "Iterator", respectively, with first-try implementation choices "HashMap" and "ArrayList" for the first two.)
- Lew
Daniel Dyer - 13 Feb 2007 23:23 GMT > FWIW, Java 2 is obsolete. Java 4 is the current "grandparent" version, > Java 5 is two-and-a-half years old, more or less, and Java 6 is the > current version. There is no Java 4. The release prior to Java 5 was still officially Java 2 (version 1.4.2).
> (However, Java 2 references will probably still talk about "Hashtable", > "Vector" and "Enumeration" where a modern reference would probably > recommend "Map", "List" and "Iterator", respectively, with first-try > implementation choices "HashMap" and "ArrayList" for the first two.) Maybe, but all of those newer classes you mention were introduced in the first Java 2 release (version 1.2), so a good Java 2 reference should have switched to using those classes rather than the older ones.
Dan.
 Signature Daniel Dyer https://watchmaker.dev.java.net - Evolutionary Algorithm Framework for Java
Lew - 13 Feb 2007 23:53 GMT Lew wrote:
>> FWIW, Java 2 is obsolete. Java 4 is the current "grandparent" version, >> Java 5 is two-and-a-half years old, more or less, and Java 6 is the >> current version.
> There is no Java 4. The release prior to Java 5 was still officially > Java 2 (version 1.4.2). OK, good point. I was confused by the change in nomenclature. So Java 2 is not obsolete, only aged and creaky. (Java 1.3 and earlier are obsolete.)
>> (However, Java 2 references will probably still talk about >> "Hashtable", "Vector" and "Enumeration" where a modern reference would >> probably recommend "Map", "List" and "Iterator", respectively, with >> first-try implementation choices "HashMap" and "ArrayList" for the >> first two.)
> Maybe, but all of those newer classes you mention were introduced in the > first Java 2 release (version 1.2), so a good Java 2 reference should > have switched to using those classes rather than the older ones. "Should have" doesn't mean "did". That is why I used the weasel-word "probably". I still see tons of people learning "Hashtable" and the rest; they can't have just come up with this on their own, nu?
As you say, a /good/ Java 2 reference /should/ teach the Collections framework. Conversely, if it doesn't it's not as good.
- Lew
David Segall - 11 Feb 2007 16:26 GMT >I don't know which of the following languages would suit best my project >: Visual Basic (6 Not this one. Microsoft have declared it obsolete. They claim it still works under Vista but it is likely you will have to change languages for the next Microsoft OS.
> or .net), This is probably the easiest. You can download the free Express Edition from here <http://msdn.microsoft.com/vstudio/express/vb/> and you will probably find the code to play your short sound in a Microsoft tutorial. If not, Google will find some code for you to try.
> Java This is probably the language to go for if you never want to learn another one. It is supported by all the heavies in the computer industry and it includes the tools you need to play sound files. Download the JDK 6 with NetBeans 5.5 from <http://java.sun.com/javase/downloads/index.jsp> and search <http://java.sun.com> for some code to show you how to play sound files. It is more difficult than VB.Net only because there is a huge choice of development tools in Java so the tutorials are more general than the equivalent one in VB.
> or even php. Not this one. PHP is for web based applications and I would strongly recommend that you start with a desktop application.
>I've even thought of plugins which would use external players >like winamp or windows media player. Unless you need many of the features of these players like play lists, visualization and recognizing CDs you will find that using the built in libraries for manipulating music files easier to use than communicating with an external program.
ThL - 11 Feb 2007 18:29 GMT Hi David, David Segall a écrit :
>> I don't know which of the following languages would suit best my project >> : Visual Basic (6 > Not this one. Microsoft have declared it obsolete. They claim it still > works under Vista but it is likely you will have to change languages > for the next Microsoft OS. This is what I thought.
>> or .net), > This is probably the easiest. You can download the free Express > Edition from here <http://msdn.microsoft.com/vstudio/express/vb/> and > you will probably find the code to play your short sound in a > Microsoft tutorial. If not, Google will find some code for you to try. How much "harder" is Java ?
>> Java > This is probably the language to go for if you never want to learn [quoted text clipped - 6 lines] > choice of development tools in Java so the tutorials are more general > than the equivalent one in VB. What about the syntax ? Both are object-oriented, right ?
>> or even php. > Not this one. PHP is for web based applications and I would strongly > recommend that you start with a desktop application. Right.
>> I've even thought of plugins which would use external players >> like winamp or windows media player. > Unless you need many of the features of these players like play lists, > visualization and recognizing CDs you will find that using the built > in libraries for manipulating music files easier to use than > communicating with an external program. I only need to play the file and stop it.
Thanks for your answer, David.
Thierry
Lew - 11 Feb 2007 19:30 GMT > How much "harder" is Java ? No easy answer. Parts of Java are so much easier to learn than Basic or C/C++, other parts are so much harder, the bulk is about the same.
"Real programmers can program in FORTRAN in any language." (source unknown)
If you understand software development and programming principles, particularly object-oriented programming, particularly polymorphism, then you will learn how to use Java very quickly. (One week is not uncommon.) Likewise, you can spend the rest of your life learning it and never really master it. (Eight years and counting, in my case, and that only since I started getting a paycheck for it. More like eleven years if you count when I started learning Java.)
It's more than knowing the language. The APIs are vital and monstrously extensive, and that's just core Java without any additional acronyms (JEE, JWS, JMS, JMX, ...) or third-party products.
I spend half my professional life learning what I'm doing. That was true for C, C++ and FORTRAN as well, and remains true for SQL and other languages, as well as everything else in this profession.
> What about the syntax ? Both are object-oriented, right ? The syntax between Java, C++ and C# is very similar, enough to really mess you up as you switch between them, because "similar" also means "different". Smalltalk and JORF [1] are also object-oriented but differ from the Algolish world rather sharply. FoxPro is object-oriented, too. You cannot generalize difficulty just from that attribute.
I am familiar with C++ and Java, less so with C#. I rate C++ as "more difficult" than Java, and what I know of C# puts it on a par with Java. That's just me, of course.
[1] an obscure, nearly private object-oriented language from the 80s, named after a goat. <http://www.pycs.net/lateral/weblog/2005/12/20.html>
- Lew
David Segall - 12 Feb 2007 15:30 GMT >How much "harder" is Java [than VB.Net]? >What about the syntax ? Both are object-oriented, right ? If you were learning to _read_ the two languages you would find VB.Net a little easier because you are used to the BASIC syntax but the difference would not be significant. Both are object oriented and you will have to learn to think in that idiom.
To my mind there are two big differences in writing the two languages.
1. Java is much older than VB.Net. There is a huge body of code in the form of Java libraries. This has the advantage that somebody has probably already written the code you need but makes it difficult to find exactly which method you should use. The problem is compounded by the necessity for backward compatibility which means there are often several ways to achieve the same result and it can be difficult for a beginner to determine the "current" way.
2. VB.Net has only one development environment. That means that all the code you read and all the instructions you find on the Web will work as expected. If they say choose the xyz menu, select abc and paste this code it will work. Java has dozens of different development environments so that most examples and tutorials are designed for none of them.
The comparison often ends up with command line Java versus the VB.Net IDE. On that basis it would take an hour to get "Hello World" to appear in the middle of the window in VB and a week in Java.
In my first post I "instructed" you to download the NetBeans/Java SDK bundle. Comparing that to VB.Net it might take two hours to get "Hello World" to appear in the middle of the window but, unlike VB, when you resize the window your text will stay in the middle!
NetBeans will also help with the library problem above. When you cut and paste some code from the Web into your program NetBeans will usually provide the code you need to include it.
- So, to guess a quantative answer to your first question, I would go for twice as hard if you use any of the IDEs I list at <http://ide.profectus.com.au> and your application does not use one of the thousands of methods that are available in Java but not in VB.Net.
Arne Vajhøj - 13 Feb 2007 02:07 GMT > 2. VB.Net has only one development environment. Wring.
I use two: Visual Studio and SharpDevelop.
Other may exist.
Arne
David Segall - 13 Feb 2007 15:24 GMT >> 2. VB.Net has only one development environment. > >Wring. > >I use two: Visual Studio and SharpDevelop. Why/when do you use the latter?
Arne Vajhøj - 14 Feb 2007 00:07 GMT >>> 2. VB.Net has only one development environment. >> Wring. >> >> I use two: Visual Studio and SharpDevelop. > Why/when do you use the latter? It has some features VS does not have (at least not in the free edition).
I like the way it works better.
Arne
Oliver Wong - 12 Feb 2007 18:48 GMT > PHP is for web based applications and I would strongly > recommend that you start with a desktop application. Technically, you can build desktop applications using PHP (via http://gtk.php.net/ for example), but I agree that this is probably not a good idea for a beginner.
- Oliver
Chris Uppal - 12 Feb 2007 17:34 GMT > As an old Amos Pro basic for Amiga programmer, I've decided to go back > to coding, after giving up, 12 years ago. > I don't know which of the following languages would suit best my project > > Visual Basic (6 or .net), Java or even php. I don't want to muddy the waters here, but I would recommend /against/ Java for now.
Java is designed principally to be used in large scale programs, and very much more about making difficult things possible, than making simple things easy. In fact it /doesn't/ make simple things easy, and in particular, things that you might hope would be trivial (like putting a picture in a window and playing a sound) are not at all easy. You have to learn a lot of Java, and then on top of that learn about the (complex) libraries for doing sound and graphics, before you'll get any results.
All that's assuming that you are more interested in being able to produce results than in learning some specific programming language.
Actually, graphics and sound /are/ pretty complex, so programmers' tools like AMOS (which I also played with a bit, although I did most of my Amiga programming in C) put a lot of effort into hiding that from you. You might find it worthwhile looking for some more modern programming language/tool which takes the same approach. There are quite a lot out there, often they are based more-or-less on BASIC, so one of those might suit you. Unfortunately, I can't remember any names. A bit of Googling turns up BlitzBasic and LibertyBasic http://www.libertybasic.com/ http://www.blitzbasic.com/ but I can't comment on how suitable either would be. Perhaps your recent question on comp.programmer will produce some more recommendations.
-- chris
Oliver Wong - 12 Feb 2007 18:46 GMT >> As an old Amos Pro basic for Amiga programmer, I've decided to go back >> to coding, after giving up, 12 years ago. [quoted text clipped - 20 lines] > All that's assuming that you are more interested in being able to produce > results than in learning some specific programming language. I have to agree with this. I think it'd be relatively straightfoward to do what the OP intends in VB6, and probably equally so in VB.NET. I vaguely recall doing something similar in VB6 and all I had to do to add sound-playback-at-the-click-of-a-button was drag and drop an OCX control onto the window frame, and select the appropriate WAV file via Window's file browser.
With Java, you're looking at JMF which gets ugly, or javax.sound, both of which force you to actually type in source code (as opposed to dragging and dropping components around as you might be able to get away with in VB).
Microsoft is giving away IDEs for all their .NET languages for free. They call them "express editions". http://msdn.microsoft.com/vstudio/express/vb/
If you already know Basic, I'd recommend starting with VB.NET, and once you get comfortable with that, consider moving to C# 2.0. And from there, you can go to Java. I specify C# 2.0 because from what I understand, C# 3.0 is a very different programming language (a lot more focus on functional programming, with closures and such), and so the transition from C# 3.0 to Java might not be as smooth as from C# 2.0 to Java.
- Oliver
Arne Vajhøj - 13 Feb 2007 02:09 GMT > If you already know Basic, I'd recommend starting with VB.NET, and once > you get comfortable with that, consider moving to C# 2.0. And from there, > you can go to Java. I specify C# 2.0 because from what I understand, C# 3.0 > is a very different programming language (a lot more focus on functional > programming, with closures and such), and so the transition from C# 3.0 to > Java might not be as smooth as from C# 2.0 to Java. C# 3.0 is not GA yet.
(.NET 3.0 uses C# 2.0 while C# 3.0 will come with .NET 3.5 according to the MS numerologists)
When C# 3.0 is GA maybe Java 7 may be GA too and maybe with closures as well.
Arne
Arne Vajhøj - 13 Feb 2007 02:13 GMT >> I don't want to muddy the waters here, but I would recommend /against/ >> Java for [quoted text clipped - 22 lines] > onto the window frame, and select the appropriate WAV file via Window's file > browser. The difference between VB.NET and Java in way to work is rather small.
VB.NET is not VB7 - it is C# with VB syntax.
For the specific purpose which may require tight integration with OS specific components the MS route be quicker.
But in general I do buy the argument that Java is harder to get started with than VB.NET.
Arne
T Lariviere - 16 Feb 2007 19:51 GMT ThL a écrit :
> Hi everyone, > As an old Amos Pro basic for Amiga programmer, I've decided to go back [quoted text clipped - 15 lines] > your comments. > Thierry Well I never expected so many replies to my original question. And instructive ones in particular ! The java community is just like what a friend described : vast and friendly ! I'll now start my investigation following the tracks you kindly set for me. Thank you all ! Thierry
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|