audio MIDI Music Algorithms Interfaces Programming Acoustics Context
> Audio > Synthesis > Rendering a phrase    
 
   

Rendering a phrase      

This class shows a multi-note phrase can be rendered as an audio file.

To hear the result download the MP3 file below.

WaveformExample2.mp3 [100K]

View / Download source

Lets have a closer look. 
import jm.music.data.*;
import jm.JMC;
import jm.audio.*;
import jm.util.*;
 
public class WaveformExample2 implements JMC {
	
	public static void main(String[] args) {
		new WaveformExample2();
	}
	
	public WaveformExample2() {	
// make a jmusic score Phrase melody = new Phrase(); for(int i = 0; i < 24; i++) { Note n = new Note((int)(Math.random() * 12) * 2 + 60, QUAVER); melody.addNote(n); } Score score = new Score(new Part(melody)); // set up audio instrument Instrument sineWave = new SimpleSineInst(44100); // for jMusic 1.1 or earlier put the instrument in an array // Instrument[] ensemble = {sineWave}; // render audio file of the score Write.au(score, "WaveformExample2.au", sineWave); // for jMusic 1.1 or earlier substitute the line above with // Write.au(score, "WaveformExample.au", ensemble); } }

The code for rendering a score as audio is identical regardless of the number of notes.
This class creates a melodic phrase of 24 notes which is rendered with a sine wave instrument.

In jMusic, each note is rendered in turn to a temporary file on the hard drive as floating point data.
The obvious effect of this is that the time taken to render depends on the number and length of notes in the score.
As well the higher the sample rate the more claulations for each note are required.
Therefore it can be convenient to render draft versions of your composition at a low sample rate to save time then,
when happy with the piece, increase the sample rate and render a final version.

After rendering each note as floating point data jMusic then converts the temporary file to an .au formated file.
This conversion involves normalising the values to maximise the dynamic range and changing the floating point values
to interger eqivalents required by the .au file format. (Mostcommon audio formats, including wav, aiff and mp3 are integer data formats).

 

 

jMusic Australia Council Queensland University of Technology Sitemap Contact Home Home http://www.qut.com http://explodingart.com/jmusic http://www.ozco.gov.au

Digital Instrument making Home