Sambalmueslies Blog Eine Meinung etwas abseits des Mainstream

23Okt/120

Java Sinus Generator

package de.sambalmueslie.sine_generator;

/**
 * Generate a sine.
 * 
 * Copyright (C) 2012 Oliver Eckle
 * 
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 * 
 */
public class SineGenerator {

	/** the maximum samples per oscillation. */
	private static final int MAX_SAMPLES_PER_OSCILLATION = 160;
	/** the minimum samples per oscillation. */
	private static final int MIN_SAMPLES_PER_OSCILLATION = 2;

	/**
	 * Constructor.
	 * 
	 * @param theSampleRate
	 *            the sample rate
	 * @param theMaximumAmplitude
	 *            the maximum amplitude
	 */
	public SineGenerator(final int theSampleRate,
			final short theMaximumAmplitude) {
		sampleRate = theSampleRate;
		maximumAmplitude = theMaximumAmplitude;
	}

	/**
	 * Generate sine oscillation samples for a defined total length.
	 * 
	 * @param frequency
	 *            the freqency
	 * @param totalSamples
	 *            the total samples
	 * @return the result
	 */
	public short[] generateSineOscillationSamples(final int frequency,
			final int totalSamples) {
		final short[] result = new short[totalSamples];
		final short[] singleResult = generateSingleSineOscillationSamples(frequency);
		for (int i = 0; i < totalSamples; i++) {
			final int j = i % singleResult.length;
			result[i] = singleResult[j];
		}
		return result;
	}

	/**
	 * Generate the samples for one single sine oscillation.
	 * 
	 * @param frequency
	 *            the frequency
	 * @return the generated samples
	 */
	public short[] generateSingleSineOscillationSamples(final int frequency) {
		final int samples = calculateSamplesPerOscillation(frequency);
		final short[] result = new short[samples];
		final int samplesMiddle = samples / 2;
		for (int i = 0; i < samples; i++) {
			if (i < samplesMiddle) {
				final double c = (i == 0) ? 0 : 2 * Math.PI * i / samples;
				final double sineVal = Math.sin(c);
				result[i] = (short) (sineVal * maximumAmplitude);
			} else {
				result[i] = (short) (result[i - samplesMiddle] * -1);
			}
		}
		return result;
	}

	/**
	 * Calculate the total samples per oscillation.
	 * 
	 * @param frequency
	 *            the frequency
	 * @return the calculated samples
	 */
	private int calculateSamplesPerOscillation(final int frequency) {
		if (frequency <= 0) {
			return MAX_SAMPLES_PER_OSCILLATION;
		}
		final int samples = sampleRate / frequency;
		if (samples > MAX_SAMPLES_PER_OSCILLATION) {
			return MAX_SAMPLES_PER_OSCILLATION;
		} else if (samples < MIN_SAMPLES_PER_OSCILLATION) {
			return MIN_SAMPLES_PER_OSCILLATION;
		}
		return samples;
	}

	/** the amplitude. */
	private final int maximumAmplitude;
	/** the sample rate. */
	private final int sampleRate;

}

 

SineGenerator

16Nov/110

Gut Ding will Weile haben

Heute geht es um folgende Bibelstelle.

Liebe Brüder, wenn in schwierigen Situationen euer Glaube geprüft wird, dann freut euch darüber.

Denn wenn ihr euch darin bewährt, wächst eure Geduld.

Und durch die Geduld werdet ihr bis zum Ende durchhalten, denn dann wird euer Glaube zur vollen
Reife gelangen und vollkommen sein und nichts wird euch fehlen.
(Jakobus 1,2-4 Bibel)

28Jul/110

Wikinger Wolfram der Mönch

Die Geschichte von Wolfram dem Mönch.

Wikinger Wolfram der Mönch

Viel Spaß

Gruß Oli

19Apr/110

Java Tutorial : MVC am Beispiel Obstkorb

Hier mal vorab der Sourcecode als Eclipse-Projekt :-)

hier steht wie man es importiert http://www.jpa-hibernate.de/beispiele/import.html

hier das Tutorial Java Tutorial - MVC mit Obstkorb

und hier der Source als Download Java Tutorial MVC Fruitbasket

Gruß Oli

veröffentlicht unter: Software, Tutorial keine Kommentare
10Apr/112

Der Hingucker

Die Geschichte vom barmherzigen Samariter kennt wohl jeder Mensch, der sich ein klein wenig mit dem Christentum beschäftigt hat. Wenn ich damit bei meinen Jungscharkids aufschlage, dann werde ich in der Regel mit einem „Kennen wir schon“ konfrontiert. Wenn man dann mal genauer nachfragt hat der arme Samariter plötzlich dann Besuch von den drei Weisen aus dem Morgenland bekommen und musste mit Mose im Fischbauch übernachten. Kurz gesagt, es ist doch nicht alles so ganz bekannt. Aber wenn ich an mich als etwas fortgeschrittenen Christen denke, da ist die Geschichte doch wirklich auch so bekannt, wie sie von Jesus erzählt wurde. Doch ist auch der Inhalt immer so ganz klar? Was wollte Jesus damit eigentlich aussagen? Gibt es vielleicht trotz, dass ich es schon gefühlte tausendmal gehört habe etwas, was mein Leben inspiriert oder wo Gott etwas an mir verändern möchte? Eine Perspektive auf diese Geschichte habe ich mit „Der Hingucker“ überschrieben. Doch zuerst möchte ich einmal die Geschichte selbst erzählen, damit wir alle auf demselben Stand sind.

29Mrz/111

Oli’s Jam

Der Oli hat sich mal bisschen ausgetobt :-)

Oli's Jam - Versuch 2

veröffentlicht unter: Musik 1 Kommentar
16Feb/110

Geistige Waffenrüstung heute

In Epheser 6 gibt Paulus den Christen ein paar Tipps wie sie ihren Glauben am besten leben sollen. Dazu bedient er sich eines Vergleiches, indem er das Beispiel eines römischen Soldaten heranzieht. Damit konnte damals wohl jeder Mensch etwas anfangen, da die Weltmacht Rom mit ihren Soldaten quasi überall präsent war. Doch heute ist das alles ein wenig anders. Wie würde Paulus heute argumentieren? Vielleicht anhand eines Computers?

7Feb/110

Passah vs. Abendmahl

Was haben Passsha und Abendmahl miteinander zu tun und welche Möglichkeiten gibt es dies auf etwas andere Art und Weise zu gestalten? Damit möchte sich der nächste Artikel befassen.

9Nov/101

Kinderschokolade

Folgendes Zitat hat mich inspiriert: „In einer 200g Jubiläumspackung sind die wichtigsten Bestandteile aus einem halben Liter Milch enthalten. Kinderschokolade heißt: mehr Milch, weniger Kakao“

Ok dann wollen wir doch mal rechnen.

3Okt/100

Die Bergpredigt

Bei der Bergpredigt handelt es sich um eine Predigt von Jesus, die in Matthäus 5 bis Matthäus 7 überliefert ist. Nachfolgend sollen die einzelnen Abschnitte, so weit ich es verstehe, erläutert werden.