#include <dirent.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include "bass.h"
#include "bassenc.h"
#include "bassmix.h"
HSTREAM chan1,chan2,mix,chan;
HENCODE enc1,enc2;
char file[200];
int flip=0,a=0,i=0,ende;
char buf[20000];
int main() {
DIR *hdir;
struct dirent *entry[500];
hdir=opendir("/path/to/mp3");
while(entry[i]=readdir(hdir)) i++;
//closedir(hdir);
ende=i;
srand(time(0));
BASS_Init(0,44100,0,0,0);
mix=BASS_Mixer_StreamCreate(44100,2,BASS_MIXER_NONSTOP|BASS_STREAM_DECODE);
while(1) {
i=rand()%ende;
sprintf(file,"/path/to/mp3/%s",entry[i]->d_name);
if (flip==0) {
chan1=BASS_StreamCreateFile(0,file,0,0,BASS_STREAM_DECODE);
BASS_Mixer_StreamAddChannel(mix,chan1,BASS_STREAM_AUTOFREE);
flip=1;
chan=chan1;
}
else {
chan2=BASS_StreamCreateFile(0,file,0,0,BASS_STREAM_DECODE);
BASS_Mixer_StreamAddChannel(mix,chan2,BASS_STREAM_AUTOFREE);
flip=0;
chan=chan2;
}
if (a==0) {
a=1;
enc1=BASS_Encode_Start(mix,"lame -b 128 - -",BASS_ENCODE_AUTOFREE,0,0);
enc2=BASS_Encode_Start(mix,"aacplusenc - - 32",BASS_ENCODE_AUTOFREE,0,0);
BASS_Encode_CastInit(enc1,"localhost:8000","sax",BASS_ENCODE_TYPE_MP3,"Traumwelt Radio","http://www.djtraumwelt.de","Elektro / Minimal",0,0,128,1);
BASS_Encode_CastInit(enc2,"localhost:8010","copy",BASS_ENCODE_TYPE_AAC,"Traumwelt Radio","http://www.djtraumwelt.de","Elektro / Minimal",0,0,32,1);
}
BASS_Encode_CastSetTitle(enc1,entry[i]->d_name,"http://www.djtraumwelt.de");
BASS_Encode_CastSetTitle(enc2,entry[i]->d_name,"http://www.djtraumwelt.de");
while (BASS_ChannelIsActive(chan) && BASS_Encode_IsActive(enc1) && BASS_Encode_IsActive(enc2)) {
BASS_ChannelGetData(mix, buf, sizeof(buf)); // process some data
}
BASS_Mixer_ChannelRemove(chan1);
BASS_Mixer_ChannelRemove(chan2);
BASS_StreamFree(chan1);
BASS_StreamFree(chan2);
if (!BASS_Encode_IsActive(enc1) || !BASS_Encode_IsActive(enc2)) {
BASS_Encode_Stop(enc1);
BASS_Encode_Stop(enc2);
BASS_StreamFree(enc1);
BASS_StreamFree(enc2);
a=0;
sleep(1);
}
}
return 0;
}
this is my autodj and always when the next track is playing, more memory it uses. more and more and more. anyone here, who knows the reason?