kopia lustrzana https://github.com/xdsopl/robot36
update rendering mode and activity title from decoder
rodzic
3401038ab1
commit
eb7a494fe4
|
|
@ -37,6 +37,8 @@ public class ImageView extends SurfaceView implements SurfaceHolder.Callback {
|
|||
boolean takeABreak = true, cantTouchThis = true;
|
||||
int imageWidth = 320;
|
||||
int imageHeight = 240;
|
||||
MainActivity activity;
|
||||
String title;
|
||||
final SurfaceHolder holder;
|
||||
final Bitmap bitmap;
|
||||
final Paint paint;
|
||||
|
|
@ -47,11 +49,22 @@ public class ImageView extends SurfaceView implements SurfaceHolder.Callback {
|
|||
final int sampleRate = 44100;
|
||||
final short[] audioBuffer;
|
||||
final int[] pixelBuffer;
|
||||
final int[] currentMode;
|
||||
|
||||
final RenderScript rs;
|
||||
final Allocation rsDecoderAudioBuffer, rsDecoderPixelBuffer, rsDecoderValueBuffer;
|
||||
final Allocation rsDecoderAudioBuffer, rsDecoderPixelBuffer;
|
||||
final Allocation rsDecoderValueBuffer, rsDecoderCurrentMode;
|
||||
final ScriptC_decoder rsDecoder;
|
||||
|
||||
final int mode_raw = 0;
|
||||
final int mode_robot36 = 1;
|
||||
final int mode_robot72 = 2;
|
||||
final int mode_martin1 = 3;
|
||||
final int mode_martin2 = 4;
|
||||
final int mode_scottie1 = 5;
|
||||
final int mode_scottie2 = 6;
|
||||
final int mode_scottieDX = 7;
|
||||
|
||||
final Thread thread = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
@ -92,93 +105,121 @@ public class ImageView extends SurfaceView implements SurfaceHolder.Callback {
|
|||
audioBuffer = new short[framesPerSecond * bufferSizeInSamples];
|
||||
|
||||
int maxHorizontalLength = 2 * sampleRate;
|
||||
currentMode = new int[1];
|
||||
|
||||
rs = RenderScript.create(context);
|
||||
rsDecoderAudioBuffer = Allocation.createSized(rs, Element.I16(rs), audioBuffer.length, Allocation.USAGE_SHARED | Allocation.USAGE_SCRIPT);
|
||||
rsDecoderValueBuffer = Allocation.createSized(rs, Element.U8(rs), maxHorizontalLength, Allocation.USAGE_SCRIPT);
|
||||
rsDecoderPixelBuffer = Allocation.createSized(rs, Element.I32(rs), pixelBuffer.length, Allocation.USAGE_SHARED | Allocation.USAGE_SCRIPT);
|
||||
rsDecoderCurrentMode = Allocation.createSized(rs, Element.I32(rs), 1, Allocation.USAGE_SHARED | Allocation.USAGE_SCRIPT);
|
||||
rsDecoder = new ScriptC_decoder(rs);
|
||||
rsDecoder.bind_audio_buffer(rsDecoderAudioBuffer);
|
||||
rsDecoder.bind_value_buffer(rsDecoderValueBuffer);
|
||||
rsDecoder.bind_pixel_buffer(rsDecoderPixelBuffer);
|
||||
rsDecoder.bind_current_mode(rsDecoderCurrentMode);
|
||||
rsDecoder.invoke_initialize(sampleRate, maxHorizontalLength, bitmap.getWidth(), bitmap.getHeight());
|
||||
|
||||
thread.start();
|
||||
}
|
||||
void debug_sync() {
|
||||
synchronized (thread) {
|
||||
imageWidth = 320;
|
||||
imageHeight = bitmap.getHeight();
|
||||
rsDecoder.invoke_debug_sync();
|
||||
}
|
||||
}
|
||||
void debug_image() {
|
||||
synchronized (thread) {
|
||||
imageWidth = 320;
|
||||
imageHeight = bitmap.getHeight();
|
||||
rsDecoder.invoke_debug_image();
|
||||
}
|
||||
}
|
||||
void debug_both() {
|
||||
synchronized (thread) {
|
||||
imageWidth = 320;
|
||||
imageHeight = bitmap.getHeight();
|
||||
rsDecoder.invoke_debug_both();
|
||||
}
|
||||
}
|
||||
void robot36_mode() {
|
||||
synchronized (thread) {
|
||||
imageWidth = 320;
|
||||
imageHeight = 240;
|
||||
rsDecoder.invoke_robot36_mode();
|
||||
}
|
||||
}
|
||||
void robot72_mode() {
|
||||
synchronized (thread) {
|
||||
imageWidth = 320;
|
||||
imageHeight = 240;
|
||||
rsDecoder.invoke_robot72_mode();
|
||||
}
|
||||
}
|
||||
void martin1_mode() {
|
||||
synchronized (thread) {
|
||||
imageWidth = 320;
|
||||
imageHeight = 256;
|
||||
rsDecoder.invoke_martin1_mode();
|
||||
}
|
||||
}
|
||||
void martin2_mode() {
|
||||
synchronized (thread) {
|
||||
imageWidth = 320;
|
||||
imageHeight = 256;
|
||||
rsDecoder.invoke_martin2_mode();
|
||||
}
|
||||
}
|
||||
void scottie1_mode() {
|
||||
synchronized (thread) {
|
||||
imageWidth = 320;
|
||||
imageHeight = 256;
|
||||
rsDecoder.invoke_scottie1_mode();
|
||||
}
|
||||
}
|
||||
void scottie2_mode() {
|
||||
synchronized (thread) {
|
||||
imageWidth = 320;
|
||||
imageHeight = 256;
|
||||
rsDecoder.invoke_scottie2_mode();
|
||||
}
|
||||
}
|
||||
void scottieDX_mode() {
|
||||
synchronized (thread) {
|
||||
imageWidth = 320;
|
||||
imageHeight = 256;
|
||||
rsDecoder.invoke_scottieDX_mode();
|
||||
}
|
||||
}
|
||||
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
|
||||
|
||||
void updateTitle(int id) { activity.updateTitle(activity.getString(id)); }
|
||||
void switch_mode(int mode)
|
||||
{
|
||||
synchronized (thread) {
|
||||
canvasWidth = width;
|
||||
canvasHeight = height;
|
||||
switch (mode) {
|
||||
case mode_raw:
|
||||
imageWidth = 320;
|
||||
imageHeight = bitmap.getHeight();
|
||||
updateTitle(R.string.action_debug_mode);
|
||||
break;
|
||||
case mode_robot36:
|
||||
imageWidth = 320;
|
||||
imageHeight = 240;
|
||||
updateTitle(R.string.action_robot36_mode);
|
||||
break;
|
||||
case mode_robot72:
|
||||
imageWidth = 320;
|
||||
imageHeight = 240;
|
||||
updateTitle(R.string.action_robot72_mode);
|
||||
break;
|
||||
case mode_martin1:
|
||||
imageWidth = 320;
|
||||
imageHeight = 256;
|
||||
updateTitle(R.string.action_martin1_mode);
|
||||
break;
|
||||
case mode_martin2:
|
||||
imageWidth = 320;
|
||||
imageHeight = 256;
|
||||
updateTitle(R.string.action_martin2_mode);
|
||||
break;
|
||||
case mode_scottie1:
|
||||
imageWidth = 320;
|
||||
imageHeight = 256;
|
||||
updateTitle(R.string.action_scottie1_mode);
|
||||
break;
|
||||
case mode_scottie2:
|
||||
imageWidth = 320;
|
||||
imageHeight = 256;
|
||||
updateTitle(R.string.action_scottie2_mode);
|
||||
break;
|
||||
case mode_scottieDX:
|
||||
imageWidth = 320;
|
||||
imageHeight = 256;
|
||||
updateTitle(R.string.action_scottieDX_mode);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
void pause() {
|
||||
|
|
@ -201,6 +242,12 @@ public class ImageView extends SurfaceView implements SurfaceHolder.Callback {
|
|||
thread.notify();
|
||||
}
|
||||
}
|
||||
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
|
||||
synchronized (thread) {
|
||||
canvasWidth = width;
|
||||
canvasHeight = height;
|
||||
}
|
||||
}
|
||||
public void surfaceCreated(SurfaceHolder holder) {
|
||||
synchronized (thread) {
|
||||
cantTouchThis = false;
|
||||
|
|
@ -241,5 +288,8 @@ public class ImageView extends SurfaceView implements SurfaceHolder.Callback {
|
|||
rsDecoder.invoke_decode(samples);
|
||||
rsDecoderPixelBuffer.copyTo(pixelBuffer);
|
||||
bitmap.setPixels(pixelBuffer, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
|
||||
|
||||
rsDecoderCurrentMode.copyTo(currentMode);
|
||||
switch_mode(currentMode[0]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,11 +24,25 @@ import android.view.MenuItem;
|
|||
|
||||
public class MainActivity extends Activity {
|
||||
ImageView view;
|
||||
|
||||
void updateTitle(final String newTitle)
|
||||
{
|
||||
if (getTitle() != newTitle) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
setTitle(newTitle);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
view = (ImageView)findViewById(R.id.image);
|
||||
view.activity = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
<string name="action_debug_sync">Debug Sync</string>
|
||||
<string name="action_debug_image">Debug Image</string>
|
||||
<string name="action_debug_both">Debug Image and Sync</string>
|
||||
<string name="action_debug_mode">Debug Mode</string>
|
||||
<string name="action_robot36_mode">Robot36 Mode</string>
|
||||
<string name="action_robot72_mode">Robot72 Mode</string>
|
||||
<string name="action_martin1_mode">Martin1 Mode</string>
|
||||
|
|
|
|||
|
|
@ -27,10 +27,7 @@ limitations under the License.
|
|||
#include "modes.rsh"
|
||||
#include "constants.rsh"
|
||||
#include "state.rsh"
|
||||
|
||||
short *audio_buffer;
|
||||
uchar *value_buffer;
|
||||
uchar4 *pixel_buffer;
|
||||
#include "exports.rsh"
|
||||
|
||||
static inline uchar4 rgb(uchar r, uchar g, uchar b) { return (uchar4){ b, g, r, 255 }; }
|
||||
static inline uchar4 yuv(uchar y, uchar u, uchar v)
|
||||
|
|
@ -145,13 +142,13 @@ void decode(int samples) {
|
|||
int sync_pulse = !sync_level && sync_counter >= sync_length;
|
||||
sync_counter = sync_level ? sync_counter + 1 : 0;
|
||||
|
||||
if (current_mode != mode_raw) {
|
||||
if (*current_mode != mode_raw) {
|
||||
int detected_mode = calibration_detector(dat_value, cnt_active, cnt_quantized);
|
||||
if (detected_mode >= 0)
|
||||
reset();
|
||||
switch_mode(detected_mode);
|
||||
int estimated_mode = scanline_estimator(sync_level);
|
||||
if (estimated_mode >= 0 && estimated_mode != current_mode)
|
||||
if (estimated_mode >= 0 && estimated_mode != *current_mode)
|
||||
reset();
|
||||
switch_mode(estimated_mode);
|
||||
}
|
||||
|
|
@ -167,7 +164,7 @@ void decode(int samples) {
|
|||
seperator_counter = 0;
|
||||
continue;
|
||||
}
|
||||
switch (current_mode) {
|
||||
switch (*current_mode) {
|
||||
case mode_robot36:
|
||||
robot36_decoder();
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
Copyright 2014 Ahmet Inan <xdsopl@googlemail.com>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef EXPORTS_RSH
|
||||
#define EXPORTS_RSH
|
||||
|
||||
short *audio_buffer;
|
||||
uchar *value_buffer;
|
||||
uchar4 *pixel_buffer;
|
||||
int *current_mode;
|
||||
|
||||
#endif
|
||||
|
|
@ -19,12 +19,13 @@ limitations under the License.
|
|||
|
||||
#include "constants.rsh"
|
||||
#include "state.rsh"
|
||||
#include "exports.rsh"
|
||||
|
||||
void debug_sync()
|
||||
{
|
||||
save_cnt = 1;
|
||||
save_dat = 0;
|
||||
current_mode = mode_raw;
|
||||
*current_mode = mode_raw;
|
||||
sync_length = minimum_sync_length;
|
||||
maximum_length = buffer_length;
|
||||
scanline_length = maximum_length;
|
||||
|
|
@ -33,7 +34,7 @@ void debug_image()
|
|||
{
|
||||
save_dat = 1;
|
||||
save_cnt = 0;
|
||||
current_mode = mode_raw;
|
||||
*current_mode = mode_raw;
|
||||
sync_length = minimum_sync_length;
|
||||
maximum_length = buffer_length;
|
||||
scanline_length = maximum_length;
|
||||
|
|
@ -42,7 +43,7 @@ void debug_both()
|
|||
{
|
||||
save_cnt = 1;
|
||||
save_dat = 1;
|
||||
current_mode = mode_raw;
|
||||
*current_mode = mode_raw;
|
||||
sync_length = minimum_sync_length;
|
||||
maximum_length = buffer_length;
|
||||
scanline_length = maximum_length;
|
||||
|
|
@ -51,7 +52,7 @@ void robot36_mode()
|
|||
{
|
||||
save_dat = 1;
|
||||
save_cnt = 0;
|
||||
current_mode = mode_robot36;
|
||||
*current_mode = mode_robot36;
|
||||
const float tolerance = 0.8f;
|
||||
const float settling_time = 0.0011f;
|
||||
const float sync_seconds = 0.009f;
|
||||
|
|
@ -75,7 +76,7 @@ void robot72_mode()
|
|||
{
|
||||
save_dat = 1;
|
||||
save_cnt = 0;
|
||||
current_mode = mode_robot72;
|
||||
*current_mode = mode_robot72;
|
||||
const float tolerance = 0.8f;
|
||||
const float settling_time = 0.0011f;
|
||||
const float sync_seconds = 0.009f;
|
||||
|
|
@ -103,7 +104,7 @@ void martin1_mode()
|
|||
{
|
||||
save_cnt = 0;
|
||||
save_dat = 1;
|
||||
current_mode = mode_martin1;
|
||||
*current_mode = mode_martin1;
|
||||
const float tolerance = 0.5f;
|
||||
const float sync_seconds = 0.004862f;
|
||||
const float sync_porch_seconds = 0.000572f;
|
||||
|
|
@ -126,7 +127,7 @@ void martin2_mode()
|
|||
{
|
||||
save_cnt = 0;
|
||||
save_dat = 1;
|
||||
current_mode = mode_martin2;
|
||||
*current_mode = mode_martin2;
|
||||
const float tolerance = 0.5f;
|
||||
const float sync_seconds = 0.004862f;
|
||||
const float sync_porch_seconds = 0.000572f;
|
||||
|
|
@ -149,7 +150,7 @@ void scottie1_mode()
|
|||
{
|
||||
save_cnt = 0;
|
||||
save_dat = 1;
|
||||
current_mode = mode_scottie1;
|
||||
*current_mode = mode_scottie1;
|
||||
const float tolerance = 0.8f;
|
||||
const float settling_time = 0.0011f;
|
||||
const float sync_seconds = 0.009f;
|
||||
|
|
@ -173,7 +174,7 @@ void scottie2_mode()
|
|||
{
|
||||
save_cnt = 0;
|
||||
save_dat = 1;
|
||||
current_mode = mode_scottie2;
|
||||
*current_mode = mode_scottie2;
|
||||
const float tolerance = 0.8f;
|
||||
const float settling_time = 0.0011f;
|
||||
const float sync_seconds = 0.009f;
|
||||
|
|
@ -197,7 +198,7 @@ void scottieDX_mode()
|
|||
{
|
||||
save_cnt = 0;
|
||||
save_dat = 1;
|
||||
current_mode = mode_scottieDX;
|
||||
*current_mode = mode_scottieDX;
|
||||
const float tolerance = 0.8f;
|
||||
const float settling_time = 0.0011f;
|
||||
const float sync_seconds = 0.009f;
|
||||
|
|
@ -220,7 +221,7 @@ void scottieDX_mode()
|
|||
|
||||
static void switch_mode(int new_mode)
|
||||
{
|
||||
if (new_mode == current_mode)
|
||||
if (new_mode == *current_mode)
|
||||
return;
|
||||
switch (new_mode) {
|
||||
case mode_robot36:
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ limitations under the License.
|
|||
static ema_t avg_power, leader_lowpass;
|
||||
static ddc_t cnt_ddc, dat_ddc;
|
||||
static fmd_t cnt_fmd, dat_fmd;
|
||||
static int sample_rate, current_mode, even_hpos;
|
||||
static int sample_rate, even_hpos;
|
||||
static int maximum_variance, minimum_sync_length;
|
||||
static int scanline_length, minimum_length, maximum_length;
|
||||
static int vis_timeout, vis_length, bit_length;
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue