Welcome to mirror list, hosted at ThFree Co, Russian Federation.

EncodingConfiguration.java « javaFlacEncoder « src - github.com/ClusterM/android-speech-recognition.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 437805f78162e676d124ff164aebc25c0dee6300 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*
 * Copyright (C) 2010  Preston Lacey http://javaflacencoder.sourceforge.net/
 * All Rights Reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

package javaFlacEncoder;

/**
 * This class defines the configuration options that are allowed to change
 * within a FLAC stream. Options here may be changed from one frame to the next.
 * In general, the settings should not need altered, but the option to do so
 * remains.
 * 
 * @author Preston Lacey
 */
public class EncodingConfiguration implements Cloneable {

  /**
   * Defines the options for channel configuration to use. LEFT & RIGHT
   * channels refers to stereo audio as expected. INDEPENDENT channels refer to
   * each channel encoded separately. SIDE channel is the difference of the
   * LEFT and RIGHT channels(LEFT-RIGHT). MID channel is the integer average of
   * LEFT and RIGHT channels( (LEFT+RIGHT)/2 ). Options using MID and/or SIDE
   * channels may benefit encoding by taking advantage of similarities between
   * the channels, and are available in FLAC for STEREO streams only. In
   * general, ENCODER_CHOICE should be chosen.
   */
  public enum ChannelConfig {
    /** Encode channels independently **/
    INDEPENDENT,
    /** Encode LEFT and SIDE channels for stereo stream */
    LEFT_SIDE,
    /** Encode RIGHT and SIDE channels for stereo stream */
    RIGHT_SIDE,
    /** Encode MID and SIDE channels for stereo stream */
    MID_SIDE,
    /** Encode all options possible, and take the best(slow)*/
    EXHAUSTIVE,
    /** Let the encoder decide which to use.(recommended) */
    ENCODER_CHOICE
  };

  /**
   * Defines the various subframe types that may be used. If you don't know
   * what these are, choose EXHAUSTIVE(for description of subframe types, see
   * the flac format documentation at http://flac.sourceforge.net/format.html)
   */
  public enum SubframeType {
    /** Constant subframe, do not choose unless you are sure you're encoding
     * digital silence */
    CONSTANT,
    /** Decent compression, fasted option */
    FIXED,
    /** Better compression, slower */
    LPC,
    /** No compression, simply wraps unencoded audio into a FLAC stream */
    VERBATIM,
    /** Best compression, slightly slower than LPC alone, lets encoder choose
     * the best(Recommended). */
    EXHAUSTIVE
  }
   
  /** Maximum LPC order possible(as defined by FLAC format) */
  public static final int MAX_LPC_ORDER = 32;
  /** Minimum LPC order possible(as defined by FLAC format) */
  public static final int MIN_LPC_ORDER = 1;
  /** Maximum Rice Partition order possible(as defined by FLAC Format) */
  public static final int MAX_RICE_PARTITION_ORDER = 15;
  /** Default subframe type to use*/
  public static final SubframeType DEFAULT_SUBFRAME_TYPE = SubframeType.EXHAUSTIVE;
  /** Default channel configuration */
  public static final ChannelConfig DEFAULT_CHANNEL_CONFIG = ChannelConfig.ENCODER_CHOICE;
  /** Default maximum lpc order to use */
  public static final int DEFAULT_MAX_LPC_ORDER = 12;
  /** Default minimum lpc order to use */
  public static final int DEFAULT_MIN_LPC_ORDER = 1;
  /** Default maximum Rice partition order */
  public static final int DEFAULT_MAX_RICE_ORDER = 0;


  ChannelConfig channelConfig;
  SubframeType subframeType;
  int minimumLPCOrder = 1;
  int maximumLPCOrder = 16;
  int maximumRicePartitionOrder = 0;

  /**
   * Constructor, uses defaults for all options. These defaults should be good
   * for most purposes.
   */
  public EncodingConfiguration() {
    subframeType = DEFAULT_SUBFRAME_TYPE;
    channelConfig = DEFAULT_CHANNEL_CONFIG;
    maximumLPCOrder = DEFAULT_MAX_LPC_ORDER;
    minimumLPCOrder = DEFAULT_MIN_LPC_ORDER;
    maximumRicePartitionOrder = DEFAULT_MAX_RICE_ORDER;
  }

  /**
   * Copy constructor.
   * @param e EncodingConfiguration object to copy. Must not be null.
   */
  public EncodingConfiguration(EncodingConfiguration e) {
    subframeType = e.subframeType;
    channelConfig = e.channelConfig;
    minimumLPCOrder = e.minimumLPCOrder;
    maximumLPCOrder = e.maximumLPCOrder;
    maximumRicePartitionOrder = e.maximumRicePartitionOrder;
  }

  /**
   * Set the channel configuration to use. Channel configuration refers to the
   * way multiple channels are processed. See documentation for
   * {@link ChannelConfig ChannelConfig} for more info on choices.
   * @param conf Channel configuration to use.
   */
  public void setChannelConfig(ChannelConfig conf) {
    channelConfig = conf;
  }

  /**
   * Get the current channel configuration value.
   * @return current channel configuration value
   */
  public ChannelConfig getChannelConfig() {
    return channelConfig;
  }

  /**
   * Set the subframe type to use. This refers to the way each subframe(channel)
   * is compressed. See documentation for {@link SubframeType SubframeType} for
   * more info on choices.
   * @param type
   */
  public void setSubframeType(SubframeType type) {
    subframeType = type;
  }

  /**
   * Get the current subframe type
   * @return current subframe type
   */
  public SubframeType getSubframeType() {
    return subframeType;
  }

  /**
   * Get current minimum LPC order
   * @return current minimum lpc order
   */
  public int getMinLPCOrder() { return minimumLPCOrder; }

  /**
   * Get maximum LPC order
   * @return current maximum lpc order
   */
  public int getMaxLPCOrder() { return maximumLPCOrder; }
  /**
   * Set the minimum LPC order. If order given is out of the valid range(as
   * defined by {@link EncodingConfiguration#MAX_LPC_ORDER MAX_LPC_ORDER} and
   * {@link EncodingConfiguration#MIN_LPC_ORDER MIN_LPC_ORDER}), it will be
   * set to the closest valid value instead.
   * @param order minimum LPC order to use
   */
  public void setMinLPCOrder(int order) {
    minimumLPCOrder = (order < MIN_LPC_ORDER) ? MIN_LPC_ORDER:order;
    minimumLPCOrder = (minimumLPCOrder > MAX_LPC_ORDER) ?
    MAX_LPC_ORDER:minimumLPCOrder;
  }
  /**
   * Set the maximum LPC order. If order given is out of the valid range
   * (as defined by {@link EncodingConfiguration#MAX_LPC_ORDER MAX_LPC_ORDER}
   * and {@link EncodingConfiguration#MIN_LPC_ORDER MIN_LPC_ORDER}), it will be
   * set to the closest valid value instead.
   * @param order maximum LPC order to use
   */
  public void setMaxLPCOrder(int order) {
    maximumLPCOrder = (order < MIN_LPC_ORDER) ? MIN_LPC_ORDER:order;
    maximumLPCOrder = (maximumLPCOrder > MAX_LPC_ORDER) ?
    MAX_LPC_ORDER:maximumLPCOrder;
  }
}