WaveformData.java revision 6f3c808b4f134eba1dfb57e13853addc351ca76f
1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.media.videoeditor;
18
19/**
20 * Class which describes the waveform data of an audio track. The gain values
21 * represent the average gain for an audio frame. For audio codecs which do
22 * not operate on a per frame bases (eg. ALAW, ULAW) a reasonable audio frame
23 * duration will be assumed (eg. 50ms).
24 * {@hide}
25 */
26public class WaveformData {
27    // Instance variables
28    private final int mFrameDurationMs;
29    private final int mFramesCount;
30    private final short[] mGains;
31
32    /**
33     * This constructor shall not be used
34     */
35    @SuppressWarnings("unused")
36    private WaveformData() {
37        mFrameDurationMs = 0;
38        mFramesCount = 0;
39        mGains = null;
40    }
41
42    /**
43     * Constructor
44     *
45     * @param audioWaveformFilename The name of the audio waveform file
46     */
47    WaveformData(String audioWaveformFilename) {
48        // TODO: Read these values from the file
49        mFrameDurationMs = 20;
50        mFramesCount = 300000 / mFrameDurationMs;
51        mGains = new short[mFramesCount];
52        for (int i = 0; i < mFramesCount; i++) {
53            mGains[i] = (short)((i * 5) % 256);
54        }
55    }
56
57    /**
58     * @return The duration of a frame in milliseconds
59     */
60    public int getFrameDuration() {
61        return mFrameDurationMs;
62    }
63
64    /**
65     * @return The number of frames within the waveform data
66     */
67    public int getFramesCount() {
68        return mFramesCount;
69    }
70
71    /**
72     * @return The array of frame gains. The size of the array is the frames
73     *  count. The values of the frame gains range from 0 to 256.
74     */
75    public short[] getFrameGains() {
76        return mGains;
77    }
78}
79