Skip to content

Commit

Permalink
Merge pull request #392 from nicolas-f/no_a_weighting_spectrum
Browse files Browse the repository at this point in the history
No a weighting spectrum
  • Loading branch information
nicolas-f authored Sep 25, 2023
2 parents 318cc7d + f97ff8b commit e7d1581
Show file tree
Hide file tree
Showing 43 changed files with 6,245 additions and 1,662 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/noisecapture.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ jobs:
- uses: actions/checkout@v3
with:
submodules: true
- name: Set up JDK 11
uses: actions/setup-java@v1
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: 11
distribution: 'temurin'
java-version: '11'
- name: Put gradle.properties settings
run: |
touch gradle.properties
Expand All @@ -31,4 +32,9 @@ jobs:
$HOME/.m2/
$HOME/.gradle/caches/
$HOME/.gradle/wrapper/
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
- name: Archive production artifacts
uses: actions/upload-artifact@v2
with:
name: NoiseCapture_unsigned
path: app/build/outputs/apk/release/app-release-unsigned.apk
7 changes: 4 additions & 3 deletions .github/workflows/onomap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: 11
distribution: 'temurin'
java-version: '11'
- name: Building
run: cd onomap-geoserver/geoserver/ && ./gradlew test --info --stacktrace
- name: Clean
Expand Down
358 changes: 268 additions & 90 deletions app/src/main/java/org/noise_planet/noisecapture/AudioProcess.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -496,11 +496,6 @@ private void playNewTrack() {
double rms = dbToRms(99 - (splLoop++) * DB_STEP);
short[] data = makeWhiteNoiseSignal(44100, rms);
double[] fftCenterFreq = FFTSignalProcessing.computeFFTCenterFrequency(AudioProcess.REALTIME_SAMPLE_RATE_LIMITATION);
FFTSignalProcessing fftSignalProcessing = new FFTSignalProcessing(44100, fftCenterFreq, 44100);
fftSignalProcessing.addSample(data);
whiteNoisedB = fftSignalProcessing.computeGlobalLeq();
freqLeqStats.add(new LinearCalibrationResult(fftSignalProcessing.processSample(FFTSignalProcessing.WINDOW_TYPE.TUKEY, false, false)));
LOGGER.info("Emit white noise of "+whiteNoisedB+" dB");
if(audioTrack == null) {
audioTrack = new AudioTrack(getAudioOutput(), 44100, AudioFormat.CHANNEL_OUT_MONO,
AudioFormat.ENCODING_PCM_16BIT, data.length * (Short.SIZE / 8), AudioTrack.MODE_STATIC);
Expand Down Expand Up @@ -623,7 +618,7 @@ private void updateLineChart() {

// Read all white noise values for indexing before usage
int idStep = 0;
double referenceLevel = freqLeqStats.get(0).whiteNoiseLevel.getGlobaldBaValue();
double referenceLevel = freqLeqStats.get(0).whiteNoiseLevel.getWindowLeq();
for(LinearCalibrationResult result : freqLeqStats) {
ArrayList<Entry> yMeasure = new ArrayList<Entry>();
int idfreq = 0;
Expand All @@ -634,7 +629,7 @@ private void updateLineChart() {
yMeasure.add(new Entry(dbLevel, idfreq++));
}
LineDataSet freqSet = new LineDataSet(yMeasure, String.format(Locale.getDefault(),"%d dB",
(int)(result.whiteNoiseLevel.getGlobaldBaValue() - referenceLevel)));
(int)(result.whiteNoiseLevel.getWindowLeq() - referenceLevel)));
freqSet.setColor(ColorTemplate.COLORFUL_COLORS[idStep % ColorTemplate.COLORFUL_COLORS.length]);
freqSet.setFillColor(ColorTemplate.COLORFUL_COLORS[idStep % ColorTemplate.COLORFUL_COLORS.length]);
freqSet.setValueTextColor(Color.WHITE);
Expand Down Expand Up @@ -680,16 +675,16 @@ private void updateScatterChart() {
ArrayList<IScatterDataSet> dataSets = new ArrayList<IScatterDataSet>();

// Frequency count, one dataset by frequency
int dataSetCount = freqLeqStats.get(freqLeqStats.size() - 1).whiteNoiseLevel.getdBaLevels().length;
int dataSetCount = freqLeqStats.get(freqLeqStats.size() - 1).whiteNoiseLevel.getSpl().length;

Set<Integer> whiteNoiseValuesSet = new TreeSet<Integer>();


// Read all white noise values for indexing before usage
for(LinearCalibrationResult result : freqLeqStats) {
for(int idFreq = 0; idFreq < result.whiteNoiseLevel.getdBaLevels().length; idFreq++) {
float dbLevel = result.whiteNoiseLevel.getdBaLevels()[idFreq];
float referenceDbLevel = freqLeqStats.get(0).whiteNoiseLevel.getdBaLevels()[idFreq];
for(int idFreq = 0; idFreq < result.whiteNoiseLevel.getSpl().length; idFreq++) {
double dbLevel = result.whiteNoiseLevel.getSpl()[idFreq];
double referenceDbLevel = freqLeqStats.get(0).whiteNoiseLevel.getSpl()[idFreq];
whiteNoiseValuesSet.add((int)(dbLevel - referenceDbLevel));
}
}
Expand All @@ -712,8 +707,8 @@ private void updateScatterChart() {
ArrayList<Entry> yMeasure = new ArrayList<Entry>();
for (LinearCalibrationResult result : freqLeqStats) {
float dbLevel = (float) result.measure[freqId].getLeqMean();
float referenceDbLevel = freqLeqStats.get(0).whiteNoiseLevel.getdBaLevels()[freqId];
int whiteNoise = (int) (result.whiteNoiseLevel.getdBaLevels()[freqId] - referenceDbLevel);
double referenceDbLevel = freqLeqStats.get(0).whiteNoiseLevel.getSpl()[freqId];
int whiteNoise = (int) (result.whiteNoiseLevel.getSpl()[freqId] - referenceDbLevel);
YMax = Math.max(YMax, dbLevel);
YMin = Math.min(YMin, dbLevel);
yMeasure.add(new Entry(dbLevel, Arrays.binarySearch(whiteNoiseValues, whiteNoise)));
Expand Down Expand Up @@ -746,7 +741,7 @@ private double[] computePearson() {
return null;
}
// Frequency count, one dataset by frequency
int dataSetCount = freqLeqStats.get(freqLeqStats.size() - 1).whiteNoiseLevel.getdBaLevels().length;
int dataSetCount = freqLeqStats.get(freqLeqStats.size() - 1).whiteNoiseLevel.getSpl().length;
double[] pearsonCoefficient = new double[dataSetCount];

StringBuilder log = new StringBuilder();
Expand All @@ -756,7 +751,7 @@ private double[] computePearson() {
int idStep = 0;
for(LinearCalibrationResult result : freqLeqStats) {
double dbLevel = result.measure[freqId].getLeqMean();
double whiteNoise = result.whiteNoiseLevel.getdBaLevels()[freqId];
double whiteNoise = result.whiteNoiseLevel.getSpl()[freqId];
xValues[idStep] = whiteNoise;
yValues[idStep] = dbLevel;
if(freqId == 0) {
Expand Down Expand Up @@ -955,9 +950,9 @@ public void setGlobalMeasure(LeqStats globalMeasure) {
}

public void pushMeasure(FFTSignalProcessing.ProcessingResult measure) {
float[] measureLevels = measure.getdBaLevels();
double[] measureLevels = measure.getSpl();
if(this.measure == null) {
this.measure = new LeqStats[measure.getdBaLevels().length];
this.measure = new LeqStats[measure.getSpl().length];
for(int idFreq = 0; idFreq < this.measure.length; idFreq++) {
this.measure[idFreq] = new LeqStats();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
import org.noise_planet.jwarble.MessageCallback;
import org.noise_planet.jwarble.OpenWarble;
import org.orbisgis.sos.LeqStats;
import org.orbisgis.sos.SOSSignalProcessing;
import org.orbisgis.sos.ThirdOctaveBandsFiltering;
import org.orbisgis.sos.Window;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -563,7 +563,7 @@ private static class AcousticModemListener implements AudioProcess.ProcessingThr
private final AtomicBoolean canceled;
private final AtomicBoolean recording;
private OpenWarble openWarble;
private Queue<short[]> bufferToProcess = new ConcurrentLinkedQueue<short[]>();
private Queue<float[]> bufferToProcess = new ConcurrentLinkedQueue<float[]>();

public AcousticModemListener(CalibrationService calibrationService, AtomicBoolean
canceled, AtomicBoolean recording) {
Expand All @@ -577,7 +577,7 @@ public void setAcousticModem(OpenWarble openWarble) {
}

@Override
public void addSample(short[] sample) {
public void addSample(float[] sample) {
if(recording.get()) {
bufferToProcess.add(sample);
}
Expand All @@ -587,14 +587,14 @@ public void addSample(short[] sample) {
public void run() {
while (!canceled.get() && openWarble != null) {
while(!bufferToProcess.isEmpty()) {
short[] buffer = bufferToProcess.poll();
float[] buffer = bufferToProcess.poll();
if(buffer != null) {
boolean doProcessBuffer = true;
while(doProcessBuffer) {
doProcessBuffer = false;
double[] samples = new double[Math.min(buffer.length, openWarble.getMaxPushSamplesLength())];
for (int i = 0; i < samples.length; i++) {
samples[i] = buffer[i] / (double)Short.MAX_VALUE;
samples[i] = buffer[i];
}
openWarble.pushSamples(samples);
if (buffer.length > samples.length) {
Expand All @@ -611,6 +611,31 @@ public void run() {
}
}
}

@Override
public void setAweighting(boolean Aweighting) {

}

@Override
public void setGain(double gain) {

}

@Override
public double getProcessingDelayTime() {
return 0;
}

@Override
public boolean isProcessing() {
return false;
}

@Override
public double getLeq() {
return 0;
}
}

private static class PinkNoiseFeed implements Runnable {
Expand All @@ -625,7 +650,7 @@ public PinkNoiseFeed(CalibrationService calibrationService, AudioTrack audioTrac
this.calibrationService = calibrationService;
this.audioTrack = audioTrack;
sampleBufferLength = (int)(audioTrack.getSampleRate() * maxLength);
signal = SOSSignalProcessing.makePinkNoise(sampleBufferLength, (short)powerRMS, 0);
signal = Window.makePinkNoise(sampleBufferLength, (short)powerRMS, 0);
bufferSize = (int)(audioTrack.getSampleRate() * 0.1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ record = recordList.get(0);
// Message for starting a record
Toast.makeText(getApplicationContext(),
getString(R.string.no_results), Toast.LENGTH_LONG).show();
initDrawer(record != null ? record.getId() : null);
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,11 @@ protected void checkTransferResults() {
*/
public boolean isOnline() {
try {
URL url = new URL(MeasurementUploadWPS.CHECK_UPLOAD_AVAILABILITY);
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
String serverUrl = sharedPref.getString("settings_onomap_url",
MeasurementUploadWPS.BASE_URL);
serverUrl += "/geoserver/ows?service=wps&version=1.0.0&request=GetCapabilities";
URL url = new URL(serverUrl);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
int code = urlConnection.getResponseCode();
return code == 200 || code == 301 || code == 302;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,12 +438,12 @@ private void updateSpectrumGUI() {
ArrayList<String> xVals = new ArrayList<String>();
ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
double[] freqLabels = measurementService.getAudioProcess().getRealtimeCenterFrequency();
float[] freqValues = measurementService.getAudioProcess().getThirdOctaveFrequencySPL();
double[] freqValues = measurementService.getAudioProcess().getThirdOctaveFrequencySPL();
for(int idfreq =0; idfreq < freqLabels.length; idfreq++) {
xVals.add(Spectrogram.formatFrequency((int)freqLabels[idfreq]));
// Sum values
// Compute frequency range covered by frequency
yVals1.add(new BarEntry(new float[] {freqValues[idfreq]}, idfreq));
yVals1.add(new BarEntry(new float[] {(float)freqValues[idfreq]}, idfreq));
}

BarDataSet set1 = new BarDataSet(yVals1, "DataSet");
Expand Down Expand Up @@ -483,7 +483,7 @@ public void run() {
AudioProcess.STATE.CLOSED && !activity.measurementService.isCanceled()) {
try {
Thread.sleep(200);
int progress = activity.measurementService.getAudioProcess().getRemainingNotProcessSamples();
int progress = (int)(activity.measurementService.getAudioProcess().getRemainingNotProcessTime());
if(progress != lastShownProgress) {
lastShownProgress = progress;
activity.runOnUiThread(new SetDialogMessage(processingDialog, activity.getResources().getString(R.string.measurement_processlastsamples,
Expand Down Expand Up @@ -687,7 +687,8 @@ public void onClick(View v) {
ProgressDialog myDialog = new ProgressDialog(activity);
if (!activity.measurementService.isCanceled()) {
myDialog.setMessage(resources.getString(R.string.measurement_processlastsamples,
activity.measurementService.getAudioProcess().getRemainingNotProcessSamples()));
(int)(activity.measurementService.getAudioProcess()
.getRemainingNotProcessTime())));
myDialog.setCancelable(false);
myDialog.setButton(DialogInterface.BUTTON_NEGATIVE,
resources.getText(R.string.text_CANCEL_data_transfer),
Expand Down Expand Up @@ -774,15 +775,15 @@ public void run() {
accuracyImageHint.setImageResource(R.drawable.gps_off);
accuracyText.setText(R.string.no_gps_hint);
}
// Update current location of user
final double leq = activity.measurementService.getAudioProcess().getLeq(false);
activity.setData(activity.measurementService.getAudioProcess().getLeq(false));
// Change the text and the textcolor in the corresponding textview
// for the Leqi value
LeqStats leqStats =
activity.measurementService.getFastLeqStats();
final TextView mTextView = (TextView) activity.findViewById(R.id.textView_value_SL_i);
formatdBA(leq, mTextView);
// Update current location of user
double lastLaeqFast = activity.measurementService.getLAeq();
activity.setData(lastLaeqFast);
final TextView mTextView = activity.findViewById(R.id.textView_value_SL_i);
formatdBA(lastLaeqFast, mTextView);
if(activity.measurementService.getLeqAdded() != 0) {
// Stats are only available if the recording of previous leq are activated
final TextView valueMin = (TextView) activity.findViewById(R.id
Expand All @@ -795,9 +796,7 @@ public void run() {
.textView_value_Mean_i);
formatdBA(leqStats.getLeqMean(), valueMean);
}


int nc = MeasurementActivity.getNEcatColors(leq); // Choose the color category in
int nc = MeasurementActivity.getNEcatColors(lastLaeqFast); // Choose the color category in
// function of the sound level
mTextView.setTextColor(activity.NE_COLORS[nc]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ private enum LISTENER {GPS, NETWORK, PASSIVE}
private NotificationCompat.Builder notification;
private Notification notificationInstance;
private ListenToMicrophoneDeviceSwitch audioRecordingCallback = null;
private double LAeq = 0; // last acquired fast lAeq

/**
* Class for clients to access. Because we know this service always
Expand Down Expand Up @@ -147,6 +148,13 @@ public LeqStats getLeqStats() {
return leqStats;
}

public double getLAeq() {
return LAeq;
}

public void setLAeq(double LAeq) {
this.LAeq = LAeq;
}

public LeqStats getFastLeqStats() {
return leqStatsFast;
Expand Down Expand Up @@ -619,7 +627,7 @@ public void propertyChange(PropertyChangeEvent event) {
location.getAccuracy(), location.getTime());
}
double[] freqValues = measurementService.audioProcess.getDelayedCenterFrequency();
final float[] leqs = measure.getLeqs();
final double[] leqs = measure.getLeqs();
// Add leqs to stats
measurementService.leqStats.addLeq(measure.getGlobaldBaValue());
List<Storage.LeqValue> leqValueList = new ArrayList<>(leqs.length);
Expand All @@ -633,9 +641,10 @@ public void propertyChange(PropertyChangeEvent event) {
measurementService.listeners.firePropertyChange(PROP_NEW_MEASUREMENT, null, new MeasurementEventObject(measure, leq));
}
} else if(AudioProcess.PROP_FAST_LEQ.equals(event.getPropertyName())) {
AudioProcess.AudioMeasureResult measure =
(AudioProcess.AudioMeasureResult) event.getNewValue();
measurementService.setLAeq(measure.getGlobaldBaValue());
if (measurementService.isStoring() && !measurementService.isPaused.get()) {
AudioProcess.AudioMeasureResult measure =
(AudioProcess.AudioMeasureResult) event.getNewValue();
measurementService.leqStatsFast.addLeq(measure.getGlobaldBaValue());
}
} else if (AudioProcess.PROP_STATE_CHANGED.equals(event.getPropertyName())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
package org.noise_planet.noisecapture;

import android.app.Activity;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Base64;
import android.util.Base64OutputStream;

Expand All @@ -49,7 +51,6 @@
public class MeasurementUploadWPS {
Activity activity;
public static final String BASE_URL = "https://onomap-gs.noise-planet.org";
public static final String CHECK_UPLOAD_AVAILABILITY = "https://onomap-gs.noise-planet.org/geoserver/ows?service=wps&version=1.0.0&request=GetCapabilities";

public MeasurementUploadWPS(Activity activity) {
this.activity = activity;
Expand All @@ -65,9 +66,9 @@ public void uploadRecord(int recordId) throws IOException {
// throw new IOException(activity.getText(R.string.error_already_uploaded).toString());
//}

URL url;
url = new URL(BASE_URL + "/geoserver/wps");

SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(activity);
String serverUrl = sharedPref.getString("settings_onomap_url", BASE_URL);
URL url = new URL(serverUrl + "/geoserver/wps");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("Content-Type", "text/xml");
conn.setReadTimeout(15000);
Expand Down
Loading

0 comments on commit e7d1581

Please sign in to comment.