Hello all,
First of all i am a beginner in vc++, so excuse my question if its simple.
I was wondering if I could use the data from button1 in button 2
my code is:
public:System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
OpenFileDialog open;
open.Title = "Select Wave File";
open.Multiselect = true;
open.CheckFileExists = true;
open.Filter = "Audio Files (*.wav)|*.wav";
open.FilterIndex = 2;
open.InitialDirectory="C:";
if (open.ShowDialog()==System::Windows::Forms::DialogResult::OK )
{
//convert open.FileName to unmanaged memory
String^ managedString =open.FileName;
char* filename = (char*) Marshal::StringToHGlobalAnsi(managedString ).ToPointer();
//end convertion
ifstream waveFile (filename);//open wav file
waveFile.seekg (0, ios::end); // Move the get pointer to the end of the file
int fileSize = waveFile.tellg(); // Get the offset of the get pointer
waveFile.seekg(ios::beg);//get pointer back to the beginning
unsigned char *fileData = new unsigned char [fileSize];// Allocate memory for the data
waveFile.read ((char *)fileData, fileSize);// Read the data into memory
int offset = 12;
WaveFmtSubChunk *fmtChunk = (WaveFmtSubChunk *)(fileData + offset);
// Loop through sub chunks. The fmt may not be the first one.
while (strncmp (fmtChunk->id, "fmt ", 4))
{
offset++;
if (offset > fileSize - 4)
{
delete [] fileData;
}
fmtChunk = (WaveFmtSubChunk *)(fileData + offset);
}
if (fmtChunk->format != 1)
{
delete [] fileData;
}
offset += 8; // (8 for fmt id and size members)
WaveDataSubChunk *dataChunk = (WaveDataSubChunk *)(fileData + fmtChunk->size + offset);
for (int i=0;i<10;i++)
if (!strncmp (dataChunk->id, "data", 4))
break;
else
dataChunk = (WaveDataSubChunk *)(((char *)dataChunk) + dataChunk->size + 8);
if (strncmp (dataChunk->id, "data", 4))
{
delete [] fileData;
}
textBox1->Text=open.FileName;
}
}
public:System::Void button2_Click(System::Object^ sender, System::EventArgs^ e)
{
SaveFileDialog save;
save.Title = "Save Report";
save.CheckFileExists = false;
save.Filter = "txt Files (*.txt)|*.txt";
save.FilterIndex = 2;
save.InitialDirectory="C:";
if (save.ShowDialog()==System::Windows::Forms::DialogResult::OK )
{
//convert open.FileName to unmanaged memory
String^ managedString =save.FileName;
char* savefile = (char*) Marshal::StringToHGlobalAnsi(managedString ).ToPointer();
//end convertion
std::ofstream writeReport(savefile); //generating the report file
if (writeReport.is_open() ) //check if file was created
{
//write the necessary data in the file
writeReport<<"File Size"<<fileSize<<" bytes"<<"\n"<<"Audio Sample Size"<<fmtChunk->size<<"bit"<<"\n"<<"Channels Nr."<<fmtChunk->channels<<"\n"<<"Audio SampleRate"<<fmtChunk->sampleRate<<" Hz"; //her is the error
}
else
{
exit(0); //if the report file is not created the program exits
}
textBox2->Text=save.FileName;
}
}
I get the following errors
c:\documents and settings\uidl7181\desktop\audio analyzer\audio analyzer\Form1.h(296) : error C2065: 'fileSize' : undeclared identifier
1>c:\documents and settings\uidl7181\desktop\audio analyzer\audio analyzer\Form1.h(296) : error C2065: 'fmtChunk' : undeclared identifier
1>c:\documents and settings\uidl7181\desktop\audio analyzer\audio analyzer\Form1.h(296) : error C2227: left of '->size' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>c:\documents and settings\uidl7181\desktop\audio analyzer\audio analyzer\Form1.h(296) : error C2227: left of '->channels' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>c:\documents and settings\uidl7181\desktop\audio analyzer\audio analyzer\Form1.h(296) : error C2227: left of '->sampleRate' must point to class/struct/union/generic type
1> type is ''unknown-type''