WAVE Sample Files

本文提供了多种类型的WAV文件样本,包括不同采样率、位深度及压缩格式等,适用于测试和研究各种WAV文件格式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

关于画wav文件声音数据波形图,  见上篇日志 http://blog.csdn.net/touzani/archive/2007/06/17/1654943.aspx

下面这篇文章有各种格式的wav文件地址, 可以做为素材..以供测试..

原文地址: http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/Samples.html

The following are WAVE files with various data types.

  • The files marked with an asterisk (*) will not play with Windows Media Player.
  • The file marked with a plus sign (+) plays as noise with Windows Media Player.

Sample Files from CopyAudio

The CopyAudio program (part of the AFsp package) can produce output files of a number of different types. Samples files produced by converting stereo 16-bit data are as follows. All of these files have information chunks at the end of the file after the sampled data.

Sample Files from GoldWave

The following file were created by Goldwave. The µ-law and A-law formats differ slightly from those produced by CopyAudio (The ITU-T standard is permissive as to which way to quantize sample values which fall exactly mid-way between output values.)

Multi-Channel Examples (WAVE_FORMAT_EXTENSIBLE)

A six channel (5.1 channel) audio file from the Microsoft site: 5.1 Audio

6_Channel_ID.wav (3.0 MB) Warning: LARGE file
A 6-channel WAVE file with speaker locations (FL FR FC LF BL BR)
44100 Hz, 16-bit, 5.8 s
- This file has a "cue " chunk with a count of zero cue points, followed by two empty cue point structures.

An eight channel (7.1 channel) audio file from the Microsoft site: Creating 7.1 Audio

8_Channel_ID.wav (8.8 MB) Warning: LARGE file
An 8-channel WAVE file with speaker locations (FL FR FC LF BL BR - -)
48000 Hz, 24-bit, 8.05 s
- The voice annotation and tone for this file appear in the channels in the recording as follows. The relative times of the voice annotation in the different channels is indicated by the ordinal number.
  Channel 1: 1st:  "Front Left"
  Channel 2: 2nd: "Front  Right"
  Channel 3: 3rd: "Centre"
  Channel 4: 6th:  tone
  Channel 5: 4th: "Back Left"
  Channel 6: 5th: "Back Right"
  Channel 7: 7th: "Auxiliary Left"
  Channel 8: 8th: "Auxiliary Right"

SoundCard Attrition Files (including WAVE_FORMAT_EXTENSIBLE files)

These files are taken from Soundcard Attrition Page.

  • stereol.wav (116 kB)
    A standard 16-bit stereo WAVE file, but with a long header
    22050 Hz, 16-bit, 1.32 s
    stereofl.wav (229 kB) +
    The same, but in TYPE-3 32-bit floats
    22050 Hz, 1.32 s
    4ch.wav (1,321 kB)
    Speech idents, in LCRS surround format
    44100 Hz, 3.83 s (from Microsoft)
    drmapan.wav (825 kB)
    Drum, panned ambisonically in a circle in quad format (LF, RF, LR, RR)
    22050 Hz, 4.78 s (created with CDP Multi-Channel Toolkit)

Perverse Files

The following WAVE files are perverse or have problems.

  • Pmiscck.wav (1 kB)
    WAVE file (9 samples) with an odd length intermediate chunk (type " XxXx").
    Ptjunk.wav (1 kB)
    WAVE file with trailing junk after the RIFF chunk.
    GLASS.WAV (79 kB)
    WAVE file with a RIFF chunk length larger than the file size (originally from www.sipro.com).
    Utopia Critical Stop.WAV (6 kB)
    WAVE file, PCM data, with a Fact chunk following the data. The Fact chunk contains the four characters " FILT" and not the number of samples. (From C:/WINNT/Media on a Windows 2000 system).

Other WAVE files

These files are from CCRMA at Stanford: ftp://ftp-ccrma.stanford.edu/pub/Lisp/sf.tar.gz.


width="728" scrolling="no" height="90" frameborder="0" align="middle" src="http://download1.csdn.net/down3/20070601/01184120111.htm" marginheight="0" marginwidth="0">
如果我需要将一个g711a的字节数组包装成wav格式音频,这个方法还有什么需要改进的地方 public static File createWavFile(byte[] g711aData, String outputPath) throws IOException { try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos)) { int numChannels = 1; // 单声道 long sampleRate = 8000L; // 采样率为8kHz short bitsPerSample = 16; // G.711 每样本占用一位深度为8bit short blockAlign = (short)(numChannels * bitsPerSample / 8); // 对于G.711来说就是1 // 计算实际音频数据大小 int dataSize = g711aData.length; // Write the RIFF header ("RIFF") writeFourCC(dos, "RIFF"); // Calculate file size and subtract 8 bytes for 'RIFF' marker dos.writeInt((int) (36 + dataSize)); // Write format type ("WAVE") writeFourCC(dos, "WAVE"); // Write the 'fmt ' sub-chunk with necessary parameters. writeFourCC(dos, "fmt "); // Subchunk1Size = 16 for minimum 'fmt ' dos.writeInt(16); // Audio Format: 0xFFFE to indicate non-standard codec (G.711A in this case) dos.writeShort((short) 0xFFFE); // Number of Channels & Sample Rate dos.writeShort(numChannels); dos.writeInt((int)sampleRate); // Byte rate = NumChannels * SampleRate * BitsPerSample / 8 dos.writeInt((int)((numChannels * sampleRate * bitsPerSample) / 8)); // Block Align dos.writeShort(blockAlign); // Bits Per Sample dos.writeShort(bitsPerSample); // Start writing data chunk identifier ('data') writeFourCC(dos, "data"); dos.writeInt(dataSize); // Finally add raw audio content as-is from input array //dos.write(g711aData); File outputFile = new File(outputPath); // Create target output file at specified path Files.createDirectories(outputFile.getParentFile().toPath()); FileOutputStream fos = new FileOutputStream(outputFile); System.out.println("baos.toByteArray().length:"+baos.toByteArray().length); fos.write(baos.toByteArray()); fos.flush(); OutputStream os = null; try{ os = new BufferedOutputStream(new FileOutputStream(outputPath)); System.out.println("baos.toByteArray():"+Arrays.toString(baos.toByteArray())); System.out.println("baos.toByteArray():"+baos.toByteArray().length); os.write(baos.toByteArray()); }catch (Exception e){ e.printStackTrace(); }finally { os.close(); baos.close(); } return outputFile; } }
03-11
您的方法基本实现了将 G.711A 编码的数据封装到 WAV 格式中,但是存在一些可以优化和修正的地方。以下是针对您现有代码的一些改进建议: ### 改进建议 #### 1. **修复比特率设置** - G.711 是一种压缩编码格式,每个样本实际上占用的是 **8 bit**(即 1 字节),而不是你在 `bitsPerSample` 设置的 `16`。这会影响后续计算的正确性。 #### 2. **移除冗余代码段** - 在最后部分有两次向目标文件写入相同的字节数组的操作,这是不必要的。应该只保留一次,并且注意关闭资源的方式。 #### 3. **调整音频格式标识符** - 使用 `0xFFFE` 表示非标准编解码器并不合适。对于 G.711A 来说,更常见的做法是指定为 PCM 数据,在播放时通过额外信息告知设备这是一个特殊的线性量化值而非真正的 PCM。 #### 4. **简化文件创建过程** - 可以直接使用 `Files.write` 方法来替代手动打开流再写入的过程,减少繁琐度的同时也减少了潜在的风险点。 #### 5. **确保所有 IO 流都被妥善关闭** 下面是修改后的版本: ```java import javax.sound.sampled.*; import java.io.*; import java.nio.file.*; public class WavUtils { private static final int BITS_PER_SAMPLE = 8; // G.711每样本8位 /** * 创建包含G.711A编码音频数据的WAV文件。 */ public static File createWavFile(byte[] g711aData, String outputPath) throws IOException { if (g711aData == null || g711aData.length <= 0) throw new IllegalArgumentException("Invalid audio data"); try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { writeWaveHeader(baos, g711aData.length); // 添加原始音轨数据至文件尾部 baos.write(g711aData); // 确保目录结构已准备就绪 Path parentDir = Paths.get(outputPath).getParent(); if (parentDir != null && !parentDir.toFile().exists()) Files.createDirectories(parentDir); // 把生成好的wav头加上raw data保存为目标文件 Files.write(Paths.get(outputPath), baos.toByteArray()); return new File(outputPath); } } /*** * 构造WAV头部信息 ***/ private static void writeWaveHeader(DataOutput out, int dataSize) throws IOException { int numChannels = 1; long sampleRate = 8000L; short blockAlign = (short)(numChannels * BITS_PER_SAMPLE / 8); // RIFF header ("RIFF") writeFourCC(out, "RIFF"); // Overall file size minus first eight bytes of RIFF identifier out.writeInt(36 + dataSize); // Format type ("WAVE") writeFourCC(out, "WAVE"); // fmt sub-chunk writeFourCC(out, "fmt "); // Subchunk1 Size: always 16 for minimal 'fmt ' out.writeInt(16); // Audio Format ID (PCM=1, other values vary): here we use a common format id but note that this is not strictly accurate since it's actually G.711 out.writeShort((short) 1); // Channel count out.writeShort(numChannels); // Sampling frequency out.writeInt((int) sampleRate); // Average number of bytes per second (for buffer estimation) out.writeInt((int) ((numChannels * sampleRate * BITS_PER_SAMPLE) / 8)); // Block alignment (number of bytes making up one complete sample including all channels) out.writeShort(blockAlign); // Significant bits per sample point out.writeShort(BITS_PER_SAMPLE); // Data chunk marker ('data') writeFourCC(out, "data"); // Actual length of subsequent data portion out.writeInt(dataSize); } /** Helper function to easily insert four-character codes into stream **/ private static void writeFourCC(DataOutput out, String s) throws IOException { char[] chars = s.toCharArray(); for(int i=0;i<s.length();i++){ out.writeByte(chars[i]); } } } ``` 上述改动解决了先前提到的问题,并提高了程序的健壮性和清晰度。然而值得注意的一点是:尽管我们在这里选择了 PCM 的格式 ID (`AudioFormat.WAVE_FORMAT_PCM`) 和相关的参数配置,但这只是为了让大多数媒体播放软件能够识别该文件;实际上内部存储的仍然是未经解压的 G.711 声道数据。如果您打算在某些特定平台上回放这种文件,请务必确认它们支持对 G.711 进行正确的解析。 --- ### 注意事项: - 因为这里是以 PCM 形式的假象去描述 G.711 音频帧序列,所以在实际应用当中最好附带说明或元数据指示这不是常规意义上的 PCM 波形而是某种特殊编码如 G.711; - 同样需要注意的是,不是所有的多媒体播放器都能完美兼容这种方式构造出来的 .wav 文件
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值