I am trying to do resampling in android using this library https://github.com/intervigilium/libresample/blob/master/src/net/sourceforge/resample/Resample.java#L6
but I dont know exactly what to fill in the Parameters
I want to Resample an audio file
File mySound = new File("/mySound.wav");
to 44,100 kHz
how do i do it with this library: Library Code shown below..
package net.sourceforge.resample;
public class Resample {
public static final int DEFAULT_BUFFER_SIZE = 4096;
public static final int MAX_CHANNELS = 2;
public static final int CHANNEL_MONO = 0;
public static final int CHANNEL_LEFT = 0;
public static final int CHANNEL_RIGHT = 1;
private static final String RESAMPLE_LIB = "resample";
static {
System.loadLibrary(RESAMPLE_LIB);
}
public static native void downmix(short outputBuffer[], short inputLeft[], short inputRight[], int numSamples);
public static native int resample(double factor, short inputBuffer[], short outputBuffer[], int numSamples);
public static native void initialize(int inputRate, int outputRate, int bufferSize, int channels);
public static native double getFactor();
public static native int process(short inputBuffer[], short outputBuffer[], int channel, boolean isLast);
public static native void close();
}
Related
I am very new to both java and opencv especially android. From reading, I know that camera2 API support higher resolution compared to camera1 API, which is useful for my project.
I am trying to understand face-detection sample from open cv. I know that there are javacameraview and javacamera2view classes.
so far, I understand that the activity using javacameraview. however, I don't know where the javacameraview initially called. no decalaration at all.
I believe it is called in camerabridgeviewbase. but I cannot find any initialization of javacameraview.
The main goal is to replace javacameraview with javacamera2view. or use camera2 API directly.
I understand that there are some limitation in camera2 API but that is not the main problem now.
Here is the CameraBridgeViewBase initialisation
private static final String TAG = "CameraBridge";
protected static final int MAX_UNSPECIFIED = -1;
private static final int STOPPED = 0;
private static final int STARTED = 1;
private int mState = STOPPED;
private Bitmap mCacheBitmap;
private CvCameraViewListener2 mListener;
private boolean mSurfaceExist;
private final Object mSyncObject = new Object();
protected int mFrameWidth;
protected int mFrameHeight;
protected int mMaxHeight;
protected int mMaxWidth;
protected float mScale = 1;
protected int mPreviewFormat = RGBA;
protected int mCameraIndex = CAMERA_ID_ANY;
protected boolean mEnabled;
protected boolean mCameraPermissionGranted = false;
protected FpsMeter mFpsMeter = null;
public static final int CAMERA_ID_ANY = -1;
public static final int CAMERA_ID_BACK = 99;
public static final int CAMERA_ID_FRONT = 98;
public static final int RGBA = 1;
public static final int GRAY = 2;
cheers
Well iam looking in the wrong place. It is controlled in the layout. Just replace JavaCameraView with JavaCamera2View. And done. Camera2 implemented.
I have a Util class which is capable of creating color codes(decimal).
public class ColorUtils {
private static final String RED = "ff0000";
private static final String GREEN = "00ff00";
private static final String BLUE = "0000ff";
private static final String WHITE = "ffffff";
private static final int RADIX = 16;
public static int getColorShade(String deepShade, String lightShade, float percentage) {
if (percentage > 100) {
throw new RuntimeException("Percentage can not be more than 100");
}
int deepShadeCode = Integer.parseInt(deepShade, RADIX);
int lightShadeCode = Integer.parseInt(lightShade, RADIX);
int shadeDifference = deepShadeCode - lightShadeCode;
int shadeOffset = (int) (shadeDifference * percentage)/100;
return lightShadeCode + shadeOffset;
}
public static int getColorShade(String deepShade, float percentage) {
return getColorShade(deepShade, WHITE, percentage);
}
public static int getRedColorShade(float percentage) {
return getColorShade(RED, percentage);
}
public static int getGreenColorShade(float percentage) {
return getColorShade(GREEN, percentage);
}
public static int getBlueColorShade(float percentage) {
return getColorShade(BLUE, percentage);
}
public static int getWhite() {
return Integer.parseInt(WHITE, RADIX);
}
}
Is there any way to convert it to Android color?
All I could find out is ContextCompat.getColor(this,R.color.yourcolor)
but this will take resource id in second arguments, I don't want to make color pallets in color.xml. Is there a work around?
Don't know how you create the color, but if it can extract red, green, blue, then try this:
#ColorInt int color = Color.rgb(getRedColorShade(percentage), getGreenColorShade(percentage), getBlueColorShade(percentage));
Ref here, this time it's pretty sure that this method is added from API level 1 and can be used instead of valueOf
I have checked the suggested question here, but when I checked the documentation regarding the method getNetworkInfo()here, there was no documentation regarding the possible integer values this method could handle. For an example, if I passed 0 to the getNetworkInfo() this means I am checking he mobile network, and if it is 1, I am checking the status of the WiFi.
Is there any other possible values? Why they are not in the documentation?
From the docs: http://developer.android.com/reference/android/net/ConnectivityManager.html
public static final int TYPE_NONE = -1;
public static final int TYPE_MOBILE = 0;
public static final int TYPE_WIFI = 1;
public static final int TYPE_MOBILE_MMS = 2;
public static final int TYPE_MOBILE_SUPL = 3;
public static final int TYPE_MOBILE_DUN = 4;
public static final int TYPE_MOBILE_HIPRI = 5;
public static final int TYPE_WIMAX = 6;
public static final int TYPE_BLUETOOTH = 7;
public static final int TYPE_DUMMY = 8;
public static final int TYPE_ETHERNET = 9;
public static final int TYPE_MOBILE_FOTA = 10;
public static final int TYPE_MOBILE_IMS = 11;
public static final int TYPE_MOBILE_CBS = 12;
public static final int TYPE_WIFI_P2P = 13;
public static final int TYPE_MOBILE_IA = 14;
I have integrated the zbar scanner for android to my app, i only use the app to scan the qrcode, so now i want to optimize the reader by disable the unused symbologies(like PDF417 CODE39 and etc), where should i change? And i alwaye want to know what is the meaning of the number in the file Symbol.java like "QRCODE = 64" Thx:)
These are some core files:
Config.java
public class Config
{
public static final int ENABLE = 0;
public static final int ADD_CHECK = 1;
public static final int EMIT_CHECK = 2;
public static final int ASCII = 3;
public static final int MIN_LEN = 32;
public static final int MAX_LEN = 33;
public static final int UNCERTAINTY = 64;
public static final int POSITION = 128;
public static final int X_DENSITY = 400;
public static final int Y_DENSITY = 400;
}
Symbol.java
public class Symbol
{
public static final int NONE = 0;
public static final int PARTIAL = 1;
public static final int EAN8 = 8;
public static final int UPCE = 9;
public static final int ISBN10 = 10;
public static final int UPCA = 12;
public static final int EAN13 = 13;
public static final int ISBN13 = 14;
public static final int I25 = 25;
public static final int DATABAR = 34;
public static final int DATABAR_EXP = 35;
public static final int CODABAR = 38;
public static final int CODE39 = 39;
public static final int PDF417 = 57;
public static final int QRCODE = 64;
public static final int CODE93 = 93;
public static final int CODE128 = 128;
private long peer;
private int type;
private static native void init();
Symbol(long l)
{
peer = l;
}
protected void finalize()
{
destroy();
}
public synchronized void destroy()
{
if (peer != 0L)
{
destroy(peer);
peer = 0L;
}
}
private native void destroy(long l);
public int getType()
{
if (type == 0)
type = getType(peer);
return type;
}
private native int getType(long l);
public native int getConfigMask();
public native int getModifierMask();
public native String getData();
public native byte[] getDataBytes();
public native int getQuality();
public native int getCount();
public int[] getBounds()
{
int i = getLocationSize(peer);
if (i <= 0)
return null;
int ai[] = new int[4];
int j = 0x7fffffff;
int k = 0x80000000;
int l = 0x7fffffff;
int i1 = 0x80000000;
for (int j1 = 0; j1 < i; j1++)
{
int k1 = getLocationX(peer, j1);
if (j > k1)
j = k1;
if (k < k1)
k = k1;
int l1 = getLocationY(peer, j1);
if (l > l1)
l = l1;
if (i1 < l1)
i1 = l1;
}
ai[0] = j;
ai[1] = l;
ai[2] = k - j;
ai[3] = i1 - l;
return ai;
}
private native int getLocationSize(long l);
private native int getLocationX(long l, int i);
private native int getLocationY(long l, int i);
public int[] getLocationPoint(int i)
{
int ai[] = new int[2];
ai[0] = getLocationX(peer, i);
ai[1] = getLocationY(peer, i);
return ai;
}
public native int getOrientation();
public SymbolSet getComponents()
{
return new SymbolSet(getComponents(peer));
}
private native long getComponents(long l);
native long next();
static
{
System.loadLibrary("zbarjni");
init();
}
}
Modifier.java
public class Modifier
{
public static final int GS1 = 0;
public static final int AIM = 1;
public Modifier()
{
}
}
SymbolSet.java
public class SymbolSet extends AbstractCollection
{
private long peer;
private static native void init();
SymbolSet(long l)
{
peer = l;
}
protected void finalize()
{
destroy();
}
public synchronized void destroy()
{
if (peer != 0L)
{
destroy(peer);
peer = 0L;
}
}
private native void destroy(long l);
public Iterator iterator()
{
long l = firstSymbol(peer);
if (l == 0L)
return new SymbolIterator(null);
else
return new SymbolIterator(new Symbol(l));
}
public native int size();
private native long firstSymbol(long l);
static
{
System.loadLibrary("zbarjni");
init();
}
}
Like so:
scanner = new ImageScanner();
// disable all symbologies first
scanner.setConfig(0, Config.ENABLE, 0);
// only enable QRCODE
scanner.setConfig(Symbol.QRCODE, Config.ENABLE, 1);
With setConfig there are three arguments all as int's. The first is the symbol you want to affect using a Symbol static property or use 0 for all symbols. The second is the setting you want to set using a Config static property. Third is the setting value.
I've been using Simple to try to read in my XML file to this class. I really don't know if I've annotated the classes correctly.
I don't know if I need this part:
public Frame()
{
super();
}
public Frame(int num, int x, int y, int width, int height,int offsetx,int offsety, int duration )
{
this.Num = num;
this.X = x;
this.Y = y;
this.Width = width;
this.Height = height;
this.OffsetX = offsetx;
this.OffsetY = offsety;
this.Duration = duration;]
What does super() do? Do I need getters/setters? Is what I added getters or setters? Do they call themselves automatically or what?
Here's the full class:
public class SpriteAnimationManag
{
// Animation frame class
#Element(name = "Frame")
public class Frame
{
#Element(name = "Num")
public int Num;
#Element(name = "X")
public int X;
#Element(name = "Y")
public int Y;
#Element(name = "Width")
public int Width;
#Element(name = "Height")
public int Height;
#Element(name = "OffSetX")
public int OffsetX;
#Element(name = "OffSetY")
public int OffsetY;
#Element(name = "Duration")
public float Duration;
public Frame()
{
super();
}
public Frame(int num, int x, int y, int width, int height,int offsetx,int offsety, int duration )
{
this.Num = num;
this.X = x;
this.Y = y;
this.Width = width;
this.Height = height;
this.OffsetX = offsetx;
this.OffsetY = offsety;
this.Duration = duration;
}
}
// Animaiton class to hold the name and frames
public class Animation
{
#Element(name = "Name")
public String Name;
#Element(name = "FrameRate")
public int FrameRate;//may need elementarray or list???
#Element(name = "Loop")
public boolean Loop;
#Element(name = "Pingpong")
public boolean Pingpong;
#ElementArray(name = "Frames")
public Frame[] Frames;
public Animation()
{
super();
}
public Animation(String name, int framerate, boolean loop, boolean pingpong, Frame[] frames)
{
this.Name = name;
this.FrameRate = framerate;
this.Loop = loop;
this.Pingpong = pingpong;
this.Frames = frames;
}
}
// The Sprite Texture stores the Sprite Sheet path.fr
public class SpriteTexture
{
// The Sprite Sheet texture file path
#Element(name = "path")
public String Path;
public SpriteTexture()
{
super();
}
public SpriteTexture(String path)
{
this.Path = path;
}
}
// Aniamtion Set contains the Sprite Texture and Animaitons.
#Root(name = "Animations")
public static class XNAAnimationSet
{
// The sprite texture object
#Element(name = "Texture")
public SpriteTexture SpriteTexture;
// The animation array in the Animation Set
#ElementArray(name = "Animation")
public Animation[] Animations;
public XNAAnimationSet()
{
super();
}
public XNAAnimationSet(SpriteTexture spritetexture, Animation[] animations)
{
this.SpriteTexture = spritetexture;
this.Animations = animations;
}
}
// Sprite Animation Manager class
public final static class SpriteAnimationManager
{
private static final String XNAAnimationSet = null;//was static private static
public static int AnimationCount;
// Read the Sprite Sheet Description information from the description xml file
public static XNAAnimationSet Read(String filename) throws Exception
{
XNAAnimationSet animationSet = new XNAAnimationSet();
Serializer serializer = new Persister();
try {
animationSet = serializer.read(XNAAnimationSet.class, filename );
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
// Count the animations to Animation Count
AnimationCount = animationSet.Animations.length;
return animationSet;
}
}
}
I've been trying to see what's being read by trying to write the class to a file. The file is created but it's empty.
Can someone tell me if I've annotated this correctly? What am I doing wrong?
I was using jaxb there the last day to parse my xml, I'm not sure how similiar it is to the way your doing it but ill mention a few of the things i needed:
firstly, i think i needed a no-arg constructor in my class, which for you would just be -
public Frame(){};
I believe you do need getters, what you've got there arent getters/setters, your just declaring variables, this really is fundamental java stuff so it might be worth a read up on that before you continue.
When you have your getters defined properly, you then put the #XMLElement annotation above each of them, not above your variable declarators.
A getter looks like:
#XMLElement
public string getName(){ return this.Name};
Also id recommend trying to parse one class at a time, you have multiple inner classes here which i'd imagine gets messy when your trying to parse, i think you need to have #RootElement above the class name declarator, so the xml knows what type of object your creating.
Anyway, there's a few things off the top of my head, best of luck with it!