spectrogram-android icon indicating copy to clipboard operation
spectrogram-android copied to clipboard

Visualising Spectrogram from file instead of Recording

Open leonardltk opened this issue 5 years ago • 0 comments

Hi, this is an amazing app! However, i tried to modify it to draw the spectrogram in a full audio file from my res/raw folder instead of recording from the microphone.

So far i have tried this, but it only draws a single frame. May i know why is that ?

	private void process_new() {
		// Update preferences
		loadPreferences();

		// Notify view
		frequencyView.setFFTResolution(fftResolution);
		timeView.setFFTResolution(fftResolution);

		// setBackgroundColor
		frequencyView.setBackgroundColor(Color.BLACK);
		timeView.setBackgroundColor(Color.BLACK);

		// Print live
		timeView.setWave(re);
		frequencyView.setMagnitudes(re);

		// Destroy
		runOnUiThread(() -> {
			frequencyView.invalidate();
			timeView.invalidate();
		});

	}
	public void PlaySong(View v){
		// Assume this is the loaded audio file, and fft is already processed
		// i use random numbers here just for convenience sake
		Random random = new java.util.Random();
		re = new float[fftResolution];
		for (Integer i=0; i<100; i++){
			for (Integer j=0; j<fftResolution; j++){
				re[j] = (float) random.nextInt(32)/100;
			}
			process_new();
		}
	}

On the new button that calls PlaySong, i expected it to display the latest waveform in timeView, but have 100 frames drawn in frequencyView. However this only draws 1 frames in the frequencyView. How should i edit the code do that it draws 100 frames as expected ?

leonardltk avatar Nov 18 '20 11:11 leonardltk