Ignore:
Timestamp:
03/08/16 23:22:09 (8 years ago)
Author:
davidb
Message:

Generalization of audio support to allow playback/mixer to be stereo, plus some edits to comments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/apollo/audio/SampledAudioManager.java

    r355 r1007  
    1414import org.apollo.mvc.SubjectChangedEvent;
    1515import org.apollo.util.ApolloSystemLog;
     16
    1617
    1718/**
     
    2728       
    2829        /** All internal formats have the same sample rate. */
    29         public static final float PLAYBACK_SAMPLE_RATE = 44100.0f; // Audacitys default
    30        
    31         //public static final float PLAYBACK_SAMPLE_RATE = 22050.0f; // Meldexes internal rate .. todo: fix conversions to use better rate
    32 
    33         // Used for describing the ideal default format for recorded audio and converting un-supported
     30        // The following is based on Audacity's defaults for playback
     31        public static final float PLAYBACK_SAMPLE_RATE      = 44100.0f;
     32        public static final int   PLAYBACK_BITS_PER_SAMPLE  = 16;     
     33        public static final int   PLAYBACK_NUM_CHANNELS     = 2; // stereo
     34       
     35        //public static final float PLAYBACK_SAMPLE_RATE = 22050.0f; // Meldexe's internal rate .. todo: fix conversions to use better rate
     36
     37        // Used for describing the ideal default format for recorded audio and converting unsupported
    3438        // imported audio to... The actual formats may differ depending on the data lines used
    3539       
    36         // note: Must be PCM, Mono, 16 bit.
     40        // note: Must be PCM, with values as defined for PLAYBACK_... above
    3741        private static final AudioFormat DESIRED_FORMAT = new AudioFormat( // Linear PCM Encoding
    38                         PLAYBACK_SAMPLE_RATE, // Always conform to PLAYBACK_SAMPLE_RATE
    39                         16, // bits per sample. Must be 16. Audacitys default
    40                         1, // Always use mono. Audacitys default
     42                        PLAYBACK_SAMPLE_RATE, // Always conform to PLAYBACK_SAMPLE_RATE etc
     43                        PLAYBACK_BITS_PER_SAMPLE,
     44                        PLAYBACK_NUM_CHANNELS,
    4145                        false, // ALWAYS USED SIGNED FOR BEST PERFORMACE - JAVA DOES NOT HAVE UNSIGNED TYPES
    4246                        true // Byte order
     
    231235                        // Not cadidate if not in appollos format.
    232236                        if (!candiate.getEncoding().toString().startsWith("PCM")
    233                                         || candiate.getChannels() != 1
    234                                         || candiate.getSampleSizeInBits() != 16
     237                                        || candiate.getChannels() != PLAYBACK_NUM_CHANNELS
     238                                        || candiate.getSampleSizeInBits() != PLAYBACK_BITS_PER_SAMPLE
    235239                                        || (candiate.getSampleRate() != AudioSystem.NOT_SPECIFIED &&
    236240                                                        candiate.getSampleRate() != PLAYBACK_SAMPLE_RATE))
     
    285289        /**
    286290         * Determines if an audio format requires conversion in order to be used
    287          * in Apollos.
    288          *
    289          * Audio formats must be in PCM, mono, 16-bit sample-size,
     291         * in Apollo's.
     292         *
     293         * Audio formats must be in PCM, SampledAudioManager#PLAYBACK_NUM_CHANNELS,
     294         * SampledAudioManager#PLAYBACK_BITS_PER_SAMPLE sample-size,
    290295         * SampledAudioManager#PLAYBACK_SAMPLE_RATE sample-rate and be supported
    291296         * by the output mixer.
     
    304309                if (format == null) throw new NullPointerException("format");
    305310               
    306                 if(!format.getEncoding().toString().startsWith("PCM") || format.getChannels() != 1
    307                                 || format.getSampleSizeInBits() != 16
     311                if(!format.getEncoding().toString().startsWith("PCM") || format.getChannels() != PLAYBACK_NUM_CHANNELS
     312                                || format.getSampleSizeInBits() != PLAYBACK_BITS_PER_SAMPLE
    308313                                || (format.getSampleRate() != AudioSystem.NOT_SPECIFIED &&
    309314                                                format.getSampleRate() != PLAYBACK_SAMPLE_RATE)) {
     
    313318                // Check that the format is supported by the output mixer
    314319                for (AudioFormat supported : supportedPlaybackFormats) {
    315                         if (supported.getChannels() != 1) continue;
     320                        if (supported.getChannels() != PLAYBACK_NUM_CHANNELS) continue;
    316321                        if (
    317322                                        format.getEncoding() == supported.getEncoding()
Note: See TracChangeset for help on using the changeset viewer.