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


Java AudioFormat.SIGNED属性代码示例

本文整理汇总了Java中javax.media.format.AudioFormat.SIGNED属性的典型用法代码示例。如果您正苦于以下问题:Java AudioFormat.SIGNED属性的具体用法?Java AudioFormat.SIGNED怎么用?Java AudioFormat.SIGNED使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在javax.media.format.AudioFormat的用法示例。


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

示例1: getSupportedInputFormats

@Override
public Format[] getSupportedInputFormats()
{
    // TODO: query AudioSystem
    return new Format[] {
            new AudioFormat(AudioFormat.LINEAR, -1, 8, -1, -1,
                    AudioFormat.SIGNED),
            new AudioFormat(AudioFormat.LINEAR, -1, 16, -1,
                    AudioFormat.BIG_ENDIAN, AudioFormat.SIGNED),
            new AudioFormat(AudioFormat.LINEAR, -1, 24, -1,
                    AudioFormat.BIG_ENDIAN, AudioFormat.SIGNED),
            new AudioFormat(AudioFormat.LINEAR, -1, 32, -1,
                    AudioFormat.BIG_ENDIAN, AudioFormat.SIGNED),
            new AudioFormat(AudioFormat.ULAW), // TODO: narrow down
            new AudioFormat(AudioFormat.ALAW) // TODO: narrow down
    };
}
 
开发者ID:champtar,项目名称:fmj-sourceforge-mirror,代码行数:17,代码来源:JavaSoundAUMux.java

示例2: readHeader

private void /* for now void */ readHeader()
    throws IOException, BadHeaderException {

    minLocation = getLocation(stream); // Should be zero

    long contentLength = stream.getContentLength();
    if ( contentLength != SourceStream.LENGTH_UNKNOWN ) {
        double durationSeconds = contentLength / bytesPerSecond;


        duration = new Time(durationSeconds);
        maxLocation = contentLength;

    } else {
        maxLocation = Long.MAX_VALUE;
    }

    boolean signed = true;
    boolean bigEndian = false;
    format = new AudioFormat(AudioFormat.GSM,
                             8000,  // sampleRate,
                             16,    // sampleSizeInBits,
                             1,     // channels,
                             bigEndian ? AudioFormat.BIG_ENDIAN : 
                            AudioFormat.LITTLE_ENDIAN,
                             signed ? AudioFormat.SIGNED : 
                            AudioFormat.UNSIGNED,
                             (blockSize * 8), // frameSizeInBits
                             Format.NOT_SPECIFIED,  
                             Format.byteArray);
}
 
开发者ID:champtar,项目名称:fmj-sourceforge-mirror,代码行数:31,代码来源:GsmParser.java

示例3: setInputFormat

@Override
public Format setInputFormat(Format format, int trackID)
{
    final AudioFormat af = (AudioFormat) format;
    if (af.getSampleSizeInBits() == 8
            && af.getSigned() == AudioFormat.SIGNED)
        return null; // 8-bit is always unsigned for Wav.

    if (af.getSampleSizeInBits() == 16
            && af.getSigned() == AudioFormat.UNSIGNED)
        return null; // 16-bit is always signed for Wav.

    return super.setInputFormat(format, trackID);
}
 
开发者ID:champtar,项目名称:fmj-sourceforge-mirror,代码行数:14,代码来源:WAVMux.java

示例4: processData

public void processData(Buffer buf)
{
    if (getMute() || buf.isDiscard() || (buf.getLength() <= 0))
    {
        return;
    }

    AudioFormat af = (AudioFormat) buf.getFormat();

    byte[] data = (byte[]) buf.getData();

    if (af.getEncoding().equalsIgnoreCase("LINEAR"))
    {
        if (af.getSampleSizeInBits() == 16)
        {
            int msb = 0;
            int lsb = 1;

            if (af.getEndian() == AudioFormat.LITTLE_ENDIAN)
            {
                msb = 1;
                lsb = 0;
            }

            if (af.getSigned() == AudioFormat.SIGNED)
            {
                int peak = 0;
                int samples = data.length / 2;
                for (int i = 0; i < samples; i++)
                {
                    int value = (data[(i * 2) + msb] << 8)
                            + (data[(i * 2) + lsb] & 0xff);
                    if (value < 0)
                    {
                        value = -value;
                    }

                    if (value > peak)
                    {
                        peak = value;
                    }
                }

                peakLevel = peak / 32768.0f;
            }
        }
    }
}
 
开发者ID:champtar,项目名称:fmj-sourceforge-mirror,代码行数:48,代码来源:DataSource.java

示例5: LiveStream

public LiveStream() {
if (videoData) {
    int x, y, pos, revpos;
    
    size = new Dimension(320, 240);
    maxDataLength = size.width * size.height * 3;
    rgbFormat = new RGBFormat(size, maxDataLength,
			      Format.byteArray,
			      frameRate,
			      24,
			      3, 2, 1,
			      3, size.width * 3,
			      VideoFormat.FALSE,
			      Format.NOT_SPECIFIED);
    
    // generate the data
    data = new byte[maxDataLength];
    pos = 0;
    revpos = (size.height - 1) * size.width * 3;
    for (y = 0; y < size.height / 2; y++) {
	for (x = 0; x < size.width; x++) {
	    byte value = (byte) ((y*2) & 0xFF);
	    data[pos++] = value;
	    data[pos++] = 0;
	    data[pos++] = 0;
	    data[revpos++] = value;
	    data[revpos++] = 0;
	    data[revpos++] = 0;
	}
	revpos -= size.width * 6;
    }
} else { // audio data
    audioFormat = new AudioFormat(AudioFormat.LINEAR,
				  8000.0,
				  8,
				  1,
				  Format.NOT_SPECIFIED,
				  AudioFormat.SIGNED,
				  8,
				  Format.NOT_SPECIFIED,
				  Format.byteArray);
    maxDataLength = 1000;
}

thread = new Thread(this);
   }
 
开发者ID:champtar,项目名称:fmj-sourceforge-mirror,代码行数:46,代码来源:LiveStream.java

示例6: processData

public void processData(Buffer buf)
{
    if (getMute() || buf.isDiscard() || (buf.getLength() <= 0))
    {
        return;
    }

    AudioFormat af = (AudioFormat) buf.getFormat();
    byte[] data = (byte[]) buf.getData();

    if (af.getEncoding().equalsIgnoreCase("LINEAR"))
    {
        if (af.getSampleSizeInBits() == 16)
        {
            int msb = 0;
            int lsb = 1;

            if (af.getEndian() == AudioFormat.LITTLE_ENDIAN)
            {
                msb = 1;
                lsb = 0;
            }

            if (af.getSigned() == AudioFormat.SIGNED)
            {
                int peak = 0;
                int samples = data.length / 2;
                for (int i = 0; i < samples; i++)
                {
                    int value = (data[(i * 2) + msb] << 8)
                            + (data[(i * 2) + lsb] & 0xff);
                    if (value < 0)
                    {
                        value = -value;
                    }

                    if (value > peak)
                    {
                        peak = value;
                    }
                }

                peakLevel = peak / 32768.0f;
            }
        }
    }
}
 
开发者ID:champtar,项目名称:fmj-sourceforge-mirror,代码行数:47,代码来源:JavaSoundRenderer.java

示例7: convertFormat

/**
 * Convert javax.sound.sampled.AudioFormat to
 * javax.media.format.AudioFormat.
 */
public static AudioFormat convertFormat(
        javax.sound.sampled.AudioFormat format)
{
    Encoding encoding = format.getEncoding();
    int channels = format.getChannels();
    float frameRate = format.getFrameRate();
    int frameSize = format.getFrameSize() < 0 ? format.getFrameSize()
            : (format.getFrameSize() * 8);
    float sampleRate = format.getSampleRate();
    int sampleSize = format.getSampleSizeInBits();

    int endian = format.isBigEndian() ? AudioFormat.BIG_ENDIAN
            : AudioFormat.LITTLE_ENDIAN;

    int signed = Format.NOT_SPECIFIED;
    String encodingString = AudioFormat.LINEAR;

    if (encoding == Encoding.PCM_SIGNED)
    {
        signed = AudioFormat.SIGNED;
        encodingString = AudioFormat.LINEAR;
    } else if (encoding == Encoding.PCM_UNSIGNED)
    {
        signed = AudioFormat.UNSIGNED;
        encodingString = AudioFormat.LINEAR;
    } else if (encoding == Encoding.ALAW)
    {
        encodingString = AudioFormat.ALAW;
    } else if (encoding == Encoding.ULAW)
    {
        encodingString = AudioFormat.ULAW;
    } else
    {
        encodingString = encoding.toString();

    }

    AudioFormat jmfFormat = new AudioFormat(encodingString, sampleRate,
            sampleSize, channels, endian, signed, frameSize, frameRate,
            Format.byteArray);

    return jmfFormat;
}
 
开发者ID:champtar,项目名称:fmj-sourceforge-mirror,代码行数:47,代码来源:JavaSoundUtils.java

示例8: getSupportedInputFormats

/**
 * Implements {@link Renderer#getSupportedInputFormats()}. Gets the list of
 * input <tt>Format</tt>s supported by this <tt>Renderer</tt>.
 *
 * @return the list of input <tt>Format</tt>s supported by this
 * <tt>Renderer</tt>
 * @see Renderer#getSupportedInputFormats()
 */
public Format[] getSupportedInputFormats()
{
    if (supportedInputFormats == null)
    {
        double[] supportedInputSampleRates
            = new double[1 + Constants.AUDIO_SAMPLE_RATES.length];
        int supportedInputSampleRateCount = 0;

        supportedInputSampleRates[supportedInputSampleRateCount]
                = AudioTrack.getNativeOutputSampleRate(getStreamType());
        supportedInputSampleRateCount++;
        System.arraycopy(
                Constants.AUDIO_SAMPLE_RATES, 0,
                supportedInputSampleRates, supportedInputSampleRateCount,
                Constants.AUDIO_SAMPLE_RATES.length);
        supportedInputSampleRateCount
            += Constants.AUDIO_SAMPLE_RATES.length;

        supportedInputFormats
            = new Format[2 * supportedInputSampleRateCount];
        for (int i = 0; i < supportedInputSampleRateCount; i++)
        {
            double sampleRate = supportedInputSampleRates[i];

            supportedInputFormats[2 * i]
                    = new AudioFormat(
                            AudioFormat.LINEAR,
                            sampleRate,
                            16 /* sampleSizeInBits */,
                            Format.NOT_SPECIFIED /* channels */,
                            AudioFormat.LITTLE_ENDIAN,
                            AudioFormat.SIGNED,
                            Format.NOT_SPECIFIED /* frameSizeInBits */,
                            Format.NOT_SPECIFIED /* frameRate */,
                            Format.byteArray);
            supportedInputFormats[2 * i + 1]
                    = new AudioFormat(
                            AudioFormat.LINEAR,
                            sampleRate,
                            8 /* sampleSizeInBits */,
                            Format.NOT_SPECIFIED /* channels */,
                            AudioFormat.LITTLE_ENDIAN,
                            AudioFormat.SIGNED,
                            Format.NOT_SPECIFIED /* frameSizeInBits */,
                            Format.NOT_SPECIFIED /* frameRate */,
                            Format.byteArray);
        }
    }
    return supportedInputFormats.clone();
}
 
开发者ID:zhaozw,项目名称:android-1,代码行数:58,代码来源:AudioTrackRenderer.java


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