recording sound from cocoa?

LordCoven

Registered
Hi,

I was wondering whether anyone could tell me how to record sounds from within a cocoa app. I've got an iBook (dual USB) and want to record sounds from the internal mic. NSSound is nice and easy for playing sounds, but I was wondering how to record sounds??

Any help is much appreciated ;-)

C
 
... can I infer from the severe lack of response that nobody here has actually achieved this task? ;-)

C
 
I've looked as well. In fact, I started my search just yesterday. Unfortunately, nothing on Omnigroup or macnn showed me any hope of recording music through a mic. So, apple, WTF?

Grr... and I needed this for a project...

F-bacher
 
Hey,

Just for everyone's info: I've tried recording via the Java javax.sound.sampled.* interfaces too, but that didn't want to work either!

Its got to be possible, coz SoundStudio (and various others) manage it, but I'm damned if I can figure out how ;-)

Hope someone who's done takes a peek at this forum soon ;-)))

C
 
The macosX is an unix sistem....so you must have in the /dev directory a special file who reppreset the microphone....

you can read from this file....and write in an other file (a normal file)....

you can use NSFileManager or NSPipe.....

i must say that i don't have try it.....so i can't say nothing about the quality of the sound....

PS: i realy don't know first if it work....second which is the file that represent the microphon.....

PSS: i'm sorry ...my english is realy poor ...:(
 
Hey,

Thanks for the tip ;-) Thing is, the input stream from the /dev/... is just raw data, whereas I want to record in aif or wav format - and if you think I'm gonna code those algorythms myself y'all got another think comin'! ;-)))) I really like the ease of use of the NSSound class, and would dearly love to see Apple provide us with something just as easy for recording sound.

The javax.sound.sampled.* API is in a similar state. Its a very powerful API if you want a lot of control to record stuff - but if you just want to record a wav or aif file, there are just TOO many hoops to jump through. To top it all off, the documentation for the java sound API contains quite a lot of sample code, but it always says

functionName(format); //where format is an AudioFormat

and doesn't explain how they got that format. And when you check the documentation, the AudioFormat seems to be used by EVERYTHING but generated by nothing apart from its constructors.

Woah - just realised this is turning into a bit of a Java rant, so I'll take it over to the Sun forums ;-)))

But my point is: Apple did a GREAT job on the NSSound class for playing sounds and I just wish they'd have gone that little bit futher and made it just as easy to record sound.

(The fact that this isn't the case surprised me, as on Apple's site they keep going on about how great an OS OS X is for music and sound!!!)

Anyway, I'm going to go and have a coffee and cool off a little bit. In the meantime, if anyone has found out how to record sound via the mic in a slightly easier way than having to code the codes ourselves, please let me know ;-)))

But I am sincerely greateful to the previous poster for his comments.

Right - I'm going now.

Any time now.

Right.

I'm off.

Bye.

C
 
I asked ADC the question, and they came back with this:

We recommend using the Sequence Grabber. You could easily build a Cocoa
class around Sequence Grabber calls and it will record audio for you without
you worrying about what's going on underneath. Sound Manger or Core Audio
etc. If you need access to the data directly. We recommend taking a look at
the SGDataProc Sample.

... so: has anyone used the Sequence Grabber?? Can anyone post some sample code?

Cheers,

C
 
Hey I noticed that this hasn't had a answer.

I am really interested in this. Has anyone discovered anything?
 
These C functions should be available in Cocoa/ObjC
I think you will need to include QuicktmeComponents.h

// members
SSoundInputParams mParams;
FSSpec mSpec;
ComponentInstance mSG;
SGChannel mChan;

// To initialize
mSG = OpenDefaultComponent( SeqGrabComponentType, 0 );
SGInitialize( mSG );
SGNewChannel( mSG, SoundMediaType, &mChan );
SGSetChannelUsage( mChan, seqGrabRecord | seqGrabPreview );
// to start recording
SGSetMaximumRecordTime(mSG, mDuration * 60));
SGSetDataOutput( mSG, mSpec, seqGrabToDisk );
SGStartRecord( mSG );

// to stop or pause
SGStop( mSG );
SGPause( mSG, seqGrabPause );
SGPause( mSG, seqGrabUnpause );

// to cleanup
SGDisposeChannel( mSG, mChan );
CloseComponent( mSG );
 
Thats extremly different than I expected. I was expecting some fairly complicated Core Audio calls with weird callbacks. Can you tell me why this approach instead of core audio?

Thanks lots

Matt
 
Those are high level QuickTime Sequence Grabber calls. As a consequnce they are more robust (meter levels, device selection, etc), simple to use, and crossplatform (assuming QT installed on Windows machine). The higher level the API you use, the better your application will repsond to new features and changes in the OS.

Assuming you have the complete developer package on your computer, the Quicktime documentation will be in

/Developer/Documentation/QuictTime/Index.html

The documentation will better explain usage and options better than my copy-paste jumble of code I put in the previous message.

Ghoser777 is pointing you to the same, and possibly more recent, documentation on Apple's site. There are probably better samples out there as well.
 
Back
Top