package com.codefixia.audio; import com.codefixia.drumcloud.DrumCloud; public class Maxim { private final DrumCloud drumCloud; private float sampleRate = 44100; public final float[] mtof = { 0, 8.661957f, 9.177024f, 9.722718f, 10.3f, 10.913383f, 11.562325f, 12.25f, 12.978271f, 13.75f, 14.567617f, 15.433853f, 16.351599f, 17.323914f, 18.354048f, 19.445436f, 20.601723f, 21.826765f, 23.124651f, 24.5f, 25.956543f, 27.5f, 29.135235f, 30.867706f, 32.703197f, 34.647827f, 36.708096f, 38.890873f, 41.203445f, 43.65353f, 46.249302f, 49.f, 51.913086f, 55.f, 58.27047f, 61.735413f, 65.406395f, 69.295654f, 73.416191f, 77.781746f, 82.406891f, 87.30706f, 92.498604f, 97.998856f, 103.826172f, 110.f, 116.540939f, 123.470825f, 130.81279f, 138.591309f, 146.832382f, 155.563492f, 164.813782f, 174.61412f, 184.997208f, 195.997711f, 207.652344f, 220.f, 233.081879f, 246.94165f, 261.62558f, 277.182617f, 293.664764f, 311.126984f, 329.627563f, 349.228241f, 369.994415f, 391.995422f, 415.304688f, 440.f, 466.163757f, 493.883301f, 523.25116f, 554.365234f, 587.329529f, 622.253967f, 659.255127f, 698.456482f, 739.988831f, 783.990845f, 830.609375f, 880.f, 932.327515f, 987.766602f, 1046.502319f, 1108.730469f, 1174.659058f, 1244.507935f, 1318.510254f, 1396.912964f, 1479.977661f, 1567.981689f, 1661.21875f, 1760.f, 1864.655029f, 1975.533203f, 2093.004639f, 2217.460938f, 2349.318115f, 2489.015869f, 2637.020508f, 2793.825928f, 2959.955322f, 3135.963379f, 3322.4375f, 3520.f, 3729.31f, 3951.066406f, 4186.009277f, 4434.921875f, 4698.63623f, 4978.031738f, 5274.041016f, 5587.651855f, 5919.910645f, 6271.926758f, 6644.875f, 7040.f, 7458.620117f, 7902.132812f, 8372.018555f, 8869.84375f, 9397.272461f, 9956.063477f, 10548.082031f, 11175.303711f, 11839.821289f, 12543.853516f, 13289.75f }; private AndroidAudioThread audioThread; //private PApplet processing; private void initAudioThread() { audioThread = new AndroidAudioThread(sampleRate, 256); audioThread.start(); } public void stopAudioThread() { if(audioThread!=null) audioThread.quit(); } public Maxim (DrumCloud drumCloud) { this.drumCloud=drumCloud; initAudioThread(); } public Maxim(DrumCloud drumCloud,float sampleRate) { this.drumCloud=drumCloud; this.sampleRate = sampleRate; initAudioThread(); } public AudioPlayer createEmptyPlayer() { AudioPlayer ap = new AudioPlayer(sampleRate); AddAudioGenerator(ap); ap.resetAudioPlayer(); return ap; } public void AddAudioGenerator(AudioPlayer ap) { audioThread.addAudioGenerator(ap); } public void RemoveAudioGenerator(AudioPlayer ap) { audioThread.removeAudioGenerator(ap); } public void reLoadPlayer(AudioPlayer player, short[] audioData) { player.setAudioData(audioData); } /** * load the sent file into an audio player and return it. Use * this if your audio file is not too long want precision control * over looping and play head position * @param String filename - the file to load * @return AudioPlayer - an audio player which can play the file */ public AudioPlayer loadFile(String filename) { // this will load the complete audio file into memory AudioPlayer ap = createEmptyPlayer(); reLoadPlayer(ap, ap.justLoadAudioFile ( filename) ); return ap; } public void reloadFile(AudioPlayer ap, String filename) { RemoveAudioGenerator(ap); reLoadPlayer(ap, ap.justLoadAudioFile ( filename) ); AddAudioGenerator(ap); //ap.resetAudioPlayer(); } /** * Create a wavetable player object with a wavetable of the sent * size. Small wavetables (<128) make for a 'nastier' sound! * */ public WavetableSynth createWavetableSynth(int size) { // this will load the complete audio file into memory WavetableSynth ap = new WavetableSynth(size, sampleRate); audioThread.addAudioGenerator(ap); // now we need to tell the audiothread // to ask the audioplayer for samples return ap; } /** * Create an AudioStreamPlayer which can stream audio from the * internet as well as local files. Does not provide precise * control over looping and playhead like AudioPlayer does. Use this for * longer audio files and audio from the internet. */ public AudioStreamPlayer createAudioStreamPlayer(String url) { AudioStreamPlayer asp = new AudioStreamPlayer(url); return asp; } }