Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / January 2005



Tip: Looking for answers? Try searching our database.

Capture audio on MacOS9

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Larry - 20 Jan 2005 18:14 GMT
Hi all!

I'm a Perl programmer and been using  MacOS classic since 1998.
I don't have spending money so I ain't gonna buy Mac X for the moment.
Now, I'd like to code a MacOS9 app that captures audio from an external
microphone and convert the audio in MP3 format then finally streams the
audio via Socket.
As a matter of fact, I've been trying to do that in Windows as well!
I was told that in Win I'm supposed to call the "winmm.dll" and deal
with the WaveInxxx functions.
I'm really getting into it by telling Perl to deal with winmm.dll via
WIN32::API package!

Can anyone tell me how I'm supposed to grab audio in MacOS9 from an
external mic? Can it actually be done?

(Please, don't tell me to use Real Basic!)

thanks ever so much!

Larry
Don Bruder - 21 Jan 2005 01:00 GMT
> Hi all!
>
[quoted text clipped - 17 lines]
>
> Larry

Yes, it can be done, and it's quite simple - simple enough you're
probably gonna be kicking yourself once you see how easy it is (I know
*I* did...)

Look into the QuickTime APIs - What you're trying to do is effectively
identical to video capture, you're just not interested in the video part
- just the audio portion.

As far as "streaming audio via Socket", well... "Rotsa ruck, GI!" - Macs
prior to X don't HAVE sockets to stream via. OpenTransport (A more
misnamed hodgepodge of code I've only rarely seen before...) is your
only option, unless your Perl environment provides socket-like APIs.

I'm TRYING to remedy Classic's lack of BSD/Windows-like Sockets by
writing some glue code to implement a minimal version of Sockets (and
have made some good progress), but my solution isn't quite "ready for
prime time" yet. I can Socket(), Connect(), Send(), and Recv(), but
there's still a few "toys" missing. GUSI may be an option for you (It
isn't for me, for several reasons that would take too long to go into
here) if you want to go that route - Matthias did a pretty good job of
implementing BSD-compliant sockets on Classic with that package, but
like mine, I don't feel his is "ready for prime time". Things get rather
flakey around the edges when GUSI is used for anything but the most
trivial networking - At least, that's been my experience. And with the
way it's coded (so-called "lucid code" - I prefer the phrasing
"hopelessly obfuscated under the guise of trying to be
ultra-self-documenting" - Until I looked at the GUSI source, I thought
there was no such thing as too many comments. I've changed that
belief... GUSIs comments, rather than clarifying, get in the way of any
hope of understanding what's being done.) there's not a chance in hell
I'm ever going to be able to wrap my head around it to find the problem.

Signature

Don Bruder - dakidd@sonic.net - New Email policy in effect as of Feb. 21, 2004.
Short form: I'm trashing EVERY E-mail that doesn't contain a password in the
subject unless it comes from a "whitelisted" (pre-approved by me) address.
See <http://www.sonic.net/~dakidd/main/contact.html> for full details.

Larry - 21 Jan 2005 12:57 GMT
> Yes, it can be done, and it's quite simple - simple enough you're
> probably gonna be kicking yourself once you see how easy it is (I know
[quoted text clipped - 3 lines]
> identical to video capture, you're just not interested in the video part
> - just the audio portion.

Could you give any example or just post any links?
Could I actually use the QuickTime APIs to convert the audio data in MP3?

as far as "streaming audio via Socket", well... it's quite simple
because of Perl!

thanks!
Don Bruder - 21 Jan 2005 16:01 GMT
> > Yes, it can be done, and it's quite simple - simple enough you're
> > probably gonna be kicking yourself once you see how easy it is (I know
[quoted text clipped - 5 lines]
>
> Could you give any example or just post any links?

http://www.google.com/search?q=site%3Aapple.com+%22QuickTime+API%22

Beware of possible line-wrap - no, I won't TinyURL it.

> Could I actually use the QuickTime APIs to convert the audio data in MP3?

No. Period.

Quicktime can decode and play MP3s, but has zero capability for encoding
them. Encoding is patented/licensed - at an extortionate fee. I'd *VERY*
strongly suggest that you forget about MP3 completely for this project -
The costs involved are likely to be ridiculous, especially if this is a
"one-off" type thing. Never mind the fact that MP3 is an assymmetric
compression - Doing the compression is (at least in computer terms)
glacially slow, while decompressing takes almost no time. Trying to
create an MP3 datastream "on the fly" is insanity due to this. *IF* you
manage to succeed, I'd expect that you'd see totally unacceptable
problems with "dropouts" due to the compression code not being able to
cram enough output into the decoder's buffers fast enough to be played
back without having to wait for compresser to hand off the next chunk.
In a nutshell, trying to playback MP3 that's being created "on the fly"
is almost certain to stutter, hiccup, and otherwise glitch out so badly
that it's not going to be useful for any purpose. I doubt it would even
be useful for pure "spoken word", let alone actually trying to stream
music of any quality. And that assumes that the compresser and
decompresser are on the same physical hardware - Factor in network
latency/packet loss/etc issues, and I'd expect that you're going to find
that the concept becomes, if not outright impossible, at least "not
worth the effort to bother."

If you simply MUST have some kind of compression, you ought to be
looking at compression code designed to cope well with the vagaries of
"on the fly" encoding - Something similar to what RealPlayer and similar
streaming stuff does, for instance. Unfortunately, there's no such thing
as "high fidelity" from such compression methods - I have yet to hear
*ANY* streaming media that doesn't sound like it was being played back
over a tin-can-and-string telephone.

> as far as "streaming audio via Socket", well... it's quite simple
> because of Perl!

Wasn't sure whether the perl package you were using included socket-like
capability. If it does, then the actual "ship it out" code is trivial in
comparison to the rest of what it sounds like you're trying to do.

Signature

Don Bruder - dakidd@sonic.net - New Email policy in effect as of Feb. 21, 2004.
Short form: I'm trashing EVERY E-mail that doesn't contain a password in the
subject unless it comes from a "whitelisted" (pre-approved by me) address.
See <http://www.sonic.net/~dakidd/main/contact.html> for full details.

Michael Ash - 21 Jan 2005 17:13 GMT
>> Could I actually use the QuickTime APIs to convert the audio data in MP3?
>
[quoted text clipped - 5 lines]
> The costs involved are likely to be ridiculous, especially if this is a
> "one-off" type thing.

If you don't mind violating various patents, there are quite a few free
software MP3 encoders out there that you could use without paying. I don't
know what the legality is of violating somebody's patent if you never
distribute your program, but you're pretty sure not to get caught.

> Never mind the fact that MP3 is an assymmetric
> compression - Doing the compression is (at least in computer terms)
[quoted text clipped - 4 lines]
> cram enough output into the decoder's buffers fast enough to be played
> back without having to wait for compresser to hand off the next chunk.

I'm not sure what century your posting from, but as of 2005, computers
have had enough power to encode MP3 in realtime for several years.
Realtime MP3 encoding is done routinely for internet radio stations (just
look at the Radio "playlist" in iTunes) and even my poor, pokey G4/400 was
able to encode MP3s at 3-4x realtime rate using iTunes, which is not
considered a particularly speedy MP3 encoder. Realtime MP3 encoding is not
only not insane, it's routine.
Don Bruder - 21 Jan 2005 18:45 GMT

> > Never mind the fact that MP3 is an assymmetric
> > compression - Doing the compression is (at least in computer terms)
[quoted text clipped - 7 lines]
> I'm not sure what century your posting from, but as of 2005, computers
> have had enough power to encode MP3 in realtime for several years.

With all due respect, Mike, I ain't buying that. Perhaps in part because
I've seen *ZERO* evidence of any such capability, even on "top of the
line" Wintel boxes running at multiple GHz clockrates.

> Realtime MP3 encoding is done routinely for internet radio stations

Uh-uh... I ain't buying THAT one, either. When I gave up on "internet
radio", it was mainly because the sound quality was so abysmally
horrible that I couldn't stand to listen to it for more than a couple of
minutes. And *NONE* of the applications involved knew MP3 from
marshmallows. Every single one of them used its own (proprietary, no
less) streaming codec that made whatever was playing sound like a
tin-=can-and-string telephone in an echo chamber.  

> (just look at the Radio "playlist" in iTunes)

I don't do iTunes (or any of the other "iWhatever" perversions), so I
have no clue what you're talking about when you mention the "Radio
playlist", but you're going to have a damn hard time convincing me that
*ANY* machine or program is capable of doing MP3 compression quick
enough to be used as a realtime stream source without hideous mangling
on the receiving end of things.

> and even my poor, pokey G4/400 was
> able to encode MP3s at 3-4x realtime rate using iTunes

I'm thinking we both need to step back and take a look at what we're
each calling "realtime" - For the record, I'm saying that realtime means
"the encoding happens in a span of time only slightly longer than it
would take to simply play the raw data".

For instance, if I push an AIFF file that takes 3:26 to play into an
encoder that wants to be considered "realtime", that encoder's going to
have to spit out a finished MP3 file damn close to 3:26 (give or take
5-10 seconds to allow for filesystem access overhead and the like) after
I hand it the data.

If it doesn't, it's NOT what I'd consider calling a realtime encoder,
regardless of how fast it might be.

In other words, if I shove a file into the encoder, I'll be able to play
the output - straight from the encoder - without ever knowing there was
an encoding step involved. (unless, of course, my ears are sharp enough
to pick up on any artifacts that the encoding produces)

> , which is not
> considered a particularly speedy MP3 encoder. Realtime MP3 encoding is not
> only not insane, it's routine.

I'm still not buying.

As of *RIGHT THIS INSTANT*, I've got an AIFF file being packed down into
MP3 in the background. It's about 2/3 done, and has already been "in
progress" for *AT LEAST* 10 times the playback duration of the source
file, if not more, and I expect that by the time it finishes, the total
"time to compress" will be in the neighborhood of 15-20 times the
playback duration of the piece. This is on a G4/300. Trying to stream it
out to somebody "realtime" would not only be insanity, but stark-raving
madness at the receiving end - a second or three of sound, followed by
lots of dead air, followed by a few seconds of sound, followed by lots
of dead air, lather, rinse, repeat...

That's assuming the networking code can "get a word in edgewise" to
actually send the data over the wire...

No clue about iTunes and its performance, but the MP3 encoder plugin
that I use is the quickest thing I've personally encountered for making
MP3s on a Mac.

I suspect that they're all pretty similar, since last time I looked into
the concept, there was only one "core" MP3 encoder that could be had -
legally, anyway - and it didn't come in source-code form that would
allow tweaking - It was a handful of ".h" files and a precompiled
library for <platform X> that you bought a license (and god, what a high
price-tag...) to be able to call into. NO "tweaking", "unrolling", or
other optimization possible. Basically, a "black box" that you pumped
the raw audio data and a couple of "compress it this much and put the
result here" parameters into, and waited for it to spit out MP3
compressed data.

Which should mean that, unless things have changed radically (which I
think highly unlikely due to the whole patent issue) most, if not all,
MP3 encoders are effectively running the same core code, with any speed
differences attributable solely to the following:

o hardware type (Some boxes don't do "circular shift left", aka "cshl",
natively ferinstance, which means that code that's heavy on that
operation has to "fake it", usually at a major speed penalty - Others
have a native cshl machine-language  instruction that makes it possible
for the same code runing on that hardware to beat the pants off the
machine that lacks a native "cshl")

o clock speed (It should go without saying that an 800 MHz processor is
going to get the job done quicker than a 300)

o compression amount (More compression = more time doing the
compressing).

Signature

Don Bruder - dakidd@sonic.net - New Email policy in effect as of Feb. 21, 2004.
Short form: I'm trashing EVERY E-mail that doesn't contain a password in the
subject unless it comes from a "whitelisted" (pre-approved by me) address.
See <http://www.sonic.net/~dakidd/main/contact.html> for full details.

Michael Ash - 21 Jan 2005 19:26 GMT
>> > Never mind the fact that MP3 is an assymmetric
>> > compression - Doing the compression is (at least in computer terms)
[quoted text clipped - 11 lines]
> I've seen *ZERO* evidence of any such capability, even on "top of the
> line" Wintel boxes running at multiple GHz clockrates.

Then you aren't looking hard enough, or even looking at all.

>> Realtime MP3 encoding is done routinely for internet radio stations
>
[quoted text clipped - 5 lines]
> less) streaming codec that made whatever was playing sound like a
> tin-=can-and-string telephone in an echo chamber.  

Please see one of these URLs:

http://www.shoutcast.com/
http://www.rogueamoeba.com/nicecast/

The latter is a Mac OS X product that exists for the sole purpose of
taking arbitrary audio output from your Mac and streaming it over the
internet. This is somewhat contradictory with your claims that this is
impossible.

And google for MP3 streaming servers, you'll get about a zillion hits.
Internet radio over MP3 is not a hypothetical thing, it is real, it is
here, it is *now*, and it has been for years.

>> (just look at the Radio "playlist" in iTunes)
>
[quoted text clipped - 4 lines]
> enough to be used as a realtime stream source without hideous mangling
> on the receiving end of things.

Will 422 pages of servers that are streaming MP3 in realtime on
shoutcast.com convince you? Granted, most of them are probably streaming
pre-encoded MP3s, but quite a few of them will be streaming live.

Before they started giving me mono sound, I used to occasionally listen to
Virgin Radio's internet stream. 128kbps MP3, encoded live, even with the
ads and the DJ, in real time.

If you don't believe that it's possible, that's very strange, because it's
all over the place and being used constantly.

>> and even my poor, pokey G4/400 was
>> able to encode MP3s at 3-4x realtime rate using iTunes
[quoted text clipped - 3 lines]
> "the encoding happens in a span of time only slightly longer than it
> would take to simply play the raw data".

If the encoding happens in a span of time that's 3-4 times shorter than it
would take to simply play the raw data, it doesn't count?

> For instance, if I push an AIFF file that takes 3:26 to play into an
> encoder that wants to be considered "realtime", that encoder's going to
> have to spit out a finished MP3 file damn close to 3:26 (give or take
> 5-10 seconds to allow for filesystem access overhead and the like) after
> I hand it the data.

At 3-4x realtime, this 3:26 AIFF would be encoded in about one minute. If
you don't like the fact that it's much faster, you can always put in
artificial delays, so that shouldn't be a problem.

> If it doesn't, it's NOT what I'd consider calling a realtime encoder,
> regardless of how fast it might be.

If your encoder can go faster than 1:1 (which most of them can on anything
vaguely resembling modern hardware) then you can make it realtime by
simply buffering it enough to smooth over any bumps. This buffer does not
need to be large with a standard encoder.

> In other words, if I shove a file into the encoder, I'll be able to play
> the output - straight from the encoder - without ever knowing there was
> an encoding step involved. (unless, of course, my ears are sharp enough
> to pick up on any artifacts that the encoding produces)

That basically describes how it happens. With internet radio, it works
exactly like this except that the encoding computer may be on the other
side of the planet. Unless your connection can't handle the data rate, you
don't notice.

>> , which is not
>> considered a particularly speedy MP3 encoder. Realtime MP3 encoding is not
[quoted text clipped - 12 lines]
> lots of dead air, followed by a few seconds of sound, followed by lots
> of dead air, lather, rinse, repeat...

A G4/300? I don't believe Apple ever shipped anything slower than 350, are
you sure about that?

Anyway, I performed an experiment similar to your setup. I found a CD, and
took a 4:22 track on that CD. I converted it to a 128kbps MP3 using
iTunes, and timed the wall clock time. This time also counted the time it
took me to switch to iTunes and perform the drag that initiated the
conversion. I also had iTunes set up to play the file while it was
importing, which will slow things down. The total time was... are you
ready for it? A hair over twenty-eight seconds. This is ten times faster
than playback rate. With this kind of encoding speed, you could move
regular human speech into the inaudible range on the receiving end. Of
course, you can also just insert some delays so it comes out at the same
frequency it went in.

The above test was performed on a PowerBook G4/1.5GHz. You can find plenty
of computers that will happily boot OS 9 and are not ten times slower. I'm
sure your "G4/300" is not ten times slower.

> That's assuming the networking code can "get a word in edgewise" to
> actually send the data over the wire...

The amount of CPU power required to stream 16kB/sec is laughably small
by comparison. This won't be a factor.

> No clue about iTunes and its performance, but the MP3 encoder plugin
> that I use is the quickest thing I've personally encountered for making
> MP3s on a Mac.

Then again, you are apparently not looking very hard.

> I suspect that they're all pretty similar, since last time I looked into
> the concept, there was only one "core" MP3 encoder that could be had -
[quoted text clipped - 6 lines]
> result here" parameters into, and waited for it to spit out MP3
> compressed data.

There are plenty of legal MP3 encoders out there that are written from
scratch. Of course, the authors of them pay a licensing fee to the MP3
people, but your assertion that there's only one legal MP3 encoder that's
a black box is completely wrong. MP3 won the digital audio format wars
precisely because its patent owners were relatively open with their
licensing.
Larry - 26 Jan 2005 01:39 GMT
> http://www.rogueamoeba.com/nicecast/

can anyone post a chunk of code to deal with quicktime api?
David Phillip Oster - 26 Jan 2005 16:36 GMT
> can anyone post a chunk of code to deal with quicktime api?

<http://www.google.com/search?q=sample+code+sequence+grabber>
Charlton Wilbur - 21 Jan 2005 19:29 GMT
>>>>> "DB" == Don Bruder <dakidd@sonic.net> writes:

   DB> I don't do iTunes (or any of the other "iWhatever"
   DB> perversions), so I have no clue what you're talking about when
   DB> you mention the "Radio playlist", but you're going to have a
   DB> damn hard time convincing me that *ANY* machine or program is
   DB> capable of doing MP3 compression quick enough to be used as a
   DB> realtime stream source without hideous mangling on the
   DB> receiving end of things.

Eppur si muove, buddy.

On my nearly 5-year-old iMac DV+, running a G3 at a measly 450MHz, I
can encode MP3s from CDs at a rate of encoding 2 to 3 seconds per
second of processing.  This is sufficient to make it a realtime stream
source -- and that's a computer that turns 5 this June.

On my Powerbook, it encodes somewhere between 7 and 8 seconds of music
per second of processing, and that's a computer that will turn 2 in March.

   DB> I'm thinking we both need to step back and take a look at what
   DB> we're each calling "realtime" - For the record, I'm saying
   DB> that realtime means "the encoding happens in a span of time
   DB> only slightly longer than it would take to simply play the raw
   DB> data".

If you're willing to accept "the encoding happens in a span of time
substantially *less* that it would take to simply play the raw data",
this is entirely possible now.

   DB> As of *RIGHT THIS INSTANT*, I've got an AIFF file being packed
   DB> down into MP3 in the background. It's about 2/3 done, and has
   DB> already been "in progress" for *AT LEAST* 10 times the
   DB> playback duration of the source file, if not more, and I
   DB> expect that by the time it finishes, the total "time to
   DB> compress" will be in the neighborhood of 15-20 times the
   DB> playback duration of the piece. This is on a G4/300.

This directly contradicts what I've seen with my own eyes.  A couple
days back I compressed about three hours of AIFF audio to 320Kbps AAC
on the iMac, and it took a little over an hour.  I don't know what's
going on with your setup that would make a G4/300 take 30 to 45 times
as long to encode MP3s as it takes a G3/450 to encode AACs (memory? OS
overhead?), but it's probably worth spending as much time looking into
the discrepancy as you have in arguing with us about how realtime MP3
encoding is impossible.

Charlton

Signature

cwilbur at chromatico dot net
cwilbur at mac dot com

Sherm Pendley - 21 Jan 2005 19:50 GMT
> With all due respect, Mike, I ain't buying that. Perhaps in part because
> I've seen *ZERO* evidence of any such capability

If you haven't seen it, your eyes must be closed.

> I'm thinking we both need to step back and take a look at what we're
> each calling "realtime" - For the record, I'm saying that realtime means
> "the encoding happens in a span of time only slightly longer than it
> would take to simply play the raw data".

I just ran a test. Encoding a 42-minute CD took six minutes. And my machine
is no hot rod - it's an old single G4/500. If it took 42 minutes, I'd be
looking to see what went wrong.

sherm--

Signature

Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.