Reading and manipulating a WAV file in C++





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I'm trying to write a simple program to read a WAV file in C++ and get data like sample rate and bit depth. At some point I want to use this to manipulate the data to create an audio plugin, but I want to understand this first.



#include <iostream>
#include <string>
#include <fstream>
#include <ostream>
using namespace std;

struct wavfile {
char id[4];
int totallength;
char wavefmt[8];
int format;
short pcm;
short channels;
int frequency;
int bytes_per_second;
short bytes_by_capture;
short bits_per_sample;
char data[4];
int bytes_in_data;
};

int main () {
FILE * wfile;
std::ofstream ofs;
wfile = ofs.open("tes.wav",std::ofstream::binary | std::ofstream::app); // line 31

ofs.close();

return 0;
}


When I try to run it it keep saying "assigning to 'FILE *' (aka '__sFILE *') from incompatible type 'void'"



How can I get it to open the wave file, read the data, so I can define it as a within the struct wavfile and print it back out?



Any help would be greatly appreciated, even just pointing me in the right direction or to a good resource. Thanks in advance!










share|improve this question

























  • Hello, std::ofstream::open returns void so you cannot set the value of a variable using its return value. More over std::ofsteam is an out file stream so you cannot read things from it. I think you're looking for std::ifstream (cplusplus.com/reference/istream/istream/read). And you don't need one of your variable, why do you have a FILE* and an std::ofstream? If you want to read your file, either use std::ifstream which belongs the C++ standard library or use FILE which belongs to C library but not both in the same time.

    – Siliace
    Nov 16 '18 at 23:14













  • What manual are you working from?

    – Galik
    Nov 16 '18 at 23:17


















0















I'm trying to write a simple program to read a WAV file in C++ and get data like sample rate and bit depth. At some point I want to use this to manipulate the data to create an audio plugin, but I want to understand this first.



#include <iostream>
#include <string>
#include <fstream>
#include <ostream>
using namespace std;

struct wavfile {
char id[4];
int totallength;
char wavefmt[8];
int format;
short pcm;
short channels;
int frequency;
int bytes_per_second;
short bytes_by_capture;
short bits_per_sample;
char data[4];
int bytes_in_data;
};

int main () {
FILE * wfile;
std::ofstream ofs;
wfile = ofs.open("tes.wav",std::ofstream::binary | std::ofstream::app); // line 31

ofs.close();

return 0;
}


When I try to run it it keep saying "assigning to 'FILE *' (aka '__sFILE *') from incompatible type 'void'"



How can I get it to open the wave file, read the data, so I can define it as a within the struct wavfile and print it back out?



Any help would be greatly appreciated, even just pointing me in the right direction or to a good resource. Thanks in advance!










share|improve this question

























  • Hello, std::ofstream::open returns void so you cannot set the value of a variable using its return value. More over std::ofsteam is an out file stream so you cannot read things from it. I think you're looking for std::ifstream (cplusplus.com/reference/istream/istream/read). And you don't need one of your variable, why do you have a FILE* and an std::ofstream? If you want to read your file, either use std::ifstream which belongs the C++ standard library or use FILE which belongs to C library but not both in the same time.

    – Siliace
    Nov 16 '18 at 23:14













  • What manual are you working from?

    – Galik
    Nov 16 '18 at 23:17














0












0








0








I'm trying to write a simple program to read a WAV file in C++ and get data like sample rate and bit depth. At some point I want to use this to manipulate the data to create an audio plugin, but I want to understand this first.



#include <iostream>
#include <string>
#include <fstream>
#include <ostream>
using namespace std;

struct wavfile {
char id[4];
int totallength;
char wavefmt[8];
int format;
short pcm;
short channels;
int frequency;
int bytes_per_second;
short bytes_by_capture;
short bits_per_sample;
char data[4];
int bytes_in_data;
};

int main () {
FILE * wfile;
std::ofstream ofs;
wfile = ofs.open("tes.wav",std::ofstream::binary | std::ofstream::app); // line 31

ofs.close();

return 0;
}


When I try to run it it keep saying "assigning to 'FILE *' (aka '__sFILE *') from incompatible type 'void'"



How can I get it to open the wave file, read the data, so I can define it as a within the struct wavfile and print it back out?



Any help would be greatly appreciated, even just pointing me in the right direction or to a good resource. Thanks in advance!










share|improve this question
















I'm trying to write a simple program to read a WAV file in C++ and get data like sample rate and bit depth. At some point I want to use this to manipulate the data to create an audio plugin, but I want to understand this first.



#include <iostream>
#include <string>
#include <fstream>
#include <ostream>
using namespace std;

struct wavfile {
char id[4];
int totallength;
char wavefmt[8];
int format;
short pcm;
short channels;
int frequency;
int bytes_per_second;
short bytes_by_capture;
short bits_per_sample;
char data[4];
int bytes_in_data;
};

int main () {
FILE * wfile;
std::ofstream ofs;
wfile = ofs.open("tes.wav",std::ofstream::binary | std::ofstream::app); // line 31

ofs.close();

return 0;
}


When I try to run it it keep saying "assigning to 'FILE *' (aka '__sFILE *') from incompatible type 'void'"



How can I get it to open the wave file, read the data, so I can define it as a within the struct wavfile and print it back out?



Any help would be greatly appreciated, even just pointing me in the right direction or to a good resource. Thanks in advance!







c++ audio






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 23:12







Jon Organ

















asked Nov 16 '18 at 22:59









Jon OrganJon Organ

11




11













  • Hello, std::ofstream::open returns void so you cannot set the value of a variable using its return value. More over std::ofsteam is an out file stream so you cannot read things from it. I think you're looking for std::ifstream (cplusplus.com/reference/istream/istream/read). And you don't need one of your variable, why do you have a FILE* and an std::ofstream? If you want to read your file, either use std::ifstream which belongs the C++ standard library or use FILE which belongs to C library but not both in the same time.

    – Siliace
    Nov 16 '18 at 23:14













  • What manual are you working from?

    – Galik
    Nov 16 '18 at 23:17



















  • Hello, std::ofstream::open returns void so you cannot set the value of a variable using its return value. More over std::ofsteam is an out file stream so you cannot read things from it. I think you're looking for std::ifstream (cplusplus.com/reference/istream/istream/read). And you don't need one of your variable, why do you have a FILE* and an std::ofstream? If you want to read your file, either use std::ifstream which belongs the C++ standard library or use FILE which belongs to C library but not both in the same time.

    – Siliace
    Nov 16 '18 at 23:14













  • What manual are you working from?

    – Galik
    Nov 16 '18 at 23:17

















Hello, std::ofstream::open returns void so you cannot set the value of a variable using its return value. More over std::ofsteam is an out file stream so you cannot read things from it. I think you're looking for std::ifstream (cplusplus.com/reference/istream/istream/read). And you don't need one of your variable, why do you have a FILE* and an std::ofstream? If you want to read your file, either use std::ifstream which belongs the C++ standard library or use FILE which belongs to C library but not both in the same time.

– Siliace
Nov 16 '18 at 23:14







Hello, std::ofstream::open returns void so you cannot set the value of a variable using its return value. More over std::ofsteam is an out file stream so you cannot read things from it. I think you're looking for std::ifstream (cplusplus.com/reference/istream/istream/read). And you don't need one of your variable, why do you have a FILE* and an std::ofstream? If you want to read your file, either use std::ifstream which belongs the C++ standard library or use FILE which belongs to C library but not both in the same time.

– Siliace
Nov 16 '18 at 23:14















What manual are you working from?

– Galik
Nov 16 '18 at 23:17





What manual are you working from?

– Galik
Nov 16 '18 at 23:17












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53346491%2freading-and-manipulating-a-wav-file-in-c%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53346491%2freading-and-manipulating-a-wav-file-in-c%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

List item for chat from Array inside array React Native

Thiostrepton

Caerphilly