Android Open Source - APSK Receiver






From Project

Back to project page APSK.

License

The source code is released under:

GNU General Public License

If you think the Android project APSK listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * This file is part of znudigi./*from www. j  a  v  a2s.c  o m*/
 * Released under GNU GENERAL PUBLIC LICENSE Version 2
 * See file COPYING.
 * Copyright (C) 2007-2008 Leigh L. Klotz, Jr. <Leigh@WA5ZNU.org>
 */

package org.wa5znu.znuradio.receiver;

import java.util.concurrent.ConcurrentLinkedQueue;

import net.thinkindifferent.apsk.AudioInputThread;

import org.wa5znu.znuradio.dsp.Complex;
import org.wa5znu.znuradio.modems.bpsk.BPSKDemodulator;

import android.util.Log;

public class Receiver implements ReceiverHandler, WaveHandler, Controller {
  private static final String TAG = "APSK/Receiver";

  private AudioInputThread audioInputThread;
  private Controller controller;
  private ConcurrentLinkedQueue<ModemThread> modemThreads = new ConcurrentLinkedQueue<ModemThread>();
  private SpectrumThread spectrumThread;

  private static final int REQUIRED_SAMPLE_RATE = 8000;
  private static final int sampleRates[] = {
    REQUIRED_SAMPLE_RATE, 48000
  };

  public Receiver(Controller controller) {
    this.controller=controller;
  }

  public int getSampleRate() {
    return REQUIRED_SAMPLE_RATE;
  }

  public void setSampleRate(int rate) {
    controller.setSampleRate(rate);
  }

  public boolean startReceiver() {
    if(audioInputThread != null) {
      audioInputThread.stopAudio();
    }
    boolean failed = true;
    for (int n = 0; n < sampleRates.length; n++) {
      int sampleRate = sampleRates[n];
      audioInputThread = new AudioInputThread(REQUIRED_SAMPLE_RATE, sampleRate);
      if(audioInputThread.startAudio(this)) {
  failed=false;
  setSampleRate(REQUIRED_SAMPLE_RATE);
  {
    if (spectrumThread != null) throw new RuntimeException("SpectrumThread!=null");
    spectrumThread = new SpectrumThread(this);
    spectrumThread.start();
  }
  break;
      }
    }
    // You must call addDemodulator(x,y) yourself
    return (!failed);
  }

  public Demodulator addDemodulator(ReceiverHandler receiverHandler, Controller controller) {
    Demodulator demodulator = new BPSKDemodulator(getSampleRate(), receiverHandler, controller);
    ModemThread modemThread = new ModemThread(demodulator);
    modemThread.setPriority(10);
    modemThreads.add(modemThread);
    modemThread.start();
    return demodulator;
  }

  public void handleWave(int frame, double data[], int length)  {
    if(length == -1) {
      Log.i(TAG, "[Missed sample " + frame + "]");
      return;
    }
    for (ModemThread modemThread : modemThreads) {
      modemThread.handleWave(frame, data, length);
    }
    if (spectrumThread != null) {
      spectrumThread.handleWave(frame, data, length);
    }
  }

  public void handleSpectrum(int frame, double data[], int length)  {
    controller.handleSpectrum(frame, data, length);
  }

  public void setFrequency(double f) {
    setFrequency(f, false);
  }

  public void setFrequency(double f, boolean userClick) {
    for (ModemThread modemThread : modemThreads) {
      modemThread.setFrequency(f);
    }
  }

  public void handleStage(int frame, double data[], int length) {
    controller.handleStage(frame, data, length);
  }

  public void handleStage(int frame, Complex data[], int length) {
    controller.handleStage(frame, data, length);
  }

  public void handlePhase(int frame, double phi, boolean dcd) {
    controller.handlePhase(frame, phi, dcd);
  }

  public void handleText(int frame, String text) {
    controller.handleText(frame, text);
  }

  public void showNextStage() {
    for (ModemThread modemThread : modemThreads) {
      modemThread.showNextStage();
    }
  }

}




Java Source Code List

net.thinkindifferent.apsk.APSK.java
net.thinkindifferent.apsk.AudioInputThread.java
net.thinkindifferent.apsk.Waterfall.java
org.wa5znu.znuradio.dsp.BaseFIRFilter.java
org.wa5znu.znuradio.dsp.Complex.java
org.wa5znu.znuradio.dsp.FFT.java
org.wa5znu.znuradio.dsp.FilterDesign.java
org.wa5znu.znuradio.dsp.IQFIRFilter.java
org.wa5znu.znuradio.dsp.LowPassFilterDesign.java
org.wa5znu.znuradio.dsp.Mixer.java
org.wa5znu.znuradio.dsp.RealFIRFilter.java
org.wa5znu.znuradio.dsp.Subsampler.java
org.wa5znu.znuradio.dsp.UnitPhasor.java
org.wa5znu.znuradio.dsp.Window.java
org.wa5znu.znuradio.modems.bpsk.BPSKDemodulator.java
org.wa5znu.znuradio.modems.bpsk.PSKVaricode.java
org.wa5znu.znuradio.receiver.Controller.java
org.wa5znu.znuradio.receiver.Demodulator.java
org.wa5znu.znuradio.receiver.FrequencyHandler.java
org.wa5znu.znuradio.receiver.ModemThread.java
org.wa5znu.znuradio.receiver.PhaseHandler.java
org.wa5znu.znuradio.receiver.ReceiverHandler.java
org.wa5znu.znuradio.receiver.Receiver.java
org.wa5znu.znuradio.receiver.SpectrumHandler.java
org.wa5znu.znuradio.receiver.SpectrumThread.java
org.wa5znu.znuradio.receiver.StageHandler.java
org.wa5znu.znuradio.receiver.TextHandler.java
org.wa5znu.znuradio.receiver.WaveHandler.java