Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion .gitignore
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,23 @@
*.x86.a
*.x86.i
*.bak

*.x64.a
*.x64.i
*.arm.a
*.arm.i
*.armeabi.a
*.armeabi.i
*.armeabiv7a.a
*.armeabiv7a.i
*.arm64v8a.a
*.arm64v8a.i
*.js.a
*.js.i
*.armv7.a
*.armv7.i
*.arm64.a
*.arm64.i
.bmx/
*.i2
*.exe
commands.html
33 changes: 17 additions & 16 deletions freeaudio.mod/freeaudio.bmx
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ Import "freeaudioglue.cpp"
Import "dsounddevice.cpp"
Import "mmdevice.cpp"
Extern "C"
Function OpenMultiMediaDevice()
Function OpenDirectSoundDevice()
Function OpenMultiMediaDevice:Byte Ptr()
Function OpenDirectSoundDevice:Byte Ptr()
End Extern
?MacOS
Import "-framework AudioUnit"
Import "-framework AudioToolbox"
Import "coreaudiodevice.cpp"
Extern
Function OpenCoreAudioDevice()
Function OpenCoreAudioDevice:Byte Ptr()
End Extern
?Linux
Import "-ldl"
Expand All @@ -74,8 +74,8 @@ Import "pulseaudiodevice.cpp"
'Import "ossdevice.cpp"
Extern "C"
'Function OpenOSSDevice()
Function OpenALSADevice()
Function OpenPulseAudioDevice()
Function OpenALSADevice:Byte Ptr()
Function OpenPulseAudioDevice:Byte Ptr()
End Extern
?

Expand All @@ -88,14 +88,14 @@ Const FA_CHANNELSTATUS_LOOPING=4
Const FA_CHANNELSTATUS_STREAMING=8
Const FA_CHANNELSTATUS_PAUSED=16

Function fa_Reset( audiodevice )
Function fa_Reset( audiodevice:Byte Ptr )
Function fa_Close()
Function fa_CreateSound( length,bits,channels,hertz,samples:Byte Ptr=Null,looping=False )
Function fa_WriteSound( sound,samples:Byte Ptr,length ) 'length really neceesary?
Function fa_FreeSound( sound )
Function fa_CreateSound:Byte Ptr( length,bits,channels,hertz,samples:Byte Ptr=Null,looping=False )
Function fa_WriteSound( sound:Byte Ptr,samples:Byte Ptr,length ) 'length really neceesary?
Function fa_FreeSound( sound:Byte Ptr )
Function fa_AllocChannel()
Function fa_FreeChannel( channel )
Function fa_PlaySound( sound,paused_flag,channel )
Function fa_PlaySound( sound:Byte Ptr,paused_flag,channel )

Function fa_StopChannel( channel )
Function fa_ChannelStatus( channel )
Expand All @@ -110,13 +110,14 @@ Function fa_SetChannelDepth( channel,depth# )
End Extern

Function fa_Init( deviceid )
Local device
Local device:Byte Ptr
?Win32
If deviceid
device=OpenDirectSoundDevice()
Else
device=OpenMultiMediaDevice()
EndIf
Select deviceid
Case 0
device=OpenMultiMediaDevice()
Case 1
device=OpenDirectSoundDevice()
EndSelect
?Linux
Select deviceid
Case 0
Expand Down
10 changes: 5 additions & 5 deletions freeaudio.mod/freeaudioglue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ int BBCALL fa_Close(){
return 0;
}

int BBCALL fa_PlaySound( int sound,int paused,int ch ){
int BBCALL fa_PlaySound( sample* sound,int paused,int ch ){
output *out;
bool recycle;
if (audio && sound)
Expand Down Expand Up @@ -121,7 +121,7 @@ int BBCALL fa_SetChannelDepth( int channel,float depth ){
return 0;
}

int BBCALL fa_CreateSound( int length,int bits,int channels,int freq,const char *samples,int loop ){
sample* BBCALL fa_CreateSound( int length,int bits,int channels,int freq,const char *samples,int loop ){
sample *sam;

if (io==0) return 0;
Expand All @@ -133,18 +133,18 @@ int BBCALL fa_CreateSound( int length,int bits,int channels,int freq,const char
if( samples ) sam->write((void*)samples,length,0);
}
sam->setloop(loop);
return (int)sam;
return sam;
}

int BBCALL fa_WriteSound( int sound, void *data, int samples){
int BBCALL fa_WriteSound( sample* sound, void *data, int samples){
sample *sam;

if (io==0) return 0;
sam=(sample*)sound;
return sam->write(data,samples,0);
}

int BBCALL fa_FreeSound( int sound ){
int BBCALL fa_FreeSound( sample* sound ){
sample *sam;
if (io==0) return 0;
sam=(sample*)sound;
Expand Down
8 changes: 4 additions & 4 deletions freeaudio.mod/freeaudioglue.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ extern "C" {
int fa_Reset(struct audiodevice *device);
int fa_Close();

int fa_CreateSound(int samples,int bits,int channels,int freq,const char *buf,int loop);
int fa_WriteSound( int sound, void *data, int samples);
int fa_FreeSound( int sound );
int fa_PlaySound( int sound,int paused,int channel );
sample* fa_CreateSound(int samples,int bits,int channels,int freq,const char *buf,int loop);
int fa_WriteSound( sample* sound, void *data, int samples);
int fa_FreeSound( sample* sound );
int fa_PlaySound( sample* sound,int paused,int channel );

int fa_AllocChannel();
void fa_FreeChannel( int channel );
Expand Down
14 changes: 7 additions & 7 deletions freeaudio.mod/mmdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

extern "C" audiodevice *OpenMultiMediaDevice();

static void __stdcall audioTimerProc( UINT id,UINT msg,DWORD user,DWORD u1,DWORD u2 );
static void __stdcall audioTimerProc( UINT id,UINT msg,DWORD_PTR user,DWORD_PTR u1,DWORD_PTR u2 );

struct pcmsetting
{
Expand Down Expand Up @@ -43,7 +43,7 @@ struct abuffer {
id=n;
hdr->lpData=(LPSTR)data;
hdr->dwBufferLength=size;
hdr->dwUser=(int)this;
hdr->dwUser=(DWORD_PTR)this;
hdr->dwFlags=WHDR_BEGINLOOP|WHDR_ENDLOOP;
hdr->dwLoops=0x7fffffff;
waveOutPrepareHeader(device,hdr,sizeof(WAVEHDR));
Expand Down Expand Up @@ -94,7 +94,7 @@ struct winmmdevice:audiodevice {

int reset()
{
int sz=(iswin98())?2048:1024; //10ms fragment size 20ms for windows98
int sz=2048; // 20ms fragment size
mix=new mixer(sz);
device=0;
buffersize=0;
Expand Down Expand Up @@ -126,13 +126,13 @@ struct winmmdevice:audiodevice {
{
pcmsetting pcm(freq,channels,bits);
if (bits==8) {mode=0;samplesize=1;} else {mode=1;samplesize=2;}
if (waveOutOpen(&device,WAVE_MAPPER,&pcm.wf,0,(long)this,0)) return 1;
if (waveOutOpen(&device,WAVE_MAPPER,&pcm.wf,0,(DWORD_PTR)this,0)) return 1;
buffersize=size;
bnum=0;
mix->freq=freq;
mix->channels=channels;
buffer.init(device,size*samplesize*32,0);
timeSetEvent(5,5,audioTimerProc,(DWORD)this,TIME_ONESHOT);//PERIODIC );
timeSetEvent(5,5,audioTimerProc,(DWORD_PTR)this,TIME_ONESHOT);//PERIODIC );
timeout=0;
playing=1;
lagbuffers=6;
Expand Down Expand Up @@ -195,9 +195,9 @@ struct winmmdevice:audiodevice {
}
};

static void __stdcall audioTimerProc( UINT id,UINT msg,DWORD user,DWORD u1,DWORD u2 ) {
static void __stdcall audioTimerProc( UINT id,UINT msg,DWORD_PTR user,DWORD_PTR u1,DWORD_PTR u2 ) {
((winmmdevice *)user)->flip();
timeSetEvent(5,5,audioTimerProc,(DWORD)user,TIME_ONESHOT);
timeSetEvent(5,5,audioTimerProc,(DWORD_PTR)user,TIME_ONESHOT);
}

audiodevice *OpenMultiMediaDevice() {
Expand Down
36 changes: 31 additions & 5 deletions freeaudio.mod/pulseaudiodevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <unistd.h>
#include <pulse/simple.h>
#include <pthread.h>
//to allow access to the AppTitle
#include <brl.mod/blitz.mod/blitz.h>

extern "C" audiodevice *OpenPulseAudioDevice();

Expand All @@ -26,13 +28,34 @@ int LoadPulse(){
return _pulse!=0;
}

void InitPulse(){
int InitPulse(){

if( !_pulse ) return;
if( !_pulse ) return 0;

pulse_pa_simple_new = (pa_simple* (*)(const char *, const char *, pa_stream_direction_t , const char *, const char *, const pa_sample_spec *, const pa_channel_map *, const pa_buffer_attr *, int *))dlsym(_pulse, "pa_simple_new");
pulse_pa_simple_free = (void (*)(pa_simple *))dlsym(_pulse, "pa_simple_free");
pulse_pa_simple_write = (int (*)(pa_simple *, const void *, size_t , int *))dlsym(_pulse, "pa_simple_write");

// try an open a connection to pulse - if it fails, we can presume pulse is not working?

pa_sample_spec spec;
spec.format=PA_SAMPLE_S16LE;
spec.rate=44100;
spec.channels=2;
int error = 0;

char *p=bbStringToUTF8String( bbAppTitle );
pa_simple * simple = pulse_pa_simple_new(NULL,p,PA_STREAM_PLAYBACK,NULL,"playback",&spec,NULL,NULL,&error);
bbMemFree(p);

if (simple) {
pulse_pa_simple_free(simple);

if (!error) {
return 1;
}
}
return 0;
}

}
Expand Down Expand Up @@ -72,7 +95,9 @@ struct pulseaudiodevice:audiodevice{
stereo16.rate=44100;
stereo16.channels=2;

simple=pulse_pa_simple_new(NULL,"freeaudio",PA_STREAM_PLAYBACK,NULL,"playback",&stereo16,NULL,NULL,&error);
char *p=bbStringToUTF8String( bbAppTitle );
simple=pulse_pa_simple_new(NULL,p,PA_STREAM_PLAYBACK,NULL,"playback",&stereo16,NULL,NULL,&error);
bbMemFree(p);
if (simple==NULL) return -1;

mix=new mixer(LINUXFRAG);
Expand Down Expand Up @@ -120,8 +145,9 @@ struct pulseaudiodevice:audiodevice{

audiodevice *OpenPulseAudioDevice(){
if (LoadPulse()) {
InitPulse();
return new pulseaudiodevice();
if (InitPulse()) {
return new pulseaudiodevice();
}
}
return 0;
}
Expand Down