मैं ऑडियो पोर्ट पर कुछ एफएसके मॉड्यूलेशन करना चाहता हूं। तो समस्या यह है कि मेरी साइनस लहर बहुत अच्छी नहीं है। यह भी भागों से परेशान है। मैंने http://marblemice.blogspot.com/2010/04/generate-and-play-tone-in-android.html से Playing an arbitrary tone with Android और https://market.android.com/details?id=re.serialout&feature=search_result से आगे संशोधन के साथ मूल कोड का उपयोग किया। तो विफलता कहां है? मैं क्या गलत हूँ?एंड्रॉइड में एफएसके मॉड्यूलेशन और प्लेइंग साइन टोन
private static int bitRate=300;
private static int sampleRate=48000;
private static int freq1=600;
public static void loopOnes(){
playque.add(UARTHigh);
athread.interrupt();
}
private static byte[] UARTHigh() {
int numSamples=sampleRate/bitRate;
double sample[]=new double[numSamples];
byte[] buffer=new byte[numSamples*2];
for(int i=0; i<numSamples;++i){
sample[i]=Math.sin(2*Math.PI*i*freq1/sampleRate);
}
int idx = 0;
for (final double dVal : sample) {
// scale to maximum amplitude
final short val = (short) ((dVal * 32767));
// in 16 bit wav PCM, first byte is the low order byte
buffer[idx++] = (byte) (val & 0x00ff);
buffer[idx++] = (byte) ((val & 0xff00) >>> 8);
}
return buffer;
}
private static void playSound(){
active = true;
while(active)
{
try {Thread.sleep(Long.MAX_VALUE);} catch (InterruptedException e) {
while (playque.isEmpty() == false)
{
if (atrk != null)
{
if (generatedSnd != null)
{
// Das letzte Sample erst fertig abspielen lassen
// systemClock.sleep(xx) xx könnte angepasst werden
while (atrk.getPlaybackHeadPosition() < (generatedSnd.length))
SystemClock.sleep(50); // let existing sample finish first: this can probably be set to a smarter number using the information above
}
atrk.release();
}
UpdateParameters(); // might as well do it at every iteration, it's cheap
generatedSnd = playque.poll();
length = generatedSnd.length;
if (minbufsize<length)
minbufsize=length;
atrk = new AudioTrack(AudioManager.STREAM_MUSIC,
sampleRate, AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT, minbufsize,
AudioTrack.MODE_STATIC);
atrk.setStereoVolume(1,1);
atrk.write(generatedSnd, 0, length);
atrk.play();
}
// Playque is Empty =>send StopBit!
// Set Loop Points
int setLoopError=atrk.setLoopPoints(0, length, -1);
atrk.play();
}
}
}
}
मुझे विफलता मिली। setLoopPoints (0, लंबाई/2, -1) लेकिन मुझे नहीं पता कि यह सही क्यों है। –
अभी तक आपके कोड को नहीं देखा है, लेकिन मुझे लगता है कि जब आप "साइनस तरंग" कहते हैं तो "साइन लहर" का अर्थ है। पहले मैंने सोचा था कि यह आपकी नाक के साथ कुछ करने के लिए था। :-) –
"यहां तक कि हिस्सों से परेशान" का क्या मतलब है? –