Oops! I missed to attach a program to reproduce. Sorry.
--
Morita Sho <[EMAIL PROTECTED]>
/*
* This program reproduces libao bug.
*
* Plays 500 hz sine wave about 0.4 seconds (PERIOD_SIZE * 2), and 800 hz sine wave about 0.4 seconds (PERIOD_SIZE * 2 + 1).
* The final period only contains 1 frame. Thus remaining 3708 frames are uninitialized.
*
* When AO_DRIVER is "oss", sound is correctly played as expected.
* But in "alsa", additional "500 hz sine wave about 0.1 seconds" will be played at end of playback.
*
* Note: This program assumes that period size is 3709.
*
* To compile:
* $ gcc -Wall -lao -ldl -lm -o reproduce_libao_bug reproduce_libao_bug.c
*
*/
#include <stdio.h>
#include <ao/ao.h>
#include <math.h>
/* Change this to oss to play the correct result */
#define AO_DRIVER "alsa"
//#define AO_DRIVER "oss"
#define PERIOD_SIZE 3709
static ao_sample_format format;
static ao_device *device;
void fill1( void )
{
int freq = 500;
size_t buf_size = PERIOD_SIZE * 2;
char * buffer = malloc(buf_size);
int i;
for (i = 0; i < buf_size; i++) {
char sample = (int)(0.55 * 128.0 *
sin(2 * M_PI * freq * ((float) i/format.rate)));
buffer[i] = sample;
}
ao_play(device, buffer, buf_size);
free(buffer);
}
void fill2( void )
{
int freq = 800;
size_t buf_size = PERIOD_SIZE * 2 + 1;
char * buffer = malloc(buf_size);
int i;
for (i = 0; i < buf_size; i++) {
char sample = (int)(0.55 * 128.0 *
sin(2 * M_PI * freq * ((float) i/format.rate)));
buffer[i] = sample;
}
ao_play(device, buffer, buf_size);
free(buffer);
}
int main(void)
{
ao_initialize();
printf("reproduce_libao_bug: Using " AO_DRIVER " driver.\n");
int driver_id = ao_driver_id(AO_DRIVER);
if ( driver_id == -1 ) {
fprintf(stderr, "%s driver not found.\n", AO_DRIVER);
return 0;
}
format.bits = 8;
format.channels = 1;
format.rate = 22254;
format.byte_format = AO_FMT_LITTLE;
device = ao_open_live(driver_id, &format, NULL);
if (device == NULL) {
fprintf(stderr, "Error opening device.\n");
return 1;
}
fill1();
fill2();
ao_close(device);
ao_shutdown();
return 0;
}