TarsosDSP icon indicating copy to clipboard operation
TarsosDSP copied to clipboard

AudioPlayer, when reading file : loosing audio data and can't read properly?

Open chris282 opened this issue 7 years ago • 7 comments

Hello after many trials, I was not able to get the AudioPlayer working normally. The sound is jerky , clipped , it is like the audio processor dont read the whole audio file but jump to a next step.

I tried this without any transformation on the audio stream : just one AudioProcessor is added. See the example :

File audioFile = new File(fileName);
                AudioFormat format=null;

            try {


                            dispatcher = AudioDispatcherFactory.fromFile(audioFile, 4096*100, 0);
                              format = AudioSystem.getAudioFileFormat(audioFile).getFormat();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        new Thread(dispatcher,"Audio dispatching").start();

I put here a enormous value of 4096*100 to show the problem. The problem is the same with values of : 2048 , 0 1024 , 0 2048 , 1024 etc The is still a loss of audio : we can't hear the original music

Is this normal and due to the dsp implementation?

The classes in the "examples" folder does not help, like Spectrogram.java that is not working using a AudioPlayer that play no sound at all, certainly due to bufferSize and overlap values.

I have this need because i want exactly what the Spectrogram.java is supposed to do : get a frequency visual with the sound played at the same time, with smoothness

chris282 avatar Jul 08 '16 09:07 chris282

Hi,

Could you give some details on the system you are using? Android? Windows? JRE?

Regards

Joren

JorenSix avatar Jul 12 '16 12:07 JorenSix

hello standart version (not android), Tarsos DSP 2.3, Windows, JDK 8, Netbeans 8.1

chris282 avatar Jul 12 '16 15:07 chris282

Same here, jerky sound like every period of some time some bytes are missing. Also as chris282 mentioned when buffer size is big enough, the sound is normal, and I suppose the 'stops' in sound are between buffers.

mustafin avatar Aug 29 '16 15:08 mustafin

I have a strange behavior, when using microphone input and setting values like AudioDispatcher dispatcher = AudioDispatcherFactory.fromDefaultMicrophone(22050,2048,0); It plays normal.

mustafin avatar Aug 29 '16 16:08 mustafin

Also I found that this issue happens only with stereo(2 channels) input.

mustafin avatar Sep 07 '16 04:09 mustafin

I had the same problem here, but I think I guess the magic numbers:

int audioBufferSize = format.getFrameSize() - 2; int bufferOverlap = 0;

I don't know why...

I think you should change the documentation of those numbers to something more meaningful 👍

celsogg avatar Nov 11 '16 04:11 celsogg

@celsogg How did you get AudioFormat instance?

yeahia2508 avatar Oct 23 '18 07:10 yeahia2508