Changeset 33342 in osm for applications/editors/josm/plugins/wms-turbo-challenge2/src/wmsturbochallenge/EngineSound.java
- Timestamp:
- 2017-05-27T22:56:30+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/wms-turbo-challenge2/src/wmsturbochallenge/EngineSound.java
r32914 r33342 1 1 /* 2 2 * GPLv2 or 3, Copyright (c) 2010 Andrzej Zaborowski 3 *4 * This class simulates a car engine. What does a car engine do? It5 * makes a pc-speaker-like buzz. The PC Speaker could only emit6 * a (nearly) square wave and we simulate it here for maximum realism.7 3 */ 8 4 package wmsturbochallenge; … … 16 12 import javax.sound.sampled.SourceDataLine; 17 13 14 /** 15 * This class simulates a car engine. What does a car engine do? It 16 * makes a pc-speaker-like buzz. The PC Speaker could only emit 17 * a (nearly) square wave and we simulate it here for maximum realism. 18 */ 18 19 class EngineSound { 19 publicEngineSound() {20 EngineSound() { 20 21 rpm = 0.0; 21 22 } … … 79 80 if (accel > 0.0 && rpm > 1.0 + n * 0.2 && speed > 0.0) { 80 81 rpm = 0.3 + n * 0.2; 81 n 82 n++; 82 83 } else if (accel < 0.0 && rpm < 0.3) { 83 84 if (n > 0) { 84 85 rpm = 0.7 + n * 0.1; 85 n 86 n--; 86 87 } else 87 88 rpm = 0.2; … … 133 134 bufferlen *= 2; 134 135 byte[] buffer = new byte[bufferlen]; 135 for (int b = 0; b < bufferlen; 136 for (int b = 0; b < bufferlen;) { 136 137 int j; 137 for (j = wavelen / 2; j > 0; j 138 buffer[b 139 buffer[b 138 for (j = wavelen / 2; j > 0; j--) { 139 buffer[b++] = (byte) (value >> 8); 140 buffer[b++] = (byte) (value & 0xff); 140 141 } 141 142 value = 0x10000 - value; 142 for (j = wavelen - wavelen / 2; j > 0; j 143 buffer[b 144 buffer[b 143 for (j = wavelen - wavelen / 2; j > 0; j--) { 144 buffer[b++] = (byte) (value >> 8); 145 buffer[b++] = (byte) (value & 0xff); 145 146 } 146 147 value = 0x10000 - value;
Note:
See TracChangeset
for help on using the changeset viewer.