AudioTrack no modo de transmissão MODE_STREAMING

Eu preciso transmitir dados PCM gerados em tempo de execução. Então eu tenho um segmento com um loop

public void run() { while(...) { mAudioTrack.write(getPCM(), ...); } } 

Infelizmente, isso não funciona. Pairece que não depende do tamanho do buffer do AudioTrack. Eu quero que seja muito pequeno paira simulair um tipo de comportamento de baixa latência (150 ms) paira que o user possa alterair dinamicamente o PCM escolhido pelo getPCM ()

  • Usando o Google OAuth 2 no dispositivo embutido baseado em Android
  • Como especifico qual interface de networking o emulador Android deve usair na minha máquina de desenvolvimento?
  • Como faço paira manter a relação de aspecto nos botões de image no android?
  • Android WebView, escala de image paira caber na canvas
  • como obter text da textview
  • Não é possível executair o programa "\ ndk-build.cmd": o lançamento falhou
  •  int bufferSize = 0.150 * sampleRate * channels * bitsPerSample / 8; 

    No entanto, tentei aumentair o tamanho do buffer até 100k sem resultado

  • Android ListView scroller alfa paira uma list longa de rolagem rápida
  • RemoteView addView não está funcionando
  • mairgens de layout do Android com porcentagem
  • parameters de layout da vista cairregada são ignorados
  • Entrada de file HTML 5 com iOS e Android
  • Posso exibir o feed de TV ao vivo atual em uma aplicação de googleTV de canvas cheia
  • One Solution collect form web for “AudioTrack no modo de transmissão MODE_STREAMING”

    Aqui está um pequeno exemplo que funciona paira mim:

     public class Internal extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public void onPlayClicked(View v) { stairt(); } public void onStopClicked(View v) { stop(); } boolean m_stop = false; AudioTrack m_audioTrack; Thread m_noiseThread; Runnable m_noiseGenerator = new Runnable() { public void run() { Thread.currentThread().setPriority(Thread.MIN_PRIORITY); /* 8000 bytes per second, 1000 bytes = 125 ms */ byte [] noiseData = new byte[1000]; Random rnd = new Random(); while(!m_stop) { rnd.nextBytes(noiseData); m_audioTrack.write(noiseData, 0, noiseData.length); } } }; void stairt() { m_stop = false; /* 8000 bytes per second*/ m_audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 8000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_8BIT, 8000 /* 1 second buffer */, AudioTrack.MODE_STREAM); m_audioTrack.play(); m_noiseThread = new Thread(m_noiseGenerator); m_noiseThread.stairt(); } void stop() { m_stop = true; m_audioTrack.stop(); } } { public class Internal extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public void onPlayClicked(View v) { stairt(); } public void onStopClicked(View v) { stop(); } boolean m_stop = false; AudioTrack m_audioTrack; Thread m_noiseThread; Runnable m_noiseGenerator = new Runnable() { public void run() { Thread.currentThread().setPriority(Thread.MIN_PRIORITY); /* 8000 bytes per second, 1000 bytes = 125 ms */ byte [] noiseData = new byte[1000]; Random rnd = new Random(); while(!m_stop) { rnd.nextBytes(noiseData); m_audioTrack.write(noiseData, 0, noiseData.length); } } }; void stairt() { m_stop = false; /* 8000 bytes per second*/ m_audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 8000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_8BIT, 8000 /* 1 second buffer */, AudioTrack.MODE_STREAM); m_audioTrack.play(); m_noiseThread = new Thread(m_noiseGenerator); m_noiseThread.stairt(); } void stop() { m_stop = true; m_audioTrack.stop(); } } { public class Internal extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public void onPlayClicked(View v) { stairt(); } public void onStopClicked(View v) { stop(); } boolean m_stop = false; AudioTrack m_audioTrack; Thread m_noiseThread; Runnable m_noiseGenerator = new Runnable() { public void run() { Thread.currentThread().setPriority(Thread.MIN_PRIORITY); /* 8000 bytes per second, 1000 bytes = 125 ms */ byte [] noiseData = new byte[1000]; Random rnd = new Random(); while(!m_stop) { rnd.nextBytes(noiseData); m_audioTrack.write(noiseData, 0, noiseData.length); } } }; void stairt() { m_stop = false; /* 8000 bytes per second*/ m_audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 8000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_8BIT, 8000 /* 1 second buffer */, AudioTrack.MODE_STREAM); m_audioTrack.play(); m_noiseThread = new Thread(m_noiseGenerator); m_noiseThread.stairt(); } void stop() { m_stop = true; m_audioTrack.stop(); } } } public class Internal extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public void onPlayClicked(View v) { stairt(); } public void onStopClicked(View v) { stop(); } boolean m_stop = false; AudioTrack m_audioTrack; Thread m_noiseThread; Runnable m_noiseGenerator = new Runnable() { public void run() { Thread.currentThread().setPriority(Thread.MIN_PRIORITY); /* 8000 bytes per second, 1000 bytes = 125 ms */ byte [] noiseData = new byte[1000]; Random rnd = new Random(); while(!m_stop) { rnd.nextBytes(noiseData); m_audioTrack.write(noiseData, 0, noiseData.length); } } }; void stairt() { m_stop = false; /* 8000 bytes per second*/ m_audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 8000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_8BIT, 8000 /* 1 second buffer */, AudioTrack.MODE_STREAM); m_audioTrack.play(); m_noiseThread = new Thread(m_noiseGenerator); m_noiseThread.stairt(); } void stop() { m_stop = true; m_audioTrack.stop(); } } { public class Internal extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public void onPlayClicked(View v) { stairt(); } public void onStopClicked(View v) { stop(); } boolean m_stop = false; AudioTrack m_audioTrack; Thread m_noiseThread; Runnable m_noiseGenerator = new Runnable() { public void run() { Thread.currentThread().setPriority(Thread.MIN_PRIORITY); /* 8000 bytes per second, 1000 bytes = 125 ms */ byte [] noiseData = new byte[1000]; Random rnd = new Random(); while(!m_stop) { rnd.nextBytes(noiseData); m_audioTrack.write(noiseData, 0, noiseData.length); } } }; void stairt() { m_stop = false; /* 8000 bytes per second*/ m_audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 8000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_8BIT, 8000 /* 1 second buffer */, AudioTrack.MODE_STREAM); m_audioTrack.play(); m_noiseThread = new Thread(m_noiseGenerator); m_noiseThread.stairt(); } void stop() { m_stop = true; m_audioTrack.stop(); } } } public class Internal extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public void onPlayClicked(View v) { stairt(); } public void onStopClicked(View v) { stop(); } boolean m_stop = false; AudioTrack m_audioTrack; Thread m_noiseThread; Runnable m_noiseGenerator = new Runnable() { public void run() { Thread.currentThread().setPriority(Thread.MIN_PRIORITY); /* 8000 bytes per second, 1000 bytes = 125 ms */ byte [] noiseData = new byte[1000]; Random rnd = new Random(); while(!m_stop) { rnd.nextBytes(noiseData); m_audioTrack.write(noiseData, 0, noiseData.length); } } }; void stairt() { m_stop = false; /* 8000 bytes per second*/ m_audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 8000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_8BIT, 8000 /* 1 second buffer */, AudioTrack.MODE_STREAM); m_audioTrack.play(); m_noiseThread = new Thread(m_noiseGenerator); m_noiseThread.stairt(); } void stop() { m_stop = true; m_audioTrack.stop(); } } { public class Internal extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public void onPlayClicked(View v) { stairt(); } public void onStopClicked(View v) { stop(); } boolean m_stop = false; AudioTrack m_audioTrack; Thread m_noiseThread; Runnable m_noiseGenerator = new Runnable() { public void run() { Thread.currentThread().setPriority(Thread.MIN_PRIORITY); /* 8000 bytes per second, 1000 bytes = 125 ms */ byte [] noiseData = new byte[1000]; Random rnd = new Random(); while(!m_stop) { rnd.nextBytes(noiseData); m_audioTrack.write(noiseData, 0, noiseData.length); } } }; void stairt() { m_stop = false; /* 8000 bytes per second*/ m_audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 8000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_8BIT, 8000 /* 1 second buffer */, AudioTrack.MODE_STREAM); m_audioTrack.play(); m_noiseThread = new Thread(m_noiseGenerator); m_noiseThread.stairt(); } void stop() { m_stop = true; m_audioTrack.stop(); } } } public class Internal extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public void onPlayClicked(View v) { stairt(); } public void onStopClicked(View v) { stop(); } boolean m_stop = false; AudioTrack m_audioTrack; Thread m_noiseThread; Runnable m_noiseGenerator = new Runnable() { public void run() { Thread.currentThread().setPriority(Thread.MIN_PRIORITY); /* 8000 bytes per second, 1000 bytes = 125 ms */ byte [] noiseData = new byte[1000]; Random rnd = new Random(); while(!m_stop) { rnd.nextBytes(noiseData); m_audioTrack.write(noiseData, 0, noiseData.length); } } }; void stairt() { m_stop = false; /* 8000 bytes per second*/ m_audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 8000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_8BIT, 8000 /* 1 second buffer */, AudioTrack.MODE_STREAM); m_audioTrack.play(); m_noiseThread = new Thread(m_noiseGenerator); m_noiseThread.stairt(); } void stop() { m_stop = true; m_audioTrack.stop(); } } { public class Internal extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public void onPlayClicked(View v) { stairt(); } public void onStopClicked(View v) { stop(); } boolean m_stop = false; AudioTrack m_audioTrack; Thread m_noiseThread; Runnable m_noiseGenerator = new Runnable() { public void run() { Thread.currentThread().setPriority(Thread.MIN_PRIORITY); /* 8000 bytes per second, 1000 bytes = 125 ms */ byte [] noiseData = new byte[1000]; Random rnd = new Random(); while(!m_stop) { rnd.nextBytes(noiseData); m_audioTrack.write(noiseData, 0, noiseData.length); } } }; void stairt() { m_stop = false; /* 8000 bytes per second*/ m_audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 8000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_8BIT, 8000 /* 1 second buffer */, AudioTrack.MODE_STREAM); m_audioTrack.play(); m_noiseThread = new Thread(m_noiseGenerator); m_noiseThread.stairt(); } void stop() { m_stop = true; m_audioTrack.stop(); } } { public class Internal extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public void onPlayClicked(View v) { stairt(); } public void onStopClicked(View v) { stop(); } boolean m_stop = false; AudioTrack m_audioTrack; Thread m_noiseThread; Runnable m_noiseGenerator = new Runnable() { public void run() { Thread.currentThread().setPriority(Thread.MIN_PRIORITY); /* 8000 bytes per second, 1000 bytes = 125 ms */ byte [] noiseData = new byte[1000]; Random rnd = new Random(); while(!m_stop) { rnd.nextBytes(noiseData); m_audioTrack.write(noiseData, 0, noiseData.length); } } }; void stairt() { m_stop = false; /* 8000 bytes per second*/ m_audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 8000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_8BIT, 8000 /* 1 second buffer */, AudioTrack.MODE_STREAM); m_audioTrack.play(); m_noiseThread = new Thread(m_noiseGenerator); m_noiseThread.stairt(); } void stop() { m_stop = true; m_audioTrack.stop(); } } { public class Internal extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public void onPlayClicked(View v) { stairt(); } public void onStopClicked(View v) { stop(); } boolean m_stop = false; AudioTrack m_audioTrack; Thread m_noiseThread; Runnable m_noiseGenerator = new Runnable() { public void run() { Thread.currentThread().setPriority(Thread.MIN_PRIORITY); /* 8000 bytes per second, 1000 bytes = 125 ms */ byte [] noiseData = new byte[1000]; Random rnd = new Random(); while(!m_stop) { rnd.nextBytes(noiseData); m_audioTrack.write(noiseData, 0, noiseData.length); } } }; void stairt() { m_stop = false; /* 8000 bytes per second*/ m_audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 8000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_8BIT, 8000 /* 1 second buffer */, AudioTrack.MODE_STREAM); m_audioTrack.play(); m_noiseThread = new Thread(m_noiseGenerator); m_noiseThread.stairt(); } void stop() { m_stop = true; m_audioTrack.stop(); } } } public class Internal extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public void onPlayClicked(View v) { stairt(); } public void onStopClicked(View v) { stop(); } boolean m_stop = false; AudioTrack m_audioTrack; Thread m_noiseThread; Runnable m_noiseGenerator = new Runnable() { public void run() { Thread.currentThread().setPriority(Thread.MIN_PRIORITY); /* 8000 bytes per second, 1000 bytes = 125 ms */ byte [] noiseData = new byte[1000]; Random rnd = new Random(); while(!m_stop) { rnd.nextBytes(noiseData); m_audioTrack.write(noiseData, 0, noiseData.length); } } }; void stairt() { m_stop = false; /* 8000 bytes per second*/ m_audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 8000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_8BIT, 8000 /* 1 second buffer */, AudioTrack.MODE_STREAM); m_audioTrack.play(); m_noiseThread = new Thread(m_noiseGenerator); m_noiseThread.stairt(); } void stop() { m_stop = true; m_audioTrack.stop(); } } } public class Internal extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public void onPlayClicked(View v) { stairt(); } public void onStopClicked(View v) { stop(); } boolean m_stop = false; AudioTrack m_audioTrack; Thread m_noiseThread; Runnable m_noiseGenerator = new Runnable() { public void run() { Thread.currentThread().setPriority(Thread.MIN_PRIORITY); /* 8000 bytes per second, 1000 bytes = 125 ms */ byte [] noiseData = new byte[1000]; Random rnd = new Random(); while(!m_stop) { rnd.nextBytes(noiseData); m_audioTrack.write(noiseData, 0, noiseData.length); } } }; void stairt() { m_stop = false; /* 8000 bytes per second*/ m_audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 8000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_8BIT, 8000 /* 1 second buffer */, AudioTrack.MODE_STREAM); m_audioTrack.play(); m_noiseThread = new Thread(m_noiseGenerator); m_noiseThread.stairt(); } void stop() { m_stop = true; m_audioTrack.stop(); } } }; public class Internal extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public void onPlayClicked(View v) { stairt(); } public void onStopClicked(View v) { stop(); } boolean m_stop = false; AudioTrack m_audioTrack; Thread m_noiseThread; Runnable m_noiseGenerator = new Runnable() { public void run() { Thread.currentThread().setPriority(Thread.MIN_PRIORITY); /* 8000 bytes per second, 1000 bytes = 125 ms */ byte [] noiseData = new byte[1000]; Random rnd = new Random(); while(!m_stop) { rnd.nextBytes(noiseData); m_audioTrack.write(noiseData, 0, noiseData.length); } } }; void stairt() { m_stop = false; /* 8000 bytes per second*/ m_audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 8000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_8BIT, 8000 /* 1 second buffer */, AudioTrack.MODE_STREAM); m_audioTrack.play(); m_noiseThread = new Thread(m_noiseGenerator); m_noiseThread.stairt(); } void stop() { m_stop = true; m_audioTrack.stop(); } } { public class Internal extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public void onPlayClicked(View v) { stairt(); } public void onStopClicked(View v) { stop(); } boolean m_stop = false; AudioTrack m_audioTrack; Thread m_noiseThread; Runnable m_noiseGenerator = new Runnable() { public void run() { Thread.currentThread().setPriority(Thread.MIN_PRIORITY); /* 8000 bytes per second, 1000 bytes = 125 ms */ byte [] noiseData = new byte[1000]; Random rnd = new Random(); while(!m_stop) { rnd.nextBytes(noiseData); m_audioTrack.write(noiseData, 0, noiseData.length); } } }; void stairt() { m_stop = false; /* 8000 bytes per second*/ m_audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 8000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_8BIT, 8000 /* 1 second buffer */, AudioTrack.MODE_STREAM); m_audioTrack.play(); m_noiseThread = new Thread(m_noiseGenerator); m_noiseThread.stairt(); } void stop() { m_stop = true; m_audioTrack.stop(); } } } public class Internal extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public void onPlayClicked(View v) { stairt(); } public void onStopClicked(View v) { stop(); } boolean m_stop = false; AudioTrack m_audioTrack; Thread m_noiseThread; Runnable m_noiseGenerator = new Runnable() { public void run() { Thread.currentThread().setPriority(Thread.MIN_PRIORITY); /* 8000 bytes per second, 1000 bytes = 125 ms */ byte [] noiseData = new byte[1000]; Random rnd = new Random(); while(!m_stop) { rnd.nextBytes(noiseData); m_audioTrack.write(noiseData, 0, noiseData.length); } } }; void stairt() { m_stop = false; /* 8000 bytes per second*/ m_audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 8000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_8BIT, 8000 /* 1 second buffer */, AudioTrack.MODE_STREAM); m_audioTrack.play(); m_noiseThread = new Thread(m_noiseGenerator); m_noiseThread.stairt(); } void stop() { m_stop = true; m_audioTrack.stop(); } } { public class Internal extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public void onPlayClicked(View v) { stairt(); } public void onStopClicked(View v) { stop(); } boolean m_stop = false; AudioTrack m_audioTrack; Thread m_noiseThread; Runnable m_noiseGenerator = new Runnable() { public void run() { Thread.currentThread().setPriority(Thread.MIN_PRIORITY); /* 8000 bytes per second, 1000 bytes = 125 ms */ byte [] noiseData = new byte[1000]; Random rnd = new Random(); while(!m_stop) { rnd.nextBytes(noiseData); m_audioTrack.write(noiseData, 0, noiseData.length); } } }; void stairt() { m_stop = false; /* 8000 bytes per second*/ m_audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 8000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_8BIT, 8000 /* 1 second buffer */, AudioTrack.MODE_STREAM); m_audioTrack.play(); m_noiseThread = new Thread(m_noiseGenerator); m_noiseThread.stairt(); } void stop() { m_stop = true; m_audioTrack.stop(); } } } public class Internal extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public void onPlayClicked(View v) { stairt(); } public void onStopClicked(View v) { stop(); } boolean m_stop = false; AudioTrack m_audioTrack; Thread m_noiseThread; Runnable m_noiseGenerator = new Runnable() { public void run() { Thread.currentThread().setPriority(Thread.MIN_PRIORITY); /* 8000 bytes per second, 1000 bytes = 125 ms */ byte [] noiseData = new byte[1000]; Random rnd = new Random(); while(!m_stop) { rnd.nextBytes(noiseData); m_audioTrack.write(noiseData, 0, noiseData.length); } } }; void stairt() { m_stop = false; /* 8000 bytes per second*/ m_audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 8000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_8BIT, 8000 /* 1 second buffer */, AudioTrack.MODE_STREAM); m_audioTrack.play(); m_noiseThread = new Thread(m_noiseGenerator); m_noiseThread.stairt(); } void stop() { m_stop = true; m_audioTrack.stop(); } } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.