/******************************************************************************
* *
* Copyright (c) 1999-2004 Wimba S.A., All Rights Reserved. *
* *
* COPYRIGHT: *
* This software is the property of Wimba S.A. *
* This software is redistributed under the Xiph.org variant of *
* the BSD license. *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* - Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* - Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* - Neither the name of Wimba, the Xiph.org Foundation nor the names of *
* its contributors may be used to endorse or promote products derived *
* from this software without specific prior written permission. *
* *
* WARRANTIES: *
* This software is made available by the authors in the hope *
* that it will be useful, but without any warranty. *
* Wimba S.A. is not liable for any consequence related to the *
* use of the provided software. *
* *
* Class: RawWriter.java *
* *
* Author: Marc GIMPEL *
* *
* Date: 6th January 2004 *
* *
******************************************************************************/
/* $Id: AudioFileWriter.java,v 1.1 2011/12/27 04:39:13 gauss Exp $ */
package com.gauss.writer.speex;
import java.io.DataOutput;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
/**
* Abstract Class that defines an Audio File Writer.
*
* @author Marc Gimpel, Wimba S.A. (mgimpel@horizonwimba.com)
* @version $Revision: 1.1 $
*/
public abstract class AudioFileWriter
{
/**
* Closes the output file.
* @exception IOException if there was an exception closing the Audio Writer.
*/
public abstract void close()
throws IOException;
/**
* Open the output file.
* @param file - file to open.
* @exception IOException if there was an exception opening the Audio Writer.
*/
public abstract void open(File file)
throws IOException;
/**
* Open the output file.
* @param filename - file to open.
* @exception IOException if there was an exception opening the Audio Writer.
*/
public abstract void open(String filename)
throws IOException;
/**
* Writes the header pages that start the Ogg Speex file.
* Prepares file for data to be written.
* @param comment description to be included in the header.
* @exception IOException
*/
public abstract void writeHeader(String comment)
throws IOException;
/**
* Writes a packet of audio.
* @param data audio data
* @param offset the offset from which to start reading the data.
* @param len the length of data to read.
* @exception IOException
*/
public abstract void writePacket(byte[] data, int offset, int len)
throws IOException;
/**
* Writes an Ogg Page Header to the given byte array.
* @param buf the buffer to write to.
* @param offset the from which to start writing.
* @param headerType the header type flag
* (0=normal, 2=bos: beginning of stream, 4=eos: end of stream).
* @param granulepos the absolute granule position.
* @param streamSerialNumber
* @param pageCount
* @param packetCount
* @param packetSizes
* @return the amount of data written to the buffer.
*/
public static int writeOggPageHeader(byte[] buf, int offset, int headerType,
long granulepos, int streamSerialNumber,
int pageCount, int packetCount,
byte[] packetSizes)
{
writeString(buf, offset, "OggS"); // 0 - 3: capture_pattern
buf[offset+4] = 0; // 4: stream_structure_version
buf[offset+5] = (byte) headerType; // 5: header_type_flag
writeLong(buf, offset+6, granulepos); // 6 - 13: absolute granule position
writeInt(buf, offset+14, streamSerialNumber); // 14 - 17: stream serial number
writeInt(buf, offset+18, pageCount); // 18 - 21: page sequence no
writeInt(buf, offset+22, 0); // 22 - 25: page checksum
buf[offset+26] = (byte) packetCount; // 26: page_segments
System.arraycopy(packetSizes, 0, // 27 - x: segment_table
buf, offset+27, packetCount);
return packetCount+27;
}
/**
* Builds and returns an Ogg Page Header.
* @param headerType the header type flag
* (0=normal, 2=bos: beginning of stream, 4=eos: end of stream).
* @param granulepos the absolute granule position.
* @param streamSerialNumber
* @param pageCount
* @param packetCount
* @param packetSizes
* @return an Ogg Page Header.
*/
public static byte[] buildOggPageHeader(int headerType, long granulepos,
int streamSerialNumber, int pageCount,
int packetCount, byte[] packetSizes)
{
byte[] data = new byte[packetCount+27];
writeOggPageHeader(data, 0, headerType, granulepos, streamSerialNumber,
pageCount, packetCount, packetSizes);
return data;
}
/**
* Writes a Speex Header to the given byte array.
* @param buf the buffer to write to.
* @param offset the from which to start writing.
* @param sampleRate
* @param mode
* @param channels
* @param vbr
* @param nframes
* @return the amount of data written to the buffer.
*/
public static int writeSpeexHeader(byte[] buf, int offset, int sampleRate,
int mode, int channels, boolean vbr,
int nframes)
{
writeString(buf, offset, "Speex "); // 0 - 7: speex_string
writeString(buf, offset+8, "speex-1.2rc"); // 8 - 27: speex_version
System.arraycopy(new byte[11], 0, buf, offset+17, 11); // : speex_version (fill in up to 20 bytes)
writeInt(buf, offset+28, 1); // 28 - 31: speex_version_id
writeInt(buf, offset+32, 80); // 32 - 35: header_size
writeInt(buf, offset+36, sampleRate); // 36 - 39: rate
writeInt(buf, offset+40, mode); // 40 - 43: mode (0=NB, 1=WB, 2=UWB)
writeInt(buf, offset+44, 4); // 44 - 47: mode_bitstream_version
writeInt(buf, offset+48, channels); // 48 - 5
yxkfw
- 粉丝: 82
- 资源: 2万+
最新资源
- 风光柴储直流微网(并离网均可) 含: 永磁风机+整流 光伏发+boost+mppt 柴油机380V+整流 储能双向DCDC稳压直流母线800V 离网逆变器VF控制 0.85s时刻负荷突增20kW 波
- 西门子1200PLC大型项程序,生产线生产案例,包含气缸,通讯,机械手,模拟量等,各种FB块,可用来参考和学习 若能学懂这个,大型程序基本能独当一面 plc博图15以及以上,威纶通触摸屏,共计控制2
- GWO-LSTM多变量回归预测,灰狼算法优化长短期记忆网络的回归预测(Matlab) 1.data为数据集 2.MainGWO-LSTMNN.m为程序主文件,其他为函数文件无需运行 3.命令窗口输
- Abb万能密钥,带涂胶工艺包,选项快捷方便,可做工作站-涂胶
- 三菱PLC转盘机程序 三菱plc学习借鉴程序案例,没触摸屏 此程序已经实际设备上批量应用,程序成熟可靠,借鉴价值高,程序有注释,用的三菱fx3u系列plc 是入门级三菱PLC电气爱好从业人员借鉴和参
- 储能系统双向DCDC变器 双闭环控制 蓄电池充放电仿真模型有buck模式和boost模式,依靠蓄电池充放电维持直流母线电压平衡
- 软件使用:Matlab Simulink 适用场景:采用模块化建模方法,搭建14自由度整车模型,作为整车平台适用于多种工况场景 产品simulink源码包含如下模块: 工况: 阶跃工况 包含模块
- 无感FOC 滑膜观测器 算法采用滑膜观测器,启动采用Vf,全开源c代码,全开源,启动顺滑,提供原理图、smo推导过程及仿真模型
- 50KW储能逆变器变流器结构设计图源文件 SOLID WORKS工具格式 是基于高效、可靠、免维护的理念,开发的光伏储能产品,为家庭和工业不间断供电提供了灵活多样及安全可靠的系统解决方案 离并网一体
- Simulink仿真:基于DC DC双向变器的多电池主动均衡技术 关键词:锂电池;不一致性;模糊控制理论;DC DC双向主动均衡;荷电状态(SOC);均值-差值法 参考文献:基于DC DC双向变器的多
- 西门子1200立库机器人码垛机伺服视觉AGV程序 包括2台西门子PLC1215程序和2台西门子触摸屏TP700程序 PLC与工业相机视觉定位及机器人使用Modbus TCP通讯 PLC和码垛机Modb
- 声子晶体声表面波-等离子激元效应仿真案例文献复现Surface acoustic waves-localized plasmon interaction in pillared phononic cr
- 三菱FX3U PLC FX3U-485BD自由口跟23个上海众晨Z2000变频器通讯,读运行电流,写入设定频率;读RKC RD700温控表温度值,读电能表正向有功功率;程序简洁明了,注释详细 单PL
- 水处理程序,中文注释,内容齐全,风机,阀,传感器,PID样样齐全 汽车厂大程序,有很大参考借鉴意义值得你拥有
- OMRON CP1H PLC脉冲控制三轴伺服, 码垛机,实际项目,程序结构清析,有完整的注释,重复功能做成FB功能块,在其它项目可以导出直接用,MCGS触摸屏程序,有电气CAD图纸
- 新能源电池焊接1200程序 西门子PLC做的电池焊接程序,电池包里面有n*m行列个电池,主要功能: 1.每个电池的焊点坐标能够独立调整 2.每个电池的焊接能量可独立选择 3.任意一个或者多个电池可以随
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈