对于我的应用程序,我需要在Android手机上录制来自MIC的音频,并通过TCP将其发送到需要播放的其他Android手机.
我正在使用AudioRecord和AudioTrack上课.这适用于文件 - 使用文件将音频写入文件DataOutputStream,并使用它读取DataInputStream.
但是,如果我从套接字而不是文件中获取相同的流,并尝试写入它,我会得到一个例外.
我无法理解可能出现的问题.任何帮助将不胜感激.
编辑:即使我尝试使用更大的缓冲区大小(65535字节,160000字节),问题也是一样的.
这是代码:
录音机:
int bufferSize = AudioRecord.getMinBufferSize(11025, , AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT);
AudioRecord recordInstance = new AudioRecord(MediaRecorder.AudioSource.MIC, 11025, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, bufferSize);
byte[] tempBuffer = new byte[bufferSize];
recordInstance.startRecording();
while (/*isRecording*/) {
bufferRead = recordInstance.read(tempBuffer, 0, bufferSize);
dataOutputStreamInstance.write(tempBuffer);
}
Run Code Online (Sandbox Code Playgroud)
上面的DataOutputStream获得如下:
BufferedOutputStream buff = new BufferedOutputStream(out1); //out1 is the socket's outputStream
DataOutputStream dataOutputStreamInstance = new DataOutputStream (buff);
Run Code Online (Sandbox Code Playgroud)
请你看看,让我知道我在这里做错了什么?
谢谢,
我需要this从我的setInterval处理程序访问
prefs: null,
startup : function()
{
// init prefs
...
this.retrieve_rate();
this.intervalID = setInterval(this.retrieve_rate, this.INTERVAL);
},
retrieve_rate : function()
{
var ajax = null;
ajax = new XMLHttpRequest();
ajax.open('GET', 'http://xyz.com', true);
ajax.onload = function()
{
// access prefs here
}
}
Run Code Online (Sandbox Code Playgroud)
我如何访问this.prefs ajax.onload?
header('P3P: CP="IDC DSP COR CURa ADMa OUR IND PHY ONL COM STA"');
Run Code Online (Sandbox Code Playgroud)
我从未见过这样的标题,它的用途是什么?
这是C++ 0x右值引用和临时值的后续问题
在上一个问题中,我询问了这段代码应该如何工作:
void f(const std::string &); //less efficient
void f(std::string &&); //more efficient
void g(const char * arg)
{
f(arg);
}
Run Code Online (Sandbox Code Playgroud)
由于隐式临时似乎应该调用移动重载,这种情况发生在GCC中,而不是MSVC(或MSVC的Intellisense中使用的EDG前端).
这段代码怎么样?
void f(std::string &&); //NB: No const string & overload supplied
void g1(const char * arg)
{
f(arg);
}
void g2(const std::string & arg)
{
f(arg);
}
Run Code Online (Sandbox Code Playgroud)
看来,基于我之前问题的答案,该函数g1是合法的(并且被GCC 4.3-4.5接受,但不被MSVC接受).但是,GCC和MSVC都拒绝,g2因为第13.3.3.1.4/3条禁止左值绑定到rvalue ref参数.我理解这背后的基本原理 - 在N2831"使用右值参考修复安全问题"中对此进行了解释.我也认为GCC可能正如该论文的作者所预期的那样实施该条款,因为GCC的原始补丁是由其中一位作者(Doug Gregor)撰写的.
但是,我不是很直观.对我来说,(a)a const string &在概念上更接近于string &&a const char *,而且(b)编译器可以创建一个临时字符串g2,就好像它是这样编写的:
void g2(const std::string & …Run Code Online (Sandbox Code Playgroud) 我必须说我真的很喜欢VS 2010的新代码分析,我的代码中有很多区域我没有使用CultureInfo.InvariantCulture,代码分析让我对此感到温暖.
我很确定我想使用CultureInfo.InvariantCulture代码分析检测到它在Convert.ToString操作中丢失的地方.
反正有没有让VS自动修复这种类型的警告?
请考虑以下代码,我试图仅解析文件中的第一个phpDoc样式注释(不使用任何其他库)(文件内容放在$ data变量中用于测试目的):
$data = "
/**
* @file A lot of info about this file
* Could even continue on the next line
* @author me@example.com
* @version 2010-05-01
* @todo do stuff...
*/
/**
* Comment bij functie bar()
* @param Array met dingen
*/
function bar($baz) {
echo $baz;
}
";
$data = trim(preg_replace('/\r?\n *\* */', ' ', $data));
preg_match_all('/@([a-z]+)\s+(.*?)\s*(?=$|@[a-z]+\s)/s', $data, $matches);
$info = array_combine($matches[1], $matches[2]);
print_r($info)
Run Code Online (Sandbox Code Playgroud)
除了@todo之后的所有内容(包括bar()注释块和代码)被视为以下值之外,这几乎可以正常工作@todo:
Array (
[file] => …Run Code Online (Sandbox Code Playgroud) 我有这两个文件
文件: 11
11
456123
Run Code Online (Sandbox Code Playgroud)
文件: 22
11
789
Run Code Online (Sandbox Code Playgroud)
输出 diff 11 22
2c2
< 456123
---
> 789
Run Code Online (Sandbox Code Playgroud)
输出为
< 456123
> 789
Run Code Online (Sandbox Code Playgroud)
我希望它不打印2c2和---行.我查看了手册页但找不到任何帮助.有任何想法吗?该文件有超过1000行.
它们位于:
share\gtk-2.0\demo
Run Code Online (Sandbox Code Playgroud)
但是它们都不包含main函数,我怎样才能使下面的函数textscroll.c真正起作用:
/* Text Widget/Automatic scrolling
*
* This example demonstrates how to use the gravity of
* GtkTextMarks to keep a text view scrolled to the bottom
* while appending text.
*/
#include <gtk/gtk.h>
#include "demo-common.h"
/* Scroll to the end of the buffer.
*/
static gboolean
scroll_to_end (GtkTextView *textview)
{
GtkTextBuffer *buffer;
GtkTextIter iter;
GtkTextMark *mark;
char *spaces;
static int count;
buffer = gtk_text_view_get_buffer (textview);
/* Get "end" mark. It's located at the …Run Code Online (Sandbox Code Playgroud) 我有这个代码:
Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
object nullobj = System.Reflection.Missing.Value;
object file = openFileDialog1.FileName;
Microsoft.Office.Interop.Word.Document doc = app.Documents.Open(
ref file, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj);
doc.ActiveWindow.Selection.WholeStory();
doc.ActiveWindow.Selection.Copy();
IDataObject data = Clipboard.GetDataObject();
string text = data.GetData(DataFormats.Text).ToString();
textBox2.Text = text;
doc.Close(ref nullobj, ref nullobj, ref nullobj);
app.Quit(ref nullobj, ref nullobj, ref nullobj);
Run Code Online (Sandbox Code Playgroud)
但它不会返回页码.我怎样才能获得页码?
我认为java.math.BigDecimal应该是The Answer™需要用十进制数执行无限精度算术.
请考虑以下代码段:
import java.math.BigDecimal;
//...
final BigDecimal one = BigDecimal.ONE;
final BigDecimal three = BigDecimal.valueOf(3);
final BigDecimal third = one.divide(three);
assert third.multiply(three).equals(one); // this should pass, right?
Run Code Online (Sandbox Code Playgroud)
我希望assert通过,但事实上执行甚至没有到达那里:one.divide(three)原因ArithmeticException被抛出!
Exception in thread "main" java.lang.ArithmeticException:
Non-terminating decimal expansion; no exact representable decimal result.
at java.math.BigDecimal.divide
Run Code Online (Sandbox Code Playgroud)
事实证明,API中明确记录了此行为:
在这种情况下
divide,准确的商可能有一个无限长的十进制扩展; 例如,1除以3.如果商具有非终止十进制扩展并且指定操作以返回精确结果,ArithmeticException则抛出a.否则,返回除法的确切结果,与其他操作一样.
进一步浏览API,人们发现实际上有各种重载divide执行不精确的划分,即:
final BigDecimal third = one.divide(three, 33, RoundingMode.DOWN);
System.out.println(three.multiply(third));
// prints "0.999999999999999999999999999999999"
Run Code Online (Sandbox Code Playgroud)
当然,现在显而易见的问题是"有什么意义?".BigDecimal当我们需要 …