Hi, my problem is, that once i wrote application which was able to add echo to a wav file in c++ :
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int write=0;
int read=0;
void insert(short int * tablica,short int element,int value);
void read_out(short int * liczba,short int * tablica,int value);
int main(){
FILE * file_in;
FILE * file_out;
char header[44];
file_in = fopen("output.wav","rb");
cout<<"wprowadz dlugosc echa: "<<endl;
int echo;
int count=0;
cin>>echo;
short int * fifo=new short int[echo];
short int sample;
short int temp;
file_out = fopen("new.wav","wb");
fread(header,44,1,file_in);
fwrite(header,44,1,file_out);
for(int p=0;p<echo-2;p++)
{
insert(fifo,0,echo);
}
while(fread(&sample,2,1,file_in))
{
read_out(&temp,fifo,echo);
temp = temp/3 + sample/2;
insert(fifo,temp,echo);
fwrite(&temp,2,1,file_out);
}
fclose(file_out);
fclose(file_in);
delete fifo;
return 0;
}
void insert(short int * tablica,short int element,int value)
{
tablica[write%value]=element;
write++;
}
void read_out(short int * liczba,short int * tablica,int value)
{
(*liczba)=tablica[read%value];
read++;
}
as You see above it's very simple, and I wrote it ages ago, and now I need to prepare a presentation for a JUG meeting, and it's gonna be about all java support for different kinds of sound. That's why I wanna write application to manipulate some sort of sound files ( in this case a .wav file).
My problem is that when I repeat this code in Java it works differently. first problem, is that I read samples form wav using FileInputStreamReader, and it reads either bytes or ints , and I need to read shorts, cause it's 16bit wav file. So I'm reading via FileInputStreamReader every 2 bytes, and trying to convert it to short using bit shifts, but it never works. Does anyone knows how to read stream to short type, or how to convert bytes[2] to short safely? Thanks in advance.