FileDocCategorySizeDatePackage
MpegAudioControlAdapter.javaAPI DocJMF 2.1.1e17256Mon May 12 12:21:02 BST 2003com.ibm.media.codec.audio.mpegenc

MpegAudioControlAdapter

public class MpegAudioControlAdapter extends Object implements Owned, MpegAudioControl, BitRateControl
Implementation for mpeg audio encoder control

Fields Summary
Component
component
NativeEncoder
owner
int
layer
int
bitrate
int
error_protection
int
nChannels
int
joint_stereo
int
original
int
copyright
int
layout
int
samplingFrequency
int[]
availableRates
public static final int
LAYER_1
Indicates support for audio layer 1
public static final int
LAYER_2
Indicates support for audio layer 2
public static final int
LAYER_3
Indicates support for audio layer 3
public static final int
SAMPLING_RATE_16
Indicates support for 16 KHz audio sampling rate
public static final int
SAMPLING_RATE_22_05
Indicates support for 22.05 KHz audio sampling rate
public static final int
SAMPLING_RATE_24
Indicates support for 24 KHz audio sampling rate
public static final int
SAMPLING_RATE_32
Indicates support for 32 KHz audio sampling rate
public static final int
SAMPLING_RATE_44_1
Indicates support for 44.1 KHz audio sampling rate
public static final int
SAMPLING_RATE_48
Indicates support for 48 KHz audio sampling rate
public static final int
SINGLE_CHANNEL
Indicates support for single channel layout
public static final int
TWO_CHANNELS_STEREO
Indicates support for two channels stereo layout
public static final int
TWO_CHANNELS_DUAL
Indicates support for two channels dual layout
public static final int
THREE_CHANNELS_2_1
Indicates support for three channels 2-1 layout (Left, Right and single Surround)
public static final int
THREE_CHANNELS_3_0
Indicates support for three channels 3-0 layout (Left, Center and Right)
public static final int
FOUR_CHANNELS_2_0_2_0
Indicates support for four channels 2-0 2-0 layout (Left and Right of first program, Left and Right of second program)
public static final int
FOUR_CHANNELS_2_2
Indicates support for four channels 2-2 layout (Left, Right, Left Surround and Right Surround)
public static final int
FOUR_CHANNELS_3_1
Indicates support for four channels 3-1 layout (Left, Center, Right and single Surround)
public static final int
FIVE_CHANNELS_3_0_2_0
Indicates support for five channels 3-0 2-0 layout (Left, Center and Right of first program, Left and Right of second program)
public static final int
FIVE_CHANNELS_3_2
Indicates support for five channels 3-2 layout (Left, Center, Right, Left Surround and Right surround)
String
SAMPLING_FREQUENCY_STRING
String
ERROR_PROTECTION_STRING
String
ORIGINAL_STRING
String
COPYRIGHT_STRING
String
LAYER_STRING
String
LAYER_1_STRING
String
LAYER_2_STRING
String
MODE_STRING
String
MONO_STRING
String
STEREO_STRING
String
JOINT_STEREO_STRING
String
BITRATE_STRING
Choice
ratesComp
Constructors Summary
public MpegAudioControlAdapter(NativeEncoder new_Owner, int new_Layer, int new_samplingFrequency, int new_nChannels, int new_bitrate, int new_copyright, int new_original, int new_error_protect, int new_joint_stereo)


           owner=new_Owner;
           layer=new_Layer;
           samplingFrequency=new_samplingFrequency;
           nChannels=new_nChannels;
           bitrate=new_bitrate;
           copyright=new_copyright;
           original=new_original;
           error_protection=new_error_protect;
           joint_stereo=new_joint_stereo;
    
Methods Summary
public intgetAudioLayer()
Returns the current MPEG Audio Layer.

        return layer;
    
public intgetBitRate()
Returns the current bit rate of the owning object. If the stream is of variable bit rate, then the value returned is an instantaneous or average bit rate over a period of time.

         return bitrate;
     
public intgetChannelLayout()
Returns the current MPEG Audio channel layout.

        return layout;
    
public java.awt.ComponentgetControlComponent()



        

         if (component==null) {
            Panel componentPanel=new Panel();
            componentPanel.setLayout(new com.sun.media.controls.VFlowLayout(0));

            Panel freqPanel=new Panel();
            freqPanel.setLayout(new BorderLayout() );
            freqPanel.add("West", new Label(SAMPLING_FREQUENCY_STRING,Label.CENTER) );
            freqPanel.add("East", new Label(samplingFrequency+"",Label.CENTER) );
            componentPanel.add(freqPanel);

            Panel errPanel=new Panel();
            errPanel.setLayout(new BorderLayout() );
            errPanel.add("West",new Label(ERROR_PROTECTION_STRING ,Label.CENTER) );
            Checkbox err_cb=new Checkbox(null,null,error_protection!=0);
            err_cb.addItemListener( new ItemListener() {
                  public void itemStateChanged(ItemEvent e) {
                       int new_error_protection=e.getStateChange();
                       if (!owner.isStarted) {
                           error_protection=(new_error_protection==e.SELECTED) ? 1 : 0 ;
                           owner.setErrorProtect(error_protection);
                       } else {
                           Checkbox in_cb=(Checkbox)e.getItemSelectable();
                           in_cb.setState(error_protection!=0);
                       }
                  }
	    } );
	    errPanel.add("East",err_cb );

            Panel orgPanel=new Panel();
            orgPanel.setLayout(new BorderLayout() );
            orgPanel.add("West",new Label(ORIGINAL_STRING,Label.CENTER) );
            Checkbox org_cb=new Checkbox(null,null,original!=0);
            org_cb.addItemListener( new ItemListener() {
                  public void itemStateChanged(ItemEvent e) {
                       int new_original=e.getStateChange();
                       if (!owner.isStarted) {
                           original=(new_original==e.SELECTED) ? 1 : 0 ;
                           owner.setOriginal(original);
                       } else {
                           Checkbox in_cb=(Checkbox)e.getItemSelectable();
                           in_cb.setState(original!=0);
                       }
                  }
	    } );
	    orgPanel.add("East",org_cb );

            Panel cpyPanel=new Panel();
            cpyPanel.setLayout(new BorderLayout() );
            cpyPanel.add("West",new Label(COPYRIGHT_STRING,Label.CENTER) );
            Checkbox cpy_cb=new Checkbox(null,null,copyright!=0);
            cpy_cb.addItemListener( new ItemListener() {
                  public void itemStateChanged(ItemEvent e) {
                       int new_copyright=e.getStateChange();
                       if (!owner.isStarted) {
                           copyright=(new_copyright==e.SELECTED) ? 1 : 0 ;
                           owner.setOriginal(copyright);
                       } else {
                           Checkbox in_cb=(Checkbox)e.getItemSelectable();
                           in_cb.setState(copyright!=0);
                       }
                  }
	    } );
	    cpyPanel.add("East",cpy_cb );

            Panel layerPanel=new Panel();
            layerPanel.setLayout(new BorderLayout() );
            layerPanel.add("West",new Label(LAYER_STRING,Label.CENTER) );
            Choice layer_choice=new Choice();
            layer_choice.add(LAYER_1_STRING);
            layer_choice.add(LAYER_2_STRING);
            layer_choice.select(LAYER_2_STRING);

            layer_choice.addItemListener( new ItemListener() {
                  public void itemStateChanged(ItemEvent e) {
                       String s=(String)e.getItem();
                       if (!owner.isStarted) {
                           layer=s.equals(LAYER_1_STRING) ? 1 : 2;
                           setAvailableRates();
                           owner.setLayer(layer);
                       } else {
                           Choice in_choice=(Choice)e.getItemSelectable();
                           in_choice.select( (layer==1) ? LAYER_1_STRING : LAYER_2_STRING);
                       }

                  }

	    } );
	    layerPanel.add("East",layer_choice );

            Panel cnlPanel=new Panel();
            cnlPanel.setLayout(new BorderLayout() );
            cnlPanel.add("West",new Label(MODE_STRING,Label.CENTER) );
            Choice mode_choice=new Choice();

            if (nChannels==1) {
                mode_choice.add(MONO_STRING);

            } else {
                mode_choice.add(STEREO_STRING);
                mode_choice.add(JOINT_STEREO_STRING);
                mode_choice.select( (joint_stereo !=0 ) ?
                                    JOINT_STEREO_STRING :
                                    STEREO_STRING );

                mode_choice.addItemListener( new ItemListener() {
                      public void itemStateChanged(ItemEvent e) {
                           String s=(String)e.getItem();
                           if (!owner.isStarted) {
                               joint_stereo= s.equals(STEREO_STRING) ? 0 : 1;

                               int mode=(joint_stereo==0) ?
                                    NativeEncoder.MPEG_STEREO :
                                    NativeEncoder.MPEG_JOINT_STEREO ;

                               owner.SetEncodingType(mode);
                           } else {
                               Choice in_choice=(Choice)e.getItemSelectable();
                               in_choice.select( (joint_stereo !=0 ) ?
                                                 JOINT_STEREO_STRING :
                                                 STEREO_STRING );
                           }

                      }
                    } );

            }
            cnlPanel.add("East",  mode_choice );


            Panel ratePanel=new Panel();
            ratePanel.setLayout(new BorderLayout() );
            ratePanel.add("West",new Label(BITRATE_STRING,Label.CENTER) );
            ratesComp = new Choice();
            setAvailableRates();
            ratesComp.addItemListener( new ItemListener() {
                  public void itemStateChanged(ItemEvent e) {
                       String s=(String)e.getItem();
                       if (!owner.isStarted) {
                           bitrate=Integer.parseInt(s.substring(0,3).trim());
                           owner.setBitrate(bitrate);
                       } else {
                           Choice in_choice=(Choice)e.getItemSelectable();
                           in_choice.select( bitrate+" Kbits/sec " );
                       }

                  }
	    } );
	    ratePanel.add("East",ratesComp );

            componentPanel.add(ratePanel);
            componentPanel.add(layerPanel);
//            componentPanel.add(freqPanel); //sbd:disabled
            componentPanel.add(cnlPanel);
            componentPanel.add(errPanel);
            componentPanel.add(orgPanel);
            componentPanel.add(cpyPanel);
            component=componentPanel;

	 }

         return (Component)component;
     
public booleangetLowFrequencyChannel()
Returns true if Low Frequency Channel mode is turned on.

        return false;
    
public intgetMaxSupportedBitRate()
Returns the highest bit rate that this object can encode the data stream to.

         return 448000;
     
public intgetMinSupportedBitRate()
Returns the lowest bit rate that this object can encode the data stream to.

         return 32000;
     
public booleangetMultilingualMode()
Returns true if Multilingual mode is turned on.

        return false;
    
public java.lang.ObjectgetOwner()

        return (Object)owner;
    
public intgetSupportedAudioLayers()
Returns the audio layer support capability.
The returned value consists of a logical OR among the relevant flags.

see
#LAYER_1
see
#LAYER_2
see
#LAYER_3


                                 
       
        return LAYER_1 | LAYER_2;
    
public intgetSupportedChannelLayouts()
Returns the audio channel layout support capability.
The returned value consists of a logical OR among the relevant flags.

see
#SINGLE_CHANNEL
see
#TWO_CHANNELS_STEREO
see
#TWO_CHANNELS_DUAL
see
#THREE_CHANNELS_2_1
see
#THREE_CHANNELS_3_0
see
#FOUR_CHANNELS_2_0_2_0
see
#FOUR_CHANNELS_2_2
see
#FIVE_CHANNELS_3_0_2_0
see
#FIVE_CHANNELS_3_2


                                              
       
        return SINGLE_CHANNEL | TWO_CHANNELS_STEREO;
    
public intgetSupportedSamplingRates()
Returns the audio sampling rate support capability.
The returned value consists of a logical OR among the relevant flags.

see
#SAMPLING_RATE_16
see
#SAMPLING_RATE_22_05
see
#SAMPLING_RATE_24
see
#SAMPLING_RATE_32
see
#SAMPLING_RATE_44_1
see
#SAMPLING_RATE_48


                                        
       
        return SAMPLING_RATE_32 | SAMPLING_RATE_44_1 | SAMPLING_RATE_48;
    
public booleanisLowFrequencyChannelSupported()
Returns the low freuqency channel support capability.

        return false;
    
public booleanisMultilingualModeSupported()
Returns the multilingual mode support capability.

        return false;
    
public intsetAudioLayer(int audioLayer)
Controls the MPEG Audio Layer.
Returns the layer which was actually set.

//        layer=owner.setAudioLayer(audioLayer);
        return layer;
    
voidsetAvailableRates()

        if (layer==1) {
            if (nChannels==1) {
                availableRates=owner.layer1BitRate_mono;
            } else {
                availableRates=owner.layer1BitRate_stereo;
            }
        } else {
            if (nChannels==1) {
                availableRates=owner.layer2BitRate_mono;
            } else {
                availableRates=owner.layer2BitRate_stereo;
            }
        }

        if (ratesComp!=null) {
            bitrate=128*nChannels;
            owner.setBitrate(bitrate);

            ratesComp.removeAll();
            for (int i=0;i<availableRates.length;i++) {
                ratesComp.add(availableRates[i]+" Kbits/sec ");
            }
            ratesComp.select( bitrate+" Kbits/sec " );

        }

    
public intsetBitRate(int bitrate)
Sets the bit rate of the owning object. This is mostly relevant in the case of encoders. If the bit rate cannot be controlled, then the return value is -1.

return
the bit rate that was actually set on the object, or -1 if the bit rate is not controllable.

//         bitrate=owner.setBitRate(bitrate);
         return bitrate;

     
public intsetChannelLayout(int channelLayout)
Controls the MPEG Audio channel layout.
Returns the channel layout which was actually set.

        return layout;
    
public booleansetLowFrequencyChannel(boolean on)
Controls the Low Frequency Channel mode. "true" is on; "false" is off.
Returns true if Low Frequency Channel mode is actually turned on.

        return false;
    
public booleansetMultilingualMode(boolean on)
Controls the Multilingual mode. "true" is on; "false" is off.
Returns true if Multilingual mode is actually turned on.

        return false;