Reputation: 81
I can't write a file when using WriterProcessor provided by Tarsos. The file exists, and no error is shown. But the file is empty, when I play it, there is no sound.
final Float srf = 44100.0F;
dispatcher = AudioDispatcherFactory.fromPipe(mRecordFile.getPath(), srf.intValue(), bufferSize, 0);
mOutputLowFile = new File(v.getContext().getFilesDir(), mOutputLowFileName);
RandomAccessFile outputFile = null;
try {
outputFile = new RandomAccessFile( mOutputLowFile, "rw");
} catch (FileNotFoundException e) {
Log.i(TAG, "onFFT: FileNotFoundException: " + e);
e.printStackTrace();
}
TarsosDSPAudioFormat outputFormat = new TarsosDSPAudioFormat(44100, 16, 1, true, false);
WriterProcessor writer = new WriterProcessor(outputFormat, outputFile);
dispatcher.addAudioProcessor(writer);
final AudioDispatcher finalDispatcher1 = dispatcher;
Thread recordingThread = new Thread(new Runnable() {
@Override
public void run() {
finalDispatcher1.run();
}
}, "recordingThread Thread");
recordingThread.start();
The outputFile is 1Ko big, whereas the original is 3 Ko.
Upvotes: 0
Views: 155
Reputation: 35
This is the code I'm using and it works - in the pipeline I put also a PitchProcessor (this code comes mostly from https://stackoverflow.com/a/45867328/4872992):
dispatcher = AudioDispatcherFactory.fromDefaultMicrophone(SAMPLE_RATE, 1024, 0);
AudioProcessor p = new PitchProcessor(PitchProcessor.PitchEstimationAlgorithm.FFT_YIN, 22050, 1024, pdh);
dispatcher.addAudioProcessor(p);
filePath = "/sdcard/recording_test.pcm";
RandomAccessFile outputFile = new RandomAccessFile(filePath, "rw");
TarsosDSPAudioFormat outputFormat = new TarsosDSPAudioFormat(SAMPLE_RATE, 16, 1, true, false);
WriterProcessor writer = new WriterProcessor(outputFormat, outputFile);
dispatcher.addAudioProcessor(writer);
recordingThread = new Thread(dispatcher, "Audio Dispatcher)");
recordingThread.start();
Upvotes: 1