Trying to delay a audio text file, not working!!
in
Programming Questions
•
2 years ago
Hi has anyone got anyideas as to why this code is not working. It is supposed to read in a .txt file containing audio and then delay it. Any help would be greatly appreciated. Thank you.
- PrintWriter output1,output2;
String [] tempInput;
int [] buffer;
tempInput = loadStrings("NOTE.txt");
buffer = new int[tempInput.length];
println("'temp' contains "+tempInput.length+" strings");
output1 = createWriter("audioOutput.txt");
output2 = createWriter("audioOutput_Delay.txt");
int outputFuleSizeSamples = 44100; //2 second buffer - int delayTimeSamples = 4000;
int sampleIndex = 0; //start one index
//int sampleIndex2 = sampleIndex1+1; //start the second index
float sampleIn = 0.0; //This is still the current delay line input (write) sample value.
float sampleOut = 0.0;//This is still the
//int bitRate = 9;
float [] delayBuffer = new float[outputFuleSizeSamples]; - for(int j=0;j<outputFuleSizeSamples;j+=1){
delayBuffer[j]=0;
}
for(int i=0; i<tempInput.length;i+=1){- buffer[i] = int(tempInput[i]); //convert strings to integers
buffer[i] = int(buffer[i]); //some DSP process
sampleIn = int(buffer[i]);
//output1.println(buffer[i]);
} -
output1.println(sampleIn);
//Delay section//////////////////////////
//Read delayed sample from store
sampleOut = delayBuffer[sampleIndex];
//Write input sample to store
delayBuffer[sampleIndex] = sampleIn;
//Advance index to point to next sample
sampleIndex+=1;
//Loop back to the start if the end of the usable buffer is reached
if(sampleIndex==delayTimeSamples){
sampleIndex=0;
} - //Write the delayed output to the output2 file. This will be the same size as the
//maximum delay buffer.
output2.println(sampleOut); - output1.flush();
output1.close();
output2.flush();
output2.close();
exit();
1