java类javax.sound.sampled.FloatControl.Type的实例源码

Sound.java 文件源码 项目:spjgl 阅读 30 收藏 0 点赞 0 评论 0
private void writeDataToLine() throws LineUnavailableException {
    playing = true;
    line = AudioSystem.getSourceDataLine(format);

    if (line == null) {
        return;
    }

    line.open();

    line.start();

    for (int i = 0; i < data.length && playing; i += BUFFER_SIZE) {
        if (line.isControlSupported(Type.MASTER_GAIN)) {
            final FloatControl gainControl = (FloatControl)line.getControl(Type.MASTER_GAIN);
            final float minimum = gainControl.getMinimum();
            final float maximum = gainControl.getMaximum();
            final float actualGain = Math.max(minimum, Math.min(maximum, gain));

            gainControl.setValue(actualGain);
        }

        if (i + BUFFER_SIZE > data.length) {
            i = data.length - BUFFER_SIZE;
        }

        line.write(data, i, BUFFER_SIZE);
    }

    line.drain();
}
ClipSFXModule.java 文件源码 项目:mochadoom 阅读 17 收藏 0 点赞 0 评论 0
public void setPanning(int chan,int sep){
Clip c=channels[chan];

if (c.isControlSupported(Type.PAN)){
    FloatControl bc=(FloatControl) c.getControl(Type.PAN);
    // Q: how does Doom's sep map to stereo panning?
    // A: Apparently it's 0-255 L-R.
    float pan= bc.getMinimum()+(bc.getMaximum()-bc.getMinimum())*(float)sep/ISoundDriver.PANNING_STEPS;
    bc.setValue(pan);
    }
}
DavidSFXModule.java 文件源码 项目:mochadoom 阅读 20 收藏 0 点赞 0 评论 0
/** This one will only create datalines for common clip/audioline samples
 *  directly.
 * 
 * @param c
 * @param sfxid
 */
private final void  createDataLineForChannel(int c, int sfxid){

    // None? Make a new one.

    if (channels[c].auline == null) {
        try {
            DoomSound tmp=cachedSounds.get(sfxid);
            // Sorry, Charlie. Gotta make a new one.
            DataLine.Info info = new DataLine.Info(SourceDataLine.class, DoomSound.DEFAULT_SAMPLES_FORMAT);
            channels[c].auline = (SourceDataLine) AudioSystem.getLine(info);
            channels[c].auline.open(tmp.format);
        } catch (LineUnavailableException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
                boolean errors=false;
                // Add individual volume control.
                if (channels[c].auline.isControlSupported(Type.MASTER_GAIN))
                    channels[c].vc=(FloatControl) channels[c].auline
                    .getControl(Type.MASTER_GAIN);
                else {
                System.err.print("MASTER_GAIN, ");
                errors=true;
                if (channels[c].auline.isControlSupported(Type.VOLUME))
                        channels[c].vc=(FloatControl) channels[c].auline
                        .getControl(Type.VOLUME);
                else 
                    System.err.print("VOLUME, ");
                } 


                // Add individual pitch control.
                if (channels[c].auline.isControlSupported(Type.SAMPLE_RATE)){
                    channels[c].pc=(FloatControl) channels[c].auline
                    .getControl(Type.SAMPLE_RATE);
                } else {
                    errors=true;
                    System.err.print("SAMPLE_RATE, ");
                } 

                // Add individual pan control
                if (channels[c].auline.isControlSupported(Type.BALANCE)){
                    channels[c].bc=(FloatControl) channels[c].auline
                    .getControl(FloatControl.Type.BALANCE);
                } else {
                    System.err.print("BALANCE, ");
                    errors=true;
                    if (channels[c].auline.isControlSupported(Type.PAN)){                           
                    channels[c].bc=(FloatControl) channels[c].auline
                    .getControl(FloatControl.Type.PAN);
                } else {
                    System.err.print("PANNING ");
                    }
                }

                if (errors) System.err.printf("for channel %d NOT supported!\n",c);

                channels[c].auline.start();
            }
}


问题


面经


文章

微信
公众号

扫码关注公众号