From 5ddb417b803c76f2401789c7d95efcd6f1268354 Mon Sep 17 00:00:00 2001 From: Ronny Otto Date: Tue, 18 Jun 2019 23:51:20 +0200 Subject: [PATCH] [FreeAudio.mod] Backport NG adjustments --- .gitignore | 20 ++++++++++++++++- freeaudio.mod/freeaudio.bmx | 33 ++++++++++++++------------- freeaudio.mod/freeaudioglue.cpp | 10 ++++----- freeaudio.mod/freeaudioglue.h | 8 +++---- freeaudio.mod/mmdevice.cpp | 14 ++++++------ freeaudio.mod/pulseaudiodevice.cpp | 36 +++++++++++++++++++++++++----- 6 files changed, 83 insertions(+), 38 deletions(-) mode change 100644 => 100755 .gitignore diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 index ef5cc26..5acc5b0 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/freeaudio.mod/freeaudio.bmx b/freeaudio.mod/freeaudio.bmx index a268408..7323f29 100644 --- a/freeaudio.mod/freeaudio.bmx +++ b/freeaudio.mod/freeaudio.bmx @@ -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" @@ -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 ? @@ -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 ) @@ -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 diff --git a/freeaudio.mod/freeaudioglue.cpp b/freeaudio.mod/freeaudioglue.cpp index 22fd9d5..0cedcc4 100644 --- a/freeaudio.mod/freeaudioglue.cpp +++ b/freeaudio.mod/freeaudioglue.cpp @@ -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) @@ -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; @@ -133,10 +133,10 @@ 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; @@ -144,7 +144,7 @@ int BBCALL fa_WriteSound( int sound, void *data, int samples){ 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; diff --git a/freeaudio.mod/freeaudioglue.h b/freeaudio.mod/freeaudioglue.h index 94b80f3..cbaf79c 100644 --- a/freeaudio.mod/freeaudioglue.h +++ b/freeaudio.mod/freeaudioglue.h @@ -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 ); diff --git a/freeaudio.mod/mmdevice.cpp b/freeaudio.mod/mmdevice.cpp index 5e2efd9..5ae7807 100644 --- a/freeaudio.mod/mmdevice.cpp +++ b/freeaudio.mod/mmdevice.cpp @@ -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 { @@ -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)); @@ -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; @@ -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; @@ -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() { diff --git a/freeaudio.mod/pulseaudiodevice.cpp b/freeaudio.mod/pulseaudiodevice.cpp index 8193421..7b49d9a 100644 --- a/freeaudio.mod/pulseaudiodevice.cpp +++ b/freeaudio.mod/pulseaudiodevice.cpp @@ -8,6 +8,8 @@ #include #include #include +//to allow access to the AppTitle +#include extern "C" audiodevice *OpenPulseAudioDevice(); @@ -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; } } @@ -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); @@ -120,8 +145,9 @@ struct pulseaudiodevice:audiodevice{ audiodevice *OpenPulseAudioDevice(){ if (LoadPulse()) { - InitPulse(); - return new pulseaudiodevice(); + if (InitPulse()) { + return new pulseaudiodevice(); + } } return 0; }