diff options
3 files changed, 111 insertions, 2 deletions
diff --git a/media/java/android/media/videoeditor/AudioTrack.java b/media/java/android/media/videoeditor/AudioTrack.java index 6303b9d..573208a 100755 --- a/media/java/android/media/videoeditor/AudioTrack.java +++ b/media/java/android/media/videoeditor/AudioTrack.java @@ -48,6 +48,8 @@ public class AudioTrack { // The audio waveform filename
private String mAudioWaveformFilename;
+ // The audio waveform data
+ private WaveformData mWaveformData;
/**
* An object of this type cannot be instantiated by using the default
@@ -103,6 +105,7 @@ public class AudioTrack { // The audio waveform file is generated later
mAudioWaveformFilename = null;
+ mWaveformData = null;
}
/**
@@ -161,6 +164,11 @@ public class AudioTrack { mDuckedTrackVolume = duckedTrackVolume;
mAudioWaveformFilename = audioWaveformFilename;
+ if (audioWaveformFilename != null) {
+ mWaveformData = new WaveformData(audioWaveformFilename);
+ } else {
+ mWaveformData = null;
+ }
}
/**
@@ -416,6 +424,7 @@ public class AudioTrack { throws IOException {
// TODO: Set mAudioWaveformFilename at the end once the extract is
// complete
+ mWaveformData = new WaveformData(mAudioWaveformFilename);
}
/**
@@ -431,10 +440,17 @@ public class AudioTrack { *
* @return the name of the file, null if the file does not exist
*/
- public String getAudioWaveformFilename() {
+ String getAudioWaveformFilename() {
return mAudioWaveformFilename;
}
+ /**
+ * @return The waveform data
+ */
+ public WaveformData getWaveformData() {
+ return mWaveformData;
+ }
+
/*
* {@inheritDoc}
*/
diff --git a/media/java/android/media/videoeditor/MediaVideoItem.java b/media/java/android/media/videoeditor/MediaVideoItem.java index 341bf8e..f09219d 100755 --- a/media/java/android/media/videoeditor/MediaVideoItem.java +++ b/media/java/android/media/videoeditor/MediaVideoItem.java @@ -46,6 +46,8 @@ public class MediaVideoItem extends MediaItem { private int mVolumePercentage;
private boolean mMuted;
private String mAudioWaveformFilename;
+ // The audio waveform data
+ private WaveformData mWaveformData;
/**
* An object of this type cannot be instantiated with a default constructor
@@ -115,6 +117,11 @@ public class MediaVideoItem extends MediaItem { mVolumePercentage = volumePercent;
mMuted = muted;
mAudioWaveformFilename = audioWaveformFilename;
+ if (audioWaveformFilename != null) {
+ mWaveformData = new WaveformData(audioWaveformFilename);
+ } else {
+ mWaveformData = null;
+ }
}
/**
@@ -286,6 +293,7 @@ public class MediaVideoItem extends MediaItem { public void extractAudioWaveform(ExtractAudioWaveformProgressListener listener)
throws IOException {
// TODO: Set mAudioWaveformFilename at the end once the export is complete
+ mWaveformData = new WaveformData(mAudioWaveformFilename);
}
/**
@@ -299,11 +307,18 @@ public class MediaVideoItem extends MediaItem { * @return the name of the file, null if the file has not been computed or
* if there is no Audio track in the mediaItem
*/
- public String getAudioWaveformFilename() {
+ String getAudioWaveformFilename() {
return mAudioWaveformFilename;
}
/**
+ * @return The waveform data
+ */
+ public WaveformData getWaveformData() {
+ return mWaveformData;
+ }
+
+ /**
* Set volume of the Audio track of this mediaItem
*
* @param volumePercent in %/. 100% means no change; 50% means half value, 200%
diff --git a/media/java/android/media/videoeditor/WaveformData.java b/media/java/android/media/videoeditor/WaveformData.java new file mode 100644 index 0000000..67789de --- /dev/null +++ b/media/java/android/media/videoeditor/WaveformData.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.media.videoeditor; + +/** + * Class which describes the waveform data of an audio track. The gain values + * represent the average gain for an audio frame. For audio codecs which do + * not operate on a per frame bases (eg. ALAW, ULAW) a reasonable audio frame + * duration will be assumed (eg. 50ms). + * {@hide} + */ +public class WaveformData { + // Instance variables + final int mFrameDurationMs; + final int mFramesCount; + final short[] mGains; + + /** + * This constructor shall not be used + */ + @SuppressWarnings("unused") + private WaveformData() { + mFrameDurationMs = 0; + mFramesCount = 0; + mGains = null; + } + + /** + * Constructor + * + * @param audioWaveformFilename The name of the audio waveform file + */ + WaveformData(String audioWaveformFilename) { + // TODO: Read these values from the file + mFrameDurationMs = 20; + mFramesCount = 300000 / mFrameDurationMs; + mGains = new short[mFramesCount]; + for (int i = 0; i < mFramesCount; i++) { + mGains[i] = (short)((i * 5) % 256); + } + } + + /** + * @return The duration of a frame in milliseconds + */ + public int getFrameDuration() { + return mFrameDurationMs; + } + + /** + * @return The number of frames within the waveform data + */ + public int getFramesCount() { + return mFramesCount; + } + + /** + * @return The array of frame gains. The size of the array is the frames + * count. The values of the frame gains range from 0 to 256. + */ + public short[] getFrameGains() { + return mGains; + } +} |
