audio MIDI Music Algorithms Interfaces Programming Acoustics Context
> Audio > Synthesis > Rendering with a triangle waveform    
 
   

Rendering with a triangle waveform     

This class shows how a simple score can be rendered as an audio file using a triangle waveform.

To hear the result download the MP3 file below.

WaveformExample3.mp3 [104K]

View / Download source

Lets have a closer look. 
import jm.music.data.*;
import jm.JMC;
import jm.audio.*;
import jm.util.*;
 
// this class introduces triangle wave 
 
public class WaveformExample3 implements JMC {
	
	public static void main(String[] args) {
		new WaveformExample3();
	}
	
	public WaveformExample3() {
 
		// 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 wave = new TriangleInst(44100);
 
		// for jMusic 1.1 or earlier put the instrument in an array
		// Instrument[] ensemble = {wave};
		
		// render audio file of the score
		Write.au(score, "WaveformExample3.au", wave);
		// for jMusic 1.1 or earlier substitute the line above with
		// Write.au(score, "WaveformExample.au", ensemble);
	}
}
 

 

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