Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

add fade-in and fade-out effects to thumbnails

[es] :: Java :: add fade-in and fade-out effects to thumbnails

[ Pregleda: 1418 | Odgovora: 0 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

SuperC

Član broj: 120719
Poruke: 124
*.9.14.vie.surfer.at.



Profil

icon add fade-in and fade-out effects to thumbnails05.05.2010. u 22:41 - pre 169 meseci
Ima li neko ideju sta i kako ovdje uraditi?


Dakle imam odredjeni kod i sad treba u njega da dodam drugi kod gdje ce raditi ovo iz naslova odnosno ovo ispod:

Code:

•    one can call it with three parameters: an input file/directory name, an output directory, and a fade-in/out percentage float parameter X (e.g., 0.25)

•    it modifies previously generated thumbnails in way that the first X percent of an audio file have a fade-in effect and the last X percent have a fade-out effect. For instance:
o    input audio file (myMp3.mp3.wav) with length 20 seconds, and fade-in/out parameter X of 0.25
o    output = 20 second audio file (myMp3.mp3.wav) with 5 seconds fade-in effect at the beginning and 5 seconds fade-out effect at the end

•    if the first parameter is a (thumbnail) directory, it concatenates all audio thumbnails to a filer sampler.wav 

o    NOTE: this works only for audio files having the same frequency, bit-rate, and number of channels


a evo i koda zadatka:

Code:

package itm.audio;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.UnsupportedAudioFileException;

import org.tritonus.dsp.ais.AmplitudeAudioInputStream;
import org.tritonus.share.sampled.AudioSystemShadow;
import org.tritonus.share.sampled.file.AudioOutputStream;
import org.tritonus.share.sampled.file.TDataOutputStream;

/**
 * 
 * This class creates adds fade-in and fade-out effects to acoustic thumbnails
 * and concatenates all thumbnails to a single sampler audio file
 * 
 * It can be called with 3 parameters, an input filename/directory, an output
 * directory, and the length of a single fade-in our fade-out sequence in
 * percent of total audio length. It will read WAV input audio files(s), and
 * create fade-in and fade-out effects with a given length (% of total length)
 * for (a) given audio file(s).
 * 
 * If the first parameter is a directory, this class also creates an audio
 * sampler from all files (thumbnails) in this directory.
 * 
 * If the input file or the output directory do not exist, an exception is
 * thrown.
 */
public class AudioFadeInFadeOut {

    /** name of the sampler file */
    private final String SAMPLER_FILE = "sampler.wav";

    /** the length of a fadeIn/fadeOut sequence in percent of the total length */
    private float fadeInOutLength = (float) 0.25; // default

    /**
     * Constructor
     * 
     * @param fadeInOutLength
     *            the length of a fadeIn/fadeOut sequence in percent of the
     *            total length
     */
    public AudioFadeInFadeOut(float fadeInOutLength) {
        this.fadeInOutLength = fadeInOutLength;
    }

    /**
     * Processes the passed input audio file / audio file directory and stores
     * the processed files to the output directory.
     * 
     * @param input
     *            a reference to the input audio file / input directory
     * @param output
     *            a reference to the output directory
     */
    public ArrayList<File> batchProcessAudioFiles(File input, File output)
            throws IOException {
        if (!input.exists())
            throw new IOException("Input file " + input + " was not found!");
        if (!output.exists())
            throw new IOException("Output directory " + output + " not found!");
        if (!output.isDirectory())
            throw new IOException(output + " is not a directory!");

        ArrayList<File> ret = new ArrayList<File>();

        if (input.isDirectory()) {
            File[] files = input.listFiles();
            for (File f : files) {

                String ext = f.getName().substring(
                        f.getName().lastIndexOf(".") + 1).toLowerCase();
                if (ext.equals("wav")) {
                    try {
                        File result = processAudio(f, output);
                        System.out.println("created fadeIn/fadeOut effect for "
                                + f);
                        ret.add(result);
                    } catch (Exception e0) {
                        System.err.println("Error converting " + f + " : "
                                + e0.toString());
                    }

                }

            }

            // if input is directory of thumbs -> create sampler
            File sampler = new File(output, SAMPLER_FILE);

            createSampler(ret, sampler);

            System.out.println("Added " + ret.size()
                    + " audio thumbnails to sampler " + SAMPLER_FILE);

        } else {

            String ext = input.getName().substring(
                    input.getName().lastIndexOf(".") + 1).toLowerCase();
            if (ext.equals("wav")) {
                try {

                    File result = processAudio(input, output);

                    System.out.println("created fadeIn/fadeOut effect for "
                            + input);
                    ret.add(result);
                } catch (Exception e0) {
                    System.err.println("Error converting " + input + " : "
                            + e0.toString());
                }

            }

        }
        return ret;
    }

    /**
     * Processes the passed audio file and stores the processed file to the
     * output directory.
     * 
     * @param input
     *            a reference to the input audio File
     * @param output
     *            a reference to the output directory
     */
    protected File processAudio(File input, File output) throws IOException,
            IllegalArgumentException {
        if (!input.exists())
            throw new IOException("Input file " + input + " was not found!");
        if (input.isDirectory())
            throw new IOException("Input file " + input + " is a directory!");
        if (!output.exists())
            throw new IOException("Output directory " + output + " not found!");
        if (!output.isDirectory())
            throw new IOException(output + " is not a directory!");

        // replace the input audio file
        File outputFile = new File(output, input.getName());

        // ***************************************************************
        //   ovdje dodati kod koji radi fade-in i fade-out
        // ***************************************************************

        // load the input audio file

        // read audio data into a byte array, copy the relavant bytes at the
        // beginning at the end of the byte array, adjust the amplitude using an
        // AmplitudeAudioInputStream

        // save the audio file with fade-in and fade-out effect

        return outputFile;
    }


    /**
     * Creates a sampler from all audio input files (thumbnails) and stores it
     * in the given output file
     * 
     * @param inputFiles
     *            the input audio files (thumbnails)
     * @param output
     *            the sampler file
     */
    protected void createSampler(List<File> inputFiles, File output) {

        // ***************************************************************
        //  ovdje dodati kod koji radi fade-in i fade-out
        // ***************************************************************


    }

    /**
     * Main method. Parses the commandline parameters and prints usage
     * information if required.
     */
    public static void main(String[] args) throws Exception {

        //args = new String[] { "./test", "./test", "0.25" };

        if (args.length < 3) {
            System.out
                    .println("usage: java itm.audio.AudioFadeInFadeOut <input-audioFile> <output-directory> <fadeInOut-length>");
            System.out
                    .println("usage: java itm.audio.AudioFadeInFadeOut <input-directory> <output-directory> <fadeInOut-length>");
            System.exit(1);
        }
        File fi = new File(args[0]);
        File fo = new File(args[1]);
        Float length = new Float(args[2]);

        AudioFadeInFadeOut ah2 = new AudioFadeInFadeOut(length.floatValue());
        ah2.batchProcessAudioFiles(fi, fo);
    }

}


 
Odgovor na temu

[es] :: Java :: add fade-in and fade-out effects to thumbnails

[ Pregleda: 1418 | Odgovora: 0 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.