Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7bfcabbb authored by Gil Dobjanschi's avatar Gil Dobjanschi
Browse files

Finalized the audio track ducking API

Change-Id: I12b966c1898eaae76e9de71a6d745678dc489092
parent 4f4a5672
Loading
Loading
Loading
Loading
+34 −13
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ import java.io.IOException;

/**
 * This class allows to handle an audio track. This audio file is mixed with the
 * audio samples of the MediaItems.
 * audio samples of the media items.
 * {@hide}
 */
public class AudioTrack {
@@ -43,7 +43,7 @@ public class AudioTrack {

    // Ducking variables
    private int mDuckingThreshold;
    private int mDuckingLowVolume;
    private int mDuckedTrackVolume;
    private boolean mIsDuckingEnabled;

    // The audio waveform filename
@@ -98,7 +98,7 @@ public class AudioTrack {

        // Ducking is enabled by default
        mDuckingThreshold = 0;
        mDuckingLowVolume = 0;
        mDuckedTrackVolume = 0;
        mIsDuckingEnabled = true;

        // The audio waveform file is generated later
@@ -120,12 +120,18 @@ public class AudioTrack {
     * @param loop true to loop the audio track
     * @param volume The volume in percentage
     * @param muted true if the audio track is muted
     * @param threshold Ducking will be activated when the relative energy in
     *      the media items audio signal goes above this value. The valid
     *      range of values is 0 to 100.
     * @param duckedTrackVolume The relative volume of the audio track when ducking
     *      is active. The valid range of values is 0 to 100.
     * @param audioWaveformFilename The name of the waveform file
     *
     * @throws IOException if file is not found
     */
    AudioTrack(VideoEditor editor, String audioTrackId, String filename, long startTimeMs,
            long beginMs, long endMs, boolean loop, int volume, boolean muted,
            boolean duckingEnabled, int duckThreshold, int duckedTrackVolume,
            String audioWaveformFilename) throws IOException {
        mUniqueId = audioTrackId;
        mFilename = filename;
@@ -150,6 +156,10 @@ public class AudioTrack {
        mLoop = loop;
        mMuted = muted;

        mIsDuckingEnabled = duckingEnabled;
        mDuckingThreshold = duckThreshold;
        mDuckedTrackVolume = duckedTrackVolume;

        mAudioWaveformFilename = audioWaveformFilename;
    }

@@ -347,15 +357,26 @@ public class AudioTrack {
    }

    /**
     * TODO DEFINE
     * Enable ducking by specifying the required parameters
     *
     * @param threshold
     * @param lowVolume
     * @param volume
     * @param threshold Ducking will be activated when the relative energy in
     *      the media items audio signal goes above this value. The valid
     *      range of values is 0 to 100.
     * @param duckedTrackVolume The relative volume of the audio track when ducking
     *      is active. The valid range of values is 0 to 100.
     */
    public void enableDucking(int threshold, int lowVolume, int volume) {
    public void enableDucking(int threshold, int duckedTrackVolume) {
        if (threshold < 0 || threshold > 100) {
            throw new IllegalArgumentException("Invalid threshold value: " + threshold);
        }

        if (duckedTrackVolume < 0 || duckedTrackVolume > 100) {
            throw new IllegalArgumentException("Invalid duckedTrackVolume value: "
                    + duckedTrackVolume);
        }

        mDuckingThreshold = threshold;
        mDuckingLowVolume = lowVolume;
        mDuckedTrackVolume = duckedTrackVolume;
        mIsDuckingEnabled = true;
    }

@@ -374,10 +395,10 @@ public class AudioTrack {
    }

    /**
     * @return The ducking low level
     * @return The ducked track volume
     */
    public int getDuckingLowVolume() {
        return mDuckingLowVolume;
    public int getDuckedTrackVolume() {
        return mDuckedTrackVolume;
    }

    /**
+10 −1
Original line number Diff line number Diff line
@@ -90,6 +90,9 @@ public class VideoEditorTestImpl implements VideoEditor {
    private static final String ATTR_END_RECT_B = "end_b";
    private static final String ATTR_LOOP = "loop";
    private static final String ATTR_MUTED = "muted";
    private static final String ATTR_DUCK_ENABLED = "ducking_enabled";
    private static final String ATTR_DUCK_THRESHOLD = "ducking_threshold";
    private static final String ATTR_DUCKED_TRACK_VOLUME = "ducking_volume";

    // Instance variables
    private long mDurationMs;
@@ -716,6 +719,9 @@ public class VideoEditorTestImpl implements VideoEditor {
            serializer.attribute("", ATTR_BEGIN_TIME, Long.toString(at.getBoundaryBeginTime()));
            serializer.attribute("", ATTR_END_TIME, Long.toString(at.getBoundaryEndTime()));
            serializer.attribute("", ATTR_VOLUME, Integer.toString(at.getVolume()));
            serializer.attribute("", ATTR_DUCK_ENABLED, Boolean.toString(at.isDuckingEnabled()));
            serializer.attribute("", ATTR_DUCKED_TRACK_VOLUME, Integer.toString(at.getDuckedTrackVolume()));
            serializer.attribute("", ATTR_DUCK_THRESHOLD, Integer.toString(at.getDuckingThreshhold()));
            serializer.attribute("", ATTR_MUTED, Boolean.toString(at.isMuted()));
            serializer.attribute("", ATTR_LOOP, Boolean.toString(at.isLooping()));
            if (at.getAudioWaveformFilename() != null) {
@@ -1017,10 +1023,13 @@ public class VideoEditorTestImpl implements VideoEditor {
        final int volume = Integer.parseInt(parser.getAttributeValue("", ATTR_VOLUME));
        final boolean muted = Boolean.parseBoolean(parser.getAttributeValue("", ATTR_MUTED));
        final boolean loop = Boolean.parseBoolean(parser.getAttributeValue("", ATTR_LOOP));
        final boolean duckingEnabled = Boolean.parseBoolean(parser.getAttributeValue("", ATTR_DUCK_ENABLED));
        final int duckThreshold = Integer.parseInt(parser.getAttributeValue("", ATTR_DUCK_THRESHOLD));
        final int duckedTrackVolume = Integer.parseInt(parser.getAttributeValue("", ATTR_DUCKED_TRACK_VOLUME));
        final String waveformFilename = parser.getAttributeValue("", ATTR_AUDIO_WAVEFORM_FILENAME);
        try {
            final AudioTrack audioTrack = new AudioTrack(this, audioTrackId, filename, startTimeMs,
                    beginMs, endMs, loop, volume, muted, waveformFilename);
                    beginMs, endMs, loop, volume, muted, duckingEnabled, duckThreshold, duckedTrackVolume, waveformFilename);

            return audioTrack;
        } catch (IOException ex) {