Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

naveen

macrumors member
Original poster
Oct 27, 2004
43
0
hi all
I want to create a file(that may be .wav,AIFF,rtf or other) on mac system through programming. How i can do this.


Thanks and regards
 

caveman_uk

Guest
Feb 17, 2003
2,390
1
Hitchin, Herts, UK
Your question is very vague. What language would you be using? The answer would be different depending upon what you'd be using.

With Cocoa actually saving the file could be just one line of code but you'd need to prepare what you wanted to save in (probably) an NSData object first. Some file types have their own special classes to deal with this sort of thing.
 

weg

macrumors 6502a
Mar 29, 2004
888
0
nj
naveen said:
hi all
I want to create a file(that may be .wav,AIFF,rtf or other) on mac system through programming. How i can do this.


Thanks and regards

Open a Text editor, write:

#!/usr/bin/sh

echo "My Content" > filename.extension



Ok, just joking..
 

GeeYouEye

macrumors 68000
Dec 9, 2001
1,669
10
State of Denial
naveen said:
hi all
I want to create a file(that may be .wav,AIFF,rtf or other) on mac system through programming. How i can do this.


Thanks and regards

You go out and buy a book on Cocoa Programming (Aaron Hillegass wrote a good one). You read said book and follow along. Your answers will be in there for RTF, at least. For the others, read their specs and make an implementation of it, relatively easy in C.
 

naveen

macrumors member
Original poster
Oct 27, 2004
43
0
Hi all

I want to create these files using c,c++ on macintosh system. how can i save these files. how the resource fork will be handled . Plz help me i am new to mac os.


Thanks and regards
 

mkrishnan

Moderator emeritus
Jan 9, 2004
29,776
15
Grand Rapids, MI, USA
naveen said:
I want to create these files using c,c++ on macintosh system. how can i save these files. how the resource fork will be handled . Plz help me i am new to mac os.

Correct me if I'm wrong, but cross-platform files like the ones you described don't use resource forks, do they? Like the others said, you'd use Cocoa APIs to generate the files.

Here is some stuff from Apple's support pages:
 

naveen

macrumors member
Original poster
Oct 27, 2004
43
0
hi all
I am new to Mac Os. I want to create the file using C/C++ programming.


I create the file using following code and the file created but i unable to open this file.This is a .AIFF file.
FILE *fp;
fp = fopen(Audio 1_01,"wb+");

fwrite(DataBuff,SizeToSave,1,fp);

DataBuff buffer contains the raw contents of file.



I have also created the resource fork file using
File fp;
fp = fopen(._Audio 1_01,"wb+");
fwrite(ResourceBuff,SizeToSave,1,fp);
ResourceBuff buffer contains the resource raw data of file.


When i open the created file using the hex editor then I see File Type/Creator
is empty.

But i don't know how to deal with this resource fork file creation. How the created resource fork file linked to its data fork file.


When i open the created file using the hex editor then I see File Type/Creator
is empty.

If any body have idea then plz help me.

Thanx in advance
 

caveman_uk

Guest
Feb 17, 2003
2,390
1
Hitchin, Herts, UK
naveen said:
Hi all

I want to create these files using c,c++ on macintosh system. how can i save these files. how the resource fork will be handled . Plz help me i am new to mac os.


Thanks and regards
OK, we getting nearer. So you want to use C or C++ - well you could use either the BSD API's to do your file handling or Carbon. I know next to zero about carbon except that I've seen enough to want to avoid it. The BSD API's are similar but sometimes a necessary evil.

As I use the Cocoa frameworks whenever I can, I have to admit I don't really think too much about resource forks. My understanding is that they're kind of in a no-mans land with Apple varying between being ambivalent and deprecating their use. Having said that, Apple upgraded the Unix command line tools in Tiger so they now (finally) now what a resource fork is.

Getting back to the main point of your question I think actually saving your file is the least of your worries. You should be more worried about how you're actually going to create the data structures you want to save. You haven't said if you already have that part done and just want to know how to save, or if you really want to know how to create those data structures - which is a much much harder question.

Edit: Just seen your new post. The resource fork is (I believe) stored as a separate file. Do you actually need the resource fork? Does the file you create 'work' without it? Check out this link

http://www.kernelthread.com/mac/osx/arch_fs.html
 

jcgerm

macrumors member
May 28, 2003
91
0
naveen said:
hi all
I am new to Mac Os. I want to create the file using C/C++ programming.


I create the file using following code and the file created but i unable to open this file.This is a .AIFF file.
FILE *fp;
fp = fopen(Audio 1_01,"wb+");

fwrite(DataBuff,SizeToSave,1,fp);

DataBuff buffer contains the raw contents of file.



I have also created the resource fork file using
File fp;
fp = fopen(._Audio 1_01,"wb+");
fwrite(ResourceBuff,SizeToSave,1,fp);
ResourceBuff buffer contains the resource raw data of file.


When i open the created file using the hex editor then I see File Type/Creator
is empty.

But i don't know how to deal with this resource fork file creation. How the created resource fork file linked to its data fork file.


When i open the created file using the hex editor then I see File Type/Creator
is empty.

If any body have idea then plz help me.

Thanx in advance

Honestly, I wouldn't try to deal with resource forks and data forks. What you need is an API that can read/write these file types, so that you don't have to deal with them (i.e. ImageMagick for jpeg, tiff, etc.). Unless you want to sift through file specifications, I would look for an API that does all of this for you. No sense in reinventing the wheel here.
 

whooleytoo

macrumors 604
Aug 2, 2002
6,607
716
Cork, Ireland.
naveen said:
hi all
I want to create a file(that may be .wav,AIFF,rtf or other) on mac system through programming. How i can do this.
Thanks and regards

For Wav or AIFF files, take a look at the QuickTime API, it should be able to export files of this type easily.
 

naveen

macrumors member
Original poster
Oct 27, 2004
43
0
As I earlier told that i am a new programmer on mac. I have knowledge of Mac(HFS and HFS+) file system. I have written a small programe in my pc(using visual c++) to recover files of a crashed mac HDD is connected to pc then my program is able to recover both data fork and resource fork. If we transfer both data fork and rosource fork of a file to mac machine the file run perfectly.

Now i am writing the same program on mac machine. I know the location of both data fork and resource fork . But my problem is how to associate them with each other. I have already discuss how i am writting both the files(data fork and resource fork).

if any body have some idea then plz help me

Thanks and regards
 

MarkHamilton

macrumors newbie
Jun 21, 2005
12
0
Albuquerque, NM, USA
naveen said:
As I earlier told that i am a new programmer on mac. I have knowledge of Mac(HFS and HFS+) file system. I have written a small programe in my pc(using visual c++) to recover files of a crashed mac HDD is connected to pc then my program is able to recover both data fork and resource fork. If we transfer both data fork and rosource fork of a file to mac machine the file run perfectly.

Now i am writing the same program on mac machine. I know the location of both data fork and resource fork . But my problem is how to associate them with each other. I have already discuss how i am writting both the files(data fork and resource fork).

if any body have some idea then plz help me

Thanks and regards


The 'Resource Manager' reference is probably where you want to look to find the information you need.

http://developer.apple.com/documentation/Carbon/Reference/Resource_Manager/index.html

In particular, check out this function:

http://developer.apple.com/document.../apple_ref/doc/uid/TP30000154-89772-TPXREF106
 

naveen

macrumors member
Original poster
Oct 27, 2004
43
0
Hi all

I have using the FSpCreate() for creating a file, when i compiling my application there is no error but still file is not created.I want to know about the FSSpec structure.

I have passed the following values to this structure
spec.vRefNum=0;
spec.parID=4029;
unsigned char filename[64]="Aman";
spec.name=filename;
FSpCreate(&spec, 'ttxt', 'TEXT', smSystemScript); *

I want to create file on root . What i should pass to parId and vRefNum?? How i can get the Volume reference number.

Thanks and Regards

*
 

boomtopper

macrumors member
Mar 25, 2004
96
0
UK Huddersfield
Ok to do reading and writing of audio files it can be quite complex. Especially when you are manipulating the data using DSP. But here are some useful links i can give you to help.

1. The first way is to read about how wav files are structured. Becuase wav files have information burried in them such as what sample rate and bit depth. Using this source you can learn how a wav file is structured and then create your own api to read and write them.

2. You can also get this open source api called libsnd. This api will alow you to read and write wavs and other file formats.I would recommend using this becuase it works on all platforms. I would still recommend getting familiar with the wav file format, and make sure you know what all the terminology means such as sample rate.

I hope this helps.
 

logicat2001

macrumors regular
Apr 16, 2003
192
0
Minneapolis, MN
You might also read up on OS X's Audio API's re: file format conversion here: file:///Developer/ADC%20Reference%20Library/documentation/MusicAudio/Reference/CoreAudio/audio_toolbox/chapter_4_section_1.html#//apple_ref/doc/uid/TP30001108-CH205

I hope the URL translates properly, but if not, if you've installed the latest Developer docs, you should search for AudioToolbox. There are a number of convenience methods that allow for reads/writes of common audio file formats. It may or may not fit your needs, but FYI.

Best,
logicat
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.