Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

878936 Posts in 32946 Topics- by 24353 Members - Latest Member: kanki

May 23, 2013, 12:56:10 AM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)C++ Reading audio (wave) RIFF header. file pointer issue in Xcode?
Pages: [1]
Print
Author Topic: C++ Reading audio (wave) RIFF header. file pointer issue in Xcode?  (Read 1061 times)
JamesBranston
Level 0
**


View Profile Email
« on: May 05, 2011, 04:03:15 AM »

Ok so you might remember a while ago I wanted to do some DSP in C++. Since uni work weighed me down I couldnt really do much with it. I rebuilt the code now just to do a basic function of reading the RIFF header. Then I will focus on trying the DSP stuff.
So I built it after much hard work and a little external help. It SHOULD work but for some reason when I try to execute it the file pointer is not working. The Error reporting is working a treat though  Cheesy

Im working in Xcode by the way.

So here is an extract of a bit of my code. The first section is the error return when something doesnt work. This section actually works. The second bit is the file pointer section which is supposed to open the wav file. But every time i execute it returns the error:


Code:
int errormessage(const char* msg, int error = 0)
{
cout << msg << endl;
while(cin.get() != 10);

return error;
}

int main()
{
FILE *fp = NULL;
fp = fopen("test.wav", "r");
if(!fp)
{
return errormessage("Error: Cannot Open File");
}

I have the wav file named as "test.wav" and its in the same location as the build (which is: /Users/jtjbranston/Documents/Programming/ReadRIFFHeader/build/Debug/)

Am I missing something with the file pointer here? If you need the entire code I can supply (I dont see why you would though)

Thanks. Hope all is well.
« Last Edit: May 05, 2011, 05:13:58 AM by JamesBranston » Logged
LDuncan
Level 0
***



View Profile Email
« Reply #1 on: May 05, 2011, 07:48:44 AM »

I don't use Xcode so I can't comment on that, but if it helps point you in the right direction, I tried out your code and everything worked without a hitch. So... at least you know you're not going crazy--the code does do what it's supposed to do  Undecided
Logged
Nix
Level 10
*****



View Profile
« Reply #2 on: May 05, 2011, 08:55:20 AM »

You should post the wav you're trying to use.
Logged
JamesBranston
Level 0
**


View Profile Email
« Reply #3 on: May 05, 2011, 09:26:16 AM »

Heres the entire code:

http://pastebin.com/TaJGVg3E

and as for the wav file. It should work with almost all of them as long as they're named as stated in the code (they are Wav files stated by RIFF files). When I get home I will look at the code on my PC and do some more looking into Xcode (Macs are aaawkward)
Logged
LDuncan
Level 0
***



View Profile Email
« Reply #4 on: May 05, 2011, 09:50:30 AM »

Your code worked perfectly fine again for me. The only thing I can think of is that it's some weird problem with Xcode or that your .wav file is corrupted/not really in the right directory as it's supposed to be :: shrug ::

edit: how about copying the executable to another directory and pasting the .wav file in the same directory, then running the executable from there--just to make absolutely sure that your IDE isn't running the executable in some other weird directory. It sounds stupid, but I've had IDEs do dumber things to me before.
« Last Edit: May 05, 2011, 09:59:02 AM by LDuncan » Logged
twistedjoe
Level 0
**


Suddenly bananas, thousands of them!


View Profile WWW
« Reply #5 on: May 05, 2011, 01:45:42 PM »

Like the others said, it's probably a path problem. Is it a bundle or just a binary ?

If it's a bundle, it won't work this way (you would need to specify the path to the resources folder from the binary IN the bundle).

Another thing, is it Xcode 4 or 3 ? The build folder of xcode 4 is not in the ./build folder anymore, it's in
Code:
*homeFolder*/Library/Developer/Xcode/DerivedData/*project name+uniqueID*/...


So, if you are building a binary, you will need create a build phase in the project setting that copy your resources next to the binary. (product directory as the copy destination).

If you are building a bundle, just put your resources in the default resources folder of xcode, they will be copied in the resources folder of your bundle. From there there is the good solution (search the apple function that return the resources path) and the bad/easy solution (use this path "../Resources/yourwav.wav")

I hope it help.
Logged

mcc
Level 10
*****


glitch


View Profile WWW Email
« Reply #6 on: May 05, 2011, 05:39:46 PM »

Most likely the "working directory" of your program is not what you expect.

The "working directory" is sometimes surprising on OS X, and it is more confusing because with .apps the working dir is different when you run it in the finder vs. running it in Xcode.

Ways around this include:

1. Do not say "test.wav". Specify a full path.

2. Make your program command line; pass the filename as a command line argument. The cwd with command line programs is usually more obvious.

3. Call getcwd() in your program code (see man getcwd) to verify the working directory is what you think.

4. Find a copy of SDLMain.mm. Copy its code for setting the working directory to something sensible.
Logged

My projects:<br />Games: Jumpman Retro-futuristic platforming iJumpman iPhone version Drumcircle PC+smartphone music toy<br />More: RUN HELLO
Impossible
Level 3
***



View Profile Email
« Reply #7 on: May 06, 2011, 12:17:18 PM »

I'm not familiar enough with Xcode to know exactly how to do this, but in Visual Studio under debug settings you can change the working directory of your application under the debug settings.  When you launch your app from the IDE it will use the overridden working directory. So you could mess around with your project settings and get this working that way as well.
Logged
Nix
Level 10
*****



View Profile
« Reply #8 on: May 06, 2011, 03:02:41 PM »

Does Mac os x have unistd? Just use chdir
Logged
JamesBranston
Level 0
**


View Profile Email
« Reply #9 on: May 07, 2011, 04:44:09 AM »

Hi guys thanks for your input Smiley

I got it to work in the end after specifying the full path name

Code:
FILE *fp = NULL;
        fp = fopen("/Users/jtjbranston/Documents/Programming/ReadRIFFHeader/build/Debug/test.wav", "r");

Im going to research call objects soon and an external library that will allow me to have an open screen so the user can select the file. Then maybe I can resume my research into C++ DSP    Tears of Joy WTF ... Also not opening up in Terminal would be another step forward.

EDIT: Also im using Xcode 3.2.6
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic