当前位置: 首页>>代码示例>>Java>>正文


Java AudioFileFormat类代码示例

本文整理汇总了Java中javax.sound.sampled.AudioFileFormat的典型用法代码示例。如果您正苦于以下问题:Java AudioFileFormat类的具体用法?Java AudioFileFormat怎么用?Java AudioFileFormat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AudioFileFormat类属于javax.sound.sampled包,在下文中一共展示了AudioFileFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: JSBufferedSampleRecorder

import javax.sound.sampled.AudioFileFormat; //导入依赖的package包/类
/**
 * Constructs a JSBufferedSampleRecorder that expects audio in the given AudioFormat and 
 * which will save to a file with given name.
 * 
 * @param format the AudioFormat you want to record in
 * @param name the name of the file to save to (not including the extension)
 */
JSBufferedSampleRecorder(JSMinim sys,
                         String fileName, 
                         AudioFileFormat.Type fileType, 
                         AudioFormat fileFormat,
                         int bufferSize)
{
  name = fileName;
  type = fileType;
  format = fileFormat;
  buffers = new ArrayList<FloatBuffer>(20);
  left = FloatBuffer.allocate(bufferSize*10);
  if ( format.getChannels() == Minim.STEREO )
  {
    right = FloatBuffer.allocate(bufferSize*10);
  }
  else
  {
    right = null;
  }
  system = sys;
}
 
开发者ID:JacobRoth,项目名称:romanov,代码行数:29,代码来源:JSBufferedSampleRecorder.java

示例2: testSampleRate

import javax.sound.sampled.AudioFileFormat; //导入依赖的package包/类
private static boolean testSampleRate(float sampleRate) {
    boolean result = true;

    try {
        // create AudioInputStream with sample rate of 10000 Hz
        ByteArrayInputStream data = new ByteArrayInputStream(new byte[1]);
        AudioFormat format = new AudioFormat(sampleRate, 8, 1, true, true);
        AudioInputStream stream = new AudioInputStream(data, format, 1);

        // write to AIFF file
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        AudioSystem.write(stream, AudioFileFormat.Type.AIFF, outputStream);
        byte[] fileData = outputStream.toByteArray();
        InputStream inputStream = new ByteArrayInputStream(fileData);
        AudioFileFormat aff = AudioSystem.getAudioFileFormat(inputStream);
        if (! equals(sampleRate, aff.getFormat().getFrameRate())) {
            out("error for sample rate " + sampleRate);
            result = false;
        }
    } catch (Exception e) {
        out(e);
        out("Test NOT FAILED");
    }
    return result;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:AiffSampleRate.java

示例3: WaveFileFormat

import javax.sound.sampled.AudioFileFormat; //导入依赖的package包/类
WaveFileFormat(AudioFileFormat.Type type, int lengthInBytes, AudioFormat format, int lengthInFrames) {

        super(type,lengthInBytes,format,lengthInFrames);

        AudioFormat.Encoding encoding = format.getEncoding();

        if( encoding.equals(AudioFormat.Encoding.ALAW) ) {
            waveType = WAVE_FORMAT_ALAW;
        } else if( encoding.equals(AudioFormat.Encoding.ULAW) ) {
            waveType = WAVE_FORMAT_MULAW;
        } else if( encoding.equals(AudioFormat.Encoding.PCM_SIGNED) ||
                   encoding.equals(AudioFormat.Encoding.PCM_UNSIGNED) ) {
            waveType = WAVE_FORMAT_PCM;
        } else {
            waveType = WAVE_FORMAT_UNKNOWN;
        }
    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:WaveFileFormat.java

示例4: getAudioInputStream

import javax.sound.sampled.AudioFileFormat; //导入依赖的package包/类
/**
 * Obtains an audio stream from the File provided.  The File must
 * point to valid audio file data.
 * @param file the File for which the <code>AudioInputStream</code> should be
 * constructed
 * @return an <code>AudioInputStream</code> object based on the audio file data pointed
 * to by the File
 * @throws UnsupportedAudioFileException if the File does not point to valid audio
 * file data recognized by the system
 * @throws IOException if an I/O exception occurs
 */
public AudioInputStream getAudioInputStream(File file)
    throws UnsupportedAudioFileException, IOException {

    FileInputStream fis = new FileInputStream(file); // throws IOException
    AudioFileFormat fileFormat = null;
    // part of fix for 4325421
    try {
        fileFormat = getCOMM(fis, false);
    } finally {
        if (fileFormat == null) {
            fis.close();
        }
    }
    return new AudioInputStream(fis, fileFormat.getFormat(), fileFormat.getFrameLength());
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:AiffFileReader.java

示例5: write

import javax.sound.sampled.AudioFileFormat; //导入依赖的package包/类
@Override
public int write(AudioInputStream stream, AudioFileFormat.Type fileType, OutputStream out) throws IOException {
    Objects.requireNonNull(stream);
    Objects.requireNonNull(fileType);
    Objects.requireNonNull(out);

    //$$fb the following check must come first ! Otherwise
    // the next frame length check may throw an IOException and
    // interrupt iterating File Writers. (see bug 4351296)

    // throws IllegalArgumentException if not supported
    WaveFileFormat waveFileFormat = (WaveFileFormat)getAudioFileFormat(fileType, stream);

    //$$fb when we got this far, we are committed to write this file

    // we must know the total data length to calculate the file length
    if( stream.getFrameLength() == AudioSystem.NOT_SPECIFIED ) {
        throw new IOException("stream length not specified");
    }

    return writeWaveFile(stream, waveFileFormat, out);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:WaveFileWriter.java

示例6: write

import javax.sound.sampled.AudioFileFormat; //导入依赖的package包/类
public int write(AudioInputStream stream, AudioFileFormat.Type fileType, OutputStream out) throws IOException {

        //$$fb the following check must come first ! Otherwise
        // the next frame length check may throw an IOException and
        // interrupt iterating File Writers. (see bug 4351296)

        // throws IllegalArgumentException if not supported
        WaveFileFormat waveFileFormat = (WaveFileFormat)getAudioFileFormat(fileType, stream);

        //$$fb when we got this far, we are committed to write this file

        // we must know the total data length to calculate the file length
        if( stream.getFrameLength() == AudioSystem.NOT_SPECIFIED ) {
            throw new IOException("stream length not specified");
        }

        int bytesWritten = writeWaveFile(stream, waveFileFormat, out);
        return bytesWritten;
    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:WaveFileWriter.java

示例7: getAudioInputStream

import javax.sound.sampled.AudioFileFormat; //导入依赖的package包/类
public AudioInputStream getAudioInputStream(InputStream stream)
        throws UnsupportedAudioFileException, IOException {

    AudioFileFormat format = getAudioFileFormat(stream);
    RIFFReader riffiterator = new RIFFReader(stream);
    if (!riffiterator.getFormat().equals("RIFF"))
        throw new UnsupportedAudioFileException();
    if (!riffiterator.getType().equals("WAVE"))
        throw new UnsupportedAudioFileException();
    while (riffiterator.hasNextChunk()) {
        RIFFReader chunk = riffiterator.nextChunk();
        if (chunk.getFormat().equals("data")) {
            return new AudioInputStream(chunk, format.getFormat(),
                    chunk.getSize());
        }
    }
    throw new UnsupportedAudioFileException();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:WaveFloatFileReader.java

示例8: getAudioInputStream

import javax.sound.sampled.AudioFileFormat; //导入依赖的package包/类
public AudioInputStream getAudioInputStream(InputStream stream)
        throws UnsupportedAudioFileException, IOException {

    AudioFileFormat format = getAudioFileFormat(stream);
    RIFFReader riffiterator = new RIFFReader(stream);
    if (!riffiterator.getFormat().equals("RIFF"))
        throw new UnsupportedAudioFileException();
    if (!riffiterator.getType().equals("WAVE"))
        throw new UnsupportedAudioFileException();
    while (riffiterator.hasNextChunk()) {
        RIFFReader chunk = riffiterator.nextChunk();
        if (chunk.getFormat().equals("data")) {
            return new AudioInputStream(chunk, format.getFormat(), chunk
                    .getSize());
        }
    }
    throw new UnsupportedAudioFileException();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:WaveExtensibleFileReader.java

示例9: getAudioFileTypes

import javax.sound.sampled.AudioFileFormat; //导入依赖的package包/类
public AudioFileFormat.Type[] getAudioFileTypes(AudioInputStream stream) {

        AudioFileFormat.Type[] filetypes = new AudioFileFormat.Type[types.length];
        System.arraycopy(types, 0, filetypes, 0, types.length);

        // make sure we can write this stream
        AudioFormat format = stream.getFormat();
        AudioFormat.Encoding encoding = format.getEncoding();

        if( (AudioFormat.Encoding.ALAW.equals(encoding)) ||
            (AudioFormat.Encoding.ULAW.equals(encoding)) ||
            (AudioFormat.Encoding.PCM_SIGNED.equals(encoding)) ||
            (AudioFormat.Encoding.PCM_UNSIGNED.equals(encoding)) ) {

            return filetypes;
        }

        return new AudioFileFormat.Type[0];
    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:AiffFileWriter.java

示例10: write

import javax.sound.sampled.AudioFileFormat; //导入依赖的package包/类
public int write(AudioInputStream stream, AudioFileFormat.Type fileType, OutputStream out) throws IOException {

        //$$fb the following check must come first ! Otherwise
        // the next frame length check may throw an IOException and
        // interrupt iterating File Writers. (see bug 4351296)

        // throws IllegalArgumentException if not supported
        AiffFileFormat aiffFileFormat = (AiffFileFormat)getAudioFileFormat(fileType, stream);

        // we must know the total data length to calculate the file length
        if( stream.getFrameLength() == AudioSystem.NOT_SPECIFIED ) {
            throw new IOException("stream length not specified");
        }

        int bytesWritten = writeAiffFile(stream, aiffFileFormat, out);
        return bytesWritten;
    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:AiffFileWriter.java

示例11: testAfterSaveToFile

import javax.sound.sampled.AudioFileFormat; //导入依赖的package包/类
/**
 * Verifies the frame length after the stream was saved/read to/from file.
 */
private static void testAfterSaveToFile(final AudioFileWriter afw,
                                        final AudioFileFormat.Type type,
                                        AudioInputStream ais)
        throws IOException {
    final File temp = File.createTempFile("sound", ".tmp");
    try {
        afw.write(ais, type, temp);
        ais = AudioSystem.getAudioInputStream(temp);
        final long frameLength = ais.getFrameLength();
        ais.close();
        validate(frameLength);
    } catch (IllegalArgumentException | UnsupportedAudioFileException
            ignored) {
    } finally {
        Files.delete(Paths.get(temp.getAbsolutePath()));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:FrameLengthAfterConversion.java

示例12: main

import javax.sound.sampled.AudioFileFormat; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    boolean foundDuplicates = false;
    AudioFileFormat.Type[]  aTypes = AudioSystem.getAudioFileTypes();
    for (int i = 0; i < aTypes.length; i++)
    {
        for (int j = 0; j < aTypes.length; j++)
        {
            if (aTypes[i].equals(aTypes[j]) && i != j) {
                foundDuplicates = true;
            }
        }
    }
    if (foundDuplicates) {
        throw new Exception("Test failed");
    } else {
        System.out.println("Test passed");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:AudioFileTypeUniqueness.java

示例13: main

import javax.sound.sampled.AudioFileFormat; //导入依赖的package包/类
public static void main(final String[] args) {
    final AudioFileFormat.Type type;
    try {
        type = new AudioFileFormat.Type(null, null);
    } catch (final Exception ignored) {
        // behaviour of null is not specified so ignore possible exceptions
        return;
    }
    final Object stub = new Object() {
        @Override
        public String toString() {
            return null;
        }
    };
    if (stub.equals(type) || type.equals(stub)) {
        throw new RuntimeException("Should not be equal");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:TypeEqualsToNull.java

示例14: getAudioFileTypes

import javax.sound.sampled.AudioFileFormat; //导入依赖的package包/类
public AudioFileFormat.Type[] getAudioFileTypes(AudioInputStream stream) {

        AudioFileFormat.Type[] filetypes = new AudioFileFormat.Type[types.length];
        System.arraycopy(types, 0, filetypes, 0, types.length);

        // make sure we can write this stream
        AudioFormat format = stream.getFormat();
        AudioFormat.Encoding encoding = format.getEncoding();

        if( AudioFormat.Encoding.ALAW.equals(encoding) ||
            AudioFormat.Encoding.ULAW.equals(encoding) ||
            AudioFormat.Encoding.PCM_SIGNED.equals(encoding) ||
            AudioFormat.Encoding.PCM_UNSIGNED.equals(encoding) ) {

            return filetypes;
        }

        return new AudioFileFormat.Type[0];
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:WaveFileWriter.java

示例15: write

import javax.sound.sampled.AudioFileFormat; //导入依赖的package包/类
@Override
public int write(AudioInputStream stream, AudioFileFormat.Type fileType, OutputStream out) throws IOException {
    Objects.requireNonNull(stream);
    Objects.requireNonNull(fileType);
    Objects.requireNonNull(out);

    //$$fb the following check must come first ! Otherwise
    // the next frame length check may throw an IOException and
    // interrupt iterating File Writers. (see bug 4351296)

    // throws IllegalArgumentException if not supported
    AiffFileFormat aiffFileFormat = (AiffFileFormat)getAudioFileFormat(fileType, stream);

    // we must know the total data length to calculate the file length
    if( stream.getFrameLength() == AudioSystem.NOT_SPECIFIED ) {
        throw new IOException("stream length not specified");
    }

    return writeAiffFile(stream, aiffFileFormat, out);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:AiffFileWriter.java


注:本文中的javax.sound.sampled.AudioFileFormat类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。