当前位置: 互联网>综合
本页文章导读:
▪获取IE默认代理配置 BOOL GetWinetProxy(LPSTR lpszProxy, UINT nProxyLen)
{
unsigned long nSize = 4096;
char szBuf[4096] = { 0 };
INTERNET_PROXY_INFO* pProxyInfo = (INTERNET_PROXY_INFO*)szBuf.........
▪Hadoop 类Grep源代码注释 /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* .........
▪Speex Acoustic Echo Cancellation (AEC) 回声消除模块的使用 背景:回声与啸叫的产生 http://blog.csdn.net/u011202336/article/details/9238397
参考资料: http://www.speex.org/docs/manual
从代码分析,下边是Speex test demo
#include <stdio.h>
#include <stdl.........
[1]获取IE默认代理配置
来源: 互联网 发布时间: 2013-10-26
BOOL GetWinetProxy(LPSTR lpszProxy, UINT nProxyLen)
{
unsigned long nSize = 4096;
char szBuf[4096] = { 0 };
INTERNET_PROXY_INFO* pProxyInfo = (INTERNET_PROXY_INFO*)szBuf;
if(!InternetQueryOption(NULL, INTERNET_OPTION_PROXY, pProxyInfo, &nSize))
{
return FALSE;
}
if (pProxyInfo->dwAccessType == INTERNET_OPEN_TYPE_DIRECT)
{
return FALSE;
int nLen = strlen(lpszProxyList);
if (lpszProxy)
{
nProxyLen = min(nLen, nProxyLen-1);
strncpy(lpszProxy, lpszProxyList, nProxyLen);
lpszProxy[nProxyLen] = 0;
}
return nLen;
/*INTERNET_PER_CONN_OPTION_LISTA List;
INTERNET_PER_CONN_OPTIONA Option[1];
unsigned long nSize = sizeof(INTERNET_PER_CONN_OPTION_LISTA);
Option[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
List.dwSize = sizeof(INTERNET_PER_CONN_OPTION_LIST);
List.pszConnection = NULL;
List.dwOptionCount = 1;
List.dwOptionError = 0;
List.pOptions = Option;
if(!InternetQueryOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION, &List, &nSize))
{
return FALSE;
}
if(Option[0].Value.pszValue != NULL)
{
int nLen = strlen(Option[0].Value.pszValue);
if (lpszProxy)
{
nProxyLen = min(nLen, nProxyLen-1);
strncpy(lpszProxy, Option[0].Value.pszValue, nProxyLen);
lpszProxy[nProxyLen] = 0;
}
GlobalFree(Option[0].Value.pszValue);
return nLen;
}*/
return FALSE;
}
{
unsigned long nSize = 4096;
char szBuf[4096] = { 0 };
INTERNET_PROXY_INFO* pProxyInfo = (INTERNET_PROXY_INFO*)szBuf;
if(!InternetQueryOption(NULL, INTERNET_OPTION_PROXY, pProxyInfo, &nSize))
{
return FALSE;
}
if (pProxyInfo->dwAccessType == INTERNET_OPEN_TYPE_DIRECT)
{
return FALSE;
}
//这里是代理列表,以\0分隔,结束处两个\0\0,一般我们取第一条代理就够了
LPCSTR lpszProxyList = (LPCSTR)(pProxyInfo + 1);int nLen = strlen(lpszProxyList);
if (lpszProxy)
{
nProxyLen = min(nLen, nProxyLen-1);
strncpy(lpszProxy, lpszProxyList, nProxyLen);
lpszProxy[nProxyLen] = 0;
}
return nLen;
/*INTERNET_PER_CONN_OPTION_LISTA List;
INTERNET_PER_CONN_OPTIONA Option[1];
unsigned long nSize = sizeof(INTERNET_PER_CONN_OPTION_LISTA);
Option[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
List.dwSize = sizeof(INTERNET_PER_CONN_OPTION_LIST);
List.pszConnection = NULL;
List.dwOptionCount = 1;
List.dwOptionError = 0;
List.pOptions = Option;
if(!InternetQueryOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION, &List, &nSize))
{
return FALSE;
}
if(Option[0].Value.pszValue != NULL)
{
int nLen = strlen(Option[0].Value.pszValue);
if (lpszProxy)
{
nProxyLen = min(nLen, nProxyLen-1);
strncpy(lpszProxy, Option[0].Value.pszValue, nProxyLen);
lpszProxy[nProxyLen] = 0;
}
GlobalFree(Option[0].Value.pszValue);
return nLen;
}*/
return FALSE;
}
作者:i7thTool 发表于2013-7-4 9:50:16 原文链接
阅读:56 评论:0 查看评论
[2]Hadoop 类Grep源代码注释
来源: 互联网 发布时间: 2013-10-26
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.tdxx.hadoop.example;
import java.util.Random;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.*;
import org.apache.hadoop.mapred.lib.*;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
/**
* 从input中提取与表达式相符的单词并计算词频
*
* 继承自配置基类Configured,并扩展接口Tool
* Configured类中有一个变量conf用于存储配置文件
* Tool中只有一个方法需要实现
* int run(String [] args)用于运行输入参数
* hadoop jar Grep.jar /user/hadoop/20130704/grep.txt /user/hadoop/output/ 'aaa.*'
* hadoop jar Grep.jar /user/hadoop/20130704/grep.txt /user/hadoop/output/ '[a-z.]+'
*/
public class Grep extends Configured implements Tool {
// singleton
private Grep() {
}
public int run(String[] args) throws Exception {
if (args.length < 3) {
System.out.println("Grep <inDir> <outDir> <regex> [<group>]");
ToolRunner.printGenericCommandUsage(System.out);
return -1;
}
Path tempDir = new Path("grep-temp-"
+ Integer.toString(new Random().nextInt(Integer.MAX_VALUE)));
//创建job
JobConf grepJob = new JobConf(getConf(), Grep.class);
try {
//job命名
grepJob.setJobName("grep-search");
//设置job的输入路径
FileInputFormat.setInputPaths(grepJob, args[0]);
//设置Mapper类
grepJob.setMapperClass(RegexMapper.class);
grepJob.set("mapred.mapper.regex", args[2]);
if (args.length == 4)
grepJob.set("mapred.mapper.regex.group", args[3]);
//设置Combiner类
grepJob.setCombinerClass(LongSumReducer.class);
//设置Reducer类
grepJob.setReducerClass(LongSumReducer.class);
//设置输出路径
FileOutputFormat.setOutputPath(grepJob, tempDir);
//设置输出格式
grepJob.setOutputFormat(SequenceFileOutputFormat.class);
//设置输出键的类
grepJob.setOutputKeyClass(Text.class);
//设置输出值的类
grepJob.setOutputValueClass(LongWritable.class);
//运行
JobClient.runJob(grepJob);
JobConf sortJob = new JobConf(getConf(), Grep.class);
sortJob.setJobName("grep-sort");
FileInputFormat.setInputPaths(sortJob, tempDir);
sortJob.setInputFormat(SequenceFileInputFormat.class);
sortJob.setMapperClass(InverseMapper.class);
sortJob.setNumReduceTasks(1); // write a single file
FileOutputFormat.setOutputPath(sortJob, new Path(args[1]));
sortJob.setOutputKeyComparatorClass // sort by decreasing freq
(LongWritable.DecreasingComparator.class);
JobClient.runJob(sortJob);
} finally {
FileSystem.get(grepJob).delete(tempDir, true);
}
return 0;
}
public static void main(String[] args) throws Exception {
int res = ToolRunner.run(new Configuration(), new Grep(), args);
System.exit(res);
}
}
作者:zyuc_wangxw 发表于2013-7-4 11:30:15 原文链接
阅读:0 评论:0 查看评论
[3]Speex Acoustic Echo Cancellation (AEC) 回声消除模块的使用
来源: 互联网 发布时间: 2013-10-26
背景:回声与啸叫的产生 http://blog.csdn.net/u011202336/article/details/9238397
参考资料: http://www.speex.org/docs/manual
从代码分析,下边是Speex test demo
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "speex/speex_echo.h"
#include "speex/speex_preprocess.h"
#define NN 128
#define TAIL 1024
int main(int argc, char **argv)
{
FILE *echo_fd, *ref_fd, *e_fd;
short echo_buf[NN], ref_buf[NN], e_buf[NN];
SpeexEchoState *st;
SpeexPreprocessState *den;
int sampleRate = 8000;
if (argc != 4)
{
fprintf(stderr, "testecho mic_signal.sw speaker_signal.sw output.sw\n");
exit(1);
}
echo_fd = fopen(argv[2], "rb");
ref_fd = fopen(argv[1], "rb");
e_fd = fopen(argv[3], "wb");
// Step1: 初始化结构
st = speex_echo_state_init(NN, TAIL);
den = speex_preprocess_state_init(NN, sampleRate);
//Step2: 设置相关参数
speex_echo_ctl(st, SPEEX_ECHO_SET_SAMPLING_RATE, &sampleRate);
speex_preprocess_ctl(den, SPEEX_PREPROCESS_SET_ECHO_STATE, st);
while (!feof(ref_fd) && !feof(echo_fd))
{
fread(ref_buf, sizeof(short), NN, ref_fd);
fread(echo_buf, sizeof(short), NN, echo_fd);
//Step3: 调用Api回声消除,ref_buf是麦克采集到的数据
// echo_buf:是从speaker处获取到的数据
// e_buf: 是回声消除后的数据
speex_echo_cancellation(st, ref_buf, echo_buf, e_buf);
speex_preprocess_run(den, e_buf);
fwrite(e_buf, sizeof(short), NN, e_fd);
}
//Step4: 销毁结构 释放资源
speex_echo_state_destroy(st);
speex_preprocess_state_destroy(den);
fclose(e_fd);
fclose(echo_fd);
fclose(ref_fd);
return 0;
}
Speex 源码中附带的这个例子,只适合于串行的链式媒体流,当媒体播放、媒体采集、媒体网络数据接口分属在不同现成时,就会存在同步问题,异步线程会导致信号延迟加大,回声消除收敛效果不好。其中Speex 回声消除必须按照建议的流程:
write_to_soundcard(echo_frame, frame_size); //播放音频数据,并从声卡获得播放的数据echo_frame. read_from_soundcard(input_frame, frame_size); //在数据播放后,从声卡麦克获取采集到的数据input_frame. speex_echo_cancellation(echo_state, input_frame, echo_frame, output_frame); //调用Api消除噪声,输入input_frame,echo_frame,输出out_frame
在典型的VOIP类型应用中:
echo_frame: 从RTP接收的数据包解码后,送入声卡播放,获取的数据。
input_frame: 本地麦克采集到的数据
output_frame: 回声消除后的数据,送入encodec,并构造rtp数据包,传输到远端。
典型的应用模式:
Thread A: 接收audio rtp -> decodec -----> sound card
|__> echo_frame queue
Thread B: 获取麦克数据input_frame --> speex_echo_cancellation( speex_state, input_frame, echo_frame,out_frame ) -> rtp packet -> network
也可以将rtp packet 与network 传输放到另外一个线程。
作者:u011202336 发表于2013-7-3 23:51:22 原文链接
阅读:21 评论:0 查看评论
最新技术文章: