Skip to content

Instantly share code, notes, and snippets.

@skratchdot
Created May 15, 2013 16:59
Show Gist options
  • Save skratchdot/5585490 to your computer and use it in GitHub Desktop.
Save skratchdot/5585490 to your computer and use it in GitHub Desktop.
An example of how to setup a cue point chunk. This is an invalid wav file, but shows how to manually add chunks. For an example of adding sample points, see: https://github.com/skratchdot/open-electribe-editor/blob/1a0eb8fd5dad55209335930d7aef142625365b86/com.skratchdot.electribe.model.esx/src/com/skratchdot/electribe/model/esx/impl/SampleImpl.j…
import com.skratchdot.riff.wav.ChunkCue;
import com.skratchdot.riff.wav.ChunkTypeID;
import com.skratchdot.riff.wav.CuePoint;
import com.skratchdot.riff.wav.RIFFWave;
import com.skratchdot.riff.wav.WavFactory;
public class RiffWavCuePointExample {
/**
* @param args
*/
public static void main(String[] args) {
// create wave file
RIFFWave riffWave = WavFactory.eINSTANCE.createRIFFWave();
// create cue point
CuePoint cuePoint = WavFactory.eINSTANCE.createCuePoint();
// Position: The position specifies the sample offset associated with the cue point in terms of the sample's position in the final stream of samples generated by the play list. Said in another way, if a play list chunk is specified, the position value is equal to the sample number at which this cue point will occur during playback of the entire play list as defined by the play list's order. If no play list chunk is specified this value should be 0.
cuePoint.setPosition((long) 0);
// Data Chunk ID: This value specifies the four byte ID used by the chunk containing the sample that corresponds to this cue point. A Wave file with no play list is always "data". A Wave file with a play list containing both sample data and silence may be either "data" or "slnt".
cuePoint.setDataChunkID((long) ChunkTypeID.DATA_VALUE);
// Chunk Start: The Chunk Start value specifies the byte offset into the Wave List Chunk of the chunk containing the sample that corresponds to this cue point. This is the same chunk described by the Data Chunk ID value. If no Wave List Chunk exists in the Wave file, this value is 0. If a Wave List Chunk exists, this is the offset into the "wavl" chunk. The first chunk in the Wave List Chunk would be specified with a value of 0.
cuePoint.setChunkStart((long) 0);
// Block Start: The Block Start value specifies the byte offset into the "data" or "slnt" Chunk to the start of the block containing the sample. The start of a block is defined as the first byte in uncompressed PCM wave data or the last byte in compressed wave data where decompression can begin to find the value of the corresponding sample value.
cuePoint.setBlockStart((long) 0);
// Sample Offset: The Sample Offset specifies an offset into the block (specified by Block Start) for the sample that corresponds to the cue point. In uncompressed PCM waveform data, this is simply the byte offset into the "data" chunk. In compressed waveform data, this value is equal to the number of samples (may or may not be bytes) from the Block Start to the sample that corresponds to the cue point.
cuePoint.setSampleOffset((long) 0);
// create chunk, and add it to the wave file
ChunkCue chunkCue = WavFactory.eINSTANCE.createChunkCue();
chunkCue.getCuePoints().add(cuePoint);
riffWave.getChunks().add(chunkCue);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment