如何在音频中添加帧

时间:2019-07-13 15:22:34

标签: java audio

我有音频,我想做音频隐写术,我有一个逻辑,但是我不知道源代码,我将在图片中描述我的逻辑, 首先我得到音频

 File wavFile = new File(audio.getText());
        ArrayList<Integer> dataSet = WAVRead.wavRead(wavFile);
        Waveform.drawWaveform(dataSet);

    } catch (NullPointerException | IOException e) {    //no file was selected
        //System.out.println("A WAV file was not selected");
        JFrame frame = new JFrame();
        String errorMessage = "Check Your Output";
        JOptionPane.showMessageDialog(frame, errorMessage, "File Selection Error", JOptionPane.ERROR_MESSAGE);
    }

我读了音频

    FileInputStream wavInputs = new FileInputStream(file);
    BufferedInputStream buffer = new BufferedInputStream(wavInputs);
    ArrayList<Integer> dataSet = new ArrayList<Integer>();

    buffer.skip(34);    //skips to bits per sample information

    int bps = buffer.read();
    //System.out.println("bps = " + bps);
    int bytesPerSample = bps / 8;
    byte[] dataSample = new byte[bytesPerSample];

    buffer.skip(9); //skips to the audio data (assuming 44 byte header)
    int bytesRead = buffer.read(dataSample);    //Equals bytesPerSample until it reach EOF
    while (bytesRead > 0) {
        int completeSample = dataSample[0]; //8 bits
        if (bytesPerSample == 2) {  //16 bits
            //Convert 2's complement little endian to unsigned int
            completeSample = (dataSample[0] & 0xFF) | (dataSample[1] & 0xFF) << 8;
            if (completeSample > 32678) {
                completeSample -= 65535;
            }
        }
        //System.out.println(completeSample);
        dataSet.add(completeSample);
        bytesRead = buffer.read(dataSample);
    }

    buffer.close();
    return dataSet;
}

然后我绘制波形

    numSamples = dataSet.size();        
    int tempMaxVal = 0;
    int tempMaxAbsVal = 0;
    for(int i=0; i < numSamples; i++) {
        if (dataSet.get(i) > tempMaxVal) {
            tempMaxVal = dataSet.get(i);
        }
        if (Math.abs(dataSet.get(i)) > Math.abs(tempMaxVal)) {
            tempMaxAbsVal = dataSet.get(i);
        }
    }
    maxSampleVal = tempMaxVal;
    maxAbsSampleVal = tempMaxAbsVal;

音频结果 this is an example of my audio results

,我想像图片一样在音频中添加新的帧 logic about adding frames

谁能解释我的逻辑的源代码?

0 个答案:

没有答案