added toggle for analyzer

This commit is contained in:
Ahmet Inan 2015-01-13 23:37:54 +01:00
parent 6fd48f2815
commit 9b428ce8d4
6 changed files with 46 additions and 6 deletions

View file

@ -26,6 +26,7 @@ import android.support.v8.renderscript.RenderScript;
public class Decoder {
private boolean drawImage = true, quitThread = false;
private boolean enableAnalyzer = true;
private final MainActivity activity;
private final ImageView image;
private final SpectrumView spectrum;
@ -134,6 +135,7 @@ public class Decoder {
void sharper_image() { rsDecoder.invoke_decr_blur(); }
void toggle_debug() { rsDecoder.invoke_toggle_debug(); }
void toggle_auto() { rsDecoder.invoke_toggle_auto(); }
void enable_analyzer(boolean enable) { rsDecoder.invoke_enable_analyzer((enableAnalyzer = enable) ? 1 : 0); }
void raw_mode() { rsDecoder.invoke_raw_mode(); }
void robot36_mode() { rsDecoder.invoke_robot36_mode(); }
void robot72_mode() { rsDecoder.invoke_robot72_mode(); }
@ -243,7 +245,9 @@ public class Decoder {
activity.storeBitmap(Bitmap.createBitmap(savedBuffer, savedWidth[0], savedHeight[0], Bitmap.Config.ARGB_8888));
}
rsDecoderSpectrumBuffer.copyTo(spectrumBuffer);
spectrum.bitmap.setPixels(spectrumBuffer, 0, spectrum.bitmap.getWidth(), 0, 0, spectrum.bitmap.getWidth(), spectrum.bitmap.getHeight());
if (enableAnalyzer) {
rsDecoderSpectrumBuffer.copyTo(spectrumBuffer);
spectrum.bitmap.setPixels(spectrumBuffer, 0, spectrum.bitmap.getWidth(), 0, 0, spectrum.bitmap.getWidth(), spectrum.bitmap.getHeight());
}
}
}

View file

@ -35,6 +35,7 @@ import android.provider.MediaStore;
import android.support.v4.app.NotificationCompat;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ShareActionProvider;
@ -51,6 +52,7 @@ public class MainActivity extends Activity {
private NotificationManager manager;
private ShareActionProvider share;
private int notifyID = 1;
private boolean enableAnalyzer = true;
private void showNotification() {
Intent intent = new Intent(this, MainActivity.class);
@ -163,7 +165,9 @@ public class MainActivity extends Activity {
private void changeLayoutOrientation(Configuration config) {
boolean horizontal = config.orientation == Configuration.ORIENTATION_LANDSCAPE;
findViewById(R.id.spectrum).setLayoutParams(
View spectrum = findViewById(R.id.spectrum);
spectrum.setVisibility(enableAnalyzer ? View.VISIBLE : View.GONE);
spectrum.setLayoutParams(
new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT, horizontal ? 1.0f : 10.0f));
@ -189,6 +193,10 @@ public class MainActivity extends Activity {
case R.id.action_toggle_auto:
decoder.toggle_auto();
return true;
case R.id.action_toggle_analyzer:
decoder.enable_analyzer(enableAnalyzer ^= true);
changeLayoutOrientation(getResources().getConfiguration());
return true;
case R.id.action_raw_mode:
decoder.raw_mode();
return true;

View file

@ -18,6 +18,8 @@
android:orderInCategory="100" android:showAsAction="never" />
<item android:id="@+id/action_toggle_auto" android:title="@string/action_toggle_auto"
android:orderInCategory="100" android:showAsAction="never" />
<item android:id="@+id/action_toggle_analyzer" android:title="@string/action_toggle_analyzer"
android:orderInCategory="100" android:showAsAction="never" />
<item android:id="@+id/action_raw_mode" android:title="@string/action_raw_mode"
android:orderInCategory="100" android:showAsAction="never" />
<item android:id="@+id/action_robot36_mode" android:title="@string/action_robot36_mode"

View file

@ -5,6 +5,7 @@
<string name="decoder_running">"decoder is running</string>
<string name="action_toggle_auto">Toggle Auto Mode</string>
<string name="action_toggle_debug">Toggle Debug Mode</string>
<string name="action_toggle_analyzer">Toggle Analyzer</string>
<string name="action_raw_mode">Raw Mode</string>
<string name="action_robot36_mode">Robot36 Mode</string>
<string name="action_robot72_mode">Robot72 Mode</string>

View file

@ -20,6 +20,7 @@ limitations under the License.
static ema_t avg_amplitude, leader_lowpass;
static ddc_t cnt_ddc, dat_ddc;
static fmd_t cnt_fmd, dat_fmd;
static int disable_analyzer;
static int automatic_mode_detection;
static int debug_mode;
static int current_decoder;

View file

@ -39,15 +39,36 @@ static void freq_marker(int freq)
spectrum_buffer[i] = rgb(255, 255, 255);
}
static void init_analyzer(int sw, int sh)
static void show_rainbow()
{
spectrum_width = sw;
spectrum_height = sh;
for (int j = 0; j < spectrum_height; ++j)
for (int i = 0; i < spectrum_width; ++i)
spectrum_buffer[spectrum_width * j + i] = rainbow((float)i / spectrum_width);
}
static void clear_spectrum()
{
for (int i = 0; i < spectrum_height * spectrum_width; ++i)
spectrum_buffer[i] = 0;
}
static void init_analyzer(int sw, int sh)
{
disable_analyzer = 0;
spectrum_width = sw;
spectrum_height = sh;
show_rainbow();
}
void enable_analyzer(int enable)
{
disable_analyzer = !enable;
if (disable_analyzer)
clear_spectrum();
else
show_rainbow();
}
static void spectrum_analyzer(int amplitude)
{
const int M = 7;
@ -56,6 +77,9 @@ static void spectrum_analyzer(int amplitude)
static complex_t input[radix2_N];
static complex_t output[radix2_N];
if (disable_analyzer)
return;
#if 1
const int order = 5;
const int gain = pown(M, order);