2 * $Id: test_w_saw8.c,v 1.3 2006/06/10 21:30:55 dmazzoni Exp $
4 * Generate stereo 8 bit sawtooth waveforms.
6 * Author: Phil Burk, http://www.softsynth.com
8 * This program uses PABLIO, the Portable Audio Blocking I/O Library.
9 * PABLIO is built on top of PortAudio, the Portable Audio Library.
11 * For more information see: http://www.audiomulch.com/portaudio/
12 * Copyright (c) 1999-2000 Ross Bencina and Phil Burk
14 * Permission is hereby granted, free of charge, to any person obtaining
15 * a copy of this software and associated documentation files
16 * (the "Software"), to deal in the Software without restriction,
17 * including without limitation the rights to use, copy, modify, merge,
18 * publish, distribute, sublicense, and/or sell copies of the Software,
19 * and to permit persons to whom the Software is furnished to do so,
20 * subject to the following conditions:
22 * The above copyright notice and this permission notice shall be
23 * included in all copies or substantial portions of the Software.
25 * Any person wishing to distribute modifications to the Software is
26 * requested to send the modifications to the original developer so that
27 * they can be incorporated into the canonical version.
29 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
32 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
33 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
34 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
35 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
45 #define SAMPLE_RATE (22050)
46 #define NUM_SECONDS (6)
47 #define SAMPLES_PER_FRAME (2)
50 #define FRAMES_PER_BLOCK (100)
52 unsigned char samples[FRAMES_PER_BLOCK][SAMPLES_PER_FRAME];
53 unsigned char phases[SAMPLES_PER_FRAME];
55 /*******************************************************************/
61 PABLIO_Stream *aOutStream;
63 printf("Generate unsigned 8 bit sawtooth waves using PABLIO.\n");
66 /* Open simplified blocking I/O layer on top of PortAudio. */
67 err = OpenAudioStream( &aOutStream, SAMPLE_RATE, paUInt8,
68 (PABLIO_WRITE | PABLIO_STEREO) );
69 if( err != paNoError ) goto error;
71 /* Initialize oscillator phases to "ground" level for paUInt8. */
75 for( i=0; i<(NUM_SECONDS * SAMPLE_RATE); i += FRAMES_PER_BLOCK )
77 /* Generate sawtooth waveforms in a block for efficiency. */
78 for( j=0; j<FRAMES_PER_BLOCK; j++ )
80 /* Generate a sawtooth wave by incrementing a variable. */
82 /* We don't have to do anything special to wrap when using paUint8 because
83 * 8 bit arithmetic automatically wraps. */
84 samples[j][0] = phases[0];
86 /* On the second channel, generate a higher sawtooth wave. */
88 samples[j][1] = phases[1];
91 /* Write samples to output. */
92 WriteAudioStream( aOutStream, samples, FRAMES_PER_BLOCK );
95 CloseAudioStream( aOutStream );
97 printf("Sawtooth sound test complete.\n" );
102 fprintf( stderr, "An error occured while using PABLIO\n" );
103 fprintf( stderr, "Error number: %d\n", err );
104 fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );