/*
* AMAudioFormat.java
*/
/*
* Copyright (c) 2001 by Florian Bomers <florian@bome.com>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as published
* by the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
//TODO: enable dynamic change of audio format - especially for owner client...
package com.audio;
import javax.sound.sampled.*;
public class AMAudioFormat {
public static final int FORMAT_CODE_CD=1;
public static final int FORMAT_CODE_FM=2;
public static final int FORMAT_CODE_TELEPHONE=3;
public static final int FORMAT_CODE_GSM=4;
public static final String[] FORMAT_NAMES={
"Cell phone GSM (13.2KBit/s - Modem)",
"Telephone ulaw (64KBit/s - ISDN)",
"FM quality mono (352.8KBit/s - ADSL)",
"CD quality mono (705.6KBit/s - LAN)"
};
public static final int[] FORMAT_CODES={
FORMAT_CODE_GSM,
FORMAT_CODE_TELEPHONE,
FORMAT_CODE_FM,
FORMAT_CODE_CD
};
public static final int FORMAT_CODE_DEFAULT=FORMAT_CODE_GSM;
private static int SAMPLE_RATE;
private static float LINE_FRAME_SIZE=2.0f; // always using lines with 16 bit
private static float NET_BYTES_PER_SAMPLE;
// quick look-up tables
private static final float[] netFrameSize={
1, // nothing
2, // CD
2, // FM
1, // Telephone
33.0f // GSM
};
private static final float[] netSampleRate={
1.0f, // nothing
44100.0f, // CD
22050.0f, // FM
8000.0f, // Telephone
8000.0f // GSM
};
private static final float[] netFrameRate={
1.0f, // nothing
44100.0f, // CD
22050.0f, // FM
8000.0f, // Telephone
50.0f // GSM
};
public static long lineBytes2Ms(long bytes) {
return (long) (bytes/LINE_FRAME_SIZE*1000/SAMPLE_RATE);
}
public static long netBytes2Ms(long bytes, int formatCode) {
return (long) (bytes/netFrameRate[formatCode]*1000/netFrameSize[formatCode]);
}
public static long bytes2Ms(long bytes, AudioFormat format) {
return (long) (bytes/format.getFrameRate()*1000/format.getFrameSize());
}
public static long ms2Bytes(long ms, AudioFormat format) {
return (long) (ms*format.getFrameRate()/1000*format.getFrameSize());
}
public static AudioFormat getLineAudioFormat(int formatCode) {
return getLineAudioFormat(netSampleRate[formatCode]);
}
public static AudioFormat getLineAudioFormat(float sampleRate) {
return new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED,
sampleRate, // sampleRate
16, // sampleSizeInBits
1, // channels
2, // frameSize
sampleRate, // frameRate
false); // bigEndian
// ulaw conversion does not work with Sun's ulaw provider if big endian...
}
public static AudioFormat getNetAudioFormat(int nformat) throws UnsupportedAudioFileException {
if (nformat==FORMAT_CODE_CD) {
return new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED,
44100.0f, // sampleRate
16, // sampleSizeInBits
1, // channels
2, // frameSize
44100.0f, // frameRate
true); // bigEndian
}
else if (nformat==FORMAT_CODE_FM) {
return new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED,
22050.0f, // sampleRate
16, // sampleSizeInBits
1, // channels
2, // frameSize
22050.0f, // frameRate
true); // bigEndian
}
else if (nformat==FORMAT_CODE_TELEPHONE) {
return new AudioFormat(
AudioFormat.Encoding.ULAW,
8000.0f, // sampleRate
8, // sampleSizeInBits
1, // channels
1, // frameSize
8000.0f, // frameRate
false); // bigEndian
}
else if (nformat==FORMAT_CODE_GSM) {
try {
Class.forName("org.tritonus.share.sampled.Encodings");
} catch (ClassNotFoundException cnfe) {
throw new RuntimeException("Tritonus shared classes not properly installed!");
}
return new AudioFormat(
org.tritonus.share.sampled.Encodings.getEncoding("GSM0610"),
8000.0F, // sampleRate
-1, // sampleSizeInBits
1, // channels
33, // frameSize
50.0F, // frameRate
false); // bigEndian
}
throw new RuntimeException("Wrong format code!");
}
public static int getFormatCode(AudioFormat format) {
AudioFormat.Encoding encoding = format.getEncoding();
// very simple check...
if (encoding.equals(AudioFormat.Encoding.PCM_SIGNED)) {
if (format.getSampleRate()==44100.0f) {
return FORMAT_CODE_CD;
} else {
return FORMAT_CODE_FM;
}
}
if (encoding.equals(AudioFormat.Encoding.ULAW)) {
return FORMAT_CODE_TELEPHONE;
}
if (encoding.equals(org.tritonus.share.sampled.Encodings.getEncoding("GSM0610"))) {
return FORMAT_CODE_GSM;
}
throw new RuntimeException("Wrong Format");
}
}
/*** AMAudioFormat.java ***/
没有合适的资源?快使用搜索试试~ 我知道了~
java实现网络音频 视频通信
共38个文件
class:20个
java:9个
jar:6个
3星 · 超过75%的资源 需积分: 35 156 下载量 49 浏览量
2017-08-31
20:03:26
上传
评论 12
收藏 13MB RAR 举报
温馨提示
通过java的opencv获取图像,通过java sound api读取音频,通过socket实现客户端点对点音视频通信 使用java swing开发客户端,源码中client是客户端,server是服务端,需要现开启服务端再开客户端
资源推荐
资源详情
资源评论
收起资源包目录
AudioAndVideo.rar (38个子文件)
AudioAndVideo
bin
TestClient.class 986B
VideoServer$PlayThread.class 1KB
VideoClient.class 2KB
VideoServer.class 1KB
TestServer$ServerThread.class 2KB
TestServer$CaptureThread.class 1KB
VideoServer$ServerThread.class 1KB
com
audio
AudioCapture.class 4KB
Debug.class 2KB
AudioPlayStream.class 5KB
AudioCapture$TargetDataLineIS.class 2KB
AMAudioFormat.class 4KB
TestClient$CaptureThread.class 1KB
TestServer$PlayThread.class 2KB
TestClient$PlayThread.class 2KB
DwImagePanel.class 3KB
VideoClient$1.class 702B
VideoClient$2.class 3KB
VideoServer$1.class 702B
TestServer.class 808B
.settings
org.eclipse.jdt.core.prefs 635B
src
TestServer.java 3KB
TestClient.java 2KB
VideoServer.java 2KB
com
audio
AudioCapture.java 5KB
AudioPlayStream.java 5KB
AMAudioFormat.java 6KB
Debug.java 2KB
DwImagePanel.java 3KB
VideoClient.java 3KB
.project 381B
.classpath 677B
lib
javacv.jar 1.1MB
javacpp.jar 157KB
tritonus_share-0.3.6.jar 103KB
opencv-2.4.8-windows-x86.jar 10.53MB
tritonus_gsm-0.3.6.jar 39KB
javacv-windows-x86.jar 1.29MB
共 38 条
- 1
小旋风风
- 粉丝: 4
- 资源: 34
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页