samedi 26 juin 2021

This code worked on visual studio code but wouldn't work in visual studio 2019

I have this code that converts a wave file into an array of ints in order to send it to a server.

-This code worked well in visual studio code but didn't work on visual studio 2019 and it keeps giving me this error, can you please help me.

-I want it to work in visual studio 2019 because I used to work with it for unreal and also I don't have that much time to adapt to visual studio code with unreal because the project deadline is really soon.

This is The Code:

            #include <iostream>
            #include <fstream>
            #include <cstring>
            #include <cstdlib>
            using namespace std;
            
            struct WavData{
                public:
                    int16_t* data;
                    long size;
                    
                    WavData(){
                        data=NULL;
                        size=0;
                    }   
            };
            
            
            void loadWavFile(const char* filePath,WavData *ret){
                FILE* wavFile=fopen(filePath,"r");
                if(wavFile){
                    cout<<"wav file has been opened"<<endl;
                    char id[5];
                    int32_t size;
                    int16_t format_tag,channels,block_align,bits_per_sample;
                    int32_t format_length,sample_rate,avg_bytes_sec,data_size;      
                    
                    fread(id,sizeof(char),4,wavFile);
                    id[4]='\0';
                    
                    if(!strcmp(id,"RIFF")){
                        fread(&size,sizeof(int16_t),2,wavFile);
                        fread(id,sizeof(char),4,wavFile);
                        id[4]='\0';
            
                        if(!strcmp(id,"WAVE")){
                            fread(id,sizeof(char),4,wavFile);
                            fread(&format_length,sizeof(int16_t),2,wavFile);
                            fread(&format_tag,sizeof(int16_t),1,wavFile);
                            fread(&channels,sizeof(int16_t),1,wavFile);
                            fread(&sample_rate,sizeof(int16_t),2,wavFile);
                            fread(&avg_bytes_sec,sizeof(int16_t),2,wavFile);
                            fread(&block_align,sizeof(int16_t),1,wavFile);
                            fread(&bits_per_sample,sizeof(int16_t),2,wavFile);
                            fread(id,sizeof(char),4,wavFile);
                            fread(&data_size,sizeof(int16_t),2,wavFile);
                            
                            ret->size=data_size/sizeof(int16_t);
                            // Dynamically allocated space, remember to release
                            ret->data=(int16_t*)malloc(data_size);
                            fread(ret->data,sizeof(int16_t),ret->size,wavFile);
                        }
                        else{
                            cout<<"Error: RIFF File but not a wave file\n";
                        }
                    }
                else{
                    cout<<"ERROR: not a RIFF file\n";
                }
                }
                fclose(wavFile);
            }
            
            void freeSource(WavData* data){
                free(data->data);
            }
            
            int main(){
                WavData song;
                ofstream out("Another.txt");
                const char* fname="Another.wav"; 
                loadWavFile(fname,&song);
                cout<<song.size<<endl;
            
                for(long i=0;i<song.size;i++){
                    out<<song.data[i]<<',';
                }
            
                out.close();

                freeSource(&song);
                return 0;
            }

This is the bug it gives when it stops debugging

These are the warnings it gives after compiling

Aucun commentaire:

Enregistrer un commentaire