/* (c) 2003 Martin Voelkle & Stephane Magnenat */ #include #include #include #include #include int files; int* gains; OggVorbis_File *vfs; int run; #define CLAMP(a, b, c) { if ((a)<(b)) (a)=(b); else if ((a)>(c)) (a)=(c); } void mixaudio(void *unused, Uint8 *stream, int len) { static int current_section; char current[len]; Sint32 final[len]; for (int j=0; j<(len>>1); j++) { final[j]=0; } for (int i=0; i0) { long ret = ov_read (&(((OggVorbis_File *)vfs)[i]), p, rest, 0, 2, 1, ¤t_section); if (ret == 0) { /* EOF */ run = 0; } else if (ret < 0) { /* error in the stream. Not a problem, just reporting it in case we (the app) cares. In this case, we don't. */ } rest -= ret; p += ret; } // sum sample for (int j=0; j<(len>>1); j++) { final[j] += ((Sint32)((Sint16 *)current)[j]) * gains[i]; } } for (int j=0; j<(len>>1); j++) { ((Sint16*)stream)[j] = (Sint16)(final[j] / (files<<8)); } } void redisplay(SDL_Surface *s) { for (int i=0; iformat, 255, 20, 20)); SDL_Rect black = {i*30, 0, 30, 255-gains[i]}; SDL_FillRect(s, &black, SDL_MapRGB(s->format, 50, 50, 50)); } SDL_Flip(s); } int main(int argc, char **argv) { SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO); files = argc - 1; vfs = (OggVorbis_File *)malloc(files * sizeof(OggVorbis_File)); gains = (int*)malloc(files * sizeof(int)); for (int i=0; i