Help writing a wav file into memory stick

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
PeterLeRoi
Posts: 31
Joined: Wed May 16, 2007 11:08 am

Help writing a wav file into memory stick

Post by PeterLeRoi »

I need to write the header first, and second the data. The program I´m using:

Code: Select all

void GrabaWAV(char *name,int size){
	
	int tamanno = size;
	int tamannoHeader = size + 36;
	
	int sstg = sceIoOpen(name, PSP_O_WRONLY | PSP_O_CREAT , 0777);
	printf("\nDescriptor abierto. Size = %d\n", size);
	
        sceIoWrite(sstg, "RIFF",4*sizeof(char));
        sceIoWrite(sstg, &tamannoHeader,sizeof(int));
 	sceIoWrite(sstg, "WAVE",4*sizeof(char));
	printf("RIFF chunk descriptor escrito\n");
	
	
	sceIoWrite(sstg, "fmt ",4*sizeof(char));
	sceIoWrite(sstg, "16",sizeof(int));
	sceIoWrite(sstg, "1",sizeof(short));
	sceIoWrite(sstg, "1",sizeof(short));
	sceIoWrite(sstg, "44100",sizeof(int));
	sceIoWrite(sstg, "88200",sizeof(int));
	sceIoWrite(sstg, "2",sizeof(short));
	sceIoWrite(sstg, "16",sizeof(short));
	printf("fmt sub-chunk descriptor escrito\n");
	
	
	sceIoWrite(sstg, "data",4*sizeof(char));
	sceIoWrite(sstg, &tamanno,sizeof(int));
	printf("data sub-chunk descriptor escrito\n");
	
	  
        sceIoWrite(sstg, bigbuffer, &tamanno);
        printf("Datos escritos\n");
        sceIoClose(sstg);
 }//GrabaWAV
But it creates a wav file with 0kB, and can´t be opened. I think header is right, can´t find the problem...

Edit: Sorry, the program is correct. It was a problem with the memory stick
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Wow, your output code is really messed up. For example,

Code: Select all

   sceIoWrite(sstg, "1",sizeof(short));
   sceIoWrite(sstg, "44100",sizeof(int));
"1" is a string, not a short, and "44100" is a string, not an int. If you want to output shorts and ints, point to a short or an int, not a string.
PeterLeRoi
Posts: 31
Joined: Wed May 16, 2007 11:08 am

Post by PeterLeRoi »

Yep, you´re right. But, for the wav header, need the "1" to have 2bytes (one short) and "44100" to have 4bytes (one int).

Anyway, thanks ;)
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

PeterLeRoi wrote:Yep, you´re right. But, for the wav header, need the "1" to have 2bytes (one short) and "44100" to have 4bytes (one int).

Anyway, thanks ;)
Right, so what you wanted was something like this:

Code: Select all

   short h1 = 1;
   int h2 = 44100;
   sceIoWrite(sstg, &h1,sizeof(short));
   sceIoWrite(sstg, &h2,sizeof(int));
What you REALLY need to do is define the header as a struct, fill in all the fields, then use one write command to write the struct to the file.
Post Reply